diff --git a/.clang-format b/.clang-format index 3ddd8b43f6..e58d518b3b 100644 --- a/.clang-format +++ b/.clang-format @@ -5,6 +5,7 @@ AccessModifierOffset: -1 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: true +AlignConsecutiveMacros: true AlignEscapedNewlinesLeft: true AlignOperands: true AlignTrailingComments: true diff --git a/example/src/tmq.c b/example/src/tmq.c index 8757104ad9..efb4d1830e 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -28,7 +28,7 @@ int32_t init_env() { return -1; } - TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); + TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); if (taos_errno(pRes) != 0) { printf("error in create db, reason:%s\n", taos_errstr(pRes)); return -1; @@ -42,25 +42,33 @@ int32_t init_env() { } taos_free_result(pRes); - pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, k int) tags(a int)"); + pRes = + taos_query(pConn, "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags(t1 int)"); if (taos_errno(pRes) != 0) { printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); return -1; } taos_free_result(pRes); - pRes = taos_query(pConn, "create table if not exists tu1 using st1 tags(1)"); + pRes = taos_query(pConn, "create table if not exists ct0 using st1 tags(1000)"); if (taos_errno(pRes) != 0) { printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes)); return -1; } taos_free_result(pRes); - pRes = taos_query(pConn, "create table if not exists tu2 using st1 tags(2)"); + pRes = taos_query(pConn, "create table if not exists ct1 using st1 tags(2000)"); if (taos_errno(pRes) != 0) { printf("failed to create child table tu2, reason:%s\n", taos_errstr(pRes)); return -1; } + + pRes = taos_query(pConn, "create table if not exists ct3 using st1 tags(3000)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table tu3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); return 0; } @@ -82,12 +90,40 @@ int32_t create_topic() { /*const char* sql = "select * from tu1";*/ /*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));*/ - pRes = taos_query(pConn, "create topic test_stb_topic_1 as select * from tu1"); + pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1 from ct1"); if (taos_errno(pRes) != 0) { - printf("failed to create topic test_stb_topic_1, reason:%s\n", taos_errstr(pRes)); + printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes)); return -1; } taos_free_result(pRes); + +#if 0 + pRes = taos_query(pConn, "insert into tu1 values(now, 1, 1.0, 'bi1')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + pRes = taos_query(pConn, "insert into tu1 values(now+1d, 1, 1.0, 'bi1')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + pRes = taos_query(pConn, "insert into tu2 values(now, 2, 2.0, 'bi2')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + pRes = taos_query(pConn, "insert into tu2 values(now+1d, 2, 2.0, 'bi2')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); +#endif + taos_close(pConn); return 0; } @@ -115,7 +151,7 @@ tmq_t* build_consumer() { tmq_list_t* build_topic_list() { tmq_list_t* topic_list = tmq_list_new(); - tmq_list_append(topic_list, "test_stb_topic_1"); + tmq_list_append(topic_list, "topic_ctb_column"); return topic_list; } @@ -215,8 +251,8 @@ int main(int argc, char* argv[]) { if (argc > 1) { printf("env init\n"); code = init_env(); + create_topic(); } - create_topic(); tmq_t* tmq = build_consumer(); tmq_list_t* topic_list = build_topic_list(); /*perf_loop(tmq, topic_list);*/ diff --git a/example/src/tstream.c b/example/src/tstream.c index 40d8ff9b0b..8ffa932bd2 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -20,7 +20,7 @@ #include "taos.h" int32_t init_env() { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 7010); + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); if (pConn == NULL) { return -1; } @@ -65,7 +65,7 @@ int32_t init_env() { int32_t create_stream() { printf("create stream\n"); TAOS_RES* pRes; - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 7010); + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); if (pConn == NULL) { return -1; } diff --git a/include/client/taos.h b/include/client/taos.h index 111cd8ad3b..0fd2fd8df9 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -54,6 +54,7 @@ typedef void TAOS_SUB; #define TSDB_DATA_TYPE_BLOB 18 // binary #define TSDB_DATA_TYPE_MEDIUMBLOB 19 #define TSDB_DATA_TYPE_BINARY TSDB_DATA_TYPE_VARCHAR // string +#define TSDB_DATA_TYPE_MAX 20 typedef enum { TSDB_OPTION_LOCALE, @@ -188,7 +189,7 @@ DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col); DLL_EXPORT bool taos_is_update_query(TAOS_RES *res); DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql); -DLL_EXPORT void taos_reset_current_db(TAOS *taos); +DLL_EXPORT void taos_reset_current_db(TAOS *taos); DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res); DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res); diff --git a/include/common/taosdef.h b/include/common/taosdef.h index 797ebf29c5..5001a99c2a 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -76,6 +76,13 @@ typedef enum { TSDB_SMA_TYPE_ROLLUP = 2, // Rollup SMA } ETsdbSmaType; +typedef enum { + TSDB_BSMA_TYPE_NONE = 0, // no block-wise SMA + TSDB_BSMA_TYPE_I = 1, // sum/min/max(default) +} ETsdbBSmaType; + +#define TSDB_BSMA_TYPE_LATEST TSDB_BSMA_TYPE_I + extern char *qtypeStr[]; #define TSDB_PORT_HTTP 11 diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 51eabb7d61..45f608b24e 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -37,6 +37,14 @@ enum { TMQ_MSG_TYPE__EP_RSP, }; +enum { + STREAM_TRIGGER__AT_ONCE = 1, + STREAM_TRIGGER__WINDOW_CLOSE, + STREAM_TRIGGER__BY_COUNT, + STREAM_TRIGGER__BY_BATCH_COUNT, + STREAM_TRIGGER__BY_EVENT_TIME, +}; + typedef struct { uint32_t numOfTables; SArray* pGroupList; @@ -54,13 +62,16 @@ typedef struct SColumnDataAgg { } SColumnDataAgg; typedef struct SDataBlockInfo { - STimeWindow window; - int32_t rows; - int32_t rowSize; - int16_t numOfCols; - int16_t hasVarCol; - union {int64_t uid; int64_t blockId;}; - int64_t groupId; // no need to serialize + STimeWindow window; + int32_t rows; + int32_t rowSize; + int16_t numOfCols; + int16_t hasVarCol; + union { + int64_t uid; + int64_t blockId; + }; + int64_t groupId; // no need to serialize } SDataBlockInfo; typedef struct SSDataBlock { @@ -93,7 +104,7 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock); int32_t tEncodeDataBlocks(void** buf, const SArray* blocks); void* tDecodeDataBlocks(const void* buf, SArray** blocks); -void colDataDestroy(SColumnInfoData* pColData) ; +void colDataDestroy(SColumnInfoData* pColData); static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { // WARNING: do not use info.numOfCols, @@ -182,24 +193,23 @@ typedef struct SColumn { uint8_t scale; } SColumn; -typedef struct SLimit { - int64_t limit; - int64_t offset; -} SLimit; - -typedef struct SOrder { - uint32_t order; - SColumn col; -} SOrder; - -typedef struct SGroupbyExpr { - SArray* columnInfo; // SArray, group by columns information - bool groupbyTag; // group by tag or column -} SGroupbyExpr; +typedef struct STableBlockDistInfo { + uint16_t rowSize; + uint16_t numOfFiles; + uint32_t numOfTables; + uint64_t totalSize; + uint64_t totalRows; + int32_t maxRows; + int32_t minRows; + int32_t firstSeekTimeUs; + uint32_t numOfRowsInMemTable; + uint32_t numOfSmallBlocks; + SArray *dataBlockInfos; +} STableBlockDistInfo; enum { - FUNC_PARAM_TYPE_VALUE = 0, - FUNC_PARAM_TYPE_COLUMN, + FUNC_PARAM_TYPE_VALUE = 0x1, + FUNC_PARAM_TYPE_COLUMN= 0x2, }; typedef struct SFunctParam { @@ -230,16 +240,7 @@ typedef struct SExprInfo { struct tExprNode* pExpr; } SExprInfo; -typedef struct SStateWindow { - SColumn col; -} SStateWindow; - -typedef struct SSessionWindow { - int64_t gap; // gap between two session window(in microseconds) - SColumn col; -} SSessionWindow; - -#define QUERY_ASC_FORWARD_STEP 1 +#define QUERY_ASC_FORWARD_STEP 1 #define QUERY_DESC_FORWARD_STEP -1 #define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 3afdcfba8e..d6d82875e0 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -113,6 +113,20 @@ static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uin pColumnInfoData->hasNull = true; } +static FORCE_INLINE void colDataAppendNNULL(SColumnInfoData* pColumnInfoData, uint32_t start, size_t nRows) { + if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { + for(int32_t i = start; i < start + nRows; ++i) { + pColumnInfoData->varmeta.offset[i] = -1; // it is a null value of VAR type. + } + } else { + for(int32_t i = start; i < start + nRows; ++i) { + colDataSetNull_f(pColumnInfoData->nullbitmap, i); + } + } + + pColumnInfoData->hasNull = true; +} + static FORCE_INLINE void colDataAppendInt8(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int8_t* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL); @@ -179,12 +193,14 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock); int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo); int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst); -int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows); +int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); void blockDataCleanup(SSDataBlock* pDataBlock); size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize); void* blockDataDestroy(SSDataBlock* pBlock); +int32_t blockDataTrimFirstNRows(SSDataBlock *pBlock, size_t n); + SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock); void blockDebugShowData(const SArray* dataBlocks); diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 4a3ce2db86..da724206d9 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -70,11 +70,13 @@ typedef struct { #pragma pack(pop) #define colType(col) ((col)->type) +#define colSma(col) ((col)->sma) #define colColId(col) ((col)->colId) #define colBytes(col) ((col)->bytes) #define colOffset(col) ((col)->offset) #define colSetType(col, t) (colType(col) = (t)) +#define colSetSma(col, s) (colSma(col) = (s)) #define colSetColId(col, id) (colColId(col) = (id)) #define colSetBytes(col, b) (colBytes(col) = (b)) #define colSetOffset(col, o) (colOffset(col) = (o)) @@ -139,7 +141,7 @@ typedef struct { int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); -int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col_bytes_t bytes); +int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t sma, col_id_t colId, col_bytes_t bytes); STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); // ----------------- Semantic timestamp key definition diff --git a/include/common/tmsg.h b/include/common/tmsg.h index cd16bbf862..6ec7d8c75b 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -265,6 +265,20 @@ typedef struct SSchema { char name[TSDB_COL_NAME_LEN]; } SSchema; +typedef struct { + int8_t type; + int8_t sma; // ETsdbBSmaType and default is TSDB_BSMA_TYPE_I + col_id_t colId; + int32_t bytes; + char name[TSDB_COL_NAME_LEN]; +} SSchemaEx; + +#define SSCHMEA_TYPE(s) ((s)->type) +#define SSCHMEA_SMA(s) ((s)->sma) +#define SSCHMEA_COLID(s) ((s)->colId) +#define SSCHMEA_BYTES(s) ((s)->bytes) +#define SSCHMEA_NAME(s) ((s)->name) + typedef struct { char name[TSDB_TABLE_FNAME_LEN]; int8_t igExists; @@ -524,6 +538,7 @@ typedef struct { int8_t walLevel; int8_t quorum; int8_t cacheLastRow; + int8_t replications; } SAlterDbReq; int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq); @@ -1380,11 +1395,10 @@ typedef struct { } SDDropTopicReq; typedef struct { - float xFilesFactor; - int8_t delayUnit; - int8_t nFuncIds; - int32_t* pFuncIds; - int64_t delay; + float xFilesFactor; + int32_t delay; + int8_t nFuncIds; + func_id_t* pFuncIds; } SRSmaParam; typedef struct SVCreateTbReq { @@ -1402,13 +1416,12 @@ typedef struct SVCreateTbReq { }; union { struct { - tb_uid_t suid; - uint32_t nCols; - SSchema* pSchema; - uint32_t nTagCols; - SSchema* pTagSchema; - col_id_t nBSmaCols; - col_id_t* pBSmaCols; + tb_uid_t suid; + col_id_t nCols; + col_id_t nBSmaCols; + SSchemaEx* pSchema; + col_id_t nTagCols; + SSchema* pTagSchema; SRSmaParam* pRSmaParam; } stbCfg; struct { @@ -1416,10 +1429,9 @@ typedef struct SVCreateTbReq { SKVRow pTag; } ctbCfg; struct { - uint32_t nCols; - SSchema* pSchema; - col_id_t nBSmaCols; - col_id_t* pBSmaCols; + col_id_t nCols; + col_id_t nBSmaCols; + SSchemaEx* pSchema; SRSmaParam* pRSmaParam; } ntbCfg; }; @@ -1898,7 +1910,10 @@ int32_t tDecodeSMqCMCommitOffsetReq(SCoder* decoder, SMqCMCommitOffsetReq* pReq) typedef struct { uint32_t nCols; - SSchema* pSchema; + union { + SSchema* pSchema; + SSchemaEx* pSchemaEx; + }; } SSchemaWrapper; static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) { diff --git a/include/common/tmsgcb.h b/include/common/tmsgcb.h index cb59599d9a..6c3671a8d6 100644 --- a/include/common/tmsgcb.h +++ b/include/common/tmsgcb.h @@ -50,7 +50,6 @@ typedef struct { PutToQueueFp queueFps[QUEUE_MAX]; GetQueueSizeFp qsizeFp; SendReqFp sendReqFp; - SendMnodeReqFp sendMnodeReqFp; SendRspFp sendRspFp; RegisterBrokenLinkArgFp registerBrokenLinkArgFp; ReleaseHandleFp releaseHandleFp; @@ -60,7 +59,6 @@ void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb); int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq); int32_t tmsgGetQueueSize(const SMsgCb* pMsgCb, int32_t vgId, EQueueType qtype); int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq); -int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq); void tmsgSendRsp(const SRpcMsg* pRsp); void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg); void tmsgReleaseHandle(void* handle, int8_t type); diff --git a/include/common/trow.h b/include/common/trow.h index abbe55c3a3..01f4076382 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -47,21 +47,21 @@ extern "C" { #define TD_VTYPE_NONE 0x0U // none or unknown/undefined #define TD_VTYPE_NULL 0x01U // null val #define TD_VTYPE_NORM 0x02U // normal val: not none, not null -#define TD_VTYPE_MAX 0x03U // +#define TD_VTYPE_MAX 0x03U // #define TD_VTYPE_NONE_BYTE 0x0U #define TD_VTYPE_NULL_BYTE 0x55U #define TD_VTYPE_NORM_BYTE 0xAAU -#define TD_ROWS_ALL_NORM 0x01U +#define TD_ROWS_ALL_NORM 0x01U #define TD_ROWS_NULL_NORM 0x0U -#define TD_COL_ROWS_NORM(c) ((c)->bitmap == TD_ROWS_ALL_NORM) // all rows of SDataCol/SBlockCol is NORM +#define TD_COL_ROWS_NORM(c) ((c)->bitmap == TD_ROWS_ALL_NORM) // all rows of SDataCol/SBlockCol is NORM #define TD_SET_COL_ROWS_BTIMAP(c, v) ((c)->bitmap = (v)) -#define TD_SET_COL_ROWS_NORM(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_ALL_NORM) -#define TD_SET_COL_ROWS_MISC(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_NULL_NORM) +#define TD_SET_COL_ROWS_NORM(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_ALL_NORM) +#define TD_SET_COL_ROWS_MISC(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_NULL_NORM) -#define KvConvertRatio (0.9f) +#define KvConvertRatio (0.9f) #define isSelectKVRow(klen, tlen) ((klen) < ((tlen)*KvConvertRatio)) #ifdef TD_SUPPORT_BITMAP @@ -98,7 +98,7 @@ typedef void *SRow; typedef struct { TDRowValT valType; - void * val; + void *val; } SCellVal; typedef struct { @@ -158,43 +158,43 @@ typedef struct { int16_t nBitmaps; int16_t nBoundBitmaps; int32_t offset; - void * pBitmap; - void * pOffset; + void *pBitmap; + void *pOffset; int32_t extendedRowSize; } SRowBuilder; -#define TD_ROW_HEAD_LEN (sizeof(STSRow)) +#define TD_ROW_HEAD_LEN (sizeof(STSRow)) #define TD_ROW_NCOLS_LEN (sizeof(col_id_t)) -#define TD_ROW_INFO(r) ((r)->info) -#define TD_ROW_TYPE(r) ((r)->type) -#define TD_ROW_DELETE(r) ((r)->del) -#define TD_ROW_ENDIAN(r) ((r)->endian) -#define TD_ROW_SVER(r) ((r)->sver) -#define TD_ROW_NCOLS(r) ((r)->data) // only valid for SKvRow -#define TD_ROW_DATA(r) ((r)->data) -#define TD_ROW_LEN(r) ((r)->len) -#define TD_ROW_KEY(r) ((r)->ts) +#define TD_ROW_INFO(r) ((r)->info) +#define TD_ROW_TYPE(r) ((r)->type) +#define TD_ROW_DELETE(r) ((r)->del) +#define TD_ROW_ENDIAN(r) ((r)->endian) +#define TD_ROW_SVER(r) ((r)->sver) +#define TD_ROW_NCOLS(r) ((r)->data) // only valid for SKvRow +#define TD_ROW_DATA(r) ((r)->data) +#define TD_ROW_LEN(r) ((r)->len) +#define TD_ROW_KEY(r) ((r)->ts) #define TD_ROW_KEY_ADDR(r) (r) // N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and // (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined. #define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN) -#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i)) -#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t)) -#define TD_ROW_SET_DELETE(r) (TD_ROW_DELETE(r) = 1) -#define TD_ROW_SET_SVER(r, v) (TD_ROW_SVER(r) = (v)) -#define TD_ROW_SET_LEN(r, l) (TD_ROW_LEN(r) = (l)) +#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i)) +#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t)) +#define TD_ROW_SET_DELETE(r) (TD_ROW_DELETE(r) = 1) +#define TD_ROW_SET_SVER(r, v) (TD_ROW_SVER(r) = (v)) +#define TD_ROW_SET_LEN(r, l) (TD_ROW_LEN(r) = (l)) #define TD_ROW_SET_NCOLS(r, n) (*(col_id_t *)TD_ROW_NCOLS(r) = (n)) #define TD_ROW_IS_DELETED(r) (TD_ROW_DELETE(r) == 1) -#define TD_IS_TP_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_TP) -#define TD_IS_KV_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_KV) -#define TD_IS_TP_ROW_T(t) ((t) == TD_ROW_TP) -#define TD_IS_KV_ROW_T(t) ((t) == TD_ROW_KV) +#define TD_IS_TP_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_TP) +#define TD_IS_KV_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_KV) +#define TD_IS_TP_ROW_T(t) ((t) == TD_ROW_TP) +#define TD_IS_KV_ROW_T(t) ((t) == TD_ROW_KV) -#define TD_BOOL_STR(b) ((b) ? "true" : "false") +#define TD_BOOL_STR(b) ((b) ? "true" : "false") #define isUtilizeKVRow(k, d) ((k) < ((d)*KVRatioConvert)) #define TD_ROW_COL_IDX(r) POINTER_SHIFT(TD_ROW_DATA(r), sizeof(col_id_t)) @@ -275,7 +275,7 @@ static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TD } int16_t nBytes = colIdx / TD_VTYPE_PARTS; int16_t nOffset = colIdx & TD_VTYPE_OPTR; - char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); + char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); switch (nOffset) { case 0: *pDestByte = ((*pDestByte) & 0x3F) | (valType << 6); @@ -313,7 +313,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD } int16_t nBytes = colIdx / TD_VTYPE_PARTS; int16_t nOffset = colIdx & TD_VTYPE_OPTR; - char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); + char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); switch (nOffset) { case 0: *pValType = (((*pDestByte) & 0xC0) >> 6); @@ -620,7 +620,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa if (tdValIsNorm(valType, val, colType)) { // ts key stored in STSRow.ts SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset); - char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); + char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); pColIdx->colId = colId; pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN @@ -638,7 +638,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa // NULL/None value else { SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset); - char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); + char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); pColIdx->colId = colId; pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN const void *nullVal = getNullValue(colType); @@ -775,8 +775,8 @@ static FORCE_INLINE int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, v typedef struct { STSchema *pSchema; - STSRow * pRow; - void * pBitmap; + STSRow *pRow; + void *pBitmap; uint32_t offset; col_id_t maxColId; col_id_t colIdx; // [PRIMARYKEY_TIMESTAMP_COL_ID, nSchemaCols], PRIMARYKEY_TIMESTAMP_COL_ID equals 1 @@ -881,7 +881,7 @@ static FORCE_INLINE bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colTy // internal static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx, SCellVal *pVal) { - STSRow * pRow = pIter->pRow; + STSRow *pRow = pIter->pRow; SKvRowIdx *pKvIdx = NULL; bool colFound = false; col_id_t kvNCols = tdRowGetNCols(pRow); @@ -1076,7 +1076,7 @@ typedef struct { typedef struct { STSchema *pSchema; - STSRow * pRow; + STSRow *pRow; } STSRowReader; typedef struct { diff --git a/include/common/ttime.h b/include/common/ttime.h index 57af24e635..306f54bedb 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -60,8 +60,10 @@ int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* durati int32_t taosParseTime(const char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth); void deltaToUtcInitOnce(); +char getPrecisionUnit(int32_t precision); int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision); +int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit); void taosFormatUtcTime(char *buf, int32_t bufLen, int64_t time, int32_t precision); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 73c15d508c..afd2a01540 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -82,21 +82,21 @@ #define TK_SINGLE_STABLE 64 #define TK_STREAM_MODE 65 #define TK_RETENTIONS 66 -#define TK_TABLE 67 -#define TK_NK_LP 68 -#define TK_NK_RP 69 -#define TK_STABLE 70 -#define TK_ADD 71 -#define TK_COLUMN 72 -#define TK_MODIFY 73 -#define TK_RENAME 74 -#define TK_TAG 75 -#define TK_SET 76 -#define TK_NK_EQ 77 -#define TK_USING 78 -#define TK_TAGS 79 -#define TK_NK_DOT 80 -#define TK_NK_COMMA 81 +#define TK_NK_COMMA 67 +#define TK_TABLE 68 +#define TK_NK_LP 69 +#define TK_NK_RP 70 +#define TK_STABLE 71 +#define TK_ADD 72 +#define TK_COLUMN 73 +#define TK_MODIFY 74 +#define TK_RENAME 75 +#define TK_TAG 76 +#define TK_SET 77 +#define TK_NK_EQ 78 +#define TK_USING 79 +#define TK_TAGS 80 +#define TK_NK_DOT 81 #define TK_COMMENT 82 #define TK_BOOL 83 #define TK_TINYINT 84 @@ -131,66 +131,91 @@ #define TK_FUNCTIONS 113 #define TK_INDEXES 114 #define TK_FROM 115 -#define TK_LIKE 116 -#define TK_INDEX 117 -#define TK_FULLTEXT 118 -#define TK_FUNCTION 119 -#define TK_INTERVAL 120 -#define TK_TOPIC 121 -#define TK_AS 122 -#define TK_EXPLAIN 123 -#define TK_ANALYZE 124 -#define TK_VERBOSE 125 -#define TK_NK_BOOL 126 -#define TK_RATIO 127 -#define TK_NULL 128 -#define TK_NK_VARIABLE 129 -#define TK_NK_UNDERLINE 130 -#define TK_ROWTS 131 -#define TK_TBNAME 132 -#define TK_QSTARTTS 133 -#define TK_QENDTS 134 -#define TK_WSTARTTS 135 -#define TK_WENDTS 136 -#define TK_WDURATION 137 -#define TK_BETWEEN 138 -#define TK_IS 139 -#define TK_NK_LT 140 -#define TK_NK_GT 141 -#define TK_NK_LE 142 -#define TK_NK_GE 143 -#define TK_NK_NE 144 -#define TK_MATCH 145 -#define TK_NMATCH 146 -#define TK_IN 147 -#define TK_JOIN 148 -#define TK_INNER 149 -#define TK_SELECT 150 -#define TK_DISTINCT 151 -#define TK_WHERE 152 -#define TK_PARTITION 153 -#define TK_BY 154 -#define TK_SESSION 155 -#define TK_STATE_WINDOW 156 -#define TK_SLIDING 157 -#define TK_FILL 158 -#define TK_VALUE 159 -#define TK_NONE 160 -#define TK_PREV 161 -#define TK_LINEAR 162 -#define TK_NEXT 163 -#define TK_GROUP 164 -#define TK_HAVING 165 -#define TK_ORDER 166 -#define TK_SLIMIT 167 -#define TK_SOFFSET 168 -#define TK_LIMIT 169 -#define TK_OFFSET 170 -#define TK_ASC 171 -#define TK_DESC 172 -#define TK_NULLS 173 -#define TK_FIRST 174 -#define TK_LAST 175 +#define TK_ACCOUNTS 116 +#define TK_APPS 117 +#define TK_CONNECTIONS 118 +#define TK_LICENCE 119 +#define TK_QUERIES 120 +#define TK_SCORES 121 +#define TK_TOPICS 122 +#define TK_VARIABLES 123 +#define TK_LIKE 124 +#define TK_INDEX 125 +#define TK_FULLTEXT 126 +#define TK_FUNCTION 127 +#define TK_INTERVAL 128 +#define TK_TOPIC 129 +#define TK_AS 130 +#define TK_DESC 131 +#define TK_DESCRIBE 132 +#define TK_RESET 133 +#define TK_QUERY 134 +#define TK_EXPLAIN 135 +#define TK_ANALYZE 136 +#define TK_VERBOSE 137 +#define TK_NK_BOOL 138 +#define TK_RATIO 139 +#define TK_COMPACT 140 +#define TK_VNODES 141 +#define TK_IN 142 +#define TK_OUTPUTTYPE 143 +#define TK_AGGREGATE 144 +#define TK_BUFSIZE 145 +#define TK_STREAM 146 +#define TK_INTO 147 +#define TK_KILL 148 +#define TK_CONNECTION 149 +#define TK_MERGE 150 +#define TK_VGROUP 151 +#define TK_REDISTRIBUTE 152 +#define TK_SPLIT 153 +#define TK_SYNCDB 154 +#define TK_NULL 155 +#define TK_NK_VARIABLE 156 +#define TK_NOW 157 +#define TK_ROWTS 158 +#define TK_TBNAME 159 +#define TK_QSTARTTS 160 +#define TK_QENDTS 161 +#define TK_WSTARTTS 162 +#define TK_WENDTS 163 +#define TK_WDURATION 164 +#define TK_BETWEEN 165 +#define TK_IS 166 +#define TK_NK_LT 167 +#define TK_NK_GT 168 +#define TK_NK_LE 169 +#define TK_NK_GE 170 +#define TK_NK_NE 171 +#define TK_MATCH 172 +#define TK_NMATCH 173 +#define TK_JOIN 174 +#define TK_INNER 175 +#define TK_SELECT 176 +#define TK_DISTINCT 177 +#define TK_WHERE 178 +#define TK_PARTITION 179 +#define TK_BY 180 +#define TK_SESSION 181 +#define TK_STATE_WINDOW 182 +#define TK_SLIDING 183 +#define TK_FILL 184 +#define TK_VALUE 185 +#define TK_NONE 186 +#define TK_PREV 187 +#define TK_LINEAR 188 +#define TK_NEXT 189 +#define TK_GROUP 190 +#define TK_HAVING 191 +#define TK_ORDER 192 +#define TK_SLIMIT 193 +#define TK_SOFFSET 194 +#define TK_LIMIT 195 +#define TK_OFFSET 196 +#define TK_ASC 197 +#define TK_NULLS 198 +#define TK_FIRST 199 +#define TK_LAST 200 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 @@ -204,10 +229,8 @@ #define TK_NK_COLON 500 #define TK_NK_BITNOT 501 #define TK_INSERT 502 -#define TK_INTO 503 -#define TK_NOW 504 #define TK_VALUES 507 -#define TK_IMPORT 507 +#define TK_IMPORT 509 #define TK_NK_SEMI 508 #define TK_NK_NIL 65535 diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 19442af206..1cb398fb85 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -31,6 +31,7 @@ typedef int16_t col_id_t; typedef int8_t col_type_t; typedef int32_t col_bytes_t; typedef uint16_t schema_ver_t; +typedef int32_t func_id_t; #pragma pack(push, 1) typedef struct { diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 5b88a9d6af..08ab63e55a 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -29,8 +29,7 @@ extern "C" { typedef struct SMnode SMnode; typedef struct { - int32_t dnodeId; - int64_t clusterId; + bool deploy; int8_t replica; int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; diff --git a/include/libs/command/command.h b/include/libs/command/command.h new file mode 100644 index 0000000000..7e58d39692 --- /dev/null +++ b/include/libs/command/command.h @@ -0,0 +1,24 @@ +/* + * 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 "cmdnodes.h" +#include "tmsg.h" +#include "plannodes.h" + +int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp); + +int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp); + + diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 278d9d8b7c..fe9edc323d 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -52,7 +52,12 @@ typedef struct SFuncExecFuncs { FExecFinalize finalize; } SFuncExecFuncs; -#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results +typedef struct SFileBlockInfo { + int32_t numBlocksOfStep; +} SFileBlockInfo; + +#define TSDB_BLOCK_DIST_STEP_ROWS 8 +#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results #define FUNCTION_TYPE_SCALAR 1 #define FUNCTION_TYPE_AGG 2 @@ -101,10 +106,6 @@ typedef struct SFuncExecFuncs { #define FUNCTION_DERIVATIVE 32 #define FUNCTION_BLKINFO 33 -#define FUNCTION_HISTOGRAM 34 -#define FUNCTION_HLL 35 -#define FUNCTION_MODE 36 -#define FUNCTION_SAMPLE 37 #define FUNCTION_COV 38 @@ -183,11 +184,11 @@ typedef struct SqlFunctionCtx { int32_t columnIndex; // TODO remove it uint8_t currentStage; // record current running step, default: 0 bool isAggSet; + int64_t startTs; // timestamp range of current query when function is executed on a specific data block, TODO remove it ///////////////////////////////////////////////////////////////// bool stableQuery; int16_t functionId; // function id char * pOutput; // final result output buffer, point to sdata->data - int64_t startTs; // timestamp range of current query when function is executed on a specific data block int32_t numOfParams; SVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param int64_t *ptsList; // corresponding timestamp array list diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 7d46b543cb..0969fb203a 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -72,10 +72,15 @@ typedef enum EFunctionType { FUNCTION_TYPE_ATAN, // string function - FUNCTION_TYPE_CHAR_LENGTH = 1500, + FUNCTION_TYPE_LENGTH = 1500, + FUNCTION_TYPE_CHAR_LENGTH, FUNCTION_TYPE_CONCAT, FUNCTION_TYPE_CONCAT_WS, - FUNCTION_TYPE_LENGTH, + FUNCTION_TYPE_LOWER, + FUNCTION_TYPE_UPPER, + FUNCTION_TYPE_LTRIM, + FUNCTION_TYPE_RTRIM, + FUNCTION_TYPE_SUBSTR, // conversion function FUNCTION_TYPE_CAST = 2000, diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index a03c496b4f..069aec14b5 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -20,8 +20,14 @@ extern "C" { #endif +#include "query.h" #include "querynodes.h" +#define DESCRIBE_RESULT_COLS 4 +#define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE) +#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE) +#define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE) + typedef struct SDatabaseOptions { ENodeType type; int32_t numOfBlocks; @@ -32,7 +38,9 @@ typedef struct SDatabaseOptions { int32_t fsyncPeriod; int32_t maxRowsPerBlock; int32_t minRowsPerBlock; - int32_t keep; + int32_t keep0; + int32_t keep1; + int32_t keep2; int32_t precision; int32_t quorum; int32_t replica; @@ -70,7 +78,9 @@ typedef struct SAlterDatabaseStmt { typedef struct STableOptions { ENodeType type; - int32_t keep; + int32_t keep0; + int32_t keep1; + int32_t keep2; int32_t ttl; char comments[TSDB_STB_COMMENT_LEN]; SNodeList* pSma; @@ -187,6 +197,12 @@ typedef struct SShowStmt { SNode* pTbNamePattern; // SValueNode } SShowStmt; +typedef struct SShowCreatStmt { + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; +} SShowCreatStmt; + typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT @@ -247,6 +263,13 @@ typedef struct SAlterLocalStmt { char value[TSDB_DNODE_VALUE_LEN]; } SAlterLocalStmt; +typedef struct SDescribeStmt { + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + STableMeta* pMeta; +} SDescribeStmt; + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 83c0bccaaf..9668082696 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -101,6 +101,17 @@ typedef enum ENodeType { QUERY_NODE_DROP_TOPIC_STMT, QUERY_NODE_ALTER_LOCAL_STMT, QUERY_NODE_EXPLAIN_STMT, + QUERY_NODE_DESCRIBE_STMT, + QUERY_NODE_RESET_QUERY_CACHE_STMT, + QUERY_NODE_COMPACT_STMT, + QUERY_NODE_CREATE_FUNCTION_STMT, + QUERY_NODE_DROP_FUNCTION_STMT, + QUERY_NODE_CREATE_STREAM_STMT, + QUERY_NODE_DROP_STREAM_STMT, + QUERY_NODE_MERGE_VGROUP_STMT, + QUERY_NODE_REDISTRIBUTE_VGROUP_STMT, + QUERY_NODE_SPLIT_VGROUP_STMT, + QUERY_NODE_SYNCDB_STMT, QUERY_NODE_SHOW_DATABASES_STMT, QUERY_NODE_SHOW_TABLES_STMT, QUERY_NODE_SHOW_STABLES_STMT, @@ -113,6 +124,18 @@ typedef enum ENodeType { QUERY_NODE_SHOW_FUNCTIONS_STMT, QUERY_NODE_SHOW_INDEXES_STMT, QUERY_NODE_SHOW_STREAMS_STMT, + QUERY_NODE_SHOW_APPS_STMT, + QUERY_NODE_SHOW_CONNECTIONS_STMT, + QUERY_NODE_SHOW_LICENCE_STMT, + QUERY_NODE_SHOW_CREATE_DATABASE_STMT, + QUERY_NODE_SHOW_CREATE_TABLE_STMT, + QUERY_NODE_SHOW_CREATE_STABLE_STMT, + QUERY_NODE_SHOW_QUERIES_STMT, + QUERY_NODE_SHOW_SCORES_STMT, + QUERY_NODE_SHOW_TOPICS_STMT, + QUERY_NODE_SHOW_VARIABLE_STMT, + QUERY_NODE_KILL_CONNECTION_STMT, + QUERY_NODE_KILL_QUERY_STMT, // logic plan node QUERY_NODE_LOGIC_PLAN_SCAN, @@ -213,6 +236,8 @@ int32_t nodesStringToNode(const char* pStr, SNode** pNode); int32_t nodesListToString(const SNodeList* pList, bool format, char** pStr, int32_t* pLen); int32_t nodesStringToList(const char* pStr, SNodeList** pList); +int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len); + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index f41e049196..37163f60dd 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -253,7 +253,7 @@ typedef struct SIntervalPhysiNode { int64_t sliding; int8_t intervalUnit; int8_t slidingUnit; - uint8_t precision; + uint8_t precision; SFillNode* pFill; } SIntervalPhysiNode; diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 23a63c1a0b..ca4646a5ca 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -277,7 +277,6 @@ typedef struct SVnodeModifOpStmt { ENodeType nodeType; ENodeType sqlNodeType; SArray* pDataBlocks; // data block for each vgroup, SArray. - int8_t schemaAttache; // denote if submit block is built with table schema or not uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert uint32_t insertType; // insert data from [file|sql statement| bound statement] const char* sql; // current sql statement position @@ -306,6 +305,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod bool nodesIsExprNode(const SNode* pNode); +bool nodesIsUnaryOp(const SOperatorNode* pOp); bool nodesIsArithmeticOp(const SOperatorNode* pOp); bool nodesIsComparisonOp(const SOperatorNode* pOp); bool nodesIsJsonOp(const SOperatorNode* pOp); @@ -314,6 +314,7 @@ bool nodesIsTimeorderQuery(const SNode* pQuery); bool nodesIsTimelineQuery(const SNode* pQuery); void* nodesGetValueFromNode(SValueNode *pNode); +char* nodesGetStrValueFromNode(SValueNode *pNode); #ifdef __cplusplus } diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 0747534721..f10185c44f 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -55,6 +55,7 @@ typedef struct SQuery { SArray* pDbList; SArray* pTableList; bool showRewrite; + bool localCmd; } SQuery; int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery); diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index f487e5ae22..bb550e75e8 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -53,6 +53,7 @@ typedef struct SIndexMeta { } SIndexMeta; + /* * ASSERT(sizeof(SCTableMeta) == 24) * ASSERT(tableType == TSDB_CHILD_TABLE) @@ -235,6 +236,11 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t } \ } while (0) +#define QRY_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) +#define QRY_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) +#define QRY_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) + + #ifdef __cplusplus } #endif diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index 7bc0ee42e9..b5acc64f0b 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -42,6 +42,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type); int32_t vectorGetConvertType(int32_t type1, int32_t type2); int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut); +/* Math functions */ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); @@ -58,6 +59,17 @@ int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +/* String functions */ +int32_t lengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t charLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t lowerFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t upperFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t ltrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t rtrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); + bool getTimePseudoFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 8b1ac3ed8d..e635227eaa 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -61,16 +61,16 @@ extern "C" { } \ } -#define WAL_HEAD_VER 0 +#define WAL_HEAD_VER 0 #define WAL_NOSUFFIX_LEN 20 -#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1) -#define WAL_LOG_SUFFIX "log" +#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1) +#define WAL_LOG_SUFFIX "log" #define WAL_INDEX_SUFFIX "idx" -#define WAL_REFRESH_MS 1000 -#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead)) -#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) -#define WAL_FILE_LEN (WAL_PATH_LEN + 32) -#define WAL_MAGIC 0xFAFBFCFDULL +#define WAL_REFRESH_MS 1000 +#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead)) +#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) +#define WAL_FILE_LEN (WAL_PATH_LEN + 32) +#define WAL_MAGIC 0xFAFBFCFDULL #define WAL_CUR_FAILED 1 @@ -150,14 +150,15 @@ typedef struct SWal { } SWal; // WAL HANDLE typedef struct SWalReadHandle { - SWal *pWal; - TdFilePtr pReadLogTFile; - TdFilePtr pReadIdxTFile; - int64_t curFileFirstVer; - int64_t curVersion; - int64_t capacity; - int64_t status; // if cursor valid - SWalHead *pHead; + SWal *pWal; + TdFilePtr pReadLogTFile; + TdFilePtr pReadIdxTFile; + int64_t curFileFirstVer; + int64_t curVersion; + int64_t capacity; + int64_t status; // if cursor valid + TdThreadMutex mutex; + SWalHead *pHead; } SWalReadHandle; #pragma pack(pop) @@ -191,6 +192,7 @@ int32_t walEndSnapshot(SWal *); SWalReadHandle *walOpenReadHandle(SWal *); void walCloseReadHandle(SWalReadHandle *); int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver); +int32_t walReadWithHandle_s(SWalReadHandle *pRead, int64_t ver, SWalReadHead **ppHead); // deprecated #if 0 diff --git a/include/os/osMemory.h b/include/os/osMemory.h index 62ac82782c..e516000c66 100644 --- a/include/os/osMemory.h +++ b/include/os/osMemory.h @@ -32,13 +32,16 @@ extern "C" { void *taosMemoryMalloc(int32_t size); void *taosMemoryCalloc(int32_t num, int32_t size); void *taosMemoryRealloc(void *ptr, int32_t size); +void *taosMemoryStrDup(void *ptr); void taosMemoryFree(const void *ptr); int32_t taosMemorySize(void *ptr); #define taosMemoryFreeClear(ptr) \ do { \ - taosMemoryFree(ptr); \ - (ptr)=NULL; \ + if (ptr) { \ + taosMemoryFree(ptr); \ + (ptr) = NULL; \ + } \ } while (0) #ifdef __cplusplus diff --git a/include/os/osProc.h b/include/os/osProc.h index e76e22a54e..f09b695ef4 100644 --- a/include/os/osProc.h +++ b/include/os/osProc.h @@ -20,11 +20,12 @@ extern "C" { #endif -// start a copy of itself -int32_t taosNewProc(const char *args); - -// the length of the new name must be less than the original name to take effect -void taosSetProcName(char **argv, const char *name); +int32_t taosNewProc(char **args); +void taosWaitProc(int32_t pid); +void taosKillProc(int32_t pid); +bool taosProcExist(int32_t pid); +void taosSetProcName(int32_t argc, char **argv, const char *name); +void taosSetProcPath(int32_t argc, char **argv); #ifdef __cplusplus } diff --git a/include/os/osShm.h b/include/os/osShm.h index d26a99e277..61ffc0f6cc 100644 --- a/include/os/osShm.h +++ b/include/os/osShm.h @@ -26,7 +26,7 @@ typedef struct { void* ptr; } SShm; -int32_t taosCreateShm(SShm *pShm, int32_t shmsize) ; +int32_t taosCreateShm(SShm *pShm, int32_t key, int32_t shmsize) ; void taosDropShm(SShm *pShm); int32_t taosAttachShm(SShm *pShm); diff --git a/include/os/osSignal.h b/include/os/osSignal.h index e9fb13e870..e22c43684c 100644 --- a/include/os/osSignal.h +++ b/include/os/osSignal.h @@ -49,7 +49,7 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp); void taosIgnSignal(int32_t signum); void taosDflSignal(int32_t signum); -void taosKillChildOnSelfStopped(); +void taosKillChildOnParentStopped(); #ifdef __cplusplus } diff --git a/include/os/osTime.h b/include/os/osTime.h index 9e426455dc..766fec0fbd 100644 --- a/include/os/osTime.h +++ b/include/os/osTime.h @@ -46,6 +46,14 @@ extern "C" { #define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24) #define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7) +#define NANOSECOND_PER_USEC (1000L) +#define NANOSECOND_PER_MSEC (1000000L) +#define NANOSECOND_PER_SEC (1000000000L) +#define NANOSECOND_PER_MINUTE (NANOSECOND_PER_SEC * 60) +#define NANOSECOND_PER_HOUR (NANOSECOND_PER_MINUTE * 60) +#define NANOSECOND_PER_DAY (NANOSECOND_PER_HOUR * 24) +#define NANOSECOND_PER_WEEK (NANOSECOND_PER_DAY * 7) + int32_t taosGetTimeOfDay(struct timeval *tv); //@return timestamp in second diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 27145afc3d..4e2cb7944a 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -479,6 +479,9 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613) #define TSDB_CODE_PAR_EXPRIE_STATEMENT TAOS_DEF_ERROR_CODE(0, 0x2614) #define TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2615) +#define TSDB_CODE_PAR_DB_NOT_SPECIFIED TAOS_DEF_ERROR_CODE(0, 0x2616) +#define TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME TAOS_DEF_ERROR_CODE(0, 0x2617) +#define TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR TAOS_DEF_ERROR_CODE(0, 0x2618) #ifdef __cplusplus } diff --git a/include/util/tcoding.h b/include/util/tcoding.h index 838b175a28..3f00c79f46 100644 --- a/include/util/tcoding.h +++ b/include/util/tcoding.h @@ -57,6 +57,8 @@ static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) { return POINTER_SHIFT(buf, sizeof(*value)); } +static FORCE_INLINE void *taosSkipFixedLen(const void *buf, size_t len) { return POINTER_SHIFT(buf, len); } + // ---- Fixed U16 static FORCE_INLINE int32_t taosEncodeFixedU16(void **buf, uint16_t value) { if (buf != NULL) { diff --git a/include/util/tdef.h b/include/util/tdef.h index 43981adea2..be88afcf66 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -128,18 +128,20 @@ extern const int32_t TYPE_BYTES[15]; } while (0) typedef enum EOperatorType { - // arithmetic operator + // binary arithmetic operator OP_TYPE_ADD = 1, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV, OP_TYPE_MOD, + // unary arithmetic operator + OP_TYPE_MINUS, // bit operator OP_TYPE_BIT_AND, OP_TYPE_BIT_OR, - // comparison operator + // binary comparison operator OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, @@ -152,6 +154,7 @@ typedef enum EOperatorType { OP_TYPE_NOT_LIKE, OP_TYPE_MATCH, OP_TYPE_NMATCH, + // unary comparison operator OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL, OP_TYPE_IS_TRUE, @@ -224,6 +227,7 @@ typedef enum ELogicConditionType { #define TSDB_APP_NAME_LEN TSDB_UNI_LEN #define TSDB_STB_COMMENT_LEN 1024 + /** * 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. @@ -303,13 +307,13 @@ typedef enum ELogicConditionType { #define TSDB_MAX_TOTAL_BLOCKS 10000 #define TSDB_DEFAULT_TOTAL_BLOCKS 6 -#define TSDB_MIN_DAYS_PER_FILE 1 -#define TSDB_MAX_DAYS_PER_FILE 3650 -#define TSDB_DEFAULT_DAYS_PER_FILE 10 +#define TSDB_MIN_DAYS_PER_FILE 60 // unit minute +#define TSDB_MAX_DAYS_PER_FILE (3650 * 1440) +#define TSDB_DEFAULT_DAYS_PER_FILE (10 * 1440) -#define TSDB_MIN_KEEP 1 // data in db to be reserved. -#define TSDB_MAX_KEEP 365000 // data in db to be reserved. -#define TSDB_DEFAULT_KEEP 3650 // ten years +#define TSDB_MIN_KEEP (1 * 1440) // data in db to be reserved. unit minute +#define TSDB_MAX_KEEP (365000 * 1440) // data in db to be reserved. +#define TSDB_DEFAULT_KEEP (3650 * 1440) // ten years #define TSDB_MIN_MIN_ROW_FBLOCK 10 #define TSDB_MAX_MIN_ROW_FBLOCK 1000 @@ -327,7 +331,7 @@ typedef enum ELogicConditionType { #define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond #define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second -#define TSDB_MIN_WAL_LEVEL 0 +#define TSDB_MIN_WAL_LEVEL 1 #define TSDB_MAX_WAL_LEVEL 2 #define TSDB_DEFAULT_WAL_LEVEL 1 @@ -388,6 +392,7 @@ typedef enum ELogicConditionType { #define TSDB_DEFAULT_EXPLAIN_RATIO 0.001 #define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024 +#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY PLAN" #define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 @@ -479,6 +484,9 @@ enum { #define QND_VGID 1 #define VND_VGID 0 +#define MAX_NUM_STR_SIZE 40 + + #ifdef __cplusplus } #endif diff --git a/include/util/tprocess.h b/include/util/tprocess.h index 3a47450eec..bc0c8fe5a4 100644 --- a/include/util/tprocess.h +++ b/include/util/tprocess.h @@ -22,7 +22,7 @@ extern "C" { #endif -typedef enum { PROC_REQ, PROC_RSP, PROC_REG, PROC_RELEASE } ProcFuncType; +typedef enum { PROC_QUEUE, PROC_REQ, PROC_RSP, PROC_REGIST, PROC_RELEASE } ProcFuncType; typedef struct SProcQueue SProcQueue; typedef struct SProcObj SProcObj; @@ -53,7 +53,7 @@ void taosProcCleanup(SProcObj *pProc); int32_t taosProcRun(SProcObj *pProc); int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, ProcFuncType ftype); -int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, +void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, ProcFuncType ftype); #ifdef __cplusplus diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index a632337d4a..8ee6c31ba1 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories( target_link_libraries( taos INTERFACE api - PRIVATE os util common transport nodes parser planner catalog scheduler function qcom + PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom ) if(${BUILD_TEST}) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 49cb12cccd..0749ce9e7d 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -136,7 +136,7 @@ typedef struct STscObj { uint32_t connId; int32_t connType; uint64_t id; // ref ID returned by taosAddRef - TdThreadMutex mutex; // used to protect the operation on db + TdThreadMutex mutex; // used to protect the operation on db int32_t numOfReqs; // number of sqlObj bound to this connection SAppInstInfo* pAppInfo; } STscObj; @@ -152,7 +152,8 @@ typedef struct SResultColumn { typedef struct SReqResultInfo { const char* pRspMsg; const char* pData; - TAOS_FIELD* fields; + TAOS_FIELD* fields; // todo, column names are not needed. + TAOS_FIELD* userFields; // the fields info that return to user uint32_t numOfCols; int32_t* length; char** convertBuf; @@ -221,6 +222,7 @@ void destroyRequest(SRequestObj* pRequest); char* getDbOfConnection(STscObj* pObj); void setConnectionDB(STscObj* pTscObj, const char* db); +void resetConnectDB(STscObj* pTscObj); void taos_init_imp(void); int taos_options_imp(TSDB_OPTION option, const char* str); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 53cc77af1a..769870ada8 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -169,6 +169,7 @@ static void doFreeReqResultInfo(SReqResultInfo *pResInfo) { taosMemoryFreeClear(pResInfo->row); taosMemoryFreeClear(pResInfo->pCol); taosMemoryFreeClear(pResInfo->fields); + taosMemoryFreeClear(pResInfo->userFields); if (pResInfo->convertBuf != NULL) { for (int32_t i = 0; i < pResInfo->numOfCols; ++i) { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index d8017a8727..80559c025f 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -1,6 +1,7 @@ #include "clientInt.h" #include "clientLog.h" +#include "command.h" #include "scheduler.h" #include "tdatablock.h" #include "tdef.h" @@ -55,7 +56,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, } char localDb[TSDB_DB_NAME_LEN] = {0}; - if (db != NULL) { + if (db != NULL && strlen(db) > 0) { if (!validateDbName(db)) { terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; return NULL; @@ -163,6 +164,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery) { if ((*pQuery)->haveResultSet) { setResSchemaInfo(&pRequest->body.resInfo, (*pQuery)->pResSchema, (*pQuery)->numOfResCols); } + TSWAP(pRequest->dbList, (*pQuery)->pDbList, SArray*); TSWAP(pRequest->tableList, (*pQuery)->pTableList, SArray*); } @@ -170,7 +172,21 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery) { return code; } +int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { + SRetrieveTableRsp* pRsp = NULL; + int32_t code = qExecCommand(pQuery->pRoot, &pRsp); + if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { + code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp); + } + return code; +} + int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { + // drop table if exists not_exists_table + if (NULL == pQuery->pCmdMsg) { + return TSDB_CODE_SUCCESS; + } + SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg; pRequest->type = pMsgInfo->msgType; pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL}; @@ -213,12 +229,24 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t assert(pSchema != NULL && numOfCols > 0); pResInfo->numOfCols = numOfCols; - pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(pSchema[0])); + pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD)); + pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD)); for (int32_t i = 0; i < pResInfo->numOfCols; ++i) { pResInfo->fields[i].bytes = pSchema[i].bytes; - pResInfo->fields[i].type = pSchema[i].type; + pResInfo->fields[i].type = pSchema[i].type; + + pResInfo->userFields[i].bytes = pSchema[i].bytes; + pResInfo->userFields[i].type = pSchema[i].type; + + if (pSchema[i].type == TSDB_DATA_TYPE_VARCHAR) { + pResInfo->userFields[i].bytes -= VARSTR_HEADER_SIZE; + } else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) { + pResInfo->userFields[i].bytes = (pResInfo->userFields[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + } + tstrncpy(pResInfo->fields[i].name, pSchema[i].name, tListLen(pResInfo->fields[i].name)); + tstrncpy(pResInfo->userFields[i].name, pSchema[i].name, tListLen(pResInfo->userFields[i].name)); } } @@ -259,7 +287,9 @@ SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); CHECK_CODE_GOTO(parseSql(pRequest, false, &pQuery), _return); - if (pQuery->directRpc) { + if (pQuery->localCmd) { + CHECK_CODE_GOTO(execLocalCmd(pRequest, pQuery), _return); + } else if (pQuery->directRpc) { CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return); } else { CHECK_CODE_GOTO(getPlan(pRequest, pQuery, &pRequest->body.pDag, pNodeList), _return); @@ -464,9 +494,11 @@ static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { taosMemoryFreeClear(pMsgBody->msgInfo.pData); taosMemoryFreeClear(pMsgBody); } + bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType) { return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || msgType == TDMT_VND_QUERY_HEARTBEAT_RSP; } + void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->ahandle; assert(pMsg->ahandle != NULL); @@ -647,6 +679,11 @@ void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) { } } + if (pResultInfo->completed) { + pResultInfo->numOfRows = 0; + return NULL; + } + SMsgSendInfo* body = buildMsgInfoImpl(pRequest); int64_t transporterId = 0; @@ -716,6 +753,7 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 pStart += colLength[i]; } + // convert UCS4-LE encoded character to native multi-bytes character in current data block. for (int32_t i = 0; i < numOfCols; ++i) { int32_t type = pResultInfo->fields[i].type; int32_t bytes = pResultInfo->fields[i].bytes; @@ -742,6 +780,7 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 } pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; + pResultInfo->row[i] = pResultInfo->pCol[i].pData; } } @@ -767,6 +806,16 @@ void setConnectionDB(STscObj* pTscObj, const char* db) { taosThreadMutexUnlock(&pTscObj->mutex); } +void resetConnectDB(STscObj* pTscObj) { + if (pTscObj == NULL) { + return; + } + + taosThreadMutexLock(&pTscObj->mutex); + pTscObj->db[0] = 0; + taosThreadMutexUnlock(&pTscObj->mutex); +} + int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) { assert(pResultInfo != NULL && pRsp != NULL); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 42d4b5b2e5..0ca6169883 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -146,7 +146,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { } SReqResultInfo *pResInfo = &(((SRequestObj *)res)->body.resInfo); - return pResInfo->fields; + return pResInfo->userFields; } TAOS_RES *taos_query(TAOS *taos, const char *sql) { @@ -365,8 +365,7 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { } bool taos_is_update_query(TAOS_RES *res) { - // TODO - return true; + return taos_num_fields(res) == 0; } int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { @@ -393,8 +392,11 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int taos_validate_sql(TAOS *taos, const char *sql) { return true; } void taos_reset_current_db(TAOS *taos) { - // TODO - return; + if (taos == NULL) { + return; + } + + resetConnectDB(taos); } const char *taos_get_server_info(TAOS *taos) { diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 1fa267ae7e..426a62433b 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -78,6 +78,7 @@ struct tmq_t { STscObj* pTscObj; tmq_commit_cb* commit_cb; int32_t nextTopicIdx; + int8_t epStatus; int32_t waitingRequest; int32_t readyRequest; SArray* clientTopics; // SArray @@ -255,6 +256,7 @@ void tmqClearUnhandleMsg(tmq_t* tmq) { break; } + msg = NULL; taosReadAllQitems(tmq->mqueue, tmq->qall); while (1) { taosGetQitem(tmq->qall, (void**)&msg); @@ -310,6 +312,7 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs pTmq->epoch = 0; pTmq->waitingRequest = 0; pTmq->readyRequest = 0; + pTmq->epStatus = 0; // set conf strcpy(pTmq->clientId, conf->clientId); strcpy(pTmq->groupId, conf->groupId); @@ -787,7 +790,7 @@ void tmqShowMsg(tmq_message_t* tmq_message) { static bool noPrintSchema; char pBuf[128]; SMqPollRsp* pRsp = &tmq_message->msg; - int32_t colNum = pRsp->schema->nCols; + int32_t colNum = 2; if (!noPrintSchema) { printf("|"); for (int32_t i = 0; i < colNum; i++) { @@ -832,12 +835,13 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { tmq_t* tmq = pParam->tmq; if (code != 0) { tscWarn("msg discard, code:%x", code); - goto WRITE_QUEUE_FAIL; + goto CREATE_MSG_FAIL; } int32_t msgEpoch = ((SMqRspHead*)pMsg->pData)->epoch; int32_t tmqEpoch = atomic_load_32(&tmq->epoch); if (msgEpoch < tmqEpoch) { + /*printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);*/ tsem_post(&tmq->rspSem); tscWarn("discard rsp epoch %d, current epoch %d", msgEpoch, tmqEpoch); return 0; @@ -871,7 +875,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { /*SMqConsumeRsp* pRsp = taosMemoryCalloc(1, sizeof(SMqConsumeRsp));*/ tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t)); if (pRsp == NULL) { - goto WRITE_QUEUE_FAIL; + goto CREATE_MSG_FAIL; } memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead)); tDecodeSMqPollRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->msg); @@ -880,11 +884,16 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { // TODO: alloc mem /*pRsp->*/ /*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/ +#if 0 if (pRsp->msg.numOfTopics == 0) { /*printf("no data\n");*/ taosFreeQitem(pRsp); - goto WRITE_QUEUE_FAIL; + goto CREATE_MSG_FAIL; } +#endif + + tscError("tmq recv poll: vg %d, req offset %ld, rsp offset %ld", pParam->pVg->vgId, pRsp->msg.reqOffset, + pRsp->msg.rspOffset); pRsp->vg = pParam->pVg; taosWriteQitem(tmq->mqueue, pRsp); @@ -892,7 +901,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { tsem_post(&tmq->rspSem); return 0; -WRITE_QUEUE_FAIL: +CREATE_MSG_FAIL: if (pParam->epoch == tmq->epoch) { atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); } @@ -902,6 +911,7 @@ WRITE_QUEUE_FAIL: bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { /*printf("call update ep %d\n", epoch);*/ + tscDebug("tmq update ep epoch %d to epoch %d", tmq->epoch, epoch); bool set = false; int32_t topicNumGet = taosArrayGetSize(pRsp->topics); char vgKey[TSDB_TOPIC_FNAME_LEN + 22]; @@ -932,6 +942,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { for (int32_t k = 0; k < vgNumCur; k++) { SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, k); sprintf(vgKey, "%s:%d", topic.topicName, pVgCur->vgId); + tscDebug("epoch %d vg %d build %s\n", epoch, pVgCur->vgId, vgKey); taosHashPut(pHash, vgKey, strlen(vgKey), &pVgCur->currentOffset, sizeof(int64_t)); } break; @@ -945,9 +956,12 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { sprintf(vgKey, "%s:%d", topic.topicName, pVgEp->vgId); int64_t* pOffset = taosHashGet(pHash, vgKey, strlen(vgKey)); int64_t offset = pVgEp->offset; + tscDebug("epoch %d vg %d offset og to %ld\n", epoch, pVgEp->vgId, offset); if (pOffset != NULL) { offset = *pOffset; + tscDebug("epoch %d vg %d found %s\n", epoch, pVgEp->vgId, vgKey); } + tscDebug("epoch %d vg %d offset set to %ld\n", epoch, pVgEp->vgId, offset); SMqClientVg clientVg = { .pollCnt = 0, .currentOffset = offset, @@ -970,6 +984,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param; tmq_t* tmq = pParam->tmq; + tscDebug("consumer %ld recv ep", tmq->consumerId); if (code != 0) { tscError("get topic endpoint error, not ready, wait:%d\n", pParam->sync); goto END; @@ -1008,6 +1023,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { } END: + atomic_store_8(&tmq->epStatus, 0); if (pParam->sync) { tsem_post(&pParam->rspSem); } @@ -1015,10 +1031,16 @@ END: } int32_t tmqAskEp(tmq_t* tmq, bool sync) { + int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1); + if (epStatus == 1) { + tscDebug("consumer %ld skip ask ep", tmq->consumerId); + return 0; + } int32_t tlen = sizeof(SMqCMGetSubEpReq); SMqCMGetSubEpReq* req = taosMemoryMalloc(tlen); if (req == NULL) { tscError("failed to malloc get subscribe ep buf"); + atomic_store_8(&tmq->epStatus, 0); return -1; } req->consumerId = htobe64(tmq->consumerId); @@ -1029,6 +1051,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { if (pParam == NULL) { tscError("failed to malloc subscribe param"); taosMemoryFree(req); + atomic_store_8(&tmq->epStatus, 0); return -1; } pParam->tmq = tmq; @@ -1040,6 +1063,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { tsem_destroy(&pParam->rspSem); taosMemoryFree(pParam); taosMemoryFree(req); + atomic_store_8(&tmq->epStatus, 0); return -1; } @@ -1057,6 +1081,8 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); + tscDebug("consumer %ld ask ep", tmq->consumerId); + int64_t transporterId = 0; asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); @@ -1195,6 +1221,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); int32_t vgStatus = atomic_val_compare_exchange_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE, TMQ_VG_STATUS__WAIT); if (vgStatus != TMQ_VG_STATUS__IDLE) { + tscDebug("consumer %ld skip vg %d", tmq->consumerId, pVg->vgId); continue; } SMqPollReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg); @@ -1238,6 +1265,8 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { int64_t transporterId = 0; /*printf("send poll\n");*/ atomic_add_fetch_32(&tmq->waitingRequest, 1); + tscDebug("consumer %ld send poll: vg %d, req offset %ld", tmq->consumerId, pVg->vgId, pVg->currentOffset); + /*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/ asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo); pVg->pollCnt++; tmq->pollCnt++; @@ -1247,13 +1276,13 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { } // return -int32_t tmqHandleRes(tmq_t* tmq, SMqRspHead* rspHead, bool* pReset) { +int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspHead* rspHead, bool* pReset) { if (rspHead->mqMsgType == TMQ_MSG_TYPE__EP_RSP) { /*printf("ep %d %d\n", rspMsg->head.epoch, tmq->epoch);*/ if (rspHead->epoch > atomic_load_32(&tmq->epoch)) { SMqCMGetSubEpRsp* rspMsg = (SMqCMGetSubEpRsp*)rspHead; tmqUpdateEp(tmq, rspHead->epoch, rspMsg); - tmqClearUnhandleMsg(tmq); + /*tmqClearUnhandleMsg(tmq);*/ *pReset = true; } else { *pReset = false; @@ -1284,6 +1313,11 @@ tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfRese /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ pVg->currentOffset = rspMsg->msg.rspOffset; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); + if (rspMsg->msg.numOfTopics == 0) { + taosFreeQitem(rspMsg); + rspHead = NULL; + continue; + } return rspMsg; } else { /*printf("epoch mismatch\n");*/ @@ -1292,10 +1326,10 @@ tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfRese } else { /*printf("handle ep rsp %d\n", rspMsg->head.mqMsgType);*/ bool reset = false; - tmqHandleRes(tmq, rspHead, &reset); + tmqHandleNoPollRsp(tmq, rspHead, &reset); taosFreeQitem(rspHead); if (pollIfReset && reset) { - printf("reset and repoll\n"); + tscDebug("consumer %ld reset and repoll", tmq->consumerId); tmqPollImpl(tmq, blockingTime); } } @@ -1534,24 +1568,3 @@ TAOS_ROW tmq_get_row(tmq_message_t* message) { } char* tmq_get_topic_name(tmq_message_t* message) { return "not implemented yet"; } - -#if 0 -tmq_t* tmqCreateConsumerImpl(TAOS* conn, tmq_conf_t* conf) { - tmq_t* pTmq = taosMemoryMalloc(sizeof(tmq_t)); - if (pTmq == NULL) { - return NULL; - } - strcpy(pTmq->groupId, conf->groupId); - strcpy(pTmq->clientId, conf->clientId); - pTmq->pTscObj = (STscObj*)conn; - pTmq->pTscObj->connType = HEARTBEAT_TYPE_MQ; - return pTmq; -} - - -static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { - assert(pMsgBody != NULL); - taosMemoryFreeClear(pMsgBody->msgInfo.pData); - taosMemoryFreeClear(pMsgBody); -} -#endif diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 67f4f251f2..46aeb83943 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1105,7 +1105,7 @@ void blockDataCleanup(SSDataBlock* pDataBlock) { } } -int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows) { +int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows) { if (0 == numOfRows) { return TSDB_CODE_SUCCESS; } @@ -1147,7 +1147,7 @@ int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows) { for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i); - code = blockDataEnsureColumnCapacity(p, numOfRows); + code = colInfoDataEnsureCapacity(p, numOfRows); if (code) { return code; } @@ -1202,6 +1202,63 @@ void colDataDestroy(SColumnInfoData* pColData) { taosMemoryFree(pColData->pData); } + +static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) { + int32_t len = BitmapLen(total); + + int32_t newLen = BitmapLen(total - n); + if (n%8 == 0) { + memmove(nullBitmap, nullBitmap + n/8, newLen); + } else { + int32_t tail = n % 8; + int32_t i = 0; + + uint8_t* p = (uint8_t*) nullBitmap; + while(i < len) { + uint8_t v = p[i]; + + p[i] = 0; + p[i] = (v << tail); + + if (i < len - 1) { + uint8_t next = p[i + 1]; + p[i] |= (next >> (8 - tail)); + } + + i += 1; + } + } +} + +static void colDataTrimFirstNRows(SColumnInfoData* pColInfoData, size_t n, size_t total) { + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + memmove(pColInfoData->varmeta.offset, &pColInfoData->varmeta.offset[n], (total - n)); + memset(&pColInfoData->varmeta.offset[total - n - 1], 0, n); + } else { + int32_t bytes = pColInfoData->info.bytes; + memmove(pColInfoData->pData, ((char*)pColInfoData->pData + n * bytes), (total - n) * bytes); + doShiftBitmap(pColInfoData->nullbitmap, n, total); + } +} + +int32_t blockDataTrimFirstNRows(SSDataBlock *pBlock, size_t n) { + if (n == 0) { + return TSDB_CODE_SUCCESS; + } + + if (pBlock->info.rows <= n) { + blockDataCleanup(pBlock); + } else { + for(int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + colDataTrimFirstNRows(pColInfoData, n, pBlock->info.rows); + } + + pBlock->info.rows -= n; + } + return TSDB_CODE_SUCCESS; +} + int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) { int64_t tbUid = pBlock->info.uid; int16_t numOfCols = pBlock->info.numOfCols; @@ -1341,6 +1398,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { return buf; } + void blockDebugShowData(const SArray* dataBlocks) { char pBuf[128]; int32_t sz = taosArrayGetSize(dataBlocks); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 7fd66e95ad..1d7a4aeb8f 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -85,6 +85,7 @@ int tdEncodeSchema(void **buf, STSchema *pSchema) { for (int i = 0; i < schemaNCols(pSchema); i++) { STColumn *pCol = schemaColAt(pSchema, i); tlen += taosEncodeFixedI8(buf, colType(pCol)); + tlen += taosEncodeFixedI8(buf, colSma(pCol)); tlen += taosEncodeFixedI16(buf, colColId(pCol)); tlen += taosEncodeFixedI16(buf, colBytes(pCol)); } @@ -107,12 +108,14 @@ void *tdDecodeSchema(void *buf, STSchema **pRSchema) { for (int i = 0; i < numOfCols; i++) { col_type_t type = 0; + int8_t sma = TSDB_BSMA_TYPE_NONE; col_id_t colId = 0; col_bytes_t bytes = 0; buf = taosDecodeFixedI8(buf, &type); + buf = taosDecodeFixedI8(buf, &sma); buf = taosDecodeFixedI16(buf, &colId); buf = taosDecodeFixedI32(buf, &bytes); - if (tdAddColToSchema(&schemaBuilder, type, colId, bytes) < 0) { + if (tdAddColToSchema(&schemaBuilder, type, sma, colId, bytes) < 0) { tdDestroyTSchemaBuilder(&schemaBuilder); return NULL; } @@ -148,7 +151,7 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) { pBuilder->version = version; } -int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col_bytes_t bytes) { +int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t sma, col_id_t colId, col_bytes_t bytes) { if (!isValidDataType(type)) return -1; if (pBuilder->nCols >= pBuilder->tCols) { @@ -161,6 +164,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col STColumn *pCol = &(pBuilder->columns[pBuilder->nCols]); colSetType(pCol, type); colSetColId(pCol, colId); + colSetSma(pCol, sma); if (pBuilder->nCols == 0) { colSetOffset(pCol, 0); } else { @@ -168,9 +172,6 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]); } - // TODO: set sma value by user input - pCol->sma = 1; - if (IS_VAR_DATA_TYPE(type)) { colSetBytes(pCol, bytes); pBuilder->tlen += (TYPE_BYTES[type] + bytes); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 7a9014dc43..3a144a8a8e 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -296,33 +296,30 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { switch (pReq->type) { case TD_SUPER_TABLE: tlen += taosEncodeFixedI64(buf, pReq->stbCfg.suid); - tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nCols); - for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) { + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nCols); + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); + for (col_id_t i = 0; i < pReq->stbCfg.nCols; ++i) { tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type); + tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].sma); tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pSchema[i].colId); tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].bytes); tlen += taosEncodeString(buf, pReq->stbCfg.pSchema[i].name); } - tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nTagCols); - for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) { + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nTagCols); + for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) { tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type); tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pTagSchema[i].colId); tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes); tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name); } - tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); - for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { - tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); - } if (pReq->rollup && pReq->stbCfg.pRSmaParam) { SRSmaParam *param = pReq->stbCfg.pRSmaParam; - tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); - tlen += taosEncodeFixedI8(buf, param->delayUnit); + tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); + tlen += taosEncodeFixedI32(buf, param->delay); tlen += taosEncodeFixedI8(buf, param->nFuncIds); for (int8_t i = 0; i < param->nFuncIds; ++i) { tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); } - tlen += taosEncodeFixedI64(buf, param->delay); } break; case TD_CHILD_TABLE: @@ -330,26 +327,23 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += tdEncodeKVRow(buf, pReq->ctbCfg.pTag); break; case TD_NORMAL_TABLE: - tlen += taosEncodeFixedU32(buf, pReq->ntbCfg.nCols); - for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) { + tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nCols); + tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nBSmaCols); + for (col_id_t i = 0; i < pReq->ntbCfg.nCols; ++i) { tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type); + tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].sma); tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.pSchema[i].colId); tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes); tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name); } - tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nBSmaCols); - for (col_id_t i = 0; i < pReq->ntbCfg.nBSmaCols; ++i) { - tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.pBSmaCols[i]); - } if (pReq->rollup && pReq->ntbCfg.pRSmaParam) { SRSmaParam *param = pReq->ntbCfg.pRSmaParam; - tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); - tlen += taosEncodeFixedI8(buf, param->delayUnit); + tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); + tlen += taosEncodeFixedI32(buf, param->delay); tlen += taosEncodeFixedI8(buf, param->nFuncIds); for (int8_t i = 0; i < param->nFuncIds; ++i) { tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); } - tlen += taosEncodeFixedI64(buf, param->delay); } break; default: @@ -370,45 +364,38 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { switch (pReq->type) { case TD_SUPER_TABLE: buf = taosDecodeFixedI64(buf, &(pReq->stbCfg.suid)); - buf = taosDecodeFixedU32(buf, &(pReq->stbCfg.nCols)); - pReq->stbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nCols * sizeof(SSchema)); - for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) { + buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nCols)); + buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); + pReq->stbCfg.pSchema = (SSchemaEx *)taosMemoryMalloc(pReq->stbCfg.nCols * sizeof(SSchemaEx)); + for (col_id_t i = 0; i < pReq->stbCfg.nCols; i++) { buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type)); + buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].sma)); buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.pSchema[i].colId)); buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].bytes)); buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name); } - buf = taosDecodeFixedU32(buf, &pReq->stbCfg.nTagCols); + buf = taosDecodeFixedI16(buf, &pReq->stbCfg.nTagCols); pReq->stbCfg.pTagSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nTagCols * sizeof(SSchema)); - for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) { + for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; i++) { buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type)); buf = taosDecodeFixedI16(buf, &pReq->stbCfg.pTagSchema[i].colId); buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); } - buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); - if (pReq->stbCfg.nBSmaCols > 0) { - pReq->stbCfg.pBSmaCols = (col_id_t *)taosMemoryMalloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); - for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { - buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); - } - } else { - pReq->stbCfg.pBSmaCols = NULL; - } if (pReq->rollup) { pReq->stbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam)); SRSmaParam *param = pReq->stbCfg.pRSmaParam; - buf = taosDecodeFixedU32(buf, (uint32_t *)¶m->xFilesFactor); - buf = taosDecodeFixedI8(buf, ¶m->delayUnit); + buf = taosDecodeBinaryTo(buf, (void*)¶m->xFilesFactor, sizeof(param->xFilesFactor)); + buf = taosDecodeFixedI32(buf, ¶m->delay); buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); if (param->nFuncIds > 0) { + param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t)); for (int8_t i = 0; i < param->nFuncIds; ++i) { buf = taosDecodeFixedI32(buf, param->pFuncIds + i); } } else { param->pFuncIds = NULL; } - buf = taosDecodeFixedI64(buf, ¶m->delay); } else { pReq->stbCfg.pRSmaParam = NULL; } @@ -418,37 +405,30 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = tdDecodeKVRow(buf, &pReq->ctbCfg.pTag); break; case TD_NORMAL_TABLE: - buf = taosDecodeFixedU32(buf, &pReq->ntbCfg.nCols); - pReq->ntbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->ntbCfg.nCols * sizeof(SSchema)); - for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) { + buf = taosDecodeFixedI16(buf, &pReq->ntbCfg.nCols); + buf = taosDecodeFixedI16(buf, &(pReq->ntbCfg.nBSmaCols)); + pReq->ntbCfg.pSchema = (SSchemaEx *)taosMemoryMalloc(pReq->ntbCfg.nCols * sizeof(SSchemaEx)); + for (col_id_t i = 0; i < pReq->ntbCfg.nCols; i++) { buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type); + buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].sma); buf = taosDecodeFixedI16(buf, &pReq->ntbCfg.pSchema[i].colId); buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); } - buf = taosDecodeFixedI16(buf, &(pReq->ntbCfg.nBSmaCols)); - if (pReq->ntbCfg.nBSmaCols > 0) { - pReq->ntbCfg.pBSmaCols = (col_id_t *)taosMemoryMalloc(pReq->ntbCfg.nBSmaCols * sizeof(col_id_t)); - for (col_id_t i = 0; i < pReq->ntbCfg.nBSmaCols; ++i) { - buf = taosDecodeFixedI16(buf, pReq->ntbCfg.pBSmaCols + i); - } - } else { - pReq->ntbCfg.pBSmaCols = NULL; - } if (pReq->rollup) { pReq->ntbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam)); SRSmaParam *param = pReq->ntbCfg.pRSmaParam; - buf = taosDecodeFixedU32(buf, (uint32_t *)¶m->xFilesFactor); - buf = taosDecodeFixedI8(buf, ¶m->delayUnit); + buf = taosDecodeBinaryTo(buf, (void*)¶m->xFilesFactor, sizeof(param->xFilesFactor)); + buf = taosDecodeFixedI32(buf, ¶m->delay); buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); if (param->nFuncIds > 0) { + param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t)); for (int8_t i = 0; i < param->nFuncIds; ++i) { buf = taosDecodeFixedI32(buf, param->pFuncIds + i); } } else { param->pFuncIds = NULL; } - buf = taosDecodeFixedI64(buf, ¶m->delay); } else { pReq->ntbCfg.pRSmaParam = NULL; } @@ -1629,6 +1609,7 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->quorum) < 0) return -1; if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->replications) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -1650,6 +1631,7 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->quorum) < 0) return -1; if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); diff --git a/source/common/src/tmsgcb.c b/source/common/src/tmsgcb.c index e90634a604..cb5e2b07c1 100644 --- a/source/common/src/tmsgcb.c +++ b/source/common/src/tmsgcb.c @@ -32,10 +32,6 @@ int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq) { return (*pMsgCb->sendReqFp)(pMsgCb->pWrapper, epSet, pReq); } -int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq) { - return (*pMsgCb->sendMnodeReqFp)(pMsgCb->pWrapper, pReq); -} - void tmsgSendRsp(const SRpcMsg* pRsp) { return (*tsDefaultMsgCb.sendRspFp)(tsDefaultMsgCb.pWrapper, pRsp); } void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg) { diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 510a2809e7..a65352f2b9 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -361,6 +361,18 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) { return 0; } +char getPrecisionUnit(int32_t precision) { + static char units[3] = {TIME_UNIT_MILLISECOND, TIME_UNIT_MICROSECOND, TIME_UNIT_NANOSECOND}; + switch (precision) { + case TSDB_TIME_PRECISION_MILLI: + case TSDB_TIME_PRECISION_MICRO: + case TSDB_TIME_PRECISION_NANO: + return units[precision]; + default: + return 0; + } +} + int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) { assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO || fromPrecision == TSDB_TIME_PRECISION_NANO); @@ -370,6 +382,33 @@ int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrec return (int64_t)((double)time * factors[fromPrecision][toPrecision]); } +int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit) { + assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO || + fromPrecision == TSDB_TIME_PRECISION_NANO); + static double factors[3] = {1000000., 1000., 1.}; + switch (toUnit) { + case 's': + return time * factors[fromPrecision] / NANOSECOND_PER_SEC; + case 'm': + return time * factors[fromPrecision] / NANOSECOND_PER_MINUTE; + case 'h': + return time * factors[fromPrecision] / NANOSECOND_PER_HOUR; + case 'd': + return time * factors[fromPrecision] / NANOSECOND_PER_DAY; + case 'w': + return time * factors[fromPrecision] / NANOSECOND_PER_WEEK; + case 'a': + return time * factors[fromPrecision] / NANOSECOND_PER_MSEC; + case 'u': + return time * factors[fromPrecision] / NANOSECOND_PER_USEC; + case 'b': + return time * factors[fromPrecision]; + default: { + return -1; + } + } +} + static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) { switch (unit) { case 's': @@ -688,4 +727,4 @@ void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) length += (int32_t)strftime(ts + length, 40 - length, "%z", ptm); tstrncpy(buf, ts, bufLen); -} \ No newline at end of file +} diff --git a/source/common/src/ttypes.c b/source/common/src/ttypes.c index 0c1bafbeb8..ef75adeb5d 100644 --- a/source/common/src/ttypes.c +++ b/source/common/src/ttypes.c @@ -431,7 +431,7 @@ FORCE_INLINE void *getDataMax(int32_t type) { } } -bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_UBIGINT; } +bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type < TSDB_DATA_TYPE_MAX; } void setVardataNull(void *val, int32_t type) { if (type == TSDB_DATA_TYPE_BINARY) { diff --git a/source/dnode/mgmt/bm/src/bmInt.c b/source/dnode/mgmt/bm/src/bmInt.c index 4b87f4463c..4ca7afbb6d 100644 --- a/source/dnode/mgmt/bm/src/bmInt.c +++ b/source/dnode/mgmt/bm/src/bmInt.c @@ -19,12 +19,7 @@ static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { - SMsgCb msgCb = {0}; - msgCb.pWrapper = pMgmt->pWrapper; - msgCb.sendReqFp = dndSendReqToDnode; - msgCb.sendMnodeReqFp = dndSendReqToMnode; - msgCb.sendRspFp = dndSendRsp; - msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; + SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/dm/src/dmFile.c b/source/dnode/mgmt/dm/src/dmFile.c index 444f18e6e0..d5105bcb1b 100644 --- a/source/dnode/mgmt/dm/src/dmFile.c +++ b/source/dnode/mgmt/dm/src/dmFile.c @@ -200,7 +200,7 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { taosMemoryFree(content); char realfile[PATH_MAX]; - snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pMgmt->path, TD_DIRSEP); if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/dnode/mgmt/dm/src/dmMsg.c b/source/dnode/mgmt/dm/src/dmMsg.c index b08657d4dc..2167e16248 100644 --- a/source/dnode/mgmt/dm/src/dmMsg.c +++ b/source/dnode/mgmt/dm/src/dmMsg.c @@ -53,7 +53,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { tSerializeSStatusReq(pHead, contLen, &req); taosArrayDestroy(req.pVloads); - SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)9527}; + SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; pMgmt->statusSent = 1; dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); diff --git a/source/dnode/mgmt/main/exe/dndMain.c b/source/dnode/mgmt/main/exe/dndMain.c index 1dcb312724..c6a109d62a 100644 --- a/source/dnode/mgmt/main/exe/dndMain.c +++ b/source/dnode/mgmt/main/exe/dndMain.c @@ -30,33 +30,26 @@ static struct { } global = {0}; static void dndStopDnode(int signum, void *info, void *ctx) { - dInfo("signal:%d is received", signum); SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); if (pDnode != NULL) { dndHandleEvent(pDnode, DND_EVENT_STOP); } } -static void dndHandleChild(int signum, void *info, void *ctx) { - dInfo("signal:%d is received", signum); - dndHandleEvent(global.pDnode, DND_EVENT_CHILD); -} - static void dndSetSignalHandle() { taosSetSignal(SIGTERM, dndStopDnode); taosSetSignal(SIGHUP, dndStopDnode); taosSetSignal(SIGINT, dndStopDnode); + taosSetSignal(SIGTSTP, dndStopDnode); taosSetSignal(SIGABRT, dndStopDnode); taosSetSignal(SIGBREAK, dndStopDnode); + taosSetSignal(SIGQUIT, dndStopDnode); if (!tsMultiProcess) { - // Set the single process signal - } else if (global.ntype == DNODE) { - // When the child process exits, the parent process receives a signal - taosSetSignal(SIGCHLD, dndHandleChild); + } else if (global.ntype == DNODE || global.ntype == NODE_MAX) { + taosIgnSignal(SIGCHLD); } else { - // When the parent process exits, the child process will receive the SIGKILL signal - taosKillChildOnSelfStopped(); + taosKillChildOnParentStopped(); } } @@ -77,14 +70,14 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { tstrncpy(global.apolloUrl, argv[++i], PATH_MAX); } else if (strcmp(argv[i], "-e") == 0) { tstrncpy(global.envFile, argv[++i], PATH_MAX); - } else if (strcmp(argv[i], "-k") == 0) { - global.generateGrant = true; } else if (strcmp(argv[i], "-n") == 0) { global.ntype = atoi(argv[++i]); if (global.ntype <= DNODE || global.ntype > NODE_MAX) { - printf("'-n' range is [1-5], default is 0\n"); + printf("'-n' range is [1 - %d], default is 0\n", NODE_MAX - 1); return -1; } + } else if (strcmp(argv[i], "-k") == 0) { + global.generateGrant = true; } else if (strcmp(argv[i], "-C") == 0) { global.dumpConfig = true; } else if (strcmp(argv[i], "-V") == 0) { @@ -140,23 +133,24 @@ static int32_t dndInitLog() { return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); } -static void dndSetProcName(char **argv) { - if (global.ntype != DNODE) { +static void dndSetProcInfo(int32_t argc, char **argv) { + taosSetProcPath(argc, argv); + if (global.ntype != DNODE && global.ntype != NODE_MAX) { const char *name = dndNodeProcStr(global.ntype); - taosSetProcName(argv, name); + taosSetProcName(argc, argv, name); } } static int32_t dndRunDnode() { if (dndInit() != 0) { - dError("failed to initialize environment since %s", terrstr()); + dError("failed to init environment since %s", terrstr()); return -1; } SDnodeOpt option = dndGetOpt(); SDnode *pDnode = dndCreate(&option); if (pDnode == NULL) { - dError("failed to to create dnode object since %s", terrstr()); + dError("failed to to create dnode since %s", terrstr()); return -1; } else { global.pDnode = pDnode; @@ -213,6 +207,6 @@ int main(int argc, char const *argv[]) { return 0; } - dndSetProcName((char **)argv); + dndSetProcInfo(argc, (char **)argv); return dndRunDnode(); } diff --git a/source/dnode/mgmt/main/inc/dnd.h b/source/dnode/mgmt/main/inc/dnd.h index 7e87d26af4..f3a409f257 100644 --- a/source/dnode/mgmt/main/inc/dnd.h +++ b/source/dnode/mgmt/main/inc/dnd.h @@ -134,32 +134,42 @@ typedef struct SDnode { SMgmtWrapper wrappers[NODE_MAX]; } SDnode; +// dndFile.h +int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); +int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); + +// dndInt.h +EDndStatus dndGetStatus(SDnode *pDnode); +void dndSetStatus(SDnode *pDnode, EDndStatus stat); +void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType nodeType); +int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); +void dndReleaseWrapper(SMgmtWrapper *pWrapper); + +// dndMonitor.h +void dndSendMonitorReport(SDnode *pDnode); + +// dndMsg.h +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg); + +// dndStr.h +const char *dndStatStr(EDndStatus stat); const char *dndNodeLogStr(ENodeType ntype); const char *dndNodeProcStr(ENodeType ntype); -EDndStatus dndGetStatus(SDnode *pDnode); -void dndSetStatus(SDnode *pDnode, EDndStatus stat); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndSendMonitorReport(SDnode *pDnode); +const char *dndEventStr(EDndEvent ev); +// dndTransport.h int32_t dndInitServer(SDnode *pDnode); void dndCleanupServer(SDnode *pDnode); int32_t dndInitClient(SDnode *pDnode); void dndCleanupClient(SDnode *pDnode); -int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg); int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); -int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg); +int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg); void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); -int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); -int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); - -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType nodeType); -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); -void dndReleaseWrapper(SMgmtWrapper *pWrapper); - #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/main/inc/dndInt.h b/source/dnode/mgmt/main/inc/dndInt.h index 612d35d513..0c4ada1df3 100644 --- a/source/dnode/mgmt/main/inc/dndInt.h +++ b/source/dnode/mgmt/main/inc/dndInt.h @@ -29,26 +29,24 @@ extern "C" { #endif -// dndInt.c -int32_t dndInit(); -void dndCleanup(); -const char *dndStatStr(EDndStatus stat); -void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup); -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); +// dndEnv.h +int32_t dndInit(); +void dndCleanup(); -// dndMsg.c -void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, SEpSet *pEpSet); - -// dndExec.c +// dndExec.h int32_t dndOpenNode(SMgmtWrapper *pWrapper); void dndCloseNode(SMgmtWrapper *pWrapper); int32_t dndRun(SDnode *pDnode); -// dndObj.c +// dndInt.c SDnode *dndCreate(const SDnodeOpt *pOption); void dndClose(SDnode *pDnode); void dndHandleEvent(SDnode *pDnode, EDndEvent event); +// dndMsg.c +void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, SEpSet *pEpSet); +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); + // dndTransport.c int32_t dndInitMsgHandle(SDnode *pDnode); void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); diff --git a/source/dnode/mgmt/main/src/dndEnv.c b/source/dnode/mgmt/main/src/dndEnv.c new file mode 100644 index 0000000000..9f75594335 --- /dev/null +++ b/source/dnode/mgmt/main/src/dndEnv.c @@ -0,0 +1,59 @@ +/* + * 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 "dndInt.h" +#include "wal.h" + +static int8_t once = DND_ENV_INIT; + +int32_t dndInit() { + dDebug("start to init dnode env"); + if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) { + terrno = TSDB_CODE_REPEAT_INIT; + dError("failed to init dnode env since %s", terrstr()); + return -1; + } + + taosIgnSIGPIPE(); + taosBlockSIGPIPE(); + taosResolveCRC(); + + SMonCfg monCfg = {0}; + monCfg.maxLogs = tsMonitorMaxLogs; + monCfg.port = tsMonitorPort; + monCfg.server = tsMonitorFqdn; + monCfg.comp = tsMonitorComp; + if (monInit(&monCfg) != 0) { + dError("failed to init monitor since %s", terrstr()); + return -1; + } + + dInfo("dnode env is initialized"); + return 0; +} + +void dndCleanup() { + dDebug("start to cleanup dnode env"); + if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) { + dError("dnode env is already cleaned up"); + return; + } + + monCleanup(); + walCleanUp(); + taosStopCacheRefreshWorker(); + dInfo("dnode env is cleaned up"); +} diff --git a/source/dnode/mgmt/main/src/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c index d74adf45d1..8837da6d48 100644 --- a/source/dnode/mgmt/main/src/dndExec.c +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -17,12 +17,12 @@ #include "dndInt.h" static bool dndRequireNode(SMgmtWrapper *pWrapper) { - bool required = false; - int32_t code =(*pWrapper->fp.requiredFp)(pWrapper, &required); + bool required = false; + int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required); if (!required) { - dDebug("node:%s, no need to start", pWrapper->name); + dDebug("node:%s, does not require startup", pWrapper->name); } else { - dDebug("node:%s, need to start", pWrapper->name); + dDebug("node:%s, needs to be started", pWrapper->name); } return required; } @@ -45,7 +45,7 @@ int32_t dndOpenNode(SMgmtWrapper *pWrapper) { } void dndCloseNode(SMgmtWrapper *pWrapper) { - dDebug("node:%s, start to close", pWrapper->name); + dDebug("node:%s, mgmt start to close", pWrapper->name); pWrapper->required = false; taosWLockLatch(&pWrapper->latch); if (pWrapper->deployed) { @@ -62,37 +62,7 @@ void dndCloseNode(SMgmtWrapper *pWrapper) { taosProcCleanup(pWrapper->pProc); pWrapper->pProc = NULL; } - dDebug("node:%s, has been closed", pWrapper->name); -} - -static int32_t dndRunInSingleProcess(SDnode *pDnode) { - dInfo("dnode start to run in single process"); - - for (ENodeType n = DNODE; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); - if (!pWrapper->required) continue; - - if (dndOpenNode(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dndSetStatus(pDnode, DND_STAT_RUNNING); - - for (ENodeType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pWrapper->fp.startFp == NULL) continue; - if ((*pWrapper->fp.startFp)(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dInfo("dnode running in single process"); - return 0; + dDebug("node:%s, mgmt has been closed", pWrapper->name); } static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, @@ -120,10 +90,10 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, ProcFuncType ftype) { pMsg->pCont = pCont; - dTrace("msg:%p, get from parent queue, handle:%p app:%p", pMsg, pMsg->handle, pMsg->ahandle); + dTrace("msg:%p, get from parent queue, ftype:%d handle:%p, app:%p", pMsg, ftype, pMsg->handle, pMsg->ahandle); switch (ftype) { - case PROC_REG: + case PROC_REGIST: rpcRegisterBrokenLinkArg(pMsg); break; case PROC_RELEASE: @@ -131,17 +101,99 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t rpcFreeCont(pCont); break; case PROC_REQ: - // todo send to dnode dndSendReqToMnode(pWrapper, pMsg); - default: + // dndSendReq(pWrapper, (const SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); + break; + case PROC_RSP: dndSendRpcRsp(pWrapper, pMsg); break; + default: + break; } taosMemoryFree(pMsg); } +static int32_t dndNewProc(SMgmtWrapper *pWrapper, ENodeType n) { + char tstr[8] = {0}; + char *args[6] = {0}; + snprintf(tstr, sizeof(tstr), "%d", n); + args[1] = "-c"; + args[2] = configDir; + args[3] = "-n"; + args[4] = tstr; + args[5] = NULL; + + int32_t pid = taosNewProc(args); + if (pid <= 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr()); + return -1; + } + + pWrapper->procId = pid; + dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid); + return 0; +} + +static SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { + SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, + .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, + .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, + .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, + .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, + .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, + .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, + .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, + .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, + .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, + .shm = pWrapper->shm, + .pParent = pWrapper, + .name = pWrapper->name}; + return cfg; +} + +static int32_t dndRunInSingleProcess(SDnode *pDnode) { + dInfo("dnode run in single process"); + + for (ENodeType n = DNODE; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + pWrapper->required = dndRequireNode(pWrapper); + if (!pWrapper->required) continue; + + if (dndOpenNode(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + + dndSetStatus(pDnode, DND_STAT_RUNNING); + + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (pWrapper->fp.startFp == NULL) continue; + if ((*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + + dInfo("TDengine initialized successfully"); + dndReportStartup(pDnode, "TDengine", "initialized successfully"); + while (1) { + if (pDnode->event == DND_EVENT_STOP) { + dInfo("dnode is about to stop"); + dndSetStatus(pDnode, DND_STAT_STOPPED); + break; + } + taosMsleep(100); + } + + return 0; +} + static int32_t dndRunInParentProcess(SDnode *pDnode) { - dInfo("dnode start to run in parent process"); + dInfo("dnode run in parent process"); SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE]; if (dndOpenNode(pDWrapper) != 0) { dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); @@ -153,28 +205,16 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { pWrapper->required = dndRequireNode(pWrapper); if (!pWrapper->required) continue; - int64_t shmsize = 1024 * 1024 * 2; // size will be a configuration item - if (taosCreateShm(&pWrapper->shm, shmsize) != 0) { + int32_t shmsize = 1024 * 1024 * 2; // size will be a configuration item + if (taosCreateShm(&pWrapper->shm, n, shmsize) != 0) { terrno = TAOS_SYSTEM_ERROR(terrno); - dError("node:%s, failed to create shm size:%" PRId64 " since %s", pWrapper->name, shmsize, terrstr()); + dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr()); return -1; } + dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize); - SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, - .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, - .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, - .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, - .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, - .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, - .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .shm = pWrapper->shm, - .pParent = pWrapper, - .isChild = false, - .name = pWrapper->name}; - + SProcCfg cfg = dndGenProcCfg(pWrapper); + cfg.isChild = false; pWrapper->procType = PROC_PARENT; pWrapper->pProc = taosProcInit(&cfg); if (pWrapper->pProc == NULL) { @@ -195,15 +235,9 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { if (pDnode->ntype == NODE_MAX) { dInfo("node:%s, should be started manually", pWrapper->name); } else { - char args[PATH_MAX]; - int32_t pid = taosNewProc(args); - if (pid <= 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr()); + if (dndNewProc(pWrapper, n) != 0) { return -1; } - pWrapper->procId = pid; - dInfo("node:%s, run in new process, pid:%d", pWrapper->name, pid); } if (taosProcRun(pWrapper->pProc) != 0) { @@ -219,13 +253,56 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { return -1; } - dInfo("dnode running in parent process"); + dInfo("TDengine initialized successfully"); + dndReportStartup(pDnode, "TDengine", "initialized successfully"); + + while (1) { + if (pDnode->event == DND_EVENT_STOP) { + dInfo("dnode is about to stop"); + dndSetStatus(pDnode, DND_STAT_STOPPED); + + for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (pDnode->ntype == NODE_MAX) continue; + + if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { + dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); + taosKillProc(pWrapper->procId); + dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); + taosWaitProc(pWrapper->procId); + dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId); + } + } + break; + } else { + for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (pDnode->ntype == NODE_MAX) continue; + + if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { + dInfo("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); + dndNewProc(pWrapper, n); + } + } + } + + taosMsleep(100); + } + return 0; } static int32_t dndRunInChildProcess(SDnode *pDnode) { - dInfo("dnode start to run in child process"); SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; + dInfo("%s run in child process", pWrapper->name); + + pWrapper->required = dndRequireNode(pWrapper); + if (!pWrapper->required) { + dError("%s does not require startup", pWrapper->name); + return -1; + } SMsgCb msgCb = dndCreateMsgcb(pWrapper); tmsgSetDefaultMsgCb(&msgCb); @@ -236,21 +313,8 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { return -1; } - SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, - .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, - .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, - .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, - .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, - .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, - .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .shm = pWrapper->shm, - .pParent = pWrapper, - .isChild = true, - .name = pWrapper->name}; - + SProcCfg cfg = dndGenProcCfg(pWrapper); + cfg.isChild = true; pWrapper->pProc = taosProcInit(&cfg); if (pWrapper->pProc == NULL) { dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); @@ -264,39 +328,19 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { } } + dndSetStatus(pDnode, DND_STAT_RUNNING); + if (taosProcRun(pWrapper->pProc) != 0) { dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); return -1; } - dInfo("dnode running in child process"); - return 0; -} - -int32_t dndRun(SDnode * pDnode) { - if (!tsMultiProcess) { - if (dndRunInSingleProcess(pDnode) != 0) { - dError("failed to run dnode since %s", terrstr()); - return -1; - } - } else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { - if (dndRunInParentProcess(pDnode) != 0) { - dError("failed to run dnode in parent process since %s", terrstr()); - return -1; - } - } else { - if (dndRunInChildProcess(pDnode) != 0) { - dError("failed to run dnode in child process since %s", terrstr()); - return -1; - } - } - - dndReportStartup(pDnode, "TDengine", "initialized successfully"); dInfo("TDengine initialized successfully"); - + dndReportStartup(pDnode, "TDengine", "initialized successfully"); while (1) { if (pDnode->event == DND_EVENT_STOP) { - dInfo("dnode is about to stop"); + dInfo("%s is about to stop", pWrapper->name); + dndSetStatus(pDnode, DND_STAT_STOPPED); break; } taosMsleep(100); @@ -304,3 +348,15 @@ int32_t dndRun(SDnode * pDnode) { return 0; } + +int32_t dndRun(SDnode *pDnode) { + if (!tsMultiProcess) { + return dndRunInSingleProcess(pDnode); + } else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { + return dndRunInParentProcess(pDnode); + } else { + return dndRunInChildProcess(pDnode); + } + + return 0; +} diff --git a/source/dnode/mgmt/main/src/dndFile.c b/source/dnode/mgmt/main/src/dndFile.c index 0214cf33d4..92e6cea3e1 100644 --- a/source/dnode/mgmt/main/src/dndFile.c +++ b/source/dnode/mgmt/main/src/dndFile.c @@ -179,7 +179,7 @@ int32_t dndReadShmFile(SDnode *pDnode) { } } - if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == DNODE) { + if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { for (ENodeType ntype = DNODE; ntype < NODE_MAX; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; if (pWrapper->shm.id >= 0) { @@ -194,10 +194,10 @@ int32_t dndReadShmFile(SDnode *pDnode) { dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr()); goto _OVER; } - dDebug("shmid:%d, is attached, size:%d", pWrapper->shm.id, pWrapper->shm.size); + dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->shm.id, pWrapper->shm.size); } - dDebug("successed to open %s", file); + dDebug("successed to load %s", file); code = 0; _OVER: diff --git a/source/dnode/mgmt/main/src/dndInt.c b/source/dnode/mgmt/main/src/dndInt.c index 8792147822..25e4d89c5b 100644 --- a/source/dnode/mgmt/main/src/dndInt.c +++ b/source/dnode/mgmt/main/src/dndInt.c @@ -15,47 +15,179 @@ #define _DEFAULT_SOURCE #include "dndInt.h" -#include "wal.h" -static int8_t once = DND_ENV_INIT; +static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { + pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes; + pDnode->serverPort = pOption->serverPort; + pDnode->dataDir = strdup(pOption->dataDir); + pDnode->localEp = strdup(pOption->localEp); + pDnode->localFqdn = strdup(pOption->localFqdn); + pDnode->firstEp = strdup(pOption->firstEp); + pDnode->secondEp = strdup(pOption->secondEp); + pDnode->disks = pOption->disks; + pDnode->numOfDisks = pOption->numOfDisks; + pDnode->ntype = pOption->ntype; + pDnode->rebootTime = taosGetTimestampMs(); -int32_t dndInit() { - dDebug("start to init dnode env"); - if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) { - terrno = TSDB_CODE_REPEAT_INIT; - dError("failed to init dnode env since %s", terrstr()); + if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL || + pDnode->secondEp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - taosIgnSIGPIPE(); - taosBlockSIGPIPE(); - taosResolveCRC(); - - SMonCfg monCfg = {0}; - monCfg.maxLogs = tsMonitorMaxLogs; - monCfg.port = tsMonitorPort; - monCfg.server = tsMonitorFqdn; - monCfg.comp = tsMonitorComp; - if (monInit(&monCfg) != 0) { - dError("failed to init monitor since %s", terrstr()); - return -1; + if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { + pDnode->lockfile = dndCheckRunning(pDnode->dataDir); + if (pDnode->lockfile == NULL) { + return -1; + } } - dInfo("dnode env is initialized"); return 0; } -void dndCleanup() { - dDebug("start to cleanup dnode env"); - if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) { - dError("dnode env is already cleaned up"); - return; +static void dndClearVars(SDnode *pDnode) { + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; + taosMemoryFreeClear(pMgmt->path); + } + if (pDnode->lockfile != NULL) { + taosUnLockFile(pDnode->lockfile); + taosCloseFile(&pDnode->lockfile); + pDnode->lockfile = NULL; + } + taosMemoryFreeClear(pDnode->localEp); + taosMemoryFreeClear(pDnode->localFqdn); + taosMemoryFreeClear(pDnode->firstEp); + taosMemoryFreeClear(pDnode->secondEp); + taosMemoryFreeClear(pDnode->dataDir); + taosMemoryFree(pDnode); + dDebug("dnode memory is cleared, data:%p", pDnode); +} + +SDnode *dndCreate(const SDnodeOpt *pOption) { + dDebug("start to create dnode object"); + int32_t code = -1; + char path[PATH_MAX] = {0}; + SDnode *pDnode = NULL; + + pDnode = taosMemoryCalloc(1, sizeof(SDnode)); + if (pDnode == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; } - monCleanup(); - walCleanUp(); - taosStopCacheRefreshWorker(); - dInfo("dnode env is cleaned up"); + if (dndInitVars(pDnode, pOption) != 0) { + dError("failed to init variables since %s", terrstr()); + goto _OVER; + } + + dndSetStatus(pDnode, DND_STAT_INIT); + dmGetMgmtFp(&pDnode->wrappers[DNODE]); + mmGetMgmtFp(&pDnode->wrappers[MNODE]); + vmGetMgmtFp(&pDnode->wrappers[VNODES]); + qmGetMgmtFp(&pDnode->wrappers[QNODE]); + smGetMgmtFp(&pDnode->wrappers[SNODE]); + bmGetMgmtFp(&pDnode->wrappers[BNODE]); + + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name); + pWrapper->path = strdup(path); + pWrapper->shm.id = -1; + pWrapper->pDnode = pDnode; + if (pWrapper->path == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + + pWrapper->procType = PROC_SINGLE; + taosInitRWLatch(&pWrapper->latch); + } + + if (dndInitMsgHandle(pDnode) != 0) { + dError("failed to msg handles since %s", terrstr()); + goto _OVER; + } + + if (dndReadShmFile(pDnode) != 0) { + dError("failed to read shm file since %s", terrstr()); + goto _OVER; + } + + SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]); + tmsgSetDefaultMsgCb(&msgCb); + + dInfo("dnode is created, data:%p", pDnode); + code = 0; + +_OVER: + if (code != 0 && pDnode) { + dndClearVars(pDnode); + pDnode = NULL; + dError("failed to create dnode since %s", terrstr()); + } + + return pDnode; +} + +void dndClose(SDnode *pDnode) { + if (pDnode == NULL) return; + + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + dndCloseNode(pWrapper); + } + + dndClearVars(pDnode); + dInfo("dnode is closed, data:%p", pDnode); +} + +void dndHandleEvent(SDnode *pDnode, EDndEvent event) { + if (event == DND_EVENT_STOP) { + pDnode->event = event; + } +} + +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType ntype) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; + SMgmtWrapper *pRetWrapper = pWrapper; + + taosRLockLatch(&pWrapper->latch); + if (pWrapper->deployed) { + int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); + dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); + } else { + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + pRetWrapper = NULL; + } + taosRUnLockLatch(&pWrapper->latch); + + return pRetWrapper; +} + +int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { + int32_t code = 0; + + taosRLockLatch(&pWrapper->latch); + if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) { + int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); + dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); + } else { + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + code = -1; + } + taosRUnLockLatch(&pWrapper->latch); + + return code; +} + +void dndReleaseWrapper(SMgmtWrapper *pWrapper) { + if (pWrapper == NULL) return; + + taosRLockLatch(&pWrapper->latch); + int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1); + taosRUnLockLatch(&pWrapper->latch); + dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); } void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { @@ -71,26 +203,3 @@ void dndSetStatus(SDnode *pDnode, EDndStatus status) { pDnode->status = status; } } - -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { - SStartupReq *pStartup = &pDnode->startup; - tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); - tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); - pStartup->finished = 0; -} - -void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { - memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); - pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); -} - -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { - dDebug("startup req is received"); - SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); - dndGetStartup(pDnode, pStartup); - - dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); - SRpcMsg rpcRsp = { - .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; - rpcSendResponse(&rpcRsp); -} diff --git a/source/dnode/mgmt/main/src/dndMsg.c b/source/dnode/mgmt/main/src/dndMsg.c index 3aafa5a5e3..bb0f8ccb89 100644 --- a/source/dnode/mgmt/main/src/dndMsg.c +++ b/source/dnode/mgmt/main/src/dndMsg.c @@ -66,8 +66,8 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); code = (*msgFp)(pWrapper, pMsg); } else if (pWrapper->procType == PROC_PARENT) { - dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle, - pRpc->ahandle, pMsg->user); + dTrace("msg:%p, is created and put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, + pMsg->user); code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, PROC_REQ); } else { dTrace("msg:%p, should not processed in child process, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, @@ -171,4 +171,27 @@ int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg) { terrno = TSDB_CODE_MSG_NOT_PROCESSED; return -1; } -} \ No newline at end of file +} + +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { + SStartupReq *pStartup = &pDnode->startup; + tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); + tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); + pStartup->finished = 0; +} + +void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { + memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); + pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); +} + +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { + dDebug("startup req is received"); + SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); + dndGetStartup(pDnode, pStartup); + + dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); + SRpcMsg rpcRsp = { + .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; + rpcSendResponse(&rpcRsp); +} diff --git a/source/dnode/mgmt/main/src/dndObj.c b/source/dnode/mgmt/main/src/dndObj.c deleted file mode 100644 index 44013deed8..0000000000 --- a/source/dnode/mgmt/main/src/dndObj.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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 "dndInt.h" - -static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { - pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes; - pDnode->serverPort = pOption->serverPort; - pDnode->dataDir = strdup(pOption->dataDir); - pDnode->localEp = strdup(pOption->localEp); - pDnode->localFqdn = strdup(pOption->localFqdn); - pDnode->firstEp = strdup(pOption->firstEp); - pDnode->secondEp = strdup(pOption->secondEp); - pDnode->disks = pOption->disks; - pDnode->numOfDisks = pOption->numOfDisks; - pDnode->ntype = pOption->ntype; - pDnode->rebootTime = taosGetTimestampMs(); - - if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL || - pDnode->secondEp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { - pDnode->lockfile = dndCheckRunning(pDnode->dataDir); - if (pDnode->lockfile == NULL) { - return -1; - } - } - - return 0; -} - -static void dndClearVars(SDnode *pDnode) { - for (ENodeType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; - taosMemoryFreeClear(pMgmt->path); - } - if (pDnode->lockfile != NULL) { - taosUnLockFile(pDnode->lockfile); - taosCloseFile(&pDnode->lockfile); - pDnode->lockfile = NULL; - } - taosMemoryFreeClear(pDnode->localEp); - taosMemoryFreeClear(pDnode->localFqdn); - taosMemoryFreeClear(pDnode->firstEp); - taosMemoryFreeClear(pDnode->secondEp); - taosMemoryFreeClear(pDnode->dataDir); - taosMemoryFree(pDnode); - dDebug("dnode object memory is cleared, data:%p", pDnode); -} - -SDnode *dndCreate(const SDnodeOpt *pOption) { - dDebug("start to create dnode object"); - int32_t code = -1; - char path[PATH_MAX] = {0}; - SDnode *pDnode = NULL; - - pDnode = taosMemoryCalloc(1, sizeof(SDnode)); - if (pDnode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _OVER; - } - - if (dndInitVars(pDnode, pOption) != 0) { - dError("failed to init variables since %s", terrstr()); - goto _OVER; - } - - dndSetStatus(pDnode, DND_STAT_INIT); - dmGetMgmtFp(&pDnode->wrappers[DNODE]); - mmGetMgmtFp(&pDnode->wrappers[MNODE]); - vmGetMgmtFp(&pDnode->wrappers[VNODES]); - qmGetMgmtFp(&pDnode->wrappers[QNODE]); - smGetMgmtFp(&pDnode->wrappers[SNODE]); - bmGetMgmtFp(&pDnode->wrappers[BNODE]); - - for (ENodeType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name); - pWrapper->path = strdup(path); - pWrapper->shm.id = -1; - pWrapper->pDnode = pDnode; - if (pWrapper->path == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _OVER; - } - - pWrapper->procType = PROC_SINGLE; - taosInitRWLatch(&pWrapper->latch); - } - - if (dndInitMsgHandle(pDnode) != 0) { - dError("failed to msg handles since %s", terrstr()); - goto _OVER; - } - - if (dndReadShmFile(pDnode) != 0) { - dError("failed to read shm file since %s", terrstr()); - goto _OVER; - } - - SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]); - tmsgSetDefaultMsgCb(&msgCb); - - dInfo("dnode object is created, data:%p", pDnode); - code = 0; - -_OVER: - if (code != 0 && pDnode) { - dndClearVars(pDnode); - pDnode = NULL; - dError("failed to create dnode object since %s", terrstr()); - } - - return pDnode; -} - -void dndClose(SDnode *pDnode) { - if (pDnode == NULL) return; - - if (dndGetStatus(pDnode) == DND_STAT_STOPPED) { - dError("dnode is shutting down, data:%p", pDnode); - return; - } - - dInfo("start to close dnode, data:%p", pDnode); - dndSetStatus(pDnode, DND_STAT_STOPPED); - - for (ENodeType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - dndCloseNode(pWrapper); - } - - dndClearVars(pDnode); - dInfo("dnode object is closed, data:%p", pDnode); -} - -void dndHandleEvent(SDnode *pDnode, EDndEvent event) { - dInfo("dnode object receive event %d, data:%p", event, pDnode); - pDnode->event = event; -} - -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - SMgmtWrapper *pRetWrapper = pWrapper; - - taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed) { - int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); - dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); - } else { - terrno = TSDB_CODE_NODE_NOT_DEPLOYED; - pRetWrapper = NULL; - } - taosRUnLockLatch(&pWrapper->latch); - - return pRetWrapper; -} - -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { - int32_t code = 0; - - taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) { - int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); - dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); - } else { - terrno = TSDB_CODE_NODE_NOT_DEPLOYED; - code = -1; - } - taosRUnLockLatch(&pWrapper->latch); - - return code; -} - -void dndReleaseWrapper(SMgmtWrapper *pWrapper) { - if (pWrapper == NULL) return; - - taosRLockLatch(&pWrapper->latch); - int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1); - taosRUnLockLatch(&pWrapper->latch); - dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); -} \ No newline at end of file diff --git a/source/dnode/mgmt/main/src/dndStr.c b/source/dnode/mgmt/main/src/dndStr.c index 00d8b0d6e0..8a5af68b4f 100644 --- a/source/dnode/mgmt/main/src/dndStr.c +++ b/source/dnode/mgmt/main/src/dndStr.c @@ -62,3 +62,16 @@ const char *dndNodeProcStr(ENodeType ntype) { return "taosd"; } } + +const char *dndEventStr(EDndEvent ev) { + switch (ev) { + case DND_EVENT_START: + return "start"; + case DND_EVENT_STOP: + return "stop"; + case DND_EVENT_CHILD: + return "child"; + default: + return "UNKNOWN"; + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/main/src/dndTransport.c b/source/dnode/mgmt/main/src/dndTransport.c index 6398af21dc..d463f2ba7a 100644 --- a/source/dnode/mgmt/main/src/dndTransport.c +++ b/source/dnode/mgmt/main/src/dndTransport.c @@ -319,23 +319,6 @@ static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *p return 0; } -int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { - if (pWrapper->procType != PROC_CHILD) { - SDnode *pDnode = pWrapper->pDnode; - if (dndGetStatus(pDnode) != DND_STAT_RUNNING) { - terrno = TSDB_CODE_DND_OFFLINE; - dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle); - return -1; - } - return dndSendRpcReq(&pDnode->trans, pEpSet, pReq); - } else { - while (taosProcPutToParentQ(pWrapper->pProc, pReq, sizeof(SRpcMsg), pReq->pCont, pReq->contLen, PROC_REQ) != 0) { - taosMsleep(1); - } - } - return TSDB_CODE_SUCCESS; -} - int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pReq) { SDnode *pDnode = pWrapper->pDnode; STransMgmt *pTrans = &pDnode->trans; @@ -363,13 +346,37 @@ void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { } } +int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { + SDnode *pDnode = pWrapper->pDnode; + if (dndGetStatus(pDnode) != DND_STAT_RUNNING) { + terrno = TSDB_CODE_DND_OFFLINE; + dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle); + return -1; + } + + if (pWrapper->procType != PROC_CHILD) { + return dndSendRpcReq(&pDnode->trans, pEpSet, pReq); + } else { + int32_t headLen = sizeof(SRpcMsg) + sizeof(SEpSet); + char *pHead = taosMemoryMalloc(headLen); + if (pHead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + memcpy(pHead, pReq, sizeof(SRpcMsg)); + memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet)); + + taosProcPutToParentQ(pWrapper->pProc, pReq, headLen, pReq->pCont, pReq->contLen, PROC_REQ); + taosMemoryFree(pHead); + return 0; + } +} + void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { if (pWrapper->procType != PROC_CHILD) { dndSendRpcRsp(pWrapper, pRsp); } else { - while (taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP) != 0) { - taosMsleep(1); - } + taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP); } } @@ -377,9 +384,7 @@ void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { if (pWrapper->procType != PROC_CHILD) { rpcRegisterBrokenLinkArg(pMsg); } else { - while (taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REG) != 0) { - taosMsleep(1); - } + taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGIST); } } @@ -388,20 +393,17 @@ static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) rpcReleaseHandle(handle, type); } else { SRpcMsg msg = {.handle = handle, .code = type}; - while (taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE) != 0) { - taosMsleep(1); - } + taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE); } } SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) { SMsgCb msgCb = { .pWrapper = pWrapper, + .sendReqFp = dndSendReq, + .sendRspFp = dndSendRsp, .registerBrokenLinkArgFp = dndRegisterBrokenLinkArg, .releaseHandleFp = dndReleaseHandle, - .sendMnodeReqFp = dndSendReqToMnode, - .sendReqFp = dndSendReqToDnode, - .sendRspFp = dndSendRsp, }; return msgCb; } \ No newline at end of file diff --git a/source/dnode/mgmt/mm/src/mmFile.c b/source/dnode/mgmt/mm/src/mmFile.c index e5cc0ce087..76aba771cb 100644 --- a/source/dnode/mgmt/mm/src/mmFile.c +++ b/source/dnode/mgmt/mm/src/mmFile.c @@ -111,7 +111,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno);; + terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); return -1; } @@ -145,7 +145,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); if (taosRenameFile(file, realfile) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno);; + terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to rename %s since %s", file, terrstr()); return -1; } diff --git a/source/dnode/mgmt/mm/src/mmInt.c b/source/dnode/mgmt/mm/src/mmInt.c index 3d15c9b9ae..301ca598e6 100644 --- a/source/dnode/mgmt/mm/src/mmInt.c +++ b/source/dnode/mgmt/mm/src/mmInt.c @@ -39,20 +39,11 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) { } static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { - SDnode *pDnode = pMgmt->pDnode; - pOption->dnodeId = pDnode->dnodeId; - pOption->clusterId = pDnode->clusterId; - - SMsgCb msgCb = {0}; - msgCb.pWrapper = pMgmt->pWrapper; + SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue; msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue; msgCb.queueFps[SYNC_QUEUE] = mmPutMsgToWriteQueue; - msgCb.sendReqFp = dndSendReqToDnode; - msgCb.sendMnodeReqFp = dndSendReqToMnode; - msgCb.sendRspFp = dndSendRsp; - msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; pOption->msgCb = msgCb; } @@ -66,6 +57,7 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { pReplica->id = 1; pReplica->port = pDnode->serverPort; tstrncpy(pReplica->fqdn, pDnode->localFqdn, TSDB_FQDN_LEN); + pOption->deploy = true; pMgmt->selfIndex = pOption->selfIndex; pMgmt->replica = pOption->replica; @@ -77,6 +69,7 @@ static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { pOption->selfIndex = pMgmt->selfIndex; pOption->replica = pMgmt->replica; memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); + pOption->deploy = false; } static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCreateMnodeReq *pCreate) { @@ -89,7 +82,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre pReplica->id = pCreate->replicas[i].id; pReplica->port = pCreate->replicas[i].port; memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); - if (pReplica->id == pOption->dnodeId) { + if (pReplica->id == pMgmt->pDnode->dnodeId) { pOption->selfIndex = i; } } @@ -98,6 +91,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre dError("failed to build mnode options since %s", terrstr()); return -1; } + pOption->deploy = true; pMgmt->selfIndex = pOption->selfIndex; pMgmt->replica = pOption->replica; @@ -225,9 +219,7 @@ int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) { return code; } -static int32_t mmOpen(SMgmtWrapper *pWrapper) { - return mmOpenFromMsg(pWrapper, NULL); -} +static int32_t mmOpen(SMgmtWrapper *pWrapper) { return mmOpenFromMsg(pWrapper, NULL); } static int32_t mmStart(SMgmtWrapper *pWrapper) { dDebug("mnode-mgmt start to run"); @@ -258,7 +250,7 @@ int32_t mmGetUserAuth(SMgmtWrapper *pWrapper, char *user, char *spi, char *encry } int32_t mmMonitorMnodeInfo(SMgmtWrapper *pWrapper, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, - SMonGrantInfo *pGrantInfo) { + SMonGrantInfo *pGrantInfo) { SMnodeMgmt *pMgmt = pWrapper->pMgmt; return mndGetMonitorInfo(pMgmt->pMnode, pClusterInfo, pVgroupInfo, pGrantInfo); } diff --git a/source/dnode/mgmt/qm/src/qmInt.c b/source/dnode/mgmt/qm/src/qmInt.c index 11c80a2904..8079859b96 100644 --- a/source/dnode/mgmt/qm/src/qmInt.c +++ b/source/dnode/mgmt/qm/src/qmInt.c @@ -19,15 +19,10 @@ static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { - SMsgCb msgCb = {0}; - msgCb.pWrapper = pMgmt->pWrapper; + SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); msgCb.queueFps[QUERY_QUEUE] = qmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = qmPutMsgToFetchQueue; msgCb.qsizeFp = qmGetQueueSize; - msgCb.sendReqFp = dndSendReqToDnode; - msgCb.sendMnodeReqFp = dndSendReqToMnode; - msgCb.sendRspFp = dndSendRsp; - msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/sm/src/smInt.c b/source/dnode/mgmt/sm/src/smInt.c index a639fc76bb..6d2e2aaefd 100644 --- a/source/dnode/mgmt/sm/src/smInt.c +++ b/source/dnode/mgmt/sm/src/smInt.c @@ -19,12 +19,7 @@ static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { - SMsgCb msgCb = {0}; - msgCb.pWrapper = pMgmt->pWrapper; - msgCb.sendReqFp = dndSendReqToDnode; - msgCb.sendMnodeReqFp = dndSendReqToMnode; - msgCb.sendRspFp = dndSendRsp; - msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; + SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/test/vnode/vnode.cpp b/source/dnode/mgmt/test/vnode/vnode.cpp index e2de3fc33a..40e7472d42 100644 --- a/source/dnode/mgmt/test/vnode/vnode.cpp +++ b/source/dnode/mgmt/test/vnode/vnode.cpp @@ -70,46 +70,6 @@ TEST_F(DndTestVnode, 01_Create_Vnode) { ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED); } } - - { - SCreateVnodeReq createReq = {0}; - createReq.vgId = 2; - createReq.dnodeId = 3; - strcpy(createReq.db, "1.d1"); - createReq.dbUid = 9527; - createReq.vgVersion = 1; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; - createReq.daysPerFile = 10; - createReq.daysToKeep0 = 3650; - createReq.daysToKeep1 = 3650; - createReq.daysToKeep2 = 3650; - createReq.minRows = 100; - createReq.minRows = 4096; - createReq.commitTime = 3600; - createReq.fsyncPeriod = 3000; - createReq.walLevel = 1; - createReq.precision = 0; - createReq.compression = 2; - createReq.replica = 1; - createReq.quorum = 1; - createReq.update = 0; - createReq.cacheLastRow = 0; - createReq.selfIndex = 0; - for (int r = 0; r < createReq.replica; ++r) { - SReplica* pReplica = &createReq.replicas[r]; - pReplica->id = 1; - pReplica->port = 9527; - } - - int32_t contLen = tSerializeSCreateVnodeReq(NULL, 0, &createReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSCreateVnodeReq(pReq, contLen, &createReq); - - SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_INVALID_OPTION); - } } TEST_F(DndTestVnode, 02_Alter_Vnode) { @@ -164,37 +124,37 @@ TEST_F(DndTestVnode, 03_Create_Stb) { req.keep = 0; req.type = TD_SUPER_TABLE; - SSchema schemas[5] = {0}; + SSchemaEx schemas[2] = {0}; { - SSchema* pSchema = &schemas[0]; + SSchemaEx* pSchema = &schemas[0]; pSchema->bytes = htonl(8); pSchema->type = TSDB_DATA_TYPE_TIMESTAMP; strcpy(pSchema->name, "ts"); } { - SSchema* pSchema = &schemas[1]; + SSchemaEx* pSchema = &schemas[1]; pSchema->bytes = htonl(4); pSchema->type = TSDB_DATA_TYPE_INT; strcpy(pSchema->name, "col1"); } - + SSchema tagSchemas[3] = {0}; { - SSchema* pSchema = &schemas[2]; + SSchema* pSchema = &tagSchemas[0]; pSchema->bytes = htonl(2); pSchema->type = TSDB_DATA_TYPE_TINYINT; strcpy(pSchema->name, "tag1"); } { - SSchema* pSchema = &schemas[3]; + SSchema* pSchema = &tagSchemas[1]; pSchema->bytes = htonl(8); pSchema->type = TSDB_DATA_TYPE_BIGINT; strcpy(pSchema->name, "tag2"); } { - SSchema* pSchema = &schemas[4]; + SSchema* pSchema = &tagSchemas[2]; pSchema->bytes = htonl(16); pSchema->type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema->name, "tag3"); @@ -204,7 +164,7 @@ TEST_F(DndTestVnode, 03_Create_Stb) { req.stbCfg.nCols = 2; req.stbCfg.pSchema = &schemas[0]; req.stbCfg.nTagCols = 3; - req.stbCfg.pTagSchema = &schemas[2]; + req.stbCfg.pTagSchema = &tagSchemas[0]; int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); SMsgHead* pHead = (SMsgHead*)rpcMallocCont(contLen); @@ -236,37 +196,37 @@ TEST_F(DndTestVnode, 04_Alter_Stb) { req.keep = 0; req.type = TD_SUPER_TABLE; - SSchema schemas[5] = {0}; + SSchemaEx schemas[2] = {0}; { - SSchema* pSchema = &schemas[0]; + SSchemaEx* pSchema = &schemas[0]; pSchema->bytes = htonl(8); pSchema->type = TSDB_DATA_TYPE_TIMESTAMP; strcpy(pSchema->name, "ts"); } { - SSchema* pSchema = &schemas[1]; + SSchemaEx* pSchema = &schemas[1]; pSchema->bytes = htonl(4); pSchema->type = TSDB_DATA_TYPE_INT; strcpy(pSchema->name, "col1"); } - + SSchema tagSchemas[3] = {0}; { - SSchema* pSchema = &schemas[2]; + SSchema* pSchema = &tagSchemas[0]; pSchema->bytes = htonl(2); pSchema->type = TSDB_DATA_TYPE_TINYINT; strcpy(pSchema->name, "_tag1"); } { - SSchema* pSchema = &schemas[3]; + SSchema* pSchema = &tagSchemas[1]; pSchema->bytes = htonl(8); pSchema->type = TSDB_DATA_TYPE_BIGINT; strcpy(pSchema->name, "_tag2"); } { - SSchema* pSchema = &schemas[4]; + SSchema* pSchema = &tagSchemas[2]; pSchema->bytes = htonl(16); pSchema->type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema->name, "_tag3"); @@ -276,7 +236,7 @@ TEST_F(DndTestVnode, 04_Alter_Stb) { req.stbCfg.nCols = 2; req.stbCfg.pSchema = &schemas[0]; req.stbCfg.nTagCols = 3; - req.stbCfg.pTagSchema = &schemas[2]; + req.stbCfg.pTagSchema = &tagSchemas[0]; int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); SMsgHead* pHead = (SMsgHead*)rpcMallocCont(contLen); diff --git a/source/dnode/mgmt/vm/src/vmInt.c b/source/dnode/mgmt/vm/src/vmInt.c index b52c6253dc..d9ef7b5ae6 100644 --- a/source/dnode/mgmt/vm/src/vmInt.c +++ b/source/dnode/mgmt/vm/src/vmInt.c @@ -128,16 +128,12 @@ static void *vmOpenVnodeFunc(void *param) { pMgmt->state.openVnodes, pMgmt->state.totalVnodes); dndReportStartup(pDnode, "open-vnodes", stepDesc); - SMsgCb msgCb = {0}; + SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; msgCb.queueFps[APPLY_QUEUE] = vmPutMsgToApplyQueue; msgCb.qsizeFp = vmGetQueueSize; - msgCb.sendReqFp = dndSendReqToDnode; - msgCb.sendMnodeReqFp = dndSendReqToMnode; - msgCb.sendRspFp = dndSendRsp; - msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; SVnodeCfg cfg = {.msgCb = msgCb, .pTfs = pMgmt->pTfs, .vgId = pCfg->vgId, .dbId = pCfg->dbUid}; SVnode *pImpl = vnodeOpen(pCfg->path, &cfg); if (pImpl == NULL) { diff --git a/source/dnode/mgmt/vm/src/vmMsg.c b/source/dnode/mgmt/vm/src/vmMsg.c index f00bb89354..c3ad74d246 100644 --- a/source/dnode/mgmt/vm/src/vmMsg.c +++ b/source/dnode/mgmt/vm/src/vmMsg.c @@ -68,12 +68,6 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { SWrapperCfg wrapperCfg = {0}; vmGenerateWrapperCfg(pMgmt, &createReq, &wrapperCfg); - if (createReq.dnodeId != pMgmt->pDnode->dnodeId) { - terrno = TSDB_CODE_DND_VNODE_INVALID_OPTION; - dDebug("vgId:%d, failed to create vnode since %s", createReq.vgId, terrstr()); - return -1; - } - SVnodeObj *pVnode = vmAcquireVnode(pMgmt, createReq.vgId); if (pVnode != NULL) { dDebug("vgId:%d, already exist", createReq.vgId); @@ -82,16 +76,12 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return -1; } - SMsgCb msgCb = {0}; + SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; msgCb.queueFps[APPLY_QUEUE] = vmPutMsgToApplyQueue; msgCb.qsizeFp = vmGetQueueSize; - msgCb.sendReqFp = dndSendReqToDnode; - msgCb.sendMnodeReqFp = dndSendReqToMnode; - msgCb.sendRspFp = dndSendRsp; - msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; vnodeCfg.msgCb = msgCb; vnodeCfg.pTfs = pMgmt->pTfs; diff --git a/source/dnode/mgmt/vm/src/vmWorker.c b/source/dnode/mgmt/vm/src/vmWorker.c index 9d62624756..4be6311cf8 100644 --- a/source/dnode/mgmt/vm/src/vmWorker.c +++ b/source/dnode/mgmt/vm/src/vmWorker.c @@ -187,7 +187,7 @@ static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueTyp SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId); if (pVnode == NULL) { dError("vgId:%d, failed to write msg:%p to vnode-queue since %s", pHead->vgId, pMsg, terrstr()); - return -1; + return terrno; } int32_t code = 0; diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h index 0206695b88..5b7bac4486 100644 --- a/source/dnode/mnode/impl/inc/mndCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -25,6 +25,7 @@ extern "C" { int32_t mndInitCluster(SMnode *pMnode); void mndCleanupCluster(SMnode *pMnode); int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len); +int64_t mndGetClusterId(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 6976d83abd..f418ec2290 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -620,13 +620,13 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub) static FORCE_INLINE void tDeleteSMqSubscribeObj(SMqSubscribeObj* pSub) { if (pSub->consumers) { - taosArrayDestroyEx(pSub->consumers, (void (*)(void*))tDeleteSMqSubConsumer); + //taosArrayDestroyEx(pSub->consumers, (void (*)(void*))tDeleteSMqSubConsumer); // taosArrayDestroy(pSub->consumers); pSub->consumers = NULL; } if (pSub->unassignedVg) { - taosArrayDestroyEx(pSub->unassignedVg, (void (*)(void*))tDeleteSMqConsumerEp); + //taosArrayDestroyEx(pSub->unassignedVg, (void (*)(void*))tDeleteSMqConsumerEp); // taosArrayDestroy(pSub->unassignedVg); pSub->unassignedVg = NULL; } @@ -735,6 +735,9 @@ typedef struct { int8_t createdBy; // STREAM_CREATED_BY__USER or SMA int32_t fixedSinkVgId; // 0 for shuffle int64_t smaId; // 0 for unused + int8_t trigger; + int32_t triggerParam; + int64_t waterMark; char* sql; char* logicalPlan; char* physicalPlan; diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index f89e9d8fe0..1cb0c78aa5 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -100,7 +100,6 @@ typedef struct { } SGrantInfo; typedef struct SMnode { - int32_t dnodeId; int64_t clusterId; int8_t replica; int8_t selfIndex; diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index dde7e1fe8f..94e1efde61 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -17,7 +17,7 @@ #include "mndCluster.h" #include "mndShow.h" -#define TSDB_CLUSTER_VER_NUMBE 1 +#define TSDB_CLUSTER_VER_NUMBE 1 #define TSDB_CLUSTER_RESERVE_SIZE 64 static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster); @@ -61,6 +61,23 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) { return 0; } +int64_t mndGetClusterId(SMnode *pMnode) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + int64_t clusterId = -1; + + while (1) { + SClusterObj *pCluster = NULL; + pIter = sdbFetch(pSdb, SDB_CLUSTER, pIter, (void **)&pCluster); + if (pIter == NULL) break; + + clusterId = pCluster->id; + sdbRelease(pSdb, pCluster); + } + + return clusterId; +} + static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 8eceea3d06..c4c93b7fc9 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -160,6 +160,7 @@ static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer) { static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, SMqConsumerObj *pNewConsumer) { mTrace("consumer:%" PRId64 ", perform update action", pOldConsumer->consumerId); + pOldConsumer->epoch++; // TODO handle update /*taosWLockLatch(&pOldConsumer->lock);*/ diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index bd66bdeae9..462f0eb85a 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -1309,7 +1309,7 @@ static int32_t mndGetDbMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMet cols++; pShow->bytes[cols] = 2; - pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + pSchema[cols].type = TSDB_DATA_TYPE_INT; strcpy(pSchema[cols].name, "days"); pSchema[cols].bytes = pShow->bytes[cols]; cols++; @@ -1444,7 +1444,7 @@ static void dumpDbInfoToPayload(char *data, SDbObj *pDb, SShowObj *pShow, int32_ cols++; pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int16_t *)pWrite = pDb->cfg.daysPerFile; + *(int32_t *)pWrite = pDb->cfg.daysPerFile; cols++; pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index ce08dfaaa3..92b854157b 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -53,7 +53,7 @@ static const SInfosTableSchema userDBSchema[] = { {.name = "ntables", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, {.name = "replica", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, {.name = "quorum", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "days", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "days", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "keep", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, {.name = "cache", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, @@ -89,7 +89,6 @@ static const SInfosTableSchema userStbsSchema[] = { {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_INT}, }; diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 6c38d8626c..cad89399a3 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -433,12 +433,6 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq) { pHeartbeat->connId = htonl(pHeartbeat->connId); pHeartbeat->pid = htonl(pHeartbeat->pid); - SRpcConnInfo info = {0}; - if (rpcGetConnInfo(pReq->rpcMsg.handle, &info) != 0) { - mError("user:%s, connId:%d failed to process hb since %s", pReq->user, pHeartbeat->connId, terrstr()); - return -1; - } - SConnObj *pConn = mndAcquireConn(pMnode, pHeartbeat->connId); if (pConn == NULL) { pConn = mndCreateConn(pMnode, &info, pHeartbeat->pid, pHeartbeat->app, 0); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 4b19a26bc4..85718e2037 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -423,7 +423,7 @@ static int32_t mndProcessDropQnodeReq(SNodeMsg *pReq) { DROP_QNODE_OVER: if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + mError("qnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); } mndReleaseQnode(pMnode, pObj); diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index dff918f135..5c3167dd79 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -310,6 +310,8 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); return -1; } + + pShow->numOfReads = 0; } ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type]; @@ -374,7 +376,7 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { pReq->pRsp = pRsp; pReq->rspLen = size; - if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { + if (rowsRead == 0 || rowsToRead == 0 || (rowsRead < rowsToRead)) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj((SShowObj*) pShow, true); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 5e0d9fae9a..4f24c6f7eb 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -433,7 +433,7 @@ static int32_t mndProcessDropSnodeReq(SNodeMsg *pReq) { DROP_SNODE_OVER: if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + mError("snode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); } mndReleaseSnode(pMnode, pObj); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 7799ac7562..85e7ade462 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -333,6 +333,15 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName) { return mndAcquireDb(pMnode, db); } +static FORCE_INLINE int schemaExColIdCompare(const void *colId, const void *pSchema) { + if (*(col_id_t *)colId < ((SSchemaEx *)pSchema)->colId) { + return -1; + } else if (*(col_id_t *)colId > ((SSchemaEx *)pSchema)->colId) { + return 1; + } + return 0; +} + static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) { SName name = {0}; tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); @@ -345,16 +354,91 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt req.name = (char *)tNameGetTableName(&name); req.ttl = 0; req.keep = 0; + req.rollup = pStb->aggregationMethod > -1 ? 1 : 0; req.type = TD_SUPER_TABLE; req.stbCfg.suid = pStb->uid; req.stbCfg.nCols = pStb->numOfColumns; - req.stbCfg.pSchema = pStb->pColumns; req.stbCfg.nTagCols = pStb->numOfTags; req.stbCfg.pTagSchema = pStb->pTags; + req.stbCfg.nBSmaCols = pStb->numOfSmas; + req.stbCfg.pSchema = (SSchemaEx *)taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchemaEx)); + if (req.stbCfg.pSchema == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } - int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); + int bSmaStat = 0; // no column has bsma + if (pStb->numOfSmas == pStb->numOfColumns) { // assume pColumns > 0 + bSmaStat = 1; // all columns have bsma + } else if (pStb->numOfSmas != 0) { + bSmaStat = 2; // partial columns have bsma + TASSERT(pStb->pSmas != NULL); // TODO: remove the assert + } + + for (int32_t i = 0; i < req.stbCfg.nCols; ++i) { + SSchemaEx *pSchemaEx = req.stbCfg.pSchema + i; + SSchema *pSchema = pStb->pColumns + i; + pSchemaEx->type = pSchema->type; + pSchemaEx->sma = (bSmaStat == 1) ? TSDB_BSMA_TYPE_LATEST : TSDB_BSMA_TYPE_NONE; + pSchemaEx->colId = pSchema->colId; + pSchemaEx->bytes = pSchema->bytes; + memcpy(pSchemaEx->name, pSchema->name, TSDB_COL_NAME_LEN); + } + + if (bSmaStat == 2) { + if (pStb->pSmas == NULL) { + mError("stb:%s, sma options is empty", pStb->name); + taosMemoryFreeClear(req.stbCfg.pSchema); + terrno = TSDB_CODE_MND_INVALID_STB_OPTION; + return NULL; + } + for (int32_t i = 0; i < pStb->numOfSmas; ++i) { + SSchema *pSmaSchema = pStb->pSmas + i; + SSchemaEx *pColSchema = taosbsearch(&pSmaSchema->colId, req.stbCfg.pSchema, req.stbCfg.nCols, sizeof(SSchemaEx), + schemaExColIdCompare, TD_EQ); + if (pColSchema == NULL) { + terrno = TSDB_CODE_MND_INVALID_STB_OPTION; + taosMemoryFreeClear(req.stbCfg.pSchema); + mError("stb:%s, sma col:%s not found in columns", pStb->name, pSmaSchema->name); + return NULL; + } + pColSchema->sma = TSDB_BSMA_TYPE_LATEST; + } + } + + SRSmaParam *pRSmaParam = NULL; + if (req.rollup) { + pRSmaParam = (SRSmaParam *)taosMemoryCalloc(1, sizeof(SRSmaParam)); + if (pRSmaParam == NULL) { + taosMemoryFreeClear(req.stbCfg.pSchema); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pRSmaParam->xFilesFactor = pStb->xFilesFactor; + pRSmaParam->delay = pStb->delay; + pRSmaParam->nFuncIds = 1; // only 1 aggregation method supported currently + pRSmaParam->pFuncIds = (func_id_t *)taosMemoryCalloc(pRSmaParam->nFuncIds, sizeof(func_id_t)); + if (pRSmaParam->pFuncIds == NULL) { + taosMemoryFreeClear(req.stbCfg.pRSmaParam); + taosMemoryFreeClear(req.stbCfg.pSchema); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + for (int32_t f = 0; f < pRSmaParam->nFuncIds; ++f) { + *(pRSmaParam->pFuncIds + f) = pStb->aggregationMethod; + } + req.stbCfg.pRSmaParam = pRSmaParam; + } + + int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { + if (pRSmaParam) { + taosMemoryFreeClear(pRSmaParam->pFuncIds); + taosMemoryFreeClear(pRSmaParam); + } + taosMemoryFreeClear(req.stbCfg.pSchema); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -366,6 +450,11 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt tSerializeSVCreateTbReq(&pBuf, &req); *pContLen = contLen; + if (pRSmaParam) { + taosMemoryFreeClear(pRSmaParam->pFuncIds); + taosMemoryFreeClear(pRSmaParam); + } + taosMemoryFreeClear(req.stbCfg.pSchema); return pHead; } @@ -498,7 +587,6 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj if (pReq == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -559,9 +647,9 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj } static SSchema *mndFindStbColumns(const SStbObj *pStb, const char *colName) { - for (int32_t col = 0; col < pStb->numOfColumns; col++) { + for (int32_t col = 0; col < pStb->numOfColumns; ++col) { SSchema *pSchema = &pStb->pColumns[col]; - if (strcasecmp(pStb->pColumns[col].name, colName) == 0) { + if (strncasecmp(pSchema->name, colName, TSDB_COL_NAME_LEN) == 0) { return pSchema; } } @@ -578,6 +666,9 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre stbObj.dbUid = pDb->uid; stbObj.version = 1; stbObj.nextColId = 1; + stbObj.xFilesFactor = pCreate->xFilesFactor; + stbObj.aggregationMethod = pCreate->aggregationMethod; + stbObj.delay = pCreate->delay; stbObj.ttl = pCreate->ttl; stbObj.numOfColumns = pCreate->numOfColumns; stbObj.numOfTags = pCreate->numOfTags; @@ -625,7 +716,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre SSchema *pSchema = &stbObj.pSmas[i]; SSchema *pColSchema = mndFindStbColumns(&stbObj, pField->name); if (pColSchema == NULL) { - mError("stb:%s, sma:%s not found in columns", stbObj.name, pSchema->name); + mError("stb:%s, sma:%s not found in columns", stbObj.name, pField->name); terrno = TSDB_CODE_MND_INVALID_STB_OPTION; return -1; } @@ -1061,7 +1152,6 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj if (pReq == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); - terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -1608,7 +1698,6 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 SStbObj *pStb = NULL; int32_t cols = 0; char *pWrite; - char prefix[TSDB_DB_FNAME_LEN] = {0}; SDbObj* pDb = NULL; if (strlen(pShow->db) > 0) { @@ -1653,10 +1742,6 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 *(int32_t *)pWrite = pStb->numOfTags; cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = 0; // number of tables - cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int64_t *)pWrite = pStb->updateTime; // number of tables cols++; diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 806415ccd9..211163ce35 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -237,7 +237,8 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) { for (int32_t j = 0; j < csz; j++) { SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, j); if (consumerId == pSubConsumer->consumerId) { - int32_t vgsz = taosArrayGetSize(pSubConsumer->vgInfo); + int32_t vgsz = taosArrayGetSize(pSubConsumer->vgInfo); + mInfo("topic %s has %d vg", topicName, pConsumer->epoch); SMqSubTopicEp topicEp; strcpy(topicEp.topic, topicName); topicEp.vgs = taosArrayInit(vgsz, sizeof(SMqSubVgEp)); @@ -419,7 +420,6 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { int32_t vgNum = pSub->vgNum; int32_t vgEachConsumer = vgNum / consumerNum; int32_t imbalanceVg = vgNum % consumerNum; - int32_t imbalanceSolved = 0; // iterate all consumers, set unassignedVgStash for (int32_t i = 0; i < consumerNum; i++) { @@ -446,9 +446,9 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { if (vgThisConsumerAfterRb != vgThisConsumerBeforeRb || (vgThisConsumerAfterRb != 0 && status != MQ_CONSUMER_STATUS__ACTIVE) || (vgThisConsumerAfterRb == 0 && status != MQ_CONSUMER_STATUS__LOST)) { - if (vgThisConsumerAfterRb != vgThisConsumerBeforeRb) { - pRebConsumer->epoch++; - } + /*if (vgThisConsumerAfterRb != vgThisConsumerBeforeRb) {*/ + /*pRebConsumer->epoch++;*/ + /*}*/ if (vgThisConsumerAfterRb != 0) { atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__ACTIVE); } else { @@ -460,7 +460,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer); sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY); - mndTransAppendRedolog(pTrans, pConsumerRaw); + mndTransAppendCommitlog(pTrans, pConsumerRaw); } mndReleaseConsumer(pMnode, pRebConsumer); } @@ -469,7 +469,6 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { if (taosArrayGetSize(pSub->unassignedVg) != 0) { for (int32_t i = 0; i < consumerNum; i++) { SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, i); - int32_t vgThisConsumerBeforeRb = taosArrayGetSize(pSubConsumer->vgInfo); int32_t vgThisConsumerAfterRb; if (i < imbalanceVg) vgThisConsumerAfterRb = vgEachConsumer + 1; diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 67b7d6dd45..5c3dd778e1 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -187,7 +187,7 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle return 0; } -static int32_t mndInitSteps(SMnode *pMnode) { +static int32_t mndInitSteps(SMnode *pMnode, bool deploy) { if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1; if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1; @@ -210,7 +210,7 @@ static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-infos", mndInitInfos, mndCleanupInfos) != 0) return -1; if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; - if (pMnode->clusterId <= 0) { + if (deploy) { if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1; } else { if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1; @@ -263,23 +263,15 @@ static int32_t mndExecSteps(SMnode *pMnode) { } } + pMnode->clusterId = mndGetClusterId(pMnode); return 0; } -static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { - pMnode->dnodeId = pOption->dnodeId; - pMnode->clusterId = pOption->clusterId; +static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->replica = pOption->replica; pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); pMnode->msgCb = pOption->msgCb; - - if (pMnode->dnodeId < 0 || pMnode->clusterId < 0) { - terrno = TSDB_CODE_MND_INVALID_OPTIONS; - return -1; - } - - return 0; } SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { @@ -294,6 +286,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { char timestr[24] = "1970-01-01 00:00:00.00"; (void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); + mndSetOptions(pMnode, pOption); pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep)); if (pMnode->pSteps == NULL) { @@ -312,16 +305,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return NULL; } - code = mndSetOptions(pMnode, pOption); - if (code != 0) { - code = terrno; - mError("failed to open mnode since %s", terrstr()); - mndClose(pMnode); - terrno = code; - return NULL; - } - - code = mndInitSteps(pMnode); + code = mndInitSteps(pMnode, pOption->deploy); if (code != 0) { code = terrno; mError("failed to open mnode since %s", terrstr()); diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp index 85f6a86183..4b0e33a323 100644 --- a/source/dnode/mnode/impl/test/sma/sma.cpp +++ b/source/dnode/mnode/impl/test/sma/sma.cpp @@ -42,10 +42,10 @@ void* MndTestSma::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.numOfVgroups = 2; createReq.cacheBlockSize = 16; createReq.totalBlocks = 10; - createReq.daysPerFile = 10; - createReq.daysToKeep0 = 3650; - createReq.daysToKeep1 = 3650; - createReq.daysToKeep2 = 3650; + createReq.daysPerFile = 10 * 1440; + createReq.daysToKeep0 = 3650 * 1440; + createReq.daysToKeep1 = 3650 * 1440; + createReq.daysToKeep2 = 3650 * 1440; createReq.minRows = 100; createReq.maxRows = 4096; createReq.commitTime = 3600; diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 73eefd875d..5d603ab5b2 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -35,10 +35,10 @@ void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.numOfVgroups = 2; createReq.cacheBlockSize = 16; createReq.totalBlocks = 10; - createReq.daysPerFile = 10; - createReq.daysToKeep0 = 3650; - createReq.daysToKeep1 = 3650; - createReq.daysToKeep2 = 3650; + createReq.daysPerFile = 10 * 1440; + createReq.daysToKeep0 = 3650 * 1440; + createReq.daysToKeep1 = 3650 * 1440; + createReq.daysToKeep2 = 3650 * 1440; createReq.minRows = 100; createReq.maxRows = 4096; createReq.commitTime = 3600; diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 61b99beeb7..97a144fdee 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -324,10 +324,10 @@ TEST_F(MndTestUser, 03_Alter_User) { createReq.numOfVgroups = 2; createReq.cacheBlockSize = 16; createReq.totalBlocks = 10; - createReq.daysPerFile = 10; - createReq.daysToKeep0 = 3650; - createReq.daysToKeep1 = 3650; - createReq.daysToKeep2 = 3650; + createReq.daysPerFile = 10 * 1440; + createReq.daysToKeep0 = 3650 * 1440; + createReq.daysToKeep1 = 3650 * 1440; + createReq.daysToKeep2 = 3650 * 1440; createReq.minRows = 100; createReq.maxRows = 4096; createReq.commitTime = 3600; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 204cd870f4..dc2c12a2c4 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -40,6 +40,10 @@ const char *sdbTableName(ESdbType type) { return "auth"; case SDB_ACCT: return "acct"; + case SDB_STREAM: + return "stream"; + case SDB_OFFSET: + return "offset"; case SDB_SUBSCRIBE: return "subscribe"; case SDB_CONSUMER: diff --git a/source/dnode/vnode/inc/tsdb.h b/source/dnode/vnode/inc/tsdb.h index 0d3fcffe7d..1e4a7e5a93 100644 --- a/source/dnode/vnode/inc/tsdb.h +++ b/source/dnode/vnode/inc/tsdb.h @@ -171,6 +171,8 @@ tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, void* pMemRef); +int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* pTableBlockInfo); + bool isTsdbCacheLastRow(tsdbReaderT* pTsdbReadHandle); /** diff --git a/source/dnode/vnode/src/inc/tsdbCommit.h b/source/dnode/vnode/src/inc/tsdbCommit.h index 699aeaa133..2c6dd75e03 100644 --- a/source/dnode/vnode/src/inc/tsdbCommit.h +++ b/source/dnode/vnode/src/inc/tsdbCommit.h @@ -74,4 +74,4 @@ int tsdbApplyRtn(STsdbRepo *pRepo); } #endif -#endif /* _TD_TSDB_COMMIT_H_ */ \ No newline at end of file +#endif /* _TD_TSDB_COMMIT_H_ */ diff --git a/source/dnode/vnode/src/inc/tsdbDef.h b/source/dnode/vnode/src/inc/tsdbDef.h index 02aba95517..3e42cb627a 100644 --- a/source/dnode/vnode/src/inc/tsdbDef.h +++ b/source/dnode/vnode/src/inc/tsdbDef.h @@ -79,4 +79,4 @@ static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STable *pTable, bool lock, } #endif -#endif /*_TD_TSDB_DEF_H_*/ \ No newline at end of file +#endif /*_TD_TSDB_DEF_H_*/ diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index e5d1f952a8..aa4a9fc1de 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -194,7 +194,7 @@ void tqClose(STQ*); int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version); int tqCommit(STQ*); -int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId); int32_t tqProcessSetConnReq(STQ* pTq, char* msg); int32_t tqProcessRebReq(STQ* pTq, char* msg); int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId); diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index b91c6cd9e3..9485c291ae 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -70,9 +70,12 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static void metaClearTbCfg(STbCfg *pTbCfg); static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW); static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW); +static int metaEncodeSchemaEx(void **buf, SSchemaWrapper *pSW); +static void *metaDecodeSchemaEx(void *buf, SSchemaWrapper *pSW, bool isGetEx); static void metaDBWLock(SMetaDB *pDB); static void metaDBRLock(SMetaDB *pDB); static void metaDBULock(SMetaDB *pDB); +static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx); #define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code)) @@ -155,13 +158,13 @@ void metaCloseDB(SMeta *pMeta) { } int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { - tb_uid_t uid; - char buf[512]; - char buf1[512]; - void *pBuf; - DBT key1, value1; - DBT key2, value2; - SSchema *pSchema = NULL; + tb_uid_t uid; + char buf[512]; + char buf1[512]; + void *pBuf; + DBT key1, value1; + DBT key2, value2; + SSchemaEx *pSchema = NULL; if (pTbCfg->type == META_SUPER_TABLE) { uid = pTbCfg->stbCfg.suid; @@ -204,8 +207,8 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { key2.data = &schemaKey; key2.size = sizeof(schemaKey); - SSchemaWrapper sw = {.nCols = ncols, .pSchema = pSchema}; - metaEncodeSchema(&pBuf, &sw); + SSchemaWrapper sw = {.nCols = ncols, .pSchemaEx = pSchema}; + metaEncodeSchemaEx(&pBuf, &sw); value2.data = buf1; value2.size = POINTER_DISTANCE(pBuf, buf1); @@ -298,6 +301,8 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { buf = taosDecodeFixedU32(buf, &pSW->nCols); pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols); + + int8_t dummy; for (int i = 0; i < pSW->nCols; i++) { pSchema = pSW->pSchema + i; buf = taosDecodeFixedI8(buf, &pSchema->type); @@ -309,6 +314,50 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { return buf; } +static int metaEncodeSchemaEx(void **buf, SSchemaWrapper *pSW) { + int tlen = 0; + SSchemaEx *pSchema; + + tlen += taosEncodeFixedU32(buf, pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + pSchema = pSW->pSchemaEx + i; + tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI8(buf, pSchema->sma); + tlen += taosEncodeFixedI16(buf, pSchema->colId); + tlen += taosEncodeFixedI32(buf, pSchema->bytes); + tlen += taosEncodeString(buf, pSchema->name); + } + + return tlen; +} + +static void *metaDecodeSchemaEx(void *buf, SSchemaWrapper *pSW, bool isGetEx) { + buf = taosDecodeFixedU32(buf, &pSW->nCols); + if (isGetEx) { + pSW->pSchemaEx = (SSchemaEx *)taosMemoryMalloc(sizeof(SSchemaEx) * pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + SSchemaEx *pSchema = pSW->pSchemaEx + i; + buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosDecodeFixedI8(buf, &pSchema->sma); + buf = taosDecodeFixedI16(buf, &pSchema->colId); + buf = taosDecodeFixedI32(buf, &pSchema->bytes); + buf = taosDecodeStringTo(buf, pSchema->name); + } + } else { + pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + SSchema *pSchema = pSW->pSchema + i; + buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosSkipFixedLen(buf, sizeof(int8_t)); + buf = taosDecodeFixedI16(buf, &pSchema->colId); + buf = taosDecodeFixedI32(buf, &pSchema->bytes); + buf = taosDecodeStringTo(buf, pSchema->name); + } + } + + return buf; +} + static SMetaDB *metaNewDB() { SMetaDB *pDB = NULL; pDB = (SMetaDB *)taosMemoryCalloc(1, sizeof(*pDB)); @@ -652,12 +701,16 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { } SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { + return metaGetTableSchemaImpl(pMeta, uid, sver, isinline, false); +} + +static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx) { uint32_t nCols; SSchemaWrapper *pSW = NULL; SMetaDB *pDB = pMeta->pDB; int ret; void *pBuf; - SSchema *pSchema; + // SSchema *pSchema; SSchemaKey schemaKey = {uid, sver, 0}; DBT key = {0}; DBT value = {0}; @@ -678,7 +731,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo // Decode the schema pBuf = value.data; pSW = taosMemoryMalloc(sizeof(*pSW)); - metaDecodeSchema(pBuf, pSW); + metaDecodeSchemaEx(pBuf, pSW, isGetEx); return pSW; } @@ -755,7 +808,7 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { STSchemaBuilder sb; STSchema *pTSchema = NULL; - SSchema *pSchema; + SSchemaEx *pSchema; SSchemaWrapper *pSW; STbCfg *pTbCfg; tb_uid_t quid; @@ -767,16 +820,16 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { quid = uid; } - pSW = metaGetTableSchema(pMeta, quid, sver, true); + pSW = metaGetTableSchemaImpl(pMeta, quid, sver, true, true); if (pSW == NULL) { return NULL; } // Rebuild a schema tdInitTSchemaBuilder(&sb, 0); - for (int32_t i = 0; i < pSW->nCols; i++) { - pSchema = pSW->pSchema + i; - tdAddColToSchema(&sb, pSchema->type, pSchema->colId, pSchema->bytes); + for (int32_t i = 0; i < pSW->nCols; ++i) { + pSchema = pSW->pSchemaEx + i; + tdAddColToSchema(&sb, pSchema->type, pSchema->sma, pSchema->colId, pSchema->bytes); } pTSchema = tdGetSchemaFromBuilder(&sb); tdDestroyTSchemaBuilder(&sb); diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index ee928ef039..8e82cf1abc 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -46,6 +46,10 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg); static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW); static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW); +static int metaEncodeSchemaEx(void **buf, SSchemaWrapper *pSW); +static void *metaDecodeSchemaEx(void *buf, SSchemaWrapper *pSW, bool isGetEx); + +static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx); static inline int metaUidCmpr(const void *arg1, int len1, const void *arg2, int len2) { tb_uid_t uid1, uid2; @@ -228,7 +232,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { schemaWrapper.pSchema = pTbCfg->ntbCfg.pSchema; } pVal = pBuf = buf; - metaEncodeSchema(&pBuf, &schemaWrapper); + metaEncodeSchemaEx(&pBuf, &schemaWrapper); vLen = POINTER_DISTANCE(pBuf, buf); ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen); if (ret < 0) { @@ -345,6 +349,10 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { } SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { + return *metaGetTableSchemaImpl(pMeta, uid, sver, isinline, false); +} + +static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx) { void *pKey; void *pVal; int kLen; @@ -368,7 +376,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo // decode pBuf = pVal; pSchemaWrapper = taosMemoryMalloc(sizeof(*pSchemaWrapper)); - metaDecodeSchema(pBuf, pSchemaWrapper); + metaDecodeSchemaEx(pBuf, pSchemaWrapper, isGetEx); TDB_FREE(pVal); @@ -379,7 +387,7 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { tb_uid_t quid; SSchemaWrapper *pSW; STSchemaBuilder sb; - SSchema *pSchema; + SSchemaEx *pSchema; STSchema *pTSchema; STbCfg *pTbCfg; @@ -390,15 +398,15 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { quid = uid; } - pSW = metaGetTableSchema(pMeta, quid, sver, true); + pSW = metaGetTableSchemaImpl(pMeta, quid, sver, true, true); if (pSW == NULL) { return NULL; } tdInitTSchemaBuilder(&sb, 0); for (int i = 0; i < pSW->nCols; i++) { - pSchema = pSW->pSchema + i; - tdAddColToSchema(&sb, pSchema->type, pSchema->colId, pSchema->bytes); + pSchema = pSW->pSchemaEx + i; + tdAddColToSchema(&sb, pSchema->type, pSchema->sma, pSchema->colId, pSchema->bytes); } pTSchema = tdGetSchemaFromBuilder(&sb); tdDestroyTSchemaBuilder(&sb); @@ -605,6 +613,50 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { return buf; } +static int metaEncodeSchemaEx(void **buf, SSchemaWrapper *pSW) { + int tlen = 0; + SSchemaEx *pSchema; + + tlen += taosEncodeFixedU32(buf, pSW->nCols); + for (int i = 0; i < pSW->nCols; ++i) { + pSchema = pSW->pSchemaEx + i; + tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI8(buf, pSchema->sma); + tlen += taosEncodeFixedI16(buf, pSchema->colId); + tlen += taosEncodeFixedI32(buf, pSchema->bytes); + tlen += taosEncodeString(buf, pSchema->name); + } + + return tlen; +} + +static void *metaDecodeSchemaEx(void *buf, SSchemaWrapper *pSW, bool isGetEx) { + buf = taosDecodeFixedU32(buf, &pSW->nCols); + if (isGetEx) { + pSW->pSchemaEx = (SSchemaEx *)taosMemoryMalloc(sizeof(SSchemaEx) * pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + SSchemaEx *pSchema = pSW->pSchemaEx + i; + buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosDecodeFixedI8(buf, &pSchema->sma); + buf = taosDecodeFixedI16(buf, &pSchema->colId); + buf = taosDecodeFixedI32(buf, &pSchema->bytes); + buf = taosDecodeStringTo(buf, pSchema->name); + } + } else { + pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + SSchema *pSchema = pSW->pSchema + i; + buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosSkipFixedLen(buf, sizeof(int8_t)); + buf = taosDecodeFixedI16(buf, &pSchema->colId); + buf = taosDecodeFixedI32(buf, &pSchema->bytes); + buf = taosDecodeStringTo(buf, pSchema->name); + } + } + + return buf; +} + static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) { int tsize = 0; diff --git a/source/dnode/vnode/src/meta/metaTbUid.c b/source/dnode/vnode/src/meta/metaTbUid.c index cad1eba134..1f57d1396a 100644 --- a/source/dnode/vnode/src/meta/metaTbUid.c +++ b/source/dnode/vnode/src/meta/metaTbUid.c @@ -27,5 +27,5 @@ void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ tb_uid_t metaGenerateUid(SMeta *pMeta) { // Generate a new table UID - return ++(pMeta->uidGnrt.nextUid); + return tGenIdPI32(); } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 06a2350aab..68ade46efd 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -250,7 +250,7 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu return 0; } -int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { +int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { SMqPollReq* pReq = pMsg->pCont; int64_t consumerId = pReq->consumerId; int64_t fetchOffset; @@ -264,6 +264,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { fetchOffset = pReq->currentOffset + 1; } + /*printf("tmq poll vg %d req %ld %ld\n", pTq->pVnode->vgId, pReq->currentOffset, fetchOffset);*/ + SMqPollRsp rsp = { /*.consumerId = consumerId,*/ .numOfTopics = 0, @@ -288,62 +290,74 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { rsp.reqOffset = pReq->currentOffset; rsp.skipLogNum = 0; - SWalHead* pHead; while (1) { /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/ - if (walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) { + SWalReadHead* pHead; + if (walReadWithHandle_s(pTopic->pReadhandle, fetchOffset, &pHead) < 0) { // TODO: no more log, set timer to wait blocking time // if data inserted during waiting, launch query and // response to user break; } - int8_t pos = fetchOffset % TQ_BUFFER_SIZE; - pHead = pTopic->pReadhandle->pHead; - if (pHead->head.msgType == TDMT_VND_SUBMIT) { - SSubmitReq* pCont = (SSubmitReq*)&pHead->head.body; - qTaskInfo_t task = pTopic->buffer.output[pos].task; + /*printf("vg %d offset %ld msgType %d from epoch %d\n", pTq->pVnode->vgId, fetchOffset, pHead->msgType, pReq->epoch);*/ + /*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/ + /*pHead = pTopic->pReadhandle->pHead;*/ + if (pHead->msgType == TDMT_VND_SUBMIT) { + SSubmitReq* pCont = (SSubmitReq*)&pHead->body; + /*printf("from topic %s from consumer\n", pTopic->topicName, consumerId);*/ + qTaskInfo_t task = pTopic->buffer.output[workerId].task; + ASSERT(task); qSetStreamInput(task, pCont, STREAM_DATA_TYPE_SUBMIT_BLOCK); SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); while (1) { - SSDataBlock* pDataBlock; + SSDataBlock* pDataBlock = NULL; uint64_t ts; if (qExecTask(task, &pDataBlock, &ts) < 0) { ASSERT(false); } if (pDataBlock == NULL) { - fetchOffset++; - pos = fetchOffset % TQ_BUFFER_SIZE; - rsp.skipLogNum++; + /*pos = fetchOffset % TQ_BUFFER_SIZE;*/ break; } taosArrayPush(pRes, pDataBlock); - rsp.schema = pTopic->buffer.output[pos].pReadHandle->pSchemaWrapper; - rsp.rspOffset = fetchOffset; - - rsp.numOfTopics = 1; - rsp.pBlockData = pRes; - - int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp); - void* buf = rpcMallocCont(tlen); - if (buf == NULL) { - pMsg->code = -1; - return -1; - } - ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; - ((SMqRspHead*)buf)->epoch = pReq->epoch; - ((SMqRspHead*)buf)->consumerId = consumerId; - - void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); - tEncodeSMqPollRsp(&abuf, &rsp); - /*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/ - pMsg->pCont = buf; - pMsg->contLen = tlen; - pMsg->code = 0; - tmsgSendRsp(pMsg); - return 0; } + + if (taosArrayGetSize(pRes) == 0) { + fetchOffset++; + rsp.skipLogNum++; + taosArrayDestroy(pRes); + continue; + } + rsp.schema = pTopic->buffer.output[workerId].pReadHandle->pSchemaWrapper; + rsp.rspOffset = fetchOffset; + + rsp.numOfTopics = 1; + rsp.pBlockData = pRes; + + int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp); + void* buf = rpcMallocCont(tlen); + if (buf == NULL) { + pMsg->code = -1; + taosMemoryFree(pHead); + return -1; + } + ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; + ((SMqRspHead*)buf)->epoch = pReq->epoch; + ((SMqRspHead*)buf)->consumerId = consumerId; + + void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); + tEncodeSMqPollRsp(&abuf, &rsp); + /*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/ + pMsg->pCont = buf; + pMsg->contLen = tlen; + pMsg->code = 0; + /*printf("vg %d offset %ld msgType %d from epoch %d actual rsp\n", pTq->pVnode->vgId, fetchOffset, pHead->msgType, pReq->epoch);*/ + tmsgSendRsp(pMsg); + taosMemoryFree(pHead); + return 0; } else { + taosMemoryFree(pHead); fetchOffset++; rsp.skipLogNum++; } @@ -360,6 +374,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { } ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; ((SMqRspHead*)buf)->epoch = pReq->epoch; + rsp.rspOffset = fetchOffset - 1; void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); tEncodeSMqPollRsp(&abuf, &rsp); @@ -368,6 +383,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { pMsg->contLen = tlen; pMsg->code = 0; tmsgSendRsp(pMsg); + /*printf("vg %d offset %ld from epoch %d not rsp\n", pTq->pVnode->vgId, fetchOffset, pReq->epoch);*/ /*}*/ return 0; @@ -432,7 +448,9 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg) { }; pTopic->buffer.output[i].pReadHandle = pReadHandle; pTopic->buffer.output[i].task = qCreateStreamExecTaskInfo(req.qmsg, &handle); + ASSERT(pTopic->buffer.output[i].task); } + /*printf("set topic %s to consumer %ld on vg %d\n", pTopic->topicName, req.consumerId, pTq->pVnode->vgId);*/ taosArrayPush(pConsumer->topics, pTopic); tqHandleMovePut(pTq->tqMeta, req.consumerId, pConsumer); tqHandleCommit(pTq->tqMeta, req.consumerId); diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 9c0b0802ab..a18374015b 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -142,7 +142,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { colInfo.info.colId = pColSchema->colId; colInfo.info.type = pColSchema->type; - if (blockDataEnsureColumnCapacity(&colInfo, numOfRows) < 0) { + if (colInfoDataEnsureCapacity(&colInfo, numOfRows) < 0) { taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); return NULL; } @@ -167,7 +167,8 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { break; } - if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) { + if (colDataAppend(pColData, curRow, sVal.val, false) < 0) { + /*if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) {*/ taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); return NULL; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 3e0b03f331..d5e9b55a71 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -1394,7 +1394,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF tsdbDebug("vgId:%d uid:%" PRId64 " a block of data is written to file %s, offset %" PRId64 " numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64, - REPO_ID(pRepo), TABLE_TID(pTable), TSDB_FILE_FULL_NAME(pDFile), offset, rowsToWrite, pBlock->len, + REPO_ID(pRepo), TABLE_UID(pTable), TSDB_FILE_FULL_NAME(pDFile), offset, rowsToWrite, pBlock->len, pBlock->numOfCols, pBlock->keyFirst, pBlock->keyLast); return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index bac5255d17..4a3e764b13 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -14,7 +14,7 @@ */ #include "tsdbDef.h" -#include +#include "tdatablock.h" #include "os.h" #include "talgo.h" #include "tcompare.h" @@ -31,6 +31,7 @@ #include "tlosertree.h" #include "tsdbDef.h" #include "tmsg.h" +#include "tsdbCommit.h" #define EXTRA_BYTES 2 #define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) @@ -209,34 +210,34 @@ static SArray* getDefaultLoadColumns(STsdbReadHandle* pTsdbReadHandle, bool load return pLocalIdList; } -//int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle) { -// STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; -// -// int64_t rows = 0; -// STsdbMemTable* pMemTable = pTsdbReadHandle->pMemTable; -// if (pMemTable == NULL) { return rows; } -// -//// STableData* pMem = NULL; -//// STableData* pIMem = NULL; -// -//// SMemTable* pMemT = pMemRef->snapshot.mem; -//// SMemTable* pIMemT = pMemRef->snapshot.imem; -// -// size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); -// for (int32_t i = 0; i < size; ++i) { -// STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); -// -//// if (pMemT && pCheckInfo->tableId < pMemT->maxTables) { -//// pMem = pMemT->tData[pCheckInfo->tableId]; -//// rows += (pMem && pMem->uid == pCheckInfo->tableId) ? pMem->numOfRows : 0; -//// } -//// if (pIMemT && pCheckInfo->tableId < pIMemT->maxTables) { -//// pIMem = pIMemT->tData[pCheckInfo->tableId]; -//// rows += (pIMem && pIMem->uid == pCheckInfo->tableId) ? pIMem->numOfRows : 0; -//// } -// } -// return rows; -//} +int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle) { + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; + + int64_t rows = 0; + STsdbMemTable* pMemTable = NULL;//pTsdbReadHandle->pMemTable; + if (pMemTable == NULL) { return rows; } + +// STableData* pMem = NULL; +// STableData* pIMem = NULL; + +// SMemTable* pMemT = pMemRef->snapshot.mem; +// SMemTable* pIMemT = pMemRef->snapshot.imem; + + size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); + for (int32_t i = 0; i < size; ++i) { + STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + +// if (pMemT && pCheckInfo->tableId < pMemT->maxTables) { +// pMem = pMemT->tData[pCheckInfo->tableId]; +// rows += (pMem && pMem->uid == pCheckInfo->tableId) ? pMem->numOfRows : 0; +// } +// if (pIMemT && pCheckInfo->tableId < pIMemT->maxTables) { +// pIMem = pIMemT->tData[pCheckInfo->tableId]; +// rows += (pIMem && pIMem->uid == pCheckInfo->tableId) ? pIMem->numOfRows : 0; +// } + } + return rows; +} static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo* pGroupList) { size_t numOfGroup = taosArrayGetSize(pGroupList->pGroupList); @@ -403,7 +404,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, SColumnInfoData colInfo = {{0}, 0}; colInfo.info = pCond->colList[i]; - int32_t code = blockDataEnsureColumnCapacity(&colInfo, pReadHandle->outputCapacity); + int32_t code = colInfoDataEnsureCapacity(&colInfo, pReadHandle->outputCapacity); if (code != TSDB_CODE_SUCCESS) { goto _end; } @@ -2261,12 +2262,13 @@ static void moveToNextDataBlockInCurrentFile(STsdbReadHandle* pTsdbReadHandle) { cur->mixBlock = false; cur->blockCompleted = false; } -#if 0 -int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDist* pTableBlockInfo) { + +int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* pTableBlockInfo) { STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) queryHandle; pTableBlockInfo->totalSize = 0; pTableBlockInfo->totalRows = 0; + STsdbFS* pFileHandle = REPO_FS(pTsdbReadHandle->pTsdb); // find the start data block in file @@ -2284,9 +2286,11 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDist* pTa int32_t code = TSDB_CODE_SUCCESS; int32_t numOfBlocks = 0; int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); + int defaultRows = 4096;//TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); STimeWindow win = TSWINDOW_INITIALIZER; + bool ascTraverse = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + while (true) { numOfBlocks = 0; tsdbRLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); @@ -2299,8 +2303,7 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDist* pTa tsdbGetFidKeyRange(pCfg->daysPerFile, pCfg->precision, pTsdbReadHandle->pFileGroup->fid, &win.skey, &win.ekey); // current file are not overlapped with query time window, ignore remain files - if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && win.skey > pTsdbReadHandle->window.ekey) || - (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && win.ekey < pTsdbReadHandle->window.ekey)) { + if ((ascTraverse && win.skey > pTsdbReadHandle->window.ekey) || (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)) { tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pTsdbReadHandle, pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr); @@ -2342,19 +2345,26 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDist* pTa int32_t numOfRows = pBlock[j].numOfRows; pTableBlockInfo->totalRows += numOfRows; - if (numOfRows > pTableBlockInfo->maxRows) pTableBlockInfo->maxRows = numOfRows; - if (numOfRows < pTableBlockInfo->minRows) pTableBlockInfo->minRows = numOfRows; - if (numOfRows < defaultRows) pTableBlockInfo->numOfSmallBlocks+=1; - int32_t stepIndex = (numOfRows-1)/TSDB_BLOCK_DIST_STEP_ROWS; - SFileBlockInfo *blockInfo = (SFileBlockInfo*)taosArrayGet(pTableBlockInfo->dataBlockInfos, stepIndex); - blockInfo->numBlocksOfStep++; + if (numOfRows > pTableBlockInfo->maxRows) { + pTableBlockInfo->maxRows = numOfRows; + } + + if (numOfRows < pTableBlockInfo->minRows) { + pTableBlockInfo->minRows = numOfRows; + } + + if (numOfRows < defaultRows) { + pTableBlockInfo->numOfSmallBlocks += 1; + } +// int32_t stepIndex = (numOfRows-1)/TSDB_BLOCK_DIST_STEP_ROWS; +// SFileBlockInfo *blockInfo = (SFileBlockInfo*)taosArrayGet(pTableBlockInfo->dataBlockInfos, stepIndex); +// blockInfo->numBlocksOfStep++; } } } return code; } -#endif static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exists) { STsdbFS* pFileHandle = REPO_FS(pTsdbReadHandle->pTsdb); @@ -4068,4 +4078,4 @@ void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *re //apply the hierarchical filter expression to every node in skiplist to find the qualified nodes applyFilterToSkipListNode(pSkipList, pExpr, result, param); } -#endif \ No newline at end of file +#endif diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 598647f797..30c2fe84bf 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -66,12 +66,12 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { case TDMT_VND_TABLE_META: return vnodeGetTableMeta(pVnode, pMsg); case TDMT_VND_CONSUME: - return tqProcessPollReq(pVnode->pTq, pMsg); + return tqProcessPollReq(pVnode->pTq, pMsg, pInfo->workerId); case TDMT_VND_TASK_PIPE_EXEC: case TDMT_VND_TASK_MERGE_EXEC: - return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, pInfo->workerId); + return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0); case TDMT_VND_STREAM_TRIGGER: - return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, pInfo->workerId); + return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0); case TDMT_VND_QUERY_HEARTBEAT: return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); default: diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index d6f9f0da0b..7ef0b50402 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -78,11 +78,13 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO: handle error } - // TODO: maybe need to clear the request struct + // TODO: to encapsule a free API taosMemoryFree(vCreateTbReq.stbCfg.pSchema); taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); - taosMemoryFree(vCreateTbReq.stbCfg.pBSmaCols); - taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); + if(vCreateTbReq.stbCfg.pRSmaParam) { + taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); + } taosMemoryFree(vCreateTbReq.dbFName); taosMemoryFree(vCreateTbReq.name); break; @@ -111,19 +113,24 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO: handle error vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name); } + // TODO: to encapsule a free API taosMemoryFree(pCreateTbReq->name); taosMemoryFree(pCreateTbReq->dbFName); if (pCreateTbReq->type == TD_SUPER_TABLE) { taosMemoryFree(pCreateTbReq->stbCfg.pSchema); taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); - taosMemoryFree(pCreateTbReq->stbCfg.pBSmaCols); - taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); + if (pCreateTbReq->stbCfg.pRSmaParam) { + taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); + } } else if (pCreateTbReq->type == TD_CHILD_TABLE) { taosMemoryFree(pCreateTbReq->ctbCfg.pTag); } else { taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); - taosMemoryFree(pCreateTbReq->ntbCfg.pBSmaCols); - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); + if (pCreateTbReq->ntbCfg.pRSmaParam) { + taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); + } } } @@ -148,10 +155,13 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { SVCreateTbReq vAlterTbReq = {0}; vTrace("vgId:%d, process alter stb req", pVnode->vgId); tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vAlterTbReq); + // TODO: to encapsule a free API taosMemoryFree(vAlterTbReq.stbCfg.pSchema); taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); - taosMemoryFree(vAlterTbReq.stbCfg.pBSmaCols); - taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); + if (vAlterTbReq.stbCfg.pRSmaParam) { + taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); + } taosMemoryFree(vAlterTbReq.dbFName); taosMemoryFree(vAlterTbReq.name); break; @@ -165,6 +175,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // } break; case TDMT_VND_SUBMIT: + /*printf("vnode %d write data %ld\n", pVnode->vgId, ver);*/ if (pVnode->config.streamMode == 0) { if (tsdbInsertData(pVnode->pTsdb, (SSubmitReq *)ptr, NULL) < 0) { // TODO: handle error diff --git a/source/libs/CMakeLists.txt b/source/libs/CMakeLists.txt index a1b9337fa8..b1e8be6528 100644 --- a/source/libs/CMakeLists.txt +++ b/source/libs/CMakeLists.txt @@ -17,3 +17,4 @@ add_subdirectory(tfs) add_subdirectory(monitor) add_subdirectory(nodes) add_subdirectory(scalar) +add_subdirectory(command) diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 9bd5c1c016..09f51dc03e 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -112,7 +112,14 @@ typedef struct SCtgRuntimeStat { } SCtgRuntimeStat; typedef struct SCtgCacheStat { - + uint64_t clusterNum; + uint64_t dbNum; + uint64_t tblNum; + uint64_t stblNum; + uint64_t vgHitNum; + uint64_t vgMissNum; + uint64_t tblHitNum; + uint64_t tblMissNum; } SCtgCacheStat; typedef struct SCatalogStat { @@ -186,7 +193,7 @@ typedef struct SCatalogMgmt { bool exit; SRWLatch lock; SCtgQueue queue; - TdThread updateThread; + TdThread updateThread; SHashObj *pCluster; //key: clusterId, value: SCatalog* SCatalogStat stat; SCatalogCfg cfg; @@ -204,8 +211,13 @@ typedef struct SCtgAction { #define CTG_QUEUE_ADD() atomic_add_fetch_64(&gCtgMgmt.queue.qRemainNum, 1) #define CTG_QUEUE_SUB() atomic_sub_fetch_64(&gCtgMgmt.queue.qRemainNum, 1) -#define CTG_STAT_ADD(n) atomic_add_fetch_64(&(n), 1) -#define CTG_STAT_SUB(n) atomic_sub_fetch_64(&(n), 1) +#define CTG_STAT_ADD(_item, _n) atomic_add_fetch_64(&(_item), _n) +#define CTG_STAT_SUB(_item, _n) atomic_sub_fetch_64(&(_item), _n) +#define CTG_STAT_GET(_item) atomic_load_64(&(_item)) + +#define CTG_RUNTIME_STAT_ADD(item, n) (CTG_STAT_ADD(gCtgMgmt.stat.runtime.item, n)) +#define CTG_CACHE_STAT_ADD(item, n) (CTG_STAT_ADD(gCtgMgmt.stat.cache.item, n)) +#define CTG_CACHE_STAT_SUB(item, n) (CTG_STAT_SUB(gCtgMgmt.stat.cache.item, n)) #define CTG_IS_META_NULL(type) ((type) == META_TYPE_NULL_TABLE) #define CTG_IS_META_CTABLE(type) ((type) == META_TYPE_CTABLE) @@ -291,6 +303,9 @@ typedef struct SCtgAction { #define CTG_API_ENTER() do { CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); CTG_LOCK(CTG_READ, &gCtgMgmt.lock); if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); } } while (0) +extern void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p); +extern void ctgdShowClusterCache(SCatalog* pCtg); +extern int32_t ctgdShowCacheInfo(void); #ifdef __cplusplus } diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 0305d045a9..4c5a0364e1 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -24,8 +24,8 @@ int32_t ctgActRemoveDB(SCtgMetaAction *action); int32_t ctgActRemoveStb(SCtgMetaAction *action); int32_t ctgActRemoveTbl(SCtgMetaAction *action); +extern SCtgDebug gCTGDebug; SCatalogMgmt gCtgMgmt = {0}; -SCtgDebug gCTGDebug = {0}; SCtgAction gCtgAction[CTG_ACT_MAX] = {{ CTG_ACT_UPDATE_VG, "update vgInfo", @@ -53,182 +53,6 @@ SCtgAction gCtgAction[CTG_ACT_MAX] = {{ } }; -int32_t ctgDbgEnableDebug(char *option) { - if (0 == strcasecmp(option, "lock")) { - gCTGDebug.lockEnable = true; - qDebug("lock debug enabled"); - return TSDB_CODE_SUCCESS; - } - - if (0 == strcasecmp(option, "cache")) { - gCTGDebug.cacheEnable = true; - qDebug("cache debug enabled"); - return TSDB_CODE_SUCCESS; - } - - if (0 == strcasecmp(option, "api")) { - gCTGDebug.apiEnable = true; - qDebug("api debug enabled"); - return TSDB_CODE_SUCCESS; - } - - if (0 == strcasecmp(option, "meta")) { - gCTGDebug.metaEnable = true; - qDebug("api debug enabled"); - return TSDB_CODE_SUCCESS; - } - - qError("invalid debug option:%s", option); - - return TSDB_CODE_CTG_INTERNAL_ERROR; -} - -int32_t ctgDbgGetStatNum(char *option, void *res) { - if (0 == strcasecmp(option, "runtime.qDoneNum")) { - *(uint64_t *)res = atomic_load_64(&gCtgMgmt.stat.runtime.qDoneNum); - return TSDB_CODE_SUCCESS; - } - - qError("invalid stat option:%s", option); - - return TSDB_CODE_CTG_INTERNAL_ERROR; -} - -int32_t ctgDbgGetTbMetaNum(SCtgDBCache *dbCache) { - return dbCache->tbCache.metaCache ? (int32_t)taosHashGetSize(dbCache->tbCache.metaCache) : 0; -} - -int32_t ctgDbgGetStbNum(SCtgDBCache *dbCache) { - return dbCache->tbCache.stbCache ? (int32_t)taosHashGetSize(dbCache->tbCache.stbCache) : 0; -} - -int32_t ctgDbgGetRentNum(SCtgRentMgmt *rent) { - int32_t num = 0; - for (uint16_t i = 0; i < rent->slotNum; ++i) { - SCtgRentSlot *slot = &rent->slots[i]; - if (NULL == slot->meta) { - continue; - } - - num += taosArrayGetSize(slot->meta); - } - - return num; -} - -int32_t ctgDbgGetClusterCacheNum(SCatalog* pCtg, int32_t type) { - if (NULL == pCtg || NULL == pCtg->dbCache) { - return 0; - } - - switch (type) { - case CTG_DBG_DB_NUM: - return (int32_t)taosHashGetSize(pCtg->dbCache); - case CTG_DBG_DB_RENT_NUM: - return ctgDbgGetRentNum(&pCtg->dbRent); - case CTG_DBG_STB_RENT_NUM: - return ctgDbgGetRentNum(&pCtg->stbRent); - default: - break; - } - - SCtgDBCache *dbCache = NULL; - int32_t num = 0; - void *pIter = taosHashIterate(pCtg->dbCache, NULL); - while (pIter) { - dbCache = (SCtgDBCache *)pIter; - switch (type) { - case CTG_DBG_META_NUM: - num += ctgDbgGetTbMetaNum(dbCache); - break; - case CTG_DBG_STB_NUM: - num += ctgDbgGetStbNum(dbCache); - break; - default: - ctgError("invalid type:%d", type); - break; - } - pIter = taosHashIterate(pCtg->dbCache, pIter); - } - - return num; -} - -void ctgDbgShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p) { - if (!gCTGDebug.metaEnable) { - return; - } - - STableComInfo *c = &p->tableInfo; - - if (TSDB_CHILD_TABLE == p->tableType) { - ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64, tbName, p->tableType, p->vgId, p->uid, p->suid); - return; - } else { - ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64 ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d", - tbName, p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, c->numOfColumns, c->rowSize); - } - - int32_t colNum = c->numOfColumns + c->numOfTags; - for (int32_t i = 0; i < colNum; ++i) { - SSchema *s = &p->schema[i]; - ctgDebug("[%d] name:%s, type:%d, colId:%" PRIi16 ", bytes:%d", i, s->name, s->type, s->colId, s->bytes); - } -} - -void ctgDbgShowDBCache(SCatalog* pCtg, SHashObj *dbHash) { - if (NULL == dbHash || !gCTGDebug.cacheEnable) { - return; - } - - int32_t i = 0; - SCtgDBCache *dbCache = NULL; - void *pIter = taosHashIterate(dbHash, NULL); - while (pIter) { - char *dbFName = NULL; - size_t len = 0; - - dbCache = (SCtgDBCache *)pIter; - - dbFName = taosHashGetKey(pIter, &len); - - int32_t metaNum = dbCache->tbCache.metaCache ? taosHashGetSize(dbCache->tbCache.metaCache) : 0; - int32_t stbNum = dbCache->tbCache.stbCache ? taosHashGetSize(dbCache->tbCache.stbCache) : 0; - int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION; - int32_t hashMethod = -1; - int32_t vgNum = 0; - - if (dbCache->vgInfo) { - vgVersion = dbCache->vgInfo->vgVersion; - hashMethod = dbCache->vgInfo->hashMethod; - if (dbCache->vgInfo->vgHash) { - vgNum = taosHashGetSize(dbCache->vgInfo->vgHash); - } - } - - ctgDebug("[%d] db [%.*s][%"PRIx64"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, hashMethod:%d, vgNum:%d", - i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted?"deleted":"", metaNum, stbNum, vgVersion, hashMethod, vgNum); - - pIter = taosHashIterate(dbHash, pIter); - } -} - - - - -void ctgDbgShowClusterCache(SCatalog* pCtg) { - if (!gCTGDebug.cacheEnable || NULL == pCtg) { - return; - } - - ctgDebug("## cluster %"PRIx64" %p cache Info ##", pCtg->clusterId, pCtg); - ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), - ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM)); - - ctgDbgShowDBCache(pCtg, pCtg->dbCache); -} - - void ctgFreeMetaRent(SCtgRentMgmt *mgmt) { if (NULL == mgmt->slots) { return; @@ -249,15 +73,19 @@ void ctgFreeMetaRent(SCtgRentMgmt *mgmt) { void ctgFreeTableMetaCache(SCtgTbMetaCache *cache) { CTG_LOCK(CTG_WRITE, &cache->stbLock); if (cache->stbCache) { + int32_t stblNum = taosHashGetSize(cache->stbCache); taosHashCleanup(cache->stbCache); cache->stbCache = NULL; + CTG_CACHE_STAT_SUB(stblNum, stblNum); } CTG_UNLOCK(CTG_WRITE, &cache->stbLock); CTG_LOCK(CTG_WRITE, &cache->metaLock); if (cache->metaCache) { + int32_t tblNum = taosHashGetSize(cache->metaCache); taosHashCleanup(cache->metaCache); cache->metaCache = NULL; + CTG_CACHE_STAT_SUB(tblNum, tblNum); } CTG_UNLOCK(CTG_WRITE, &cache->metaLock); } @@ -293,6 +121,8 @@ void ctgFreeHandle(SCatalog* pCtg) { ctgFreeMetaRent(&pCtg->stbRent); if (pCtg->dbCache) { + int32_t dbNum = taosHashGetSize(pCtg->dbCache); + void *pIter = taosHashIterate(pCtg->dbCache, NULL); while (pIter) { SCtgDBCache *dbCache = pIter; @@ -305,6 +135,8 @@ void ctgFreeHandle(SCatalog* pCtg) { } taosHashCleanup(pCtg->dbCache); + + CTG_CACHE_STAT_SUB(dbNum, dbNum); } taosMemoryFree(pCtg); @@ -361,7 +193,7 @@ int32_t ctgPushAction(SCatalog* pCtg, SCtgMetaAction *action) { CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.queue.qlock); CTG_QUEUE_ADD(); - CTG_STAT_ADD(gCtgMgmt.stat.runtime.qNum); + CTG_RUNTIME_STAT_ADD(qNum, 1); tsem_post(&gCtgMgmt.queue.reqSem); @@ -620,34 +452,45 @@ int32_t ctgGetDBCache(SCatalog* pCtg, const char *dbFName, SCtgDBCache **pCache) int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCache **pCache, bool *inCache) { + SCtgDBCache *dbCache = NULL; + if (NULL == pCtg->dbCache) { - *pCache = NULL; - *inCache = false; - ctgWarn("empty db cache, dbFName:%s", dbFName); - return TSDB_CODE_SUCCESS; + ctgDebug("empty db cache, dbFName:%s", dbFName); + goto _return; } - SCtgDBCache *dbCache = NULL; ctgAcquireDBCache(pCtg, dbFName, &dbCache); if (NULL == dbCache) { - *pCache = NULL; - *inCache = false; - return TSDB_CODE_SUCCESS; + ctgDebug("db %s not in cache", dbFName); + goto _return; } ctgAcquireVgInfo(pCtg, dbCache, inCache); if (!(*inCache)) { - ctgReleaseDBCache(pCtg, dbCache); - - *pCache = NULL; - return TSDB_CODE_SUCCESS; + ctgDebug("vgInfo of db %s not in cache", dbFName); + goto _return; } *pCache = dbCache; *inCache = true; + CTG_CACHE_STAT_ADD(vgHitNum, 1); + ctgDebug("Got db vgInfo from cache, dbFName:%s", dbFName); + return TSDB_CODE_SUCCESS; + +_return: + + if (dbCache) { + ctgReleaseDBCache(pCtg, dbCache); + } + + *pCache = NULL; + *inCache = false; + + CTG_CACHE_STAT_ADD(vgMissNum, 1); + return TSDB_CODE_SUCCESS; } @@ -763,11 +606,10 @@ int32_t ctgIsTableMetaExistInCache(SCatalog* pCtg, char *dbFName, char* tbName, } -int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta, int32_t *exist, int32_t flag, uint64_t *dbId) { +int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta, bool *inCache, int32_t flag, uint64_t *dbId) { if (NULL == pCtg->dbCache) { - *exist = 0; - ctgWarn("empty tbmeta cache, tbName:%s", pTableName->tname); - return TSDB_CODE_SUCCESS; + ctgDebug("empty tbmeta cache, tbName:%s", pTableName->tname); + goto _return; } char dbFName[TSDB_DB_FNAME_LEN] = {0}; @@ -782,8 +624,8 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable SCtgDBCache *dbCache = NULL; ctgAcquireDBCache(pCtg, dbFName, &dbCache); if (NULL == dbCache) { - *exist = 0; - return TSDB_CODE_SUCCESS; + ctgDebug("db %s not in cache", pTableName->tname); + goto _return; } int32_t sz = 0; @@ -792,13 +634,11 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock); if (NULL == *pTableMeta) { - *exist = 0; ctgReleaseDBCache(pCtg, dbCache); ctgDebug("tbl not in cache, dbFName:%s, tbName:%s", dbFName, pTableName->tname); - return TSDB_CODE_SUCCESS; + goto _return; } - *exist = 1; if (dbId) { *dbId = dbCache->dbId; } @@ -808,6 +648,10 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable if (tbMeta->tableType != TSDB_CHILD_TABLE) { ctgReleaseDBCache(pCtg, dbCache); ctgDebug("Got meta from cache, type:%d, dbFName:%s, tbName:%s", tbMeta->tableType, dbFName, pTableName->tname); + + *inCache = true; + CTG_CACHE_STAT_ADD(tblHitNum, 1); + return TSDB_CODE_SUCCESS; } @@ -819,8 +663,7 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable ctgReleaseDBCache(pCtg, dbCache); ctgError("stb not in stbCache, suid:%"PRIx64, tbMeta->suid); taosMemoryFreeClear(*pTableMeta); - *exist = 0; - return TSDB_CODE_SUCCESS; + goto _return; } if ((*stbMeta)->suid != tbMeta->suid) { @@ -846,8 +689,18 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable ctgReleaseDBCache(pCtg, dbCache); + *inCache = true; + CTG_CACHE_STAT_ADD(tblHitNum, 1); + ctgDebug("Got tbmeta from cache, dbFName:%s, tbName:%s", dbFName, pTableName->tname); + return TSDB_CODE_SUCCESS; + +_return: + + *inCache = false; + CTG_CACHE_STAT_ADD(tblMissNum, 1); + return TSDB_CODE_SUCCESS; } @@ -1377,6 +1230,8 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) { ctgError("taosHashPut db to cache failed, dbFName:%s", dbFName); CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } + + CTG_CACHE_STAT_ADD(dbNum, 1); SDbVgVersion vgVersion = {.dbId = newDBCache.dbId, .vgVersion = -1}; strncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName)); @@ -1436,6 +1291,8 @@ int32_t ctgRemoveDB(SCatalog* pCtg, SCtgDBCache *dbCache, const char* dbFName) { CTG_ERR_RET(TSDB_CODE_CTG_DB_DROPPED); } + CTG_CACHE_STAT_SUB(dbNum, 1); + ctgInfo("db removed from cache, dbFName:%s, dbId:%"PRIx64, dbFName, dbId); return TSDB_CODE_SUCCESS; @@ -1568,6 +1425,8 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui CTG_LOCK(CTG_WRITE, &tbCache->stbLock); if (taosHashRemove(tbCache->stbCache, &orig->suid, sizeof(orig->suid))) { ctgError("stb not exist in stbCache, dbFName:%s, stb:%s, suid:%"PRIx64, dbFName, tbName, orig->suid); + } else { + CTG_CACHE_STAT_SUB(stblNum, 1); } CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock); @@ -1594,8 +1453,12 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } + if (NULL == orig) { + CTG_CACHE_STAT_ADD(tblNum, 1); + } + ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType); - ctgDbgShowTableMeta(pCtg, tbName, meta); + ctgdShowTableMeta(pCtg, tbName, meta); if (!isStb) { CTG_UNLOCK(CTG_READ, &tbCache->metaLock); @@ -1615,6 +1478,8 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui ctgError("taosHashPut stable to stable cache failed, suid:%"PRIx64, meta->suid); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } + + CTG_CACHE_STAT_ADD(stblNum, 1); CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock); @@ -1874,7 +1739,7 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } - int32_t exist = 0; + bool inCache = false; int32_t code = 0; uint64_t dbId = 0; uint64_t suid = 0; @@ -1884,11 +1749,11 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons CTG_FLAG_SET_INF_DB(flag); } - CTG_ERR_RET(ctgGetTableMetaFromCache(pCtg, pTableName, pTableMeta, &exist, flag, &dbId)); + CTG_ERR_RET(ctgGetTableMetaFromCache(pCtg, pTableName, pTableMeta, &inCache, flag, &dbId)); int32_t tbType = 0; - if (exist) { + if (inCache) { if (CTG_FLAG_MATCH_STB(flag, (*pTableMeta)->tableType) && ((!CTG_FLAG_IS_FORCE_UPDATE(flag)) || (CTG_FLAG_IS_INF_DB(flag)))) { goto _return; } @@ -1930,8 +1795,8 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons SName stbName = *pTableName; strcpy(stbName.tname, output->tbName); - CTG_ERR_JRET(ctgGetTableMetaFromCache(pCtg, &stbName, pTableMeta, &exist, flag, NULL)); - if (0 == exist) { + CTG_ERR_JRET(ctgGetTableMetaFromCache(pCtg, &stbName, pTableMeta, &inCache, flag, NULL)); + if (!inCache) { ctgDebug("stb no longer exist, dbFName:%s, tbName:%s", output->dbFName, pTableName->tname); continue; } @@ -1943,7 +1808,7 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons _return: - if (CTG_TABLE_NOT_EXIST(code) && exist) { + if (CTG_TABLE_NOT_EXIST(code) && inCache) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; if (CTG_FLAG_IS_INF_DB(flag)) { strcpy(dbFName, pTableName->dbname); @@ -1962,7 +1827,7 @@ _return: if (*pTableMeta) { ctgDebug("tbmeta returned, tbName:%s, tbType:%d", pTableName->tname, (*pTableMeta)->tableType); - ctgDbgShowTableMeta(pCtg, pTableName->tname, *pTableMeta); + ctgdShowTableMeta(pCtg, pTableName->tname, *pTableMeta); } CTG_RET(code); @@ -2075,12 +1940,16 @@ int32_t ctgActRemoveStb(SCtgMetaAction *action) { CTG_LOCK(CTG_WRITE, &dbCache->tbCache.stbLock); if (taosHashRemove(dbCache->tbCache.stbCache, &msg->suid, sizeof(msg->suid))) { ctgDebug("stb not exist in stbCache, may be removed, dbFName:%s, stb:%s, suid:%"PRIx64, msg->dbFName, msg->stbName, msg->suid); + } else { + CTG_CACHE_STAT_SUB(stblNum, 1); } CTG_LOCK(CTG_READ, &dbCache->tbCache.metaLock); if (taosHashRemove(dbCache->tbCache.metaCache, msg->stbName, strlen(msg->stbName))) { ctgError("stb not exist in cache, dbFName:%s, stb:%s, suid:%"PRIx64, msg->dbFName, msg->stbName, msg->suid); - } + } else { + CTG_CACHE_STAT_SUB(tblNum, 1); + } CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock); CTG_UNLOCK(CTG_WRITE, &dbCache->tbCache.stbLock); @@ -2119,6 +1988,8 @@ int32_t ctgActRemoveTbl(SCtgMetaAction *action) { CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock); ctgError("stb not exist in cache, dbFName:%s, tbName:%s", msg->dbFName, msg->tbName); CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + } else { + CTG_CACHE_STAT_SUB(tblNum, 1); } CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock); @@ -2140,7 +2011,9 @@ void* ctgUpdateThreadFunc(void* param) { CTG_LOCK(CTG_READ, &gCtgMgmt.lock); while (true) { - tsem_wait(&gCtgMgmt.queue.reqSem); + if (tsem_wait(&gCtgMgmt.queue.reqSem)) { + qError("ctg tsem_wait failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); + } if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { tsem_post(&gCtgMgmt.queue.rspSem); @@ -2161,9 +2034,9 @@ void* ctgUpdateThreadFunc(void* param) { tsem_post(&gCtgMgmt.queue.rspSem); } - CTG_STAT_ADD(gCtgMgmt.stat.runtime.qDoneNum); + CTG_RUNTIME_STAT_ADD(qDoneNum, 1); - ctgDbgShowClusterCache(pCtg); + ctgdShowClusterCache(pCtg); } CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); @@ -2304,10 +2177,15 @@ int32_t catalogInit(SCatalogCfg *cfg) { CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } - CTG_ERR_RET(ctgStartUpdateThread()); - - tsem_init(&gCtgMgmt.queue.reqSem, 0, 0); - tsem_init(&gCtgMgmt.queue.rspSem, 0, 0); + if (tsem_init(&gCtgMgmt.queue.reqSem, 0, 0)) { + qError("tsem_init failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); + CTG_ERR_RET(TSDB_CODE_CTG_SYS_ERROR); + } + + if (tsem_init(&gCtgMgmt.queue.rspSem, 0, 0)) { + qError("tsem_init failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); + CTG_ERR_RET(TSDB_CODE_CTG_SYS_ERROR); + } gCtgMgmt.queue.head = taosMemoryCalloc(1, sizeof(SCtgQNode)); if (NULL == gCtgMgmt.queue.head) { @@ -2316,6 +2194,8 @@ int32_t catalogInit(SCatalogCfg *cfg) { } gCtgMgmt.queue.tail = gCtgMgmt.queue.head; + CTG_ERR_RET(ctgStartUpdateThread()); + qDebug("catalog initialized, maxDb:%u, maxTbl:%u, dbRentSec:%u, stbRentSec:%u", gCtgMgmt.cfg.maxDBCacheNum, gCtgMgmt.cfg.maxTblCacheNum, gCtgMgmt.cfg.dbRentSec, gCtgMgmt.cfg.stbRentSec); return TSDB_CODE_SUCCESS; @@ -2383,6 +2263,8 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) { } *catalogHandle = clusterCtg; + + CTG_CACHE_STAT_ADD(clusterNum, 1); return TSDB_CODE_SUCCESS; @@ -2403,10 +2285,12 @@ void catalogFreeHandle(SCatalog* pCtg) { return; } + CTG_CACHE_STAT_SUB(clusterNum, 1); + uint64_t clusterId = pCtg->clusterId; ctgFreeHandle(pCtg); - + ctgInfo("handle freed, culsterId:%"PRIx64, clusterId); } @@ -2417,24 +2301,12 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } - if (NULL == pCtg->dbCache) { - *version = CTG_DEFAULT_INVALID_VERSION; - ctgInfo("empty db cache, dbFName:%s", dbFName); - CTG_API_LEAVE(TSDB_CODE_SUCCESS); - } - SCtgDBCache *dbCache = NULL; - ctgAcquireDBCache(pCtg, dbFName, &dbCache); - if (NULL == dbCache) { - *version = CTG_DEFAULT_INVALID_VERSION; - CTG_API_LEAVE(TSDB_CODE_SUCCESS); - } - bool inCache = false; - ctgAcquireVgInfo(pCtg, dbCache, &inCache); - if (!inCache) { - ctgReleaseDBCache(pCtg, dbCache); + int32_t code = 0; + CTG_ERR_JRET(ctgAcquireVgInfoFromCache(pCtg, dbFName, &dbCache, &inCache)); + if (!inCache) { *version = CTG_DEFAULT_INVALID_VERSION; CTG_API_LEAVE(TSDB_CODE_SUCCESS); } @@ -2449,6 +2321,10 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers ctgDebug("Got db vgVersion from cache, dbFName:%s, vgVersion:%d", dbFName, *version); CTG_API_LEAVE(TSDB_CODE_SUCCESS); + +_return: + + CTG_API_LEAVE(code); } int32_t catalogGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SArray** vgroupList) { @@ -2549,11 +2425,11 @@ int32_t catalogRemoveTableMeta(SCatalog* pCtg, const SName* pTableName) { } STableMeta *tblMeta = NULL; - int32_t exist = 0; + bool inCache = false; uint64_t dbId = 0; - CTG_ERR_JRET(ctgGetTableMetaFromCache(pCtg, pTableName, &tblMeta, &exist, 0, &dbId)); + CTG_ERR_JRET(ctgGetTableMetaFromCache(pCtg, pTableName, &tblMeta, &inCache, 0, &dbId)); - if (0 == exist) { + if (!inCache) { ctgDebug("table already not in cache, db:%s, tblName:%s", pTableName->dbname, pTableName->tname); goto _return; } @@ -2851,8 +2727,13 @@ void catalogDestroy(void) { atomic_store_8((int8_t*)&gCtgMgmt.exit, true); - tsem_post(&gCtgMgmt.queue.reqSem); - tsem_post(&gCtgMgmt.queue.rspSem); + if (tsem_post(&gCtgMgmt.queue.reqSem)) { + qError("tsem_post failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); + } + + if (tsem_post(&gCtgMgmt.queue.rspSem)) { + qError("tsem_post failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); + } while (CTG_IS_LOCKED(&gCtgMgmt.lock)) { taosUsleep(1); diff --git a/source/libs/catalog/src/catalogDbg.c b/source/libs/catalog/src/catalogDbg.c new file mode 100644 index 0000000000..1d4ad0082c --- /dev/null +++ b/source/libs/catalog/src/catalogDbg.c @@ -0,0 +1,222 @@ +/* + * 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 "trpc.h" +#include "query.h" +#include "tname.h" +#include "catalogInt.h" + +extern SCatalogMgmt gCtgMgmt; +SCtgDebug gCTGDebug = {0}; + +int32_t ctgdEnableDebug(char *option) { + if (0 == strcasecmp(option, "lock")) { + gCTGDebug.lockEnable = true; + qDebug("lock debug enabled"); + return TSDB_CODE_SUCCESS; + } + + if (0 == strcasecmp(option, "cache")) { + gCTGDebug.cacheEnable = true; + qDebug("cache debug enabled"); + return TSDB_CODE_SUCCESS; + } + + if (0 == strcasecmp(option, "api")) { + gCTGDebug.apiEnable = true; + qDebug("api debug enabled"); + return TSDB_CODE_SUCCESS; + } + + if (0 == strcasecmp(option, "meta")) { + gCTGDebug.metaEnable = true; + qDebug("api debug enabled"); + return TSDB_CODE_SUCCESS; + } + + qError("invalid debug option:%s", option); + + return TSDB_CODE_CTG_INTERNAL_ERROR; +} + +int32_t ctgdGetStatNum(char *option, void *res) { + if (0 == strcasecmp(option, "runtime.qDoneNum")) { + *(uint64_t *)res = atomic_load_64(&gCtgMgmt.stat.runtime.qDoneNum); + return TSDB_CODE_SUCCESS; + } + + qError("invalid stat option:%s", option); + + return TSDB_CODE_CTG_INTERNAL_ERROR; +} + +int32_t ctgdGetTbMetaNum(SCtgDBCache *dbCache) { + return dbCache->tbCache.metaCache ? (int32_t)taosHashGetSize(dbCache->tbCache.metaCache) : 0; +} + +int32_t ctgdGetStbNum(SCtgDBCache *dbCache) { + return dbCache->tbCache.stbCache ? (int32_t)taosHashGetSize(dbCache->tbCache.stbCache) : 0; +} + +int32_t ctgdGetRentNum(SCtgRentMgmt *rent) { + int32_t num = 0; + for (uint16_t i = 0; i < rent->slotNum; ++i) { + SCtgRentSlot *slot = &rent->slots[i]; + if (NULL == slot->meta) { + continue; + } + + num += taosArrayGetSize(slot->meta); + } + + return num; +} + +int32_t ctgdGetClusterCacheNum(SCatalog* pCtg, int32_t type) { + if (NULL == pCtg || NULL == pCtg->dbCache) { + return 0; + } + + switch (type) { + case CTG_DBG_DB_NUM: + return (int32_t)taosHashGetSize(pCtg->dbCache); + case CTG_DBG_DB_RENT_NUM: + return ctgdGetRentNum(&pCtg->dbRent); + case CTG_DBG_STB_RENT_NUM: + return ctgdGetRentNum(&pCtg->stbRent); + default: + break; + } + + SCtgDBCache *dbCache = NULL; + int32_t num = 0; + void *pIter = taosHashIterate(pCtg->dbCache, NULL); + while (pIter) { + dbCache = (SCtgDBCache *)pIter; + switch (type) { + case CTG_DBG_META_NUM: + num += ctgdGetTbMetaNum(dbCache); + break; + case CTG_DBG_STB_NUM: + num += ctgdGetStbNum(dbCache); + break; + default: + ctgError("invalid type:%d", type); + break; + } + pIter = taosHashIterate(pCtg->dbCache, pIter); + } + + return num; +} + +void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p) { + if (!gCTGDebug.metaEnable) { + return; + } + + STableComInfo *c = &p->tableInfo; + + if (TSDB_CHILD_TABLE == p->tableType) { + ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64, tbName, p->tableType, p->vgId, p->uid, p->suid); + return; + } else { + ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64 ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d", + tbName, p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, c->numOfColumns, c->rowSize); + } + + int32_t colNum = c->numOfColumns + c->numOfTags; + for (int32_t i = 0; i < colNum; ++i) { + SSchema *s = &p->schema[i]; + ctgDebug("[%d] name:%s, type:%d, colId:%d, bytes:%d", i, s->name, s->type, s->colId, s->bytes); + } +} + +void ctgdShowDBCache(SCatalog* pCtg, SHashObj *dbHash) { + if (NULL == dbHash || !gCTGDebug.cacheEnable) { + return; + } + + int32_t i = 0; + SCtgDBCache *dbCache = NULL; + void *pIter = taosHashIterate(dbHash, NULL); + while (pIter) { + char *dbFName = NULL; + size_t len = 0; + + dbCache = (SCtgDBCache *)pIter; + + dbFName = taosHashGetKey(pIter, &len); + + int32_t metaNum = dbCache->tbCache.metaCache ? taosHashGetSize(dbCache->tbCache.metaCache) : 0; + int32_t stbNum = dbCache->tbCache.stbCache ? taosHashGetSize(dbCache->tbCache.stbCache) : 0; + int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION; + int32_t hashMethod = -1; + int32_t vgNum = 0; + + if (dbCache->vgInfo) { + vgVersion = dbCache->vgInfo->vgVersion; + hashMethod = dbCache->vgInfo->hashMethod; + if (dbCache->vgInfo->vgHash) { + vgNum = taosHashGetSize(dbCache->vgInfo->vgHash); + } + } + + ctgDebug("[%d] db [%.*s][%"PRIx64"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, hashMethod:%d, vgNum:%d", + i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted?"deleted":"", metaNum, stbNum, vgVersion, hashMethod, vgNum); + + pIter = taosHashIterate(dbHash, pIter); + } +} + + + + +void ctgdShowClusterCache(SCatalog* pCtg) { + if (!gCTGDebug.cacheEnable || NULL == pCtg) { + return; + } + + ctgDebug("## cluster %"PRIx64" %p cache Info BEGIN ##", pCtg->clusterId, pCtg); + ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), + ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM)); + + ctgdShowDBCache(pCtg, pCtg->dbCache); + + ctgDebug("## cluster %"PRIx64" %p cache Info END ##", pCtg->clusterId, pCtg); +} + +int32_t ctgdShowCacheInfo(void) { + if (!gCTGDebug.cacheEnable) { + return TSDB_CODE_CTG_OUT_OF_SERVICE; + } + + CTG_API_ENTER(); + + SCatalog *pCtg = NULL; + void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL); + while (pIter) { + pCtg = *(SCatalog **)pIter; + + if (pCtg) { + ctgdShowClusterCache(pCtg); + } + + pIter = taosHashIterate(gCtgMgmt.pCluster, pIter); + } + + CTG_API_LEAVE(TSDB_CODE_SUCCESS); +} + diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index e62819b078..73d0dc2011 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -38,11 +38,11 @@ namespace { extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta, - int32_t *exist, int32_t flag, uint64_t *dbId); -extern "C" int32_t ctgDbgGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type); + bool *inCache, int32_t flag, uint64_t *dbId); +extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type); extern "C" int32_t ctgActUpdateTbl(SCtgMetaAction *action); -extern "C" int32_t ctgDbgEnableDebug(char *option); -extern "C" int32_t ctgDbgGetStatNum(char *option, void *res); +extern "C" int32_t ctgdEnableDebug(char *option); +extern "C" int32_t ctgdGetStatNum(char *option, void *res); void ctgTestSetRspTableMeta(); void ctgTestSetRspCTableMeta(); @@ -140,9 +140,9 @@ void ctgTestInitLogFile() { qDebugFlag = 159; strcpy(tsLogDir, "/var/log/taos"); - ctgDbgEnableDebug("api"); - ctgDbgEnableDebug("meta"); - ctgDbgEnableDebug("cache"); + ctgdEnableDebug("api"); + ctgdEnableDebug("meta"); + ctgdEnableDebug("cache"); if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { printf("failed to open log file in directory:%s\n", tsLogDir); @@ -786,15 +786,15 @@ void *ctgTestGetCtableMetaThread(void *param) { int32_t code = 0; int32_t n = 0; STableMeta *tbMeta = NULL; - int32_t exist = 0; + bool inCache = false; SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; strcpy(cn.dbname, "db1"); strcpy(cn.tname, ctgTestCTablename); while (!ctgTestStop) { - code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &exist, 0, NULL); - if (code || 0 == exist) { + code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &inCache, 0, NULL); + if (code || !inCache) { assert(0); } @@ -879,7 +879,7 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.epSet.numOfEps, 3); - while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) { + while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) { taosMsleep(50); } @@ -899,7 +899,7 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); while (true) { - uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { taosMsleep(50); } else { @@ -994,7 +994,7 @@ TEST(tableMeta, childTableCase) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); while (true) { - uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { taosMsleep(50); } else { @@ -1103,7 +1103,7 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); while (true) { - uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { taosMsleep(50); } else { @@ -1130,7 +1130,7 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); while (true) { - uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (2 != n) { taosMsleep(50); } else { @@ -1228,7 +1228,7 @@ TEST(tableMeta, rmStbMeta) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); while (true) { - uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { taosMsleep(50); } else { @@ -1241,8 +1241,8 @@ TEST(tableMeta, rmStbMeta) { ASSERT_EQ(code, 0); while (true) { - int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); - int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM); + int32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + int32_t m = ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM); if (n || m) { taosMsleep(50); } else { @@ -1251,11 +1251,11 @@ TEST(tableMeta, rmStbMeta) { } - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 0); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 0); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -1298,7 +1298,7 @@ TEST(tableMeta, updateStbMeta) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); while (true) { - uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { taosMsleep(50); } else { @@ -1318,7 +1318,7 @@ TEST(tableMeta, updateStbMeta) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n != 3) { taosMsleep(50); } else { @@ -1326,11 +1326,11 @@ TEST(tableMeta, updateStbMeta) { } } - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 1); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 1); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1); - ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 1); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 1); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 1); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1); + ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 1); code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); ASSERT_EQ(code, 0); @@ -1388,7 +1388,7 @@ TEST(refreshGetMeta, normal2normal) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n > 0) { break; } @@ -1409,7 +1409,7 @@ TEST(refreshGetMeta, normal2normal) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); taosMemoryFreeClear(tableMeta); - while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { + while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); } @@ -1467,7 +1467,7 @@ TEST(refreshGetMeta, normal2notexist) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n > 0) { break; } @@ -1488,7 +1488,7 @@ TEST(refreshGetMeta, normal2notexist) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); taosMemoryFreeClear(tableMeta); - while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { + while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); } @@ -1541,7 +1541,7 @@ TEST(refreshGetMeta, normal2child) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n > 0) { break; } @@ -1562,7 +1562,7 @@ TEST(refreshGetMeta, normal2child) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); taosMemoryFreeClear(tableMeta); - while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { + while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); } @@ -1625,7 +1625,7 @@ TEST(refreshGetMeta, stable2child) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n > 0) { break; } @@ -1647,7 +1647,7 @@ TEST(refreshGetMeta, stable2child) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); taosMemoryFreeClear(tableMeta); - while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { + while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); } @@ -1710,7 +1710,7 @@ TEST(refreshGetMeta, stable2stable) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n > 0) { break; } @@ -1732,7 +1732,7 @@ TEST(refreshGetMeta, stable2stable) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); taosMemoryFreeClear(tableMeta); - while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { + while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); } @@ -1798,7 +1798,7 @@ TEST(refreshGetMeta, child2stable) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n > 0) { break; } @@ -1818,7 +1818,7 @@ TEST(refreshGetMeta, child2stable) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); taosMemoryFreeClear(tableMeta); - while (2 != ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { + while (2 != ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { taosMsleep(50); } @@ -2015,7 +2015,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n > 0) { break; } @@ -2041,7 +2041,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { while (true) { uint64_t n = 0; - ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); + ctgdGetStatNum("runtime.qDoneNum", (void *)&n); if (n != 3) { taosMsleep(50); } else { @@ -2266,7 +2266,7 @@ TEST(rentTest, allRent) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) { + while (ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) { taosMsleep(50); } diff --git a/source/libs/command/CMakeLists.txt b/source/libs/command/CMakeLists.txt new file mode 100644 index 0000000000..db3766d145 --- /dev/null +++ b/source/libs/command/CMakeLists.txt @@ -0,0 +1,16 @@ +aux_source_directory(src COMMAND_SRC) +add_library(command STATIC ${COMMAND_SRC}) +target_include_directories( + command + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/command" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + command + PRIVATE os util nodes catalog function transport qcom +) + +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h new file mode 100644 index 0000000000..771baca2ab --- /dev/null +++ b/source/libs/command/inc/commandInt.h @@ -0,0 +1,99 @@ +/* + * 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 _TD_QUERY_INT_H_ +#define _TD_QUERY_INT_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "nodes.h" +#include "plannodes.h" +#include "ttime.h" + +#define EXPLAIN_MAX_GROUP_NUM 100 + +//newline area +#define EXPLAIN_TAG_SCAN_FORMAT "Tag Scan on %s columns=%d width=%d" +#define EXPLAIN_TBL_SCAN_FORMAT "Table Scan on %s columns=%d width=%d" +#define EXPLAIN_SYSTBL_SCAN_FORMAT "System Table Scan on %s columns=%d width=%d" +#define EXPLAIN_PROJECTION_FORMAT "Projection columns=%d width=%d" +#define EXPLAIN_JOIN_FORMAT "%s between %d tables width=%d" +#define EXPLAIN_AGG_FORMAT "Aggragate functions=%d" +#define EXPLAIN_EXCHANGE_FORMAT "Data Exchange %d:1 width=%d" +#define EXPLAIN_SORT_FORMAT "Sort on %d Column(s) width=%d" +#define EXPLAIN_INTERVAL_FORMAT "Interval on Column %s functions=%d interval=%" PRId64 "%c offset=%" PRId64 "%c sliding=%" PRId64 "%c width=%d" +#define EXPLAIN_SESSION_FORMAT "Session gap=%" PRId64 " functions=%d width=%d" +#define EXPLAIN_ORDER_FORMAT "Order: %s" +#define EXPLAIN_FILTER_FORMAT "Filter: " +#define EXPLAIN_FILL_FORMAT "Fill: %s" +#define EXPLAIN_ON_CONDITIONS_FORMAT "Join Cond: " +#define EXPLAIN_TIMERANGE_FORMAT "Time Range: [%" PRId64 ", %" PRId64 "]" + +//append area +#define EXPLAIN_GROUPS_FORMAT " groups=%d" +#define EXPLAIN_WIDTH_FORMAT " width=%d" +#define EXPLAIN_LOOPS_FORMAT " loops=%d" +#define EXPLAIN_REVERSE_FORMAT " reverse=%d" + +typedef struct SExplainGroup { + int32_t nodeNum; + SSubplan *plan; + void *execInfo; //TODO +} SExplainGroup; + +typedef struct SExplainResNode { + SNodeList* pChildren; + SPhysiNode* pNode; + void* pExecInfo; +} SExplainResNode; + +typedef struct SQueryExplainRowInfo { + int32_t level; + int32_t len; + char *buf; +} SQueryExplainRowInfo; + +typedef struct SExplainCtx { + int32_t totalSize; + bool verbose; + char *tbuf; + SArray *rows; + SHashObj *groupHash; +} SExplainCtx; + +#define EXPLAIN_ORDER_STRING(_order) ((TSDB_ORDER_ASC == _order) ? "Ascending" : "Descending") +#define EXPLAIN_JOIN_STRING(_type) ((JOIN_TYPE_INNER == _type) ? "Inner join" : "Join") + +#define INVERAL_TIME_FROM_PRECISION_TO_UNIT(_t, _u, _p) (((_u) == 'n' || (_u) == 'y') ? (_t) : (convertTimeFromPrecisionToUnit(_t, _p, _u))) + +#define EXPLAIN_ROW_NEW(level, ...) \ + do { \ + if (isVerboseLine) { \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s", (level) * 2 + 3, ""); \ + } else { \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s%s", (level) * 2, "", "-> "); \ + } \ + tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__); \ + } while (0) + +#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__) +#define EXPLAIN_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; isVerboseLine = true; } while (0) + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_QUERY_INT_H_*/ diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c new file mode 100644 index 0000000000..4d4ac6c1e4 --- /dev/null +++ b/source/libs/command/src/command.c @@ -0,0 +1,124 @@ +/* + * 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 "command.h" +#include "tdatablock.h" + +static int32_t getSchemaBytes(const SSchema* pSchema) { + switch (pSchema->type) { + case TSDB_DATA_TYPE_BINARY: + return (pSchema->bytes - VARSTR_HEADER_SIZE); + case TSDB_DATA_TYPE_NCHAR: + return (pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + default: + return pSchema->bytes; + } +} + +static void buildRspData(const STableMeta* pMeta, char* pData) { + int32_t* pColSizes = (int32_t*)pData; + pData += DESCRIBE_RESULT_COLS * sizeof(int32_t); + int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta); + + // Field + int32_t* pOffset = (int32_t*)pData; + pData += numOfRows * sizeof(int32_t); + for (int32_t i = 0; i < numOfRows; ++i) { + STR_TO_VARSTR(pData, pMeta->schema[i].name); + int16_t len = varDataTLen(pData); + pData += len; + *pOffset = pColSizes[0]; + pOffset += 1; + pColSizes[0] += len; + } + + // Type + pOffset = (int32_t*)pData; + pData += numOfRows * sizeof(int32_t); + for (int32_t i = 0; i < numOfRows; ++i) { + STR_TO_VARSTR(pData, tDataTypes[pMeta->schema[i].type].name); + int16_t len = varDataTLen(pData); + pData += len; + *pOffset = pColSizes[1]; + pOffset += 1; + pColSizes[1] += len; + } + + // Length + pData += BitmapLen(numOfRows); + for (int32_t i = 0; i < numOfRows; ++i) { + *(int32_t*)pData = getSchemaBytes(pMeta->schema + i); + pData += sizeof(int32_t); + } + pColSizes[2] = sizeof(int32_t) * numOfRows; + + // Note + pOffset = (int32_t*)pData; + pData += numOfRows * sizeof(int32_t); + for (int32_t i = 0; i < numOfRows; ++i) { + STR_TO_VARSTR(pData, i >= pMeta->tableInfo.numOfColumns ? "TAG" : ""); + int16_t len = varDataTLen(pData); + pData += len; + *pOffset = pColSizes[3]; + pOffset += 1; + pColSizes[3] += len; + } + + for (int32_t i = 0; i < DESCRIBE_RESULT_COLS; ++i) { + pColSizes[i] = htonl(pColSizes[i]); + } +} + +static int32_t calcRspSize(const STableMeta* pMeta) { + int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta); + return sizeof(SRetrieveTableRsp) + + (numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_FIELD_LEN) + + (numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_TYPE_LEN) + + (BitmapLen(numOfRows) + numOfRows * sizeof(int32_t)) + + (numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_NOTE_LEN); +} + +static int32_t execDescribe(SNode* pStmt, SRetrieveTableRsp** pRsp) { + SDescribeStmt* pDesc = (SDescribeStmt*)pStmt; + *pRsp = taosMemoryCalloc(1, calcRspSize(pDesc->pMeta)); + if (NULL == *pRsp) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (*pRsp)->useconds = 0; + (*pRsp)->completed = 1; + (*pRsp)->precision = 0; + (*pRsp)->compressed = 0; + (*pRsp)->compLen = 0; + (*pRsp)->numOfRows = htonl(TABLE_TOTAL_COL_NUM(pDesc->pMeta)); + buildRspData(pDesc->pMeta, (*pRsp)->data); + return TSDB_CODE_SUCCESS; +} + +static int32_t execResetQueryCache() { + // todo + return TSDB_CODE_SUCCESS; +} + +int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) { + switch (nodeType(pStmt)) { + case QUERY_NODE_DESCRIBE_STMT: + return execDescribe(pStmt, pRsp); + case QUERY_NODE_RESET_QUERY_CACHE_STMT: + return execResetQueryCache(); + default: + break; + } + return TSDB_CODE_FAILED; +} diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c new file mode 100644 index 0000000000..847a863e76 --- /dev/null +++ b/source/libs/command/src/explain.c @@ -0,0 +1,687 @@ +/* + * 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 "query.h" +#include "plannodes.h" +#include "commandInt.h" + +int32_t qGenerateExplainResNode(SPhysiNode *pNode, void *pExecInfo, SExplainResNode **pRes); +int32_t qAppendTaskExplainResRows(void *pCtx, int32_t groupId, int32_t level); + + +void qFreeExplainResTree(SExplainResNode *res) { + if (NULL == res) { + return; + } + + taosMemoryFreeClear(res->pExecInfo); + + SNode* node = NULL; + FOREACH(node, res->pChildren) { + qFreeExplainResTree((SExplainResNode *)node); + } + nodesClearList(res->pChildren); + + taosMemoryFreeClear(res); +} + +void qFreeExplainCtx(void *ctx) { + if (NULL == ctx) { + return; + } + + SExplainCtx *pCtx = (SExplainCtx *)ctx; + int32_t rowSize = taosArrayGetSize(pCtx->rows); + for (int32_t i = 0; i < rowSize; ++i) { + SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i); + taosMemoryFreeClear(row->buf); + } + + taosHashCleanup(pCtx->groupHash); + taosArrayDestroy(pCtx->rows); + taosMemoryFree(pCtx); +} + +int32_t qInitExplainCtx(void **pCtx, SHashObj *groupHash, bool verbose) { + int32_t code = 0; + SExplainCtx *ctx = taosMemoryCalloc(1, sizeof(SExplainCtx)); + if (NULL == ctx) { + qError("calloc SExplainCtx failed"); + QRY_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SArray *rows = taosArrayInit(10, sizeof(SQueryExplainRowInfo)); + if (NULL == rows) { + qError("taosArrayInit SQueryExplainRowInfo failed"); + QRY_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + char *tbuf = taosMemoryMalloc(TSDB_EXPLAIN_RESULT_ROW_SIZE); + if (NULL == tbuf) { + qError("malloc size %d failed", TSDB_EXPLAIN_RESULT_ROW_SIZE); + QRY_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + ctx->verbose = verbose; + ctx->tbuf = tbuf; + ctx->rows = rows; + ctx->groupHash = groupHash; + + *pCtx = ctx; + + return TSDB_CODE_SUCCESS; + +_return: + + taosArrayDestroy(rows); + taosHashCleanup(groupHash); + taosMemoryFree(ctx); + + QRY_RET(code); +} + + +char *qFillModeString(EFillMode mode) { + switch (mode) { + case FILL_MODE_NONE: + return "none"; + case FILL_MODE_VALUE: + return "value"; + case FILL_MODE_PREV: + return "prev"; + case FILL_MODE_NULL: + return "null"; + case FILL_MODE_LINEAR: + return "linear"; + case FILL_MODE_NEXT: + return "next"; + default: + return "unknown"; + } +} + +char *qGetNameFromColumnNode(SNode *pNode) { + if (NULL == pNode || QUERY_NODE_COLUMN != pNode->type) { + return "NULL"; + } + + return ((SColumnNode *)pNode)->colName; +} + +int32_t qGenerateExplainResChildren(SPhysiNode *pNode, void *pExecInfo, SNodeList **pChildren) { + int32_t tlen = 0; + SNodeList *pPhysiChildren = NULL; + + switch (pNode->type) { + case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: { + STagScanPhysiNode *pTagScanNode = (STagScanPhysiNode *)pNode; + pPhysiChildren = pTagScanNode->node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:{ + STableScanPhysiNode *pTblScanNode = (STableScanPhysiNode *)pNode; + pPhysiChildren = pTblScanNode->scan.node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:{ + SSystemTableScanPhysiNode *pSTblScanNode = (SSystemTableScanPhysiNode *)pNode; + pPhysiChildren = pSTblScanNode->scan.node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_PROJECT:{ + SProjectPhysiNode *pPrjNode = (SProjectPhysiNode *)pNode; + pPhysiChildren = pPrjNode->node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_JOIN:{ + SJoinPhysiNode *pJoinNode = (SJoinPhysiNode *)pNode; + pPhysiChildren = pJoinNode->node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_AGG:{ + SAggPhysiNode *pAggNode = (SAggPhysiNode *)pNode; + pPhysiChildren = pAggNode->node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:{ + SExchangePhysiNode *pExchNode = (SExchangePhysiNode *)pNode; + pPhysiChildren = pExchNode->node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SORT:{ + SSortPhysiNode *pSortNode = (SSortPhysiNode *)pNode; + pPhysiChildren = pSortNode->node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ + SIntervalPhysiNode *pIntNode = (SIntervalPhysiNode *)pNode; + pPhysiChildren = pIntNode->window.node.pChildren; + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:{ + SSessionWinodwPhysiNode *pSessNode = (SSessionWinodwPhysiNode *)pNode; + pPhysiChildren = pSessNode->window.node.pChildren; + break; + } + default: + qError("not supported physical node type %d", pNode->type); + QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + if (pPhysiChildren) { + *pChildren = nodesMakeList(); + if (NULL == *pChildren) { + qError("nodesMakeList failed"); + QRY_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + } + + SNode* node = NULL; + SExplainResNode *pResNode = NULL; + FOREACH(node, pPhysiChildren) { + QRY_ERR_RET(qGenerateExplainResNode((SPhysiNode *)node, pExecInfo, &pResNode)); + QRY_ERR_RET(nodesListAppend(*pChildren, pResNode)); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t qGenerateExplainResNode(SPhysiNode *pNode, void *pExecInfo, SExplainResNode **pRes) { + if (NULL == pNode) { + *pRes = NULL; + qError("physical node is NULL"); + return TSDB_CODE_QRY_APP_ERROR; + } + + SExplainResNode *res = taosMemoryCalloc(1, sizeof(SExplainResNode)); + if (NULL == res) { + qError("calloc SPhysiNodeExplainRes failed"); + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + + int32_t code = 0; + res->pNode = pNode; + res->pExecInfo = pExecInfo; + QRY_ERR_JRET(qGenerateExplainResChildren(pNode, pExecInfo, &res->pChildren)); + + *pRes = res; + + return TSDB_CODE_SUCCESS; + +_return: + + qFreeExplainResTree(res); + + QRY_RET(code); +} + +int32_t qExplainBufAppendExecInfo(void *pExecInfo, char *tbuf, int32_t *len) { + int32_t tlen = *len; + + EXPLAIN_ROW_APPEND("(exec info here)"); + + *len = tlen; + + return TSDB_CODE_SUCCESS; +} + +int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t level) { + SQueryExplainRowInfo row = {0}; + row.buf = taosMemoryMalloc(len); + if (NULL == row.buf) { + qError("taosMemoryMalloc %d failed", len); + QRY_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + memcpy(row.buf, tbuf, len); + row.level = level; + row.len = len; + ctx->totalSize += len; + + if (NULL == taosArrayPush(ctx->rows, &row)) { + qError("taosArrayPush row to explain res rows failed"); + taosMemoryFree(row.buf); + QRY_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, int32_t level) { + int32_t tlen = 0; + bool isVerboseLine = false; + char *tbuf = ctx->tbuf; + bool verbose = ctx->verbose; + SPhysiNode* pNode = pResNode->pNode; + if (NULL == pNode) { + qError("pyhsical node in explain res node is NULL"); + return TSDB_CODE_QRY_APP_ERROR; + } + + switch (pNode->type) { + case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: { + STagScanPhysiNode *pTagScanNode = (STagScanPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_TAG_SCAN_FORMAT, pTagScanNode->tableName.tname, pTagScanNode->pScanCols->length, pTagScanNode->node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_APPEND(EXPLAIN_LOOPS_FORMAT, pTagScanNode->count); + if (pTagScanNode->reverse) { + EXPLAIN_ROW_APPEND(EXPLAIN_REVERSE_FORMAT, pTagScanNode->reverse); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pTagScanNode->order)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:{ + STableScanPhysiNode *pTblScanNode = (STableScanPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_TBL_SCAN_FORMAT, pTblScanNode->scan.tableName.tname, pTblScanNode->scan.pScanCols->length, pTblScanNode->scan.node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_APPEND(EXPLAIN_LOOPS_FORMAT, pTblScanNode->scan.count); + if (pTblScanNode->scan.reverse) { + EXPLAIN_ROW_APPEND(EXPLAIN_REVERSE_FORMAT, pTblScanNode->scan.reverse); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pTblScanNode->scan.order)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIMERANGE_FORMAT, pTblScanNode->scanRange.skey, pTblScanNode->scanRange.ekey); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + + if (pTblScanNode->scan.node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pTblScanNode->scan.node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:{ + SSystemTableScanPhysiNode *pSTblScanNode = (SSystemTableScanPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_SYSTBL_SCAN_FORMAT, pSTblScanNode->scan.tableName.tname, pSTblScanNode->scan.pScanCols->length, pSTblScanNode->scan.node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_APPEND(EXPLAIN_LOOPS_FORMAT, pSTblScanNode->scan.count); + if (pSTblScanNode->scan.reverse) { + EXPLAIN_ROW_APPEND(EXPLAIN_REVERSE_FORMAT, pSTblScanNode->scan.reverse); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pSTblScanNode->scan.order)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + + if (pSTblScanNode->scan.node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pSTblScanNode->scan.node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_PROJECT:{ + SProjectPhysiNode *pPrjNode = (SProjectPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_PROJECTION_FORMAT, pPrjNode->pProjections->length, pPrjNode->node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + if (pPrjNode->node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pPrjNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_JOIN:{ + SJoinPhysiNode *pJoinNode = (SJoinPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_JOIN_FORMAT, EXPLAIN_JOIN_STRING(pJoinNode->joinType), pJoinNode->pTargets->length, pJoinNode->node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + if (pJoinNode->node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pJoinNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_ON_CONDITIONS_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pJoinNode->pOnConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_AGG:{ + SAggPhysiNode *pAggNode = (SAggPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_AGG_FORMAT, pAggNode->pAggFuncs->length); + if (pAggNode->pGroupKeys) { + EXPLAIN_ROW_APPEND(EXPLAIN_GROUPS_FORMAT, pAggNode->pGroupKeys->length); + } + EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pAggNode->node.pOutputDataBlockDesc->outputRowSize); + + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + if (pAggNode->node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pAggNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:{ + SExchangePhysiNode *pExchNode = (SExchangePhysiNode *)pNode; + SExplainGroup *group = taosHashGet(ctx->groupHash, &pExchNode->srcGroupId, sizeof(pExchNode->srcGroupId)); + if (NULL == group) { + qError("exchange src group %d not in groupHash", pExchNode->srcGroupId); + QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + EXPLAIN_ROW_NEW(level, EXPLAIN_EXCHANGE_FORMAT, group->nodeNum, pExchNode->node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + if (pExchNode->node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pExchNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + + QRY_ERR_RET(qAppendTaskExplainResRows(ctx, pExchNode->srcGroupId, level + 1)); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SORT:{ + SSortPhysiNode *pSortNode = (SSortPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_SORT_FORMAT, pSortNode->pSortKeys->length, pSortNode->node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + if (pSortNode->node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pSortNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ + SIntervalPhysiNode *pIntNode = (SIntervalPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_INTERVAL_FORMAT, qGetNameFromColumnNode(pIntNode->pTspk), pIntNode->window.pFuncs->length, + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, pIntNode->precision), pIntNode->intervalUnit, + pIntNode->offset, getPrecisionUnit(pIntNode->precision), + INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, pIntNode->precision), pIntNode->slidingUnit, + pIntNode->window.node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + if (pIntNode->pFill) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILL_FORMAT, qFillModeString(pIntNode->pFill->mode)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + + if (pIntNode->window.node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pIntNode->window.node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:{ + SSessionWinodwPhysiNode *pIntNode = (SSessionWinodwPhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_SESSION_FORMAT, pIntNode->gap, pIntNode->window.pFuncs->length, pIntNode->window.node.pOutputDataBlockDesc->outputRowSize); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + if (pIntNode->window.node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pIntNode->window.node.pConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + break; + } + default: + qError("not supported physical node type %d", pNode->type); + return TSDB_CODE_QRY_APP_ERROR; + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t qExplainResNodeToRows(SExplainResNode *pResNode, SExplainCtx *ctx, int32_t level) { + if (NULL == pResNode) { + qError("explain res node is NULL"); + QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + int32_t code = 0; + QRY_ERR_RET(qExplainResNodeToRowsImpl(pResNode, ctx, level)); + + SNode* pNode = NULL; + FOREACH(pNode, pResNode->pChildren) { + QRY_ERR_RET(qExplainResNodeToRows((SExplainResNode *)pNode, ctx, level + 1)); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t qAppendTaskExplainResRows(void *pCtx, int32_t groupId, int32_t level) { + SExplainResNode *node = NULL; + int32_t code = 0; + SExplainCtx *ctx = (SExplainCtx *)pCtx; + + SExplainGroup *group = taosHashGet(ctx->groupHash, &groupId, sizeof(groupId)); + if (NULL == group) { + qError("group %d not in groupHash", groupId); + QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + QRY_ERR_RET(qGenerateExplainResNode(group->plan->pNode, group->execInfo, &node)); + + QRY_ERR_JRET(qExplainResNodeToRows(node, ctx, level)); + +_return: + + qFreeExplainResTree(node); + + QRY_RET(code); +} + + +int32_t qGetExplainRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { + SExplainCtx *pCtx = (SExplainCtx *)ctx; + int32_t rowNum = taosArrayGetSize(pCtx->rows); + if (rowNum <= 0) { + qError("empty explain res rows"); + QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + int32_t colNum = 1; + int32_t rspSize = sizeof(SRetrieveTableRsp) + sizeof(int32_t) * colNum + sizeof(int32_t) * rowNum + pCtx->totalSize; + SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize); + if (NULL == rsp) { + qError("malloc SRetrieveTableRsp failed, size:%d", rspSize); + QRY_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + rsp->completed = 1; + rsp->numOfRows = htonl(rowNum); + + *(int32_t *)rsp->data = htonl(pCtx->totalSize); + + int32_t *offset = (int32_t *)((char *)rsp->data + sizeof(int32_t)); + char *data = (char *)(offset + rowNum); + int32_t tOffset = 0; + + for (int32_t i = 0; i < rowNum; ++i) { + SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i); + *offset = tOffset; + tOffset += row->len; + + memcpy(data, row->buf, row->len); + + ++offset; + data += row->len; + } + + *pRsp = rsp; + + return TSDB_CODE_SUCCESS; +} + +int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) { + int32_t code = 0; + SNodeListNode *plans = NULL; + int32_t taskNum = 0; + SExplainGroup *pGroup = NULL; + void *pCtx = NULL; + int32_t rootGroupId = 0; + + if (pDag->numOfSubplans <= 0) { + qError("invalid subplan num:%d", pDag->numOfSubplans); + QRY_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + int32_t levelNum = (int32_t)LIST_LENGTH(pDag->pSubplans); + if (levelNum <= 0) { + qError("invalid level num:%d", levelNum); + QRY_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + SHashObj *groupHash = taosHashInit(EXPLAIN_MAX_GROUP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (NULL == groupHash) { + qError("groupHash %d failed", EXPLAIN_MAX_GROUP_NUM); + QRY_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + QRY_ERR_JRET(qInitExplainCtx(&pCtx, groupHash, pDag->explainInfo.verbose)); + + for (int32_t i = 0; i < levelNum; ++i) { + plans = (SNodeListNode *)nodesListGetNode(pDag->pSubplans, i); + if (NULL == plans) { + qError("empty level plan, level:%d", i); + QRY_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } + + taskNum = (int32_t)LIST_LENGTH(plans->pNodeList); + if (taskNum <= 0) { + qError("invalid level plan number:%d, level:%d", taskNum, i); + QRY_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } + + SSubplan *plan = NULL; + for (int32_t n = 0; n < taskNum; ++n) { + plan = (SSubplan *)nodesListGetNode(plans->pNodeList, n); + pGroup = taosHashGet(groupHash, &plan->id.groupId, sizeof(plan->id.groupId)); + if (pGroup) { + ++pGroup->nodeNum; + continue; + } + + SExplainGroup group = {.nodeNum = 1, .plan = plan, .execInfo = NULL}; + if (0 != taosHashPut(groupHash, &plan->id.groupId, sizeof(plan->id.groupId), &group, sizeof(group))) { + qError("taosHashPut to explainGroupHash failed, taskIdx:%d", n); + QRY_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + } + + if (0 == i) { + if (taskNum > 1) { + qError("invalid taskNum %d for level 0", taskNum); + QRY_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } + + rootGroupId = plan->id.groupId; + } + + qDebug("level %d group handled, taskNum:%d", i, taskNum); + } + + QRY_ERR_JRET(qAppendTaskExplainResRows(pCtx, rootGroupId, 0)); + + QRY_ERR_JRET(qGetExplainRspFromCtx(pCtx, pRsp)); + +_return: + + qFreeExplainCtx(pCtx); + + QRY_RET(code); +} + + + diff --git a/source/libs/command/test/CMakeLists.txt b/source/libs/command/test/CMakeLists.txt new file mode 100644 index 0000000000..6d2335d2e3 --- /dev/null +++ b/source/libs/command/test/CMakeLists.txt @@ -0,0 +1,18 @@ +MESSAGE(STATUS "build command unit test") + +# GoogleTest requires at least C++11 +SET(CMAKE_CXX_STANDARD 11) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + +ADD_EXECUTABLE(commandTest ${SOURCE_LIST}) + +TARGET_INCLUDE_DIRECTORIES( + commandTest + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/command/" + PRIVATE "${CMAKE_SOURCE_DIR}/source/libs/command/inc" +) + +TARGET_LINK_LIBRARIES( + commandTest + PUBLIC os util common nodes parser catalog transport gtest function qcom +) \ No newline at end of file diff --git a/source/libs/command/test/commandTest.cpp b/source/libs/command/test/commandTest.cpp new file mode 100644 index 0000000000..59118c501a --- /dev/null +++ b/source/libs/command/test/commandTest.cpp @@ -0,0 +1,21 @@ +/* + * 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 + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index d375299d57..8d88b94d6c 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -73,27 +73,12 @@ typedef struct SResultRowPosition { } SResultRowPosition; typedef struct SResultRowInfo { - SList *pRows; SResultRowPosition *pPosition; - SResultRow **pResult; // result list int32_t size; // number of result set int32_t capacity; // max capacity int32_t curPos; // current active result row index of pResult list } SResultRowInfo; -typedef struct SResultRowPool { - int32_t elemSize; - int32_t blockSize; - int32_t numOfElemPerBlock; - - struct { - int32_t blockIndex; - int32_t pos; - } position; - - SArray* pData; // SArray -} SResultRowPool; - struct STaskAttr; struct STaskRuntimeEnv; struct SUdfInfo; @@ -109,19 +94,27 @@ void resetResultRowInfo(struct STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* int32_t numOfClosedResultRows(SResultRowInfo* pResultRowInfo); void closeAllResultRows(SResultRowInfo* pResultRowInfo); -int32_t initResultRow(SResultRow *pResultRow); -void closeResultRow(SResultRowInfo* pResultRowInfo, int32_t slot); -bool isResultRowClosed(SResultRowInfo *pResultRowInfo, int32_t slot); -void clearResultRow(struct STaskRuntimeEnv* pRuntimeEnv, SResultRow* pResultRow); +void initResultRow(SResultRow *pResultRow); +void closeResultRow(SResultRow* pResultRow); +bool isResultRowClosed(SResultRow* pResultRow); struct SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t* offset); -void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr); int32_t getRowNumForMultioutput(struct STaskAttr* pQueryAttr, bool topBottomQuery, bool stable); -static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) { - assert(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size); - return pResultRowInfo->pResult[slot]; +static FORCE_INLINE SResultRow *getResultRow(SDiskbasedBuf* pBuf, SResultRowInfo *pResultRowInfo, int32_t slot) { + ASSERT(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size); + SResultRowPosition* pos = &pResultRowInfo->pPosition[slot]; + + SFilePage* bufPage = (SFilePage*) getBufPage(pBuf, pos->pageId); + SResultRow* pRow = (SResultRow*)((char*)bufPage + pos->offset); + return pRow; +} + +static FORCE_INLINE SResultRow *getResultRowByPos(SDiskbasedBuf* pBuf, SResultRowPosition* pos) { + SFilePage* bufPage = (SFilePage*) getBufPage(pBuf, pos->pageId); + SResultRow* pRow = (SResultRow*)((char*)bufPage + pos->offset); + return pRow; } static FORCE_INLINE char* getPosInResultPage(struct STaskAttr* pQueryAttr, SFilePage* page, int32_t rowOffset, @@ -130,6 +123,7 @@ static FORCE_INLINE char* getPosInResultPage(struct STaskAttr* pQueryAttr, SFile // int32_t numOfRows = (int32_t)getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery); return ((char *)page->data); + } static FORCE_INLINE char* getPosInResultPage_rv(SFilePage* page, int32_t rowOffset, int32_t offset) { @@ -139,23 +133,14 @@ static FORCE_INLINE char* getPosInResultPage_rv(SFilePage* page, int32_t rowOffs return (char*) page + rowOffset + offset * numOfRows; } -//bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type); -//bool notNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type); - -__filter_func_t getFilterOperator(int32_t lowerOptr, int32_t upperOptr); - -SResultRow* getNewResultRow(SResultRowPool* p); - typedef struct { SArray* pResult; // SArray int32_t colId; } SStddevInterResult; -void interResToBinary(SBufferWriter* bw, SArray* pRes, int32_t tagLen); -SArray* interResFromBinary(const char* data, int32_t len); -void freeInterResult(void* param); - void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo); +void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList); + void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo); bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo); bool hasRemainData(SGroupResInfo* pGroupResInfo); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 1d7023930d..5a3e25bd68 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -69,7 +69,7 @@ enum { typedef struct SResultRowCell { uint64_t groupId; - SResultRow* pRow; + SResultRowPosition pos; } SResultRowCell; /** @@ -128,6 +128,11 @@ typedef struct { int64_t sumRunTimes; } SOperatorProfResult; +typedef struct SLimit { + int64_t limit; + int64_t offset; +} SLimit; + typedef struct STaskCostInfo { int64_t created; int64_t start; @@ -163,6 +168,11 @@ typedef struct SOperatorCostInfo { uint64_t execCost; } SOperatorCostInfo; +typedef struct SOrder { + uint32_t order; + SColumn col; +} SOrder; + // The basic query information extracted from the SQueryInfo tree to support the // execution of query in a data node. typedef struct STaskAttr { @@ -196,7 +206,6 @@ typedef struct STaskAttr { STimeWindow window; SInterval interval; - SSessionWindow sw; int16_t precision; int16_t numOfOutput; int16_t fillType; @@ -206,13 +215,8 @@ typedef struct STaskAttr { int32_t intermediateResultRowSize; // intermediate result row size, in case of top-k query. int32_t maxTableColumnWidth; int32_t tagLen; // tag value length of current query - SGroupbyExpr* pGroupbyExpr; SExprInfo* pExpr1; - SExprInfo* pExpr2; - int32_t numOfExpr2; - SExprInfo* pExpr3; - int32_t numOfExpr3; SColumnInfo* tableCols; SColumnInfo* tagColList; @@ -220,8 +224,6 @@ typedef struct STaskAttr { int64_t* fillVal; SSingleColumnFilterInfo* pFilterInfo; - // SFilterInfo *pFilters; - void* tsdb; STableGroupInfo tableGroupInfo; // table list SArray int32_t vgId; @@ -277,8 +279,6 @@ typedef struct STaskRuntimeEnv { char* keyBuf; // window key buffer // The window result objects pool, all the resultRow Objects are allocated and managed by this object. char** prevRow; - SResultRowPool* pool; - SArray* prevResult; // intermediate result, SArray STSBuf* pTsBuf; // timestamp filter list STSCursor cur; @@ -364,6 +364,7 @@ typedef struct SSourceDataInfo { int32_t index; SRetrieveTableRsp *pRsp; uint64_t totalRows; + int32_t code; EX_SOURCE_STATUS status; } SSourceDataInfo; @@ -385,7 +386,7 @@ typedef struct SExchangeInfo { } SExchangeInfo; typedef struct STableScanInfo { - void* pTsdbReadHandle; + void* dataReader; int32_t numOfBlocks; // extract basic running information. int32_t numOfSkipped; int32_t numOfBlockStatis; @@ -394,6 +395,7 @@ typedef struct STableScanInfo { int32_t times; // repeat counts int32_t current; int32_t reverseTimes; // 0 by default + SNode* pFilterNode; // filter operator info SqlFunctionCtx* pCtx; // next operator query context SResultRowInfo* pResultRowInfo; int32_t* rowCellInfoOffset; @@ -422,6 +424,7 @@ typedef struct SStreamBlockScanInfo { uint64_t numOfRows; // total scanned rows uint64_t numOfExec; // execution times void* readerHandle; // stream block reader handle + SArray* pColMatchInfo; // } SStreamBlockScanInfo; typedef struct SSysTableScanInfo { @@ -496,14 +499,11 @@ typedef struct SProjectOperatorInfo { SOptrBasicInfo binfo; SSDataBlock *existDataBlock; int32_t threshold; + SLimit limit; + int64_t curOffset; + int64_t curOutput; } SProjectOperatorInfo; -typedef struct SLimitOperatorInfo { - SLimit limit; - int64_t currentOffset; - int64_t currentRows; -} SLimitOperatorInfo; - typedef struct SSLimitOperatorInfo { int64_t groupTotal; int64_t currentGroupOffset; @@ -522,11 +522,6 @@ typedef struct SSLimitOperatorInfo { int64_t threshold; } SSLimitOperatorInfo; -typedef struct SFilterOperatorInfo { - SSingleColumnFilterInfo* pFilterInfo; - int32_t numOfFilterCols; -} SFilterOperatorInfo; - typedef struct SFillOperatorInfo { struct SFillInfo* pFillInfo; SSDataBlock* pRes; @@ -557,15 +552,16 @@ typedef struct SGroupbyOperatorInfo { } SGroupbyOperatorInfo; typedef struct SSessionAggOperatorInfo { - SOptrBasicInfo binfo; - SAggSupporter aggSup; - SGroupResInfo groupResInfo; - STimeWindow curWindow; // current time window - TSKEY prevTs; // previous timestamp - int32_t numOfRows; // number of rows - int32_t start; // start row index - bool reptScan; // next round scan - int64_t gap; // session window gap + SOptrBasicInfo binfo; + SAggSupporter aggSup; + SGroupResInfo groupResInfo; + STimeWindow curWindow; // current time window + TSKEY prevTs; // previous timestamp + int32_t numOfRows; // number of rows + int32_t start; // start row index + bool reptScan; // next round scan + int64_t gap; // session window gap + SColumnInfoData timeWindowData; // query time window info for scalar function execution. } SSessionAggOperatorInfo; typedef struct SStateWindowOperatorInfo { @@ -636,27 +632,27 @@ typedef struct SDistinctOperatorInfo { SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t repeatTime, - int32_t reverseTime, SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo); + int32_t reverseTime, SArray* pColMatchInfo, SNode* pCondition, SExecTaskInfo* pTaskInfo); SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); -SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SExecTaskInfo* pTaskInfo); SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName, SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId); -SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo); - SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo); SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); +SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo); + SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock, int32_t fillType, char* fillVal, bool multigroupResult, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo); SOperatorInfo* createDistinctOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, @@ -673,30 +669,19 @@ SOperatorInfo* createMultiwaySortOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExp SOperatorInfo* createGlobalAggregateOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput, void* param, SArray* pUdfInfo, bool groupResultMixedUp); -SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, - int32_t numOfOutput); + SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput, void* merger, bool multigroupResult); SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema, int32_t numOfOutput); -void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols); - void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order); void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput); - -void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity); void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput); -int32_t createQueryFilter(char* data, uint16_t len, SFilterInfo** pFilters); - -int32_t createFilterInfo(STaskAttr* pQueryAttr, uint64_t qId); -void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters); - STableQueryInfo* createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow win); -STableQueryInfo* createTmpTableQueryInfo(STimeWindow win); bool isTaskKilled(SExecTaskInfo* pTaskInfo); int32_t checkForQueryBuf(size_t numOfTables); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 2c6468a13f..40e86c7840 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -53,15 +53,13 @@ int32_t getOutputInterResultBufSize(STaskAttr* pQueryAttr) { int32_t initResultRowInfo(SResultRowInfo *pResultRowInfo, int32_t size) { pResultRowInfo->size = 0; - pResultRowInfo->curPos = -1; + pResultRowInfo->curPos = -1; pResultRowInfo->capacity = size; - - pResultRowInfo->pResult = taosMemoryCalloc(pResultRowInfo->capacity, POINTER_BYTES); pResultRowInfo->pPosition = taosMemoryCalloc(pResultRowInfo->capacity, sizeof(SResultRowPosition)); - if (pResultRowInfo->pResult == NULL || pResultRowInfo->pPosition == NULL) { + + if (pResultRowInfo->pPosition == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } - return TSDB_CODE_SUCCESS; } @@ -71,17 +69,17 @@ void cleanupResultRowInfo(SResultRowInfo *pResultRowInfo) { } if (pResultRowInfo->capacity == 0) { - assert(pResultRowInfo->pResult == NULL); +// assert(pResultRowInfo->pResult == NULL); return; } for(int32_t i = 0; i < pResultRowInfo->size; ++i) { - if (pResultRowInfo->pResult[i]) { - taosMemoryFreeClear(pResultRowInfo->pResult[i]->key); - } +// if (pResultRowInfo->pResult[i]) { +// taosMemoryFreeClear(pResultRowInfo->pResult[i]->key); +// } } - taosMemoryFreeClear(pResultRowInfo->pResult); + taosMemoryFreeClear(pResultRowInfo->pPosition); } void resetResultRowInfo(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo) { @@ -90,8 +88,8 @@ void resetResultRowInfo(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRow } for (int32_t i = 0; i < pResultRowInfo->size; ++i) { - SResultRow *pWindowRes = pResultRowInfo->pResult[i]; - clearResultRow(pRuntimeEnv, pWindowRes); +// SResultRow *pWindowRes = pResultRowInfo->pResult[i]; +// clearResultRow(pRuntimeEnv, pWindowRes); int32_t groupIndex = 0; int64_t uid = 0; @@ -101,14 +99,13 @@ void resetResultRowInfo(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRow } pResultRowInfo->size = 0; - pResultRowInfo->curPos = -1; } int32_t numOfClosedResultRows(SResultRowInfo *pResultRowInfo) { int32_t i = 0; - while (i < pResultRowInfo->size && pResultRowInfo->pResult[i]->closed) { - ++i; - } +// while (i < pResultRowInfo->size && pResultRowInfo->pResult[i]->closed) { +// ++i; +// } return i; } @@ -117,21 +114,22 @@ void closeAllResultRows(SResultRowInfo *pResultRowInfo) { assert(pResultRowInfo->size >= 0 && pResultRowInfo->capacity >= pResultRowInfo->size); for (int32_t i = 0; i < pResultRowInfo->size; ++i) { - SResultRow* pRow = pResultRowInfo->pResult[i]; - if (pRow->closed) { - continue; - } +// ASSERT(0); +// SResultRow* pRow = pResultRowInfo->pResult[i]; +// if (pRow->closed) { +// continue; +// } - pRow->closed = true; +// pRow->closed = true; } } -bool isResultRowClosed(SResultRowInfo *pResultRowInfo, int32_t slot) { - return (getResultRow(pResultRowInfo, slot)->closed == true); +bool isResultRowClosed(SResultRow* pRow) { + return (pRow->closed == true); } -void closeResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) { - getResultRow(pResultRowInfo, slot)->closed = true; +void closeResultRow(SResultRow* pResultRow) { + pResultRow->closed = true; } void clearResultRow(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow) { @@ -181,29 +179,6 @@ size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) { return rowSize; } -SResultRow* getNewResultRow(SResultRowPool* p) { - if (p == NULL) { - return NULL; - } - - void* ptr = NULL; - if (p->position.pos == 0) { - ptr = taosMemoryCalloc(1, p->blockSize); - taosArrayPush(p->pData, &ptr); - - } else { - size_t last = taosArrayGetSize(p->pData); - - void** pBlock = taosArrayGet(p->pData, last - 1); - ptr = ((char*) (*pBlock)) + p->elemSize * p->position.pos; - } - - p->position.pos = (p->position.pos + 1)%p->numOfElemPerBlock; - initResultRow(ptr); - - return ptr; -} - void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) { assert(pGroupResInfo != NULL); @@ -222,6 +197,16 @@ void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo) assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo)); } +void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList) { + if (pGroupResInfo->pRows != NULL) { + taosArrayDestroy(pGroupResInfo->pRows); + } + + pGroupResInfo->pRows = pArrayList; + pGroupResInfo->index = 0; + ASSERT(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo)); +} + bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo) { if (pGroupResInfo->pRows == NULL) { return false; @@ -251,8 +236,9 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) { return (int32_t) taosArrayGetSize(pGroupResInfo->pRows); } -static int64_t getNumOfResultWindowRes(STaskRuntimeEnv* pRuntimeEnv, SResultRow *pResultRow, int32_t* rowCellInfoOffset) { +static int64_t getNumOfResultWindowRes(STaskRuntimeEnv* pRuntimeEnv, SResultRowPosition *pos, int32_t* rowCellInfoOffset) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + ASSERT(0); for (int32_t j = 0; j < pQueryAttr->numOfOutput; ++j) { int32_t functionId = 0;//pQueryAttr->pExpr1[j].base.functionId; @@ -295,25 +281,26 @@ static int32_t tableResultComparFn(const void *pLeft, const void *pRight, void * return -1; } + ASSERT(0); STableQueryInfo** pList = supporter->pTableQueryInfo; - SResultRow* pWindowRes1 = pList[left]->resInfo.pResult[leftPos]; +// SResultRow* pWindowRes1 = pList[left]->resInfo.pResult[leftPos]; // SResultRow * pWindowRes1 = getResultRow(&(pList[left]->resInfo), leftPos); - TSKEY leftTimestamp = pWindowRes1->win.skey; +// TSKEY leftTimestamp = pWindowRes1->win.skey; // SResultRowInfo *pWindowResInfo2 = &(pList[right]->resInfo); // SResultRow * pWindowRes2 = getResultRow(pWindowResInfo2, rightPos); - SResultRow* pWindowRes2 = pList[right]->resInfo.pResult[rightPos]; - TSKEY rightTimestamp = pWindowRes2->win.skey; +// SResultRow* pWindowRes2 = pList[right]->resInfo.pResult[rightPos]; +// TSKEY rightTimestamp = pWindowRes2->win.skey; - if (leftTimestamp == rightTimestamp) { +// if (leftTimestamp == rightTimestamp) { return 0; - } +// } - if (supporter->order == TSDB_ORDER_ASC) { - return (leftTimestamp > rightTimestamp)? 1:-1; - } else { - return (leftTimestamp < rightTimestamp)? 1:-1; - } +// if (supporter->order == TSDB_ORDER_ASC) { +// return (leftTimestamp > rightTimestamp)? 1:-1; +// } else { +// return (leftTimestamp < rightTimestamp)? 1:-1; +// } } int32_t tsAscOrder(const void* p1, const void* p2) { @@ -321,11 +308,12 @@ int32_t tsAscOrder(const void* p1, const void* p2) { SResultRowCell* pc2 = (SResultRowCell*) p2; if (pc1->groupId == pc2->groupId) { - if (pc1->pRow->win.skey == pc2->pRow->win.skey) { - return 0; - } else { - return (pc1->pRow->win.skey < pc2->pRow->win.skey)? -1:1; - } + ASSERT(0); +// if (pc1->pRow->win.skey == pc2->pRow->win.skey) { +// return 0; +// } else { +// return (pc1->pRow->win.skey < pc2->pRow->win.skey)? -1:1; +// } } else { return (pc1->groupId < pc2->groupId)? -1:1; } @@ -336,11 +324,12 @@ int32_t tsDescOrder(const void* p1, const void* p2) { SResultRowCell* pc2 = (SResultRowCell*) p2; if (pc1->groupId == pc2->groupId) { - if (pc1->pRow->win.skey == pc2->pRow->win.skey) { - return 0; - } else { - return (pc1->pRow->win.skey < pc2->pRow->win.skey)? 1:-1; - } + ASSERT(0); +// if (pc1->pRow->win.skey == pc2->pRow->win.skey) { +// return 0; +// } else { +// return (pc1->pRow->win.skey < pc2->pRow->win.skey)? 1:-1; +// } } else { return (pc1->groupId < pc2->groupId)? -1:1; } @@ -374,13 +363,13 @@ static int32_t mergeIntoGroupResultImplRv(STaskRuntimeEnv *pRuntimeEnv, SGroupRe break; } - int64_t num = getNumOfResultWindowRes(pRuntimeEnv, pResultRowCell->pRow, rowCellInfoOffset); + int64_t num = getNumOfResultWindowRes(pRuntimeEnv, &pResultRowCell->pos, rowCellInfoOffset); if (num <= 0) { continue; } - taosArrayPush(pGroupResInfo->pRows, &pResultRowCell->pRow); - pResultRowCell->pRow->numOfRows = (uint32_t) num; + taosArrayPush(pGroupResInfo->pRows, &pResultRowCell->pos); +// pResultRowCell->pRow->numOfRows = (uint32_t) num; } return TSDB_CODE_SUCCESS; @@ -439,9 +428,10 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv int32_t tableIndex = tMergeTreeGetChosenIndex(pTree); SResultRowInfo *pWindowResInfo = &pTableQueryInfoList[tableIndex]->resInfo; - SResultRow *pWindowRes = getResultRow(pWindowResInfo, cs.rowIndex[tableIndex]); + ASSERT(0); + SResultRow *pWindowRes = NULL;//getResultRow(pBuf, pWindowResInfo, cs.rowIndex[tableIndex]); - int64_t num = getNumOfResultWindowRes(pRuntimeEnv, pWindowRes, rowCellInfoOffset); + int64_t num = 0;//getNumOfResultWindowRes(pRuntimeEnv, pWindowRes, rowCellInfoOffset); if (num <= 0) { cs.rowIndex[tableIndex] += 1; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index f371103490..2ccc92111a 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -194,9 +194,6 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o } static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type, int16_t bytes); -static void setResultOutputBuf(STaskRuntimeEnv* pRuntimeEnv, SResultRow* pResult, SqlFunctionCtx* pCtx, - int32_t numOfCols, int32_t* rowCellInfoOffset); - void setResultRowOutputBufInitCtx(STaskRuntimeEnv* pRuntimeEnv, SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset); static bool functionNeedToExecute(SqlFunctionCtx* pCtx); @@ -214,8 +211,6 @@ static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); // static STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win); static STableIdInfo createTableIdInfo(STableQueryInfo* pTableQueryInfo); -static void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInfo* pDownstream); - static int32_t getNumOfScanTimes(STaskAttr* pQueryAttr); static void destroyBasicOperatorInfo(void* param, int32_t numOfOutput); @@ -254,7 +249,6 @@ static void operatorDummyCloseFn(void* param, int32_t numOfCols) {} static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); -static int32_t getGroupbyColumnIndex(SGroupbyExpr* pGroupbyExpr, SSDataBlock* pDataBlock); static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup); @@ -264,10 +258,6 @@ static void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, static void setResultBufSize(STaskAttr* pQueryAttr, SResultInfo* pResultInfo); static void setCtxTagForJoin(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, void* pTable); -static void setParamForStableStddev(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, - SExprInfo* pExpr); -static void setParamForStableStddevByColData(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, - SExprInfo* pExpr, char* val, int16_t bytes); static void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, int32_t tableGroupId, SExecTaskInfo* pTaskInfo); @@ -296,44 +286,6 @@ static int compareRowData(const void* a, const void* b, const void* userData) { return (in1 != NULL && in2 != NULL) ? supporter->comFunc(in1, in2) : 0; } -static void sortGroupResByOrderList(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRuntimeEnv, - SSDataBlock* pDataBlock) { - SArray* columnOrderList = getOrderCheckColumns(pRuntimeEnv->pQueryAttr); - size_t size = taosArrayGetSize(columnOrderList); - taosArrayDestroy(columnOrderList); - - if (size <= 0) { - return; - } - - int32_t orderId = pRuntimeEnv->pQueryAttr->order.col.colId; - if (orderId <= 0) { - return; - } - - 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) { - found = true; - break; - } - - dataOffset += pColInfoData->info.bytes; - } - - if (found == false) { - return; - } - - int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderId].base.resSchema.type; - - SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; - taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); -} - // setup the output buffer for each operator SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { int32_t numOfCols = LIST_LENGTH(pNode->pSlots); @@ -352,7 +304,7 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { continue; } - idata.info.type = pDescNode->dataType.type; + idata.info.type = pDescNode->dataType.type; idata.info.bytes = pDescNode->dataType.bytes; idata.info.scale = pDescNode->dataType.scale; idata.info.slotId = pDescNode->slotId; @@ -388,17 +340,6 @@ static bool isSelectivityWithTagsQuery(SqlFunctionCtx* pCtx, int32_t numOfOutput // return (numOfSelectivity > 0 && hasTags); } -static bool isProjQuery(STaskAttr* pQueryAttr) { - for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { - int32_t functId = getExprFunctionId(&pQueryAttr->pExpr1[i]); - if (functId != FUNCTION_PRJ && functId != FUNCTION_TAGPRJ) { - return false; - } - } - - return true; -} - static bool hasNull(SColumn* pColumn, SColumnDataAgg* pStatis) { if (TSDB_COL_IS_TAG(pColumn->flag) || TSDB_COL_IS_UD_COL(pColumn->flag) || pColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { @@ -430,18 +371,10 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) newCapacity += 4; } - char* t = taosMemoryRealloc(pResultRowInfo->pResult, (size_t)(newCapacity * POINTER_BYTES)); - if (t == NULL) { - longjmp(env, TSDB_CODE_QRY_OUT_OF_MEMORY); - } - pResultRowInfo->pPosition = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition)); - pResultRowInfo->pResult = (SResultRow**)t; int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity; - memset(&pResultRowInfo->pResult[pResultRowInfo->capacity], 0, POINTER_BYTES * inc); memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition)); - pResultRowInfo->capacity = (int32_t)newCapacity; } @@ -462,9 +395,8 @@ static bool chkResultRowFromKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pR if (p1 != NULL) { if (pResultRowInfo->size == 0) { existed = false; - assert(pResultRowInfo->curPos == -1); } else if (pResultRowInfo->size == 1) { - existed = (pResultRowInfo->pResult[0] == (*p1)); +// existed = (pResultRowInfo->pResult[0] == (*p1)); } else { // check if current pResultRowInfo contains the existed pResultRow SET_RES_EXT_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, uid, pResultRowInfo); int64_t* index = @@ -483,6 +415,7 @@ static bool chkResultRowFromKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pR return p1 != NULL; } +#if 0 static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, int64_t tid, char* pData, int16_t bytes, bool masterscan, uint64_t tableGroupId) { bool existed = false; @@ -500,16 +433,16 @@ static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultR if (p1 != NULL) { if (pResultRowInfo->size == 0) { existed = false; - assert(pResultRowInfo->curPos == -1); +// assert(pResultRowInfo->curPos == -1); } else if (pResultRowInfo->size == 1) { - existed = (pResultRowInfo->pResult[0] == (*p1)); - pResultRowInfo->curPos = 0; +// existed = (pResultRowInfo->pResult[0] == (*p1)); +// pResultRowInfo->curPos = 0; } else { // check if current pResultRowInfo contains the existed pResultRow SET_RES_EXT_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, tid, pResultRowInfo); int64_t* index = taosHashGet(pRuntimeEnv->pResultRowListSet, pRuntimeEnv->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes)); if (index != NULL) { - pResultRowInfo->curPos = (int32_t)*index; +// pResultRowInfo->curPos = (int32_t)*index; existed = true; } else { existed = false; @@ -559,6 +492,7 @@ static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultR return pResultRowInfo->pResult[pResultRowInfo->curPos]; } +#endif SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize) { SFilePage* pData = NULL; @@ -603,65 +537,75 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, int64_t tid, char* pData, int16_t bytes, bool masterscan, uint64_t tableGroupId, SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup) { - bool existed = false; + bool existInCurrentResusltRowInfo = false; SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, tableGroupId); - SResultRow** p1 = (SResultRow**)taosHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); + SResultRowPosition* p1 = (SResultRowPosition*)taosHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); // in case of repeat scan/reverse scan, no new time window added. if (isIntervalQuery) { if (!masterscan) { // the *p1 may be NULL in case of sliding+offset exists. - return (p1 != NULL) ? *p1 : NULL; + if (p1 != NULL) { + return getResultRowByPos(pResultBuf, p1); + } else { + return NULL; + } } if (p1 != NULL) { if (pResultRowInfo->size == 0) { - existed = false; + existInCurrentResusltRowInfo = false; // this time window created by other timestamp that does not belongs to current table. assert(pResultRowInfo->curPos == -1); } else if (pResultRowInfo->size == 1) { - existed = (pResultRowInfo->pResult[0] == (*p1)); - pResultRowInfo->curPos = 0; - } else { // check if current pResultRowInfo contains the existed pResultRow + ASSERT(0); +// existInCurrentResusltRowInfo = (pResultRowInfo->pResult[0] == (*p1)); + } else { // check if current pResultRowInfo contains the existInCurrentResusltRowInfo pResultRow SET_RES_EXT_WINDOW_KEY(pSup->keyBuf, pData, bytes, tid, pResultRowInfo); int64_t* index = taosHashGet(pSup->pResultRowListSet, pSup->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes)); if (index != NULL) { - pResultRowInfo->curPos = (int32_t)*index; - existed = true; + // TODO check the scan order for current opened time window +// pResultRowInfo->curPos = (int32_t)*index; + existInCurrentResusltRowInfo = true; } else { - existed = false; + existInCurrentResusltRowInfo = false; } } } } else { - // In case of group by column query, the required SResultRow object must be existed in the pResultRowInfo object. + // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the pResultRowInfo object. if (p1 != NULL) { - return *p1; + return getResultRowByPos(pResultBuf, p1); } } - if (!existed) { - prepareResultListBuffer(pResultRowInfo, pTaskInfo->env); - - SResultRow* pResult = NULL; - if (p1 == NULL) { - pResult = getNewResultRow_rv(pResultBuf, tableGroupId, pSup->resultRowSize); - int32_t ret = initResultRow(pResult); - if (ret != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - // add a new result set for a new group - taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pResult, POINTER_BYTES); - SResultRowCell cell = {.groupId = tableGroupId, .pRow = pResult}; - taosArrayPush(pSup->pResultRowArrayList, &cell); - } else { - pResult = *p1; + SResultRow* pResult = NULL; + if (!existInCurrentResusltRowInfo) { + // 1. close current opened time window + if (pResultRowInfo->curPos != -1) { // todo extract function + SResultRowPosition* pos = &pResultRowInfo->pPosition[pResultRowInfo->curPos]; + SFilePage* pPage = getBufPage(pResultBuf, pos->pageId); + SResultRow* pRow = (SResultRow*)((char*)pPage + pos->offset); + closeResultRow(pRow); + releaseBufPage(pResultBuf, pPage); } + prepareResultListBuffer(pResultRowInfo, pTaskInfo->env); + if (p1 == NULL) { + pResult = getNewResultRow_rv(pResultBuf, tableGroupId, pSup->resultRowSize); + initResultRow(pResult); + + // add a new result set for a new group + SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset}; + taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, POINTER_BYTES); + SResultRowCell cell = {.groupId = tableGroupId, .pos = pos}; + taosArrayPush(pSup->pResultRowArrayList, &cell); + } else { + pResult = getResultRowByPos(pResultBuf, p1); + } + + // 2. set the new time window to be the new active time window pResultRowInfo->curPos = pResultRowInfo->size; - pResultRowInfo->pPosition[pResultRowInfo->size] = - (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; - pResultRowInfo->pResult[pResultRowInfo->size++] = pResult; + pResultRowInfo->pPosition[pResultRowInfo->size++] = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; int64_t index = pResultRowInfo->curPos; SET_RES_EXT_WINDOW_KEY(pSup->keyBuf, pData, bytes, tid, pResultRowInfo); @@ -673,7 +617,7 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR longjmp(pTaskInfo->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW); } - return pResultRowInfo->pResult[pResultRowInfo->curPos]; + return pResult; } static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, TSKEY ts, STimeWindow* w, TSKEY ekey, @@ -697,7 +641,7 @@ static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, T } // get the correct time window according to the handled timestamp -static STimeWindow getActiveTimeWindow(SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, +static STimeWindow getActiveTimeWindow(SDiskbasedBuf * pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, int32_t precision, STimeWindow* win) { STimeWindow w = {0}; @@ -705,7 +649,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo* pResultRowInfo, int64_t t getInitialStartTimeWindow(pInterval, precision, ts, &w, win->ekey, true); w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; } else { - w = getResultRow(pResultRowInfo, pResultRowInfo->curPos)->win; + w = getResultRow(pBuf, pResultRowInfo, pResultRowInfo->curPos)->win; } if (w.skey > ts || w.ekey < ts) { @@ -734,7 +678,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo* pResultRowInfo, int64_t t // get the correct time window according to the handled timestamp static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo* pResultRowInfo, int64_t ts, STaskAttr* pQueryAttr) { STimeWindow w = {0}; - +#if 0 if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value // getInitialStartTimeWindow(pQueryAttr, ts, &w); @@ -746,7 +690,7 @@ static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo* pResultRowInfo, in w.ekey = w.skey + pQueryAttr->interval.interval - 1; } } else { - w = getResultRow(pResultRowInfo, pResultRowInfo->curPos)->win; + w = pRow->win; } /* @@ -756,6 +700,7 @@ static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo* pResultRowInfo, in if (w.ekey > pQueryAttr->window.ekey && QUERY_IS_ASC_QUERY(pQueryAttr)) { w.ekey = pQueryAttr->window.ekey; } +#endif return w; } @@ -820,8 +765,8 @@ static int32_t setResultOutputBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowI assert(win->skey <= win->ekey); SDiskbasedBuf* pResultBuf = pRuntimeEnv->pResultBuf; - SResultRow* pResultRow = doSetResultOutBufByKey(pRuntimeEnv, pResultRowInfo, tid, (char*)&win->skey, TSDB_KEYSIZE, - masterscan, tableGroupId); + SResultRow* pResultRow = NULL;//doSetResultOutBufByKey(pRuntimeEnv, pResultRowInfo, tid, (char*)&win->skey, TSDB_KEYSIZE, +// masterscan, tableGroupId); if (pResultRow == NULL) { *pResult = NULL; return TSDB_CODE_SUCCESS; @@ -844,8 +789,7 @@ static int32_t setResultOutputBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowI return TSDB_CODE_SUCCESS; } -static void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, SqlFunctionCtx* pCtx, - int32_t numOfOutput, int32_t* rowCellInfoOffset); +static void setResultRowOutputBufInitCtx_rv(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset); static int32_t setResultOutputBufByKey_rv(SResultRowInfo* pResultRowInfo, int64_t id, STimeWindow* win, bool masterscan, SResultRow** pResult, int64_t tableGroupId, SqlFunctionCtx* pCtx, @@ -863,7 +807,7 @@ static int32_t setResultOutputBufByKey_rv(SResultRowInfo* pResultRowInfo, int64_ // set time window for current result pResultRow->win = (*win); *pResult = pResultRow; - setResultRowOutputBufInitCtx_rv(pAggSup->pResultBuf, pResultRow, pCtx, numOfOutput, rowCellInfoOffset); + setResultRowOutputBufInitCtx_rv(pResultRow, pCtx, numOfOutput, rowCellInfoOffset); return TSDB_CODE_SUCCESS; } @@ -913,9 +857,9 @@ static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_se return forwardStep; } -static void doUpdateResultRowIndex(SResultRowInfo* pResultRowInfo, TSKEY lastKey, bool ascQuery, - bool timeWindowInterpo) { +static void doUpdateResultRowIndex(SResultRowInfo* pResultRowInfo, TSKEY lastKey, bool ascQuery, bool timeWindowInterpo) { int64_t skey = TSKEY_INITIAL_VAL; +#if 0 int32_t i = 0; for (i = pResultRowInfo->size - 1; i >= 0; --i) { SResultRow* pResult = pResultRowInfo->pResult[i]; @@ -967,6 +911,7 @@ static void doUpdateResultRowIndex(SResultRowInfo* pResultRowInfo, TSKEY lastKey pResultRowInfo->curPos = i + 1; // current not closed result object } } +#endif } static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, const STimeWindow* pWin, TSKEY lastKey, @@ -1023,7 +968,7 @@ static void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQuer pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP; pColData->info.bytes = sizeof(int64_t); - blockDataEnsureColumnCapacity(pColData, 5); + colInfoDataEnsureCapacity(pColData, 5); colDataAppendInt64(pColData, 0, &pQueryWindow->skey); colDataAppendInt64(pColData, 1, &pQueryWindow->ekey); @@ -1033,27 +978,25 @@ static void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQuer colDataAppendInt64(pColData, 4, &pQueryWindow->ekey); } -static void updateTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pWin) { +static void updateTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pWin, bool includeEndpoint) { int64_t* ts = (int64_t*)pColData->pData; + int32_t delta = includeEndpoint? 1:0; - int64_t duration = pWin->ekey - pWin->skey + 1; + int64_t duration = pWin->ekey - pWin->skey + delta; ts[2] = duration; // set the duration ts[3] = pWin->skey; // window start key - ts[4] = pWin->ekey + 1; // window end key + ts[4] = pWin->ekey + delta; // window end key } static void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order) { - SScalarParam intervalParam = {.numOfRows = 5, .columnData = pTimeWindowData}; //TODO move out of this function - updateTimeWindowInfo(pTimeWindowData, pWin); - for (int32_t k = 0; k < numOfOutput; ++k) { pCtx[k].startTs = pWin->skey; // keep it temporarialy - bool hasAgg = pCtx[k].input.colDataAggIsSet; + bool hasAgg = pCtx[k].input.colDataAggIsSet; + int32_t numOfRows = pCtx[k].input.numOfRows; int32_t startOffset = pCtx[k].input.startRowIndex; - int32_t numOfRows = pCtx[k].input.numOfRows; int32_t pos = (order == TSDB_ORDER_ASC) ? offset : offset - (forwardStep - 1); pCtx[k].input.startRowIndex = pos; @@ -1073,12 +1016,14 @@ static void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInf SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]); char* p = GET_ROWCELL_INTERBUF(pEntryInfo); - SScalarParam out = {.columnData = NULL}; - out.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); - out.columnData->info.type = TSDB_DATA_TYPE_BIGINT; - out.columnData->info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; - out.columnData->pData = p; - pCtx[k].sfp.process(&intervalParam, 1, &out); + SColumnInfoData idata = {0}; + idata.info.type = TSDB_DATA_TYPE_BIGINT; + idata.info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; + idata.pData = p; + + SScalarParam out = {.columnData = &idata}; + SScalarParam tw = {.numOfRows = 5, .columnData = pTimeWindowData}; + pCtx[k].sfp.process(&tw, 1, &out); pEntryInfo->numOfRes = 1; pEntryInfo->hasResult = ','; continue; @@ -1257,8 +1202,8 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, ASSERT(pCtx[i].input.pData[j] != NULL); } } - // setBlockStatisInfo(&pCtx[i], pBlock, pOperator->pExpr[i].base.pColumns); + // setBlockStatisInfo(&pCtx[i], pBlock, pOperator->pExpr[i].base.pColumns); // uint32_t flag = pOperator->pExpr[i].base.pParam[0].pCol->flag; // if (TSDB_COL_IS_NORMAL_COL(flag) /*|| (pCtx[i].functionId == FUNCTION_BLKINFO) || // (TSDB_COL_IS_TAG(flag) && pOperator->pRuntimeEnv->scanFlag == MERGE_STAGE)*/) { @@ -1420,15 +1365,10 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, } static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SqlFunctionCtx* pCtx, int32_t pos, - int32_t numOfRows, SArray* pDataBlock, const TSKEY* tsCols, - STimeWindow* win) { - STaskRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - - bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); - + int32_t numOfRows, SArray* pDataBlock, const TSKEY* tsCols, STimeWindow* win) { + bool ascQuery = true; TSKEY curTs = tsCols[pos]; - TSKEY lastTs = *(TSKEY*)pRuntimeEnv->prevRow[0]; + TSKEY lastTs = 0;//*(TSKEY*)pRuntimeEnv->prevRow[0]; // lastTs == INT64_MIN and pos == 0 means this is the first time window, interpolation is not needed. // start exactly from this point, no need to do interpolation @@ -1443,27 +1383,24 @@ static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SqlF return true; } - int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); + int32_t step = 1;//GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); TSKEY prevTs = ((pos == 0 && ascQuery) || (pos == (numOfRows - 1) && !ascQuery)) ? lastTs : tsCols[pos - step]; - doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pDataBlock, prevTs, pos - step, curTs, pos, key, - RESULT_ROW_START_INTERP); + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pDataBlock, prevTs, pos - step, curTs, pos, key, RESULT_ROW_START_INTERP); return true; } static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SqlFunctionCtx* pCtx, int32_t endRowIndex, SArray* pDataBlock, const TSKEY* tsCols, TSKEY blockEkey, STimeWindow* win) { - STaskRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t numOfOutput = pOperatorInfo->numOfOutput; + int32_t order = TSDB_ORDER_ASC; + int32_t numOfOutput = pOperatorInfo->numOfOutput; TSKEY actualEndKey = tsCols[endRowIndex]; - - TSKEY key = QUERY_IS_ASC_QUERY(pQueryAttr) ? win->ekey : win->skey; + TSKEY key = order ? win->ekey : win->skey; // not ended in current data block, do not invoke interpolation - if ((key > blockEkey && QUERY_IS_ASC_QUERY(pQueryAttr)) || (key < blockEkey && !QUERY_IS_ASC_QUERY(pQueryAttr))) { + if ((key > blockEkey /*&& QUERY_IS_ASC_QUERY(pQueryAttr)*/) || (key < blockEkey /*&& !QUERY_IS_ASC_QUERY(pQueryAttr)*/)) { setNotInterpoWindowKey(pCtx, numOfOutput, RESULT_ROW_END_INTERP); return false; } @@ -1474,7 +1411,7 @@ static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SqlFun return true; } - int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); + int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); int32_t nextRowIndex = endRowIndex + step; assert(nextRowIndex >= 0); @@ -1555,14 +1492,14 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe if (pSDataBlock->pDataBlock != NULL) { SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, 0); tsCols = (int64_t*)pColDataInfo->pData; - assert(tsCols[0] == pSDataBlock->info.window.skey && - tsCols[pSDataBlock->info.rows - 1] == pSDataBlock->info.window.ekey); +// assert(tsCols[0] == pSDataBlock->info.window.skey && tsCols[pSDataBlock->info.rows - 1] == +// pSDataBlock->info.window.ekey); } int32_t startPos = ascScan? 0 : (pSDataBlock->info.rows - 1); TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols, pSDataBlock->info.rows, ascScan); - STimeWindow win = getActiveTimeWindow(pResultRowInfo, ts, &pInfo->interval, pInfo->interval.precision, &pInfo->win); + STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->interval.precision, &pInfo->win); bool masterScan = true; SResultRow* pResult = NULL; @@ -1585,6 +1522,8 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe // prev time window not interpolation yet. int32_t curIndex = pResultRowInfo->curPos; + +#if 0 if (prevIndex != -1 && prevIndex < curIndex && pInfo->timeWindowInterpo) { for (int32_t j = prevIndex; j < curIndex; ++j) { // previous time window may be all closed already. SResultRow* pRes = getResultRow(pResultRowInfo, j); @@ -1619,10 +1558,12 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } } +#endif // window start key interpolation - doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, forwardStep, - pInfo->order, false); + doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, forwardStep, pInfo->order, false); + + updateTimeWindowInfo(&pInfo->timeWindowData, &win, true); doApplyFunctions(pInfo->binfo.pCtx, &win, &pInfo->timeWindowData, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); STimeWindow nextWin = win; @@ -1651,8 +1592,9 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); // window start(end) key interpolation - doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardStep, - pInfo->order, false); + doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardStep, pInfo->order, false); + + updateTimeWindowInfo(&pInfo->timeWindowData, &win, true); doApplyFunctions(pInfo->binfo.pCtx, &nextWin, &pInfo->timeWindowData, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); } @@ -1671,10 +1613,9 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe STaskRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; int32_t numOfOutput = pOperatorInfo->numOfOutput; - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); - bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); + int32_t step = 1;//GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); + bool ascQuery = true; TSKEY* tsCols = NULL; if (pSDataBlock->pDataBlock != NULL) { @@ -1687,7 +1628,7 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe int32_t startPos = ascQuery ? 0 : (pSDataBlock->info.rows - 1); TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols, pSDataBlock->info.rows, ascQuery); - STimeWindow win = getCurrentActiveTimeWindow(pResultRowInfo, ts, pQueryAttr); + STimeWindow win = {0};//getCurrentActiveTimeWindow(pResultRowInfo, ts, pQueryAttr); bool masterScan = IS_MAIN_SCAN(pRuntimeEnv); SResultRow* pResult = NULL; @@ -1703,7 +1644,7 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - TSKEY ekey = reviseWindowEkey(pQueryAttr, &win); + TSKEY ekey = 0;//reviseWindowEkey(pQueryAttr, &win); // forwardStep = getNumOfRowsInTimeWindow(pRuntimeEnv, &pSDataBlock->info, tsCols, startPos, ekey, // binarySearchForKey, true); @@ -1717,31 +1658,31 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe // startPos = getNextQualifiedWindow(pQueryAttr, &win, &pSDataBlock->info, tsCols, binarySearchForKey, // prevEndPos); if (startPos < 0) { - if ((ascQuery && win.skey <= pQueryAttr->window.ekey) || ((!ascQuery) && win.ekey >= pQueryAttr->window.ekey)) { - int32_t code = - setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, - tableGroupId, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset); - if (code != TSDB_CODE_SUCCESS || pResult == NULL) { - longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - startPos = pSDataBlock->info.rows - 1; +// if ((ascQuery && win.skey <= pQueryAttr->window.ekey) || ((!ascQuery) && win.ekey >= pQueryAttr->window.ekey)) { +// int32_t code = +// setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, +// tableGroupId, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset); +// if (code != TSDB_CODE_SUCCESS || pResult == NULL) { +// longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); +// } +// +// startPos = pSDataBlock->info.rows - 1; // window start(end) key interpolation // doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, // forwardStep); doApplyFunctions(pRuntimeEnv, pInfo->binfo.pCtx, ascQuery ? &win : &preWin, startPos, // forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); - } +// } break; } setResultRowInterpo(pResult, RESULT_ROW_END_INTERP); } - if (pQueryAttr->timeWindowInterpo) { - int32_t rowIndex = ascQuery ? (pSDataBlock->info.rows - 1) : 0; +// if (pQueryAttr->timeWindowInterpo) { +// int32_t rowIndex = ascQuery ? (pSDataBlock->info.rows - 1) : 0; // saveDataBlockLastRow(pRuntimeEnv, &pSDataBlock->info, pSDataBlock->pDataBlock, rowIndex); - } +// } // updateResultRowInfoActiveIndex(pResultRowInfo, pQueryAttr, pRuntimeEnv->current->lastKey); } @@ -1890,9 +1831,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } /*int32_t ret = */ generatedHashKey(pInfo->keyBuf, &len, pInfo->pGroupColVals); - int32_t ret = - setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, - 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); + int32_t ret = setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } @@ -1921,73 +1860,80 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } } +static void doKeepTuple(SSessionAggOperatorInfo* pInfo, int64_t ts) { + pInfo->curWindow.ekey = ts; + pInfo->prevTs = ts; + pInfo->numOfRows += 1; +} + +static void doKeepSessionStartInfo(SSessionAggOperatorInfo* pInfo, const int64_t* tsList, int32_t rowIndex) { + pInfo->start = rowIndex; + pInfo->numOfRows = 0; + pInfo->curWindow.skey = tsList[rowIndex]; +} + // todo handle multiple tables cases. static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperatorInfo* pInfo, SSDataBlock* pBlock) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - // primary timestamp column SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); - bool masterScan = true; - STimeWindow window = {0}; - int32_t numOfOutput = pOperator->numOfOutput; - int64_t gid = pBlock->info.groupId; + bool masterScan = true; + int32_t numOfOutput = pOperator->numOfOutput; + int64_t gid = pBlock->info.groupId; int64_t gap = pInfo->gap; pInfo->numOfRows = 0; - if (/*IS_REPEAT_SCAN(pRuntimeEnv) && */ !pInfo->reptScan) { + if (!pInfo->reptScan) { pInfo->reptScan = true; - pInfo->prevTs = INT64_MIN; + pInfo->prevTs = INT64_MIN; } + // In case of ascending or descending order scan data, only one time window needs to be kepted for each table. TSKEY* tsList = (TSKEY*)pColInfoData->pData; for (int32_t j = 0; j < pBlock->info.rows; ++j) { if (pInfo->prevTs == INT64_MIN) { - pInfo->curWindow.skey = tsList[j]; - pInfo->curWindow.ekey = tsList[j]; - pInfo->prevTs = tsList[j]; - pInfo->numOfRows = 1; - pInfo->start = j; + doKeepSessionStartInfo(pInfo, tsList, j); + doKeepTuple(pInfo, tsList[j]); } else if (tsList[j] - pInfo->prevTs <= gap && (tsList[j] - pInfo->prevTs) >= 0) { - pInfo->curWindow.ekey = tsList[j]; - pInfo->prevTs = tsList[j]; - pInfo->numOfRows += 1; + // The gap is less than the threshold, so it belongs to current session window that has been opened already. + doKeepTuple(pInfo, tsList[j]); if (j == 0 && pInfo->start != 0) { - pInfo->numOfRows = 1; pInfo->start = 0; } } else { // start a new session window SResultRow* pResult = NULL; + + // keep the time window for the closed time window. + STimeWindow window = pInfo->curWindow; + pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setResultOutputBufByKey_rv(&pInfo->binfo.resultRowInfo, pBlock->info.uid, &window, masterScan, - &pResult, gid, pInfo->binfo.pCtx, numOfOutput, - pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); + &pResult, gid, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } // pInfo->numOfRows data belong to the current session window - doApplyFunctions(pInfo->binfo.pCtx, &window, NULL, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); + updateTimeWindowInfo(&pInfo->timeWindowData, &window, false); + doApplyFunctions(pInfo->binfo.pCtx, &window, &pInfo->timeWindowData, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); - pInfo->curWindow.skey = tsList[j]; - pInfo->curWindow.ekey = tsList[j]; - pInfo->prevTs = tsList[j]; - pInfo->numOfRows = 1; - pInfo->start = j; + // here we start a new session window + doKeepSessionStartInfo(pInfo, tsList, j); + doKeepTuple(pInfo, tsList[j]); } } SResultRow* pResult = NULL; - - pInfo->curWindow.ekey = pInfo->curWindow.skey; - int32_t ret = setResultOutputBufByKey_rv(&pInfo->binfo.resultRowInfo, pBlock->info.uid, &window, masterScan, &pResult, - gid, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, - &pInfo->aggSup, pTaskInfo); + pInfo->curWindow.ekey = tsList[pBlock->info.rows - 1]; + int32_t ret = setResultOutputBufByKey_rv(&pInfo->binfo.resultRowInfo, pBlock->info.uid, &pInfo->curWindow, masterScan, &pResult, + gid, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } - doApplyFunctions(pInfo->binfo.pCtx, &window, NULL, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); + updateTimeWindowInfo(&pInfo->timeWindowData, &pInfo->curWindow, false); + doApplyFunctions(pInfo->binfo.pCtx, &pInfo->curWindow, &pInfo->timeWindowData, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); } static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { @@ -2014,37 +1960,14 @@ static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCo SqlFunctionCtx* pCtx = binfo->pCtx; SResultRow* pResultRow = doSetResultOutBufByKey_rv(pBuf, pResultRowInfo, groupId, (char*)pData, bytes, true, groupId, - pTaskInfo, true, pAggSup); + pTaskInfo, false, pAggSup); assert(pResultRow != NULL); setResultRowKey(pResultRow, pData, type); - - setResultRowOutputBufInitCtx_rv(pBuf, pResultRow, pCtx, numOfCols, binfo->rowCellInfoOffset); + setResultRowOutputBufInitCtx_rv(pResultRow, pCtx, numOfCols, binfo->rowCellInfoOffset); return TSDB_CODE_SUCCESS; } -static int32_t getGroupbyColumnIndex(SGroupbyExpr* pGroupbyExpr, SSDataBlock* pDataBlock) { - size_t num = taosArrayGetSize(pGroupbyExpr->columnInfo); - for (int32_t k = 0; k < num; ++k) { - SColIndex* pColIndex = taosArrayGet(pGroupbyExpr->columnInfo, k); - if (TSDB_COL_IS_TAG(pColIndex->flag)) { - continue; - } - - int32_t colId = pColIndex->colId; - - for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { - SColumnInfoData* pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); - if (pColInfo->info.colId == colId) { - return i; - } - } - } - - assert(0); - return -1; -} - static bool functionNeedToExecute(SqlFunctionCtx* pCtx) { struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); @@ -2174,8 +2097,8 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num } } pCtx->resDataInfo.interBufSize = env.calcMemSize; - } else if (pExpr->pExpr->nodeType == QUERY_NODE_COLUMN) { - } else if (pExpr->pExpr->nodeType == QUERY_NODE_OPERATOR) { + } else if (pExpr->pExpr->nodeType == QUERY_NODE_COLUMN || pExpr->pExpr->nodeType == QUERY_NODE_OPERATOR) { + pCtx->resDataInfo.interBufSize = pFunct->resSchema.bytes; // for simple column, the intermediate buffer needs to hold one element. } pCtx->input.numOfInputCols = pFunct->numOfParams; @@ -2264,64 +2187,6 @@ static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) { return NULL; } -static int32_t setupQueryRuntimeEnv(STaskRuntimeEnv* pRuntimeEnv, int32_t numOfTables, SArray* pOperator, - void* merger) { - // qDebug("QInfo:0x%"PRIx64" setup runtime env", GET_TASKID(pRuntimeEnv)); - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - - pRuntimeEnv->prevGroupId = INT32_MIN; - pRuntimeEnv->pQueryAttr = pQueryAttr; - - pRuntimeEnv->pResultRowHashTable = - taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - pRuntimeEnv->pResultRowListSet = - taosHashInit(numOfTables * 10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - pRuntimeEnv->keyBuf = taosMemoryMalloc(pQueryAttr->maxTableColumnWidth + sizeof(int64_t) + POINTER_BYTES); - // pRuntimeEnv->pool = initResultRowPool(getResultRowSize(pRuntimeEnv)); - pRuntimeEnv->pResultRowArrayList = taosArrayInit(numOfTables, sizeof(SResultRowCell)); - - pRuntimeEnv->prevRow = taosMemoryMalloc(POINTER_BYTES * pQueryAttr->numOfCols + pQueryAttr->srcRowSize); - pRuntimeEnv->tagVal = taosMemoryMalloc(pQueryAttr->tagLen); - - // NOTE: pTableCheckInfo need to update the query time range and the lastKey info - pRuntimeEnv->pTableRetrieveTsMap = - taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); - - // pRuntimeEnv->scalarSup = createScalarFuncSupport(pQueryAttr->numOfOutput); - - if (pRuntimeEnv->scalarSup == NULL || pRuntimeEnv->pResultRowHashTable == NULL || pRuntimeEnv->keyBuf == NULL || - pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL) { - goto _clean; - } - - if (pQueryAttr->numOfCols) { - char* start = POINTER_BYTES * pQueryAttr->numOfCols + (char*)pRuntimeEnv->prevRow; - pRuntimeEnv->prevRow[0] = start; - for (int32_t i = 1; i < pQueryAttr->numOfCols; ++i) { - pRuntimeEnv->prevRow[i] = pRuntimeEnv->prevRow[i - 1] + pQueryAttr->tableCols[i - 1].bytes; - } - - if (pQueryAttr->tableCols[0].type == TSDB_DATA_TYPE_TIMESTAMP) { - *(int64_t*)pRuntimeEnv->prevRow[0] = INT64_MIN; - } - } - - // qDebug("QInfo:0x%"PRIx64" init runtime environment completed", GET_TASKID(pRuntimeEnv)); - - // group by normal column, sliding window query, interval query are handled by interval query processor - // interval (down sampling operation) - return TSDB_CODE_SUCCESS; - -_clean: - // destroyScalarFuncSupport(pRuntimeEnv->scalarSup, pRuntimeEnv->pQueryAttr->numOfOutput); - taosMemoryFreeClear(pRuntimeEnv->pResultRowHashTable); - taosMemoryFreeClear(pRuntimeEnv->keyBuf); - taosMemoryFreeClear(pRuntimeEnv->prevRow); - taosMemoryFreeClear(pRuntimeEnv->tagVal); - - return TSDB_CODE_QRY_OUT_OF_MEMORY; -} - static void doFreeQueryHandle(STaskRuntimeEnv* pRuntimeEnv) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; @@ -2400,17 +2265,6 @@ void setTaskKilled(SExecTaskInfo* pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_Q // return false; //} -static bool isFirstLastRowQuery(STaskAttr* pQueryAttr) { - for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { - int32_t functionID = getExprFunctionId(&pQueryAttr->pExpr1[i]); - if (functionID == FUNCTION_LAST_ROW) { - return true; - } - } - - return false; -} - static bool isCachedLastQuery(STaskAttr* pQueryAttr) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]); @@ -2493,18 +2347,6 @@ static bool onlyOneQueryType(STaskAttr* pQueryAttr, int32_t functId, int32_t fun return true; } -static bool onlyFirstQuery(STaskAttr* pQueryAttr) { - return onlyOneQueryType(pQueryAttr, FUNCTION_FIRST, FUNCTION_FIRST_DST); -} - -static bool onlyLastQuery(STaskAttr* pQueryAttr) { - return onlyOneQueryType(pQueryAttr, FUNCTION_LAST, FUNCTION_LAST_DST); -} - -static bool notContainSessionOrStateWindow(STaskAttr* pQueryAttr) { - return !(pQueryAttr->sw.gap > 0 || pQueryAttr->stateWindow); -} - static int32_t updateBlockLoadStatus(STaskAttr* pQuery, int32_t status) { bool hasFirstLastFunc = false; bool hasOtherFunc = false; @@ -3006,7 +2848,7 @@ int32_t loadDataBlock(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, *status = BLK_DATA_ALL_NEEDED; - SArray* pCols = tsdbRetrieveDataBlock(pTableScanInfo->pTsdbReadHandle, NULL); + SArray* pCols = tsdbRetrieveDataBlock(pTableScanInfo->dataReader, NULL); if (pCols == NULL) { return terrno; } @@ -3023,6 +2865,39 @@ int32_t loadDataBlock(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, taosArraySet(pBlock->pDataBlock, pColMatchInfo->targetSlotId, p); } + if (pTableScanInfo->pFilterNode != NULL) { + SFilterInfo* filter = NULL; + int32_t code = filterInitFromNode((SNode*)pTableScanInfo->pFilterNode, &filter, 0); + + SFilterColumnParam param1 = {.numOfCols = pBlock->info.numOfCols, .pDataBlock = pBlock->pDataBlock}; + code = filterSetDataFromSlotId(filter, ¶m1); + + int8_t* rowRes = NULL; + bool keep = filterExecute(filter, pBlock, &rowRes, NULL, param1.numOfCols); + + SSDataBlock* px = createOneDataBlock(pBlock); + blockDataEnsureCapacity(px, pBlock->info.rows); + + int32_t numOfRow = 0; + for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + SColumnInfoData* pDst = taosArrayGet(px->pDataBlock, i); + SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, i); + + numOfRow = 0; + for (int32_t j = 0; j < pBlock->info.rows; ++j) { + if (rowRes[j] == 0) { + continue; + } + + colDataAppend(pDst, numOfRow, colDataGetData(pSrc, j), false); + numOfRow += 1; + } + *pSrc = *pDst; + } + + pBlock->info.rows = numOfRow; + } + return TSDB_CODE_SUCCESS; } @@ -3342,11 +3217,6 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void* pTable, SqlFunctionCtx* pCt offset += pLocalExprInfo->base.resSchema.bytes; } - - // todo : use index to avoid iterator all possible output columns - if (pQueryAttr->stableQuery && pQueryAttr->stabledev && (pRuntimeEnv->prevResult != NULL)) { - setParamForStableStddev(pRuntimeEnv, pCtx, numOfOutput, pExprInfo); - } } // set the tsBuf start position before check each data block @@ -3434,10 +3304,8 @@ void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { } } -// TODO fix this bug. -int32_t initResultRow(SResultRow* pResultRow) { +void initResultRow(SResultRow* pResultRow) { pResultRow->pEntryInfo = (struct SResultRowEntryInfo*)((char*)pResultRow + sizeof(SResultRow)); - return TSDB_CODE_SUCCESS; } /* @@ -3453,7 +3321,9 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t SqlFunctionCtx* pCtx = pInfo->pCtx; SSDataBlock* pDataBlock = pInfo->pRes; int32_t* rowCellInfoOffset = pInfo->rowCellInfoOffset; + SResultRowInfo* pResultRowInfo = &pInfo->resultRowInfo; + initResultRowInfo(pResultRowInfo, 16); int64_t tid = 0; int64_t groupId = 0; @@ -3542,19 +3412,6 @@ void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput) } } -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) { struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(&pCtx[j]); @@ -3614,9 +3471,11 @@ void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SD SFilePage* bufPage = getBufPage(pBuf, pPos->pageId); SResultRow* pRow = (SResultRow*)((char*)bufPage + pPos->offset); - if (!isResultRowClosed(pResultRowInfo, i)) { - continue; - } + + // TODO ignore the close status anyway. +// if (!isResultRowClosed(pRow)) { +// continue; +// } for (int32_t j = 0; j < numOfOutput; ++j) { pCtx[j].resultInfo = getResultCell(pRow, j, rowCellInfoOffset); @@ -3626,7 +3485,7 @@ void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SD continue; } - if (pCtx[j].fpSet.process) { // TODO set the dummy function. + if (pCtx[j].fpSet.process) { // TODO set the dummy function, to avoid the check for null ptr. pCtx[j].fpSet.finalize(&pCtx[j]); } @@ -3664,6 +3523,7 @@ void finalizeUpdatedResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbased if (pCtx[j].fpSet.process) { // TODO set the dummy function. pCtx[j].fpSet.finalize(&pCtx[j]); + pResInfo->initialized = true; } if (pRow->numOfRows < pResInfo->numOfRes) { @@ -3709,23 +3569,6 @@ STableQueryInfo* createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow return pTableQueryInfo; } -STableQueryInfo* createTmpTableQueryInfo(STimeWindow win) { - STableQueryInfo* pTableQueryInfo = taosMemoryCalloc(1, sizeof(STableQueryInfo)); - - // pTableQueryInfo->win = win; - pTableQueryInfo->lastKey = win.skey; - - // set more initial size of interval/groupby query - int32_t initialSize = 16; - int32_t code = initResultRowInfo(&pTableQueryInfo->resInfo, initialSize); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFreeClear(pTableQueryInfo); - return NULL; - } - - return pTableQueryInfo; -} - void destroyTableQueryInfoImpl(STableQueryInfo* pTableQueryInfo) { if (pTableQueryInfo == NULL) { return; @@ -3768,8 +3611,7 @@ void setResultRowOutputBufInitCtx(STaskRuntimeEnv* pRuntimeEnv, SResultRow* pRes } } -void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, SqlFunctionCtx* pCtx, - int32_t numOfOutput, int32_t* rowCellInfoOffset) { +void setResultRowOutputBufInitCtx_rv(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset) { for (int32_t i = 0; i < numOfOutput; ++i) { pCtx[i].resultInfo = getResultCell(pResult, i, rowCellInfoOffset); @@ -3782,22 +3624,13 @@ void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, S continue; } - // int32_t functionId = pCtx[i].functionId; - // if (functionId < 0) { - // continue; - // } - // if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) { - // if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i - 1].pOutput; - // } - if (!pResInfo->initialized && pCtx[i].functionId != -1) { pCtx[i].fpSet.init(&pCtx[i], pResInfo); } } } -void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, int32_t tableGroupId, - SExecTaskInfo* pTaskInfo) { +void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, int32_t tableGroupId, SExecTaskInfo* pTaskInfo) { // for simple group by query without interval, all the tables belong to one group result. int64_t uid = 0; int64_t tid = 0; @@ -3816,14 +3649,13 @@ void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, i * all group belong to one result set, and each group result has different group id so set the id to be one */ if (pResultRow->pageId == -1) { - int32_t ret = - addNewWindowResultBuf(pResultRow, pAggInfo->pResultBuf, tableGroupId, pAggInfo->binfo.pRes->info.rowSize); + int32_t ret = addNewWindowResultBuf(pResultRow, pAggInfo->pResultBuf, tableGroupId, pAggInfo->binfo.pRes->info.rowSize); if (ret != TSDB_CODE_SUCCESS) { return; } } - setResultRowOutputBufInitCtx_rv(pAggInfo->pResultBuf, pResultRow, pCtx, numOfOutput, rowCellInfoOffset); + setResultRowOutputBufInitCtx_rv(pResultRow, pCtx, numOfOutput, rowCellInfoOffset); } void setExecutionContext(int32_t numOfOutput, int32_t tableGroupId, TSKEY nextKey, SExecTaskInfo* pTaskInfo, @@ -3840,30 +3672,6 @@ void setExecutionContext(int32_t numOfOutput, int32_t tableGroupId, TSKEY nextKe pAggInfo->groupId = tableGroupId; } -void setResultOutputBuf(STaskRuntimeEnv* pRuntimeEnv, SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfCols, - int32_t* rowCellInfoOffset) { - // Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group - SFilePage* page = getBufPage(pRuntimeEnv->pResultBuf, pResult->pageId); - - int16_t offset = 0; - for (int32_t i = 0; i < numOfCols; ++i) { - pCtx[i].pOutput = getPosInResultPage(pRuntimeEnv->pQueryAttr, page, pResult->offset, offset); - offset += pCtx[i].resDataInfo.bytes; - - int32_t functionId = pCtx[i].functionId; - if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF || - functionId == FUNCTION_DERIVATIVE) { - if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i - 1].pOutput; - } - - /* - * set the output buffer information and intermediate buffer, - * not all queries require the interResultBuf, such as COUNT - */ - pCtx[i].resultInfo = getResultCell(pResult, i, rowCellInfoOffset); - } -} - void setCtxTagForJoin(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, void* pTable) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; @@ -3933,76 +3741,6 @@ int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, S return 0; } -// TODO refactor: this funciton should be merged with setparamForStableStddevColumnData function. -void setParamForStableStddev(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, - SExprInfo* pExprInfo) { -#if 0 - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - - int32_t numOfExprs = pQueryAttr->numOfOutput; - for(int32_t i = 0; i < numOfExprs; ++i) { - SExprInfo* pExprInfo1 = &(pExprInfo[i]); - if (pExprInfo1->base.functionId != FUNCTION_STDDEV_DST) { - continue; - } - - SExprBasicInfo* pExpr = &pExprInfo1->base; - - pCtx[i].param[0].arr = NULL; - pCtx[i].param[0].nType = TSDB_DATA_TYPE_INT; // avoid freeing the memory by setting the type to be int - - // TODO use hash to speedup this loop - int32_t numOfGroup = (int32_t)taosArrayGetSize(pRuntimeEnv->prevResult); - for (int32_t j = 0; j < numOfGroup; ++j) { - SInterResult* p = taosArrayGet(pRuntimeEnv->prevResult, j); - if (pQueryAttr->tagLen == 0 || memcmp(p->tags, pRuntimeEnv->tagVal, pQueryAttr->tagLen) == 0) { - int32_t numOfCols = (int32_t)taosArrayGetSize(p->pResult); - for (int32_t k = 0; k < numOfCols; ++k) { - SStddevInterResult* pres = taosArrayGet(p->pResult, k); - if (pres->info.colId == pExpr->colInfo.colId) { - pCtx[i].param[0].arr = pres->pResult; - break; - } - } - } - } - } -#endif -} - -void setParamForStableStddevByColData(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, - SExprInfo* pExpr, char* val, int16_t bytes) { - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; -#if 0 - int32_t numOfExprs = pQueryAttr->numOfOutput; - for(int32_t i = 0; i < numOfExprs; ++i) { - SExprBasicInfo* pExpr1 = &pExpr[i].base; - if (pExpr1->functionId != FUNCTION_STDDEV_DST) { - continue; - } - - pCtx[i].param[0].arr = NULL; - pCtx[i].param[0].nType = TSDB_DATA_TYPE_INT; // avoid freeing the memory by setting the type to be int - - // TODO use hash to speedup this loop - int32_t numOfGroup = (int32_t)taosArrayGetSize(pRuntimeEnv->prevResult); - for (int32_t j = 0; j < numOfGroup; ++j) { - SInterResult* p = taosArrayGet(pRuntimeEnv->prevResult, j); - if (bytes == 0 || memcmp(p->tags, val, bytes) == 0) { - int32_t numOfCols = (int32_t)taosArrayGetSize(p->pResult); - for (int32_t k = 0; k < numOfCols; ++k) { - SStddevInterResult* pres = taosArrayGet(p->pResult, k); - if (pres->info.colId == pExpr1->colInfo.colId) { - pCtx[i].param[0].arr = pres->pResult; - break; - } - } - } - } - } -#endif -} - /* * There are two cases to handle: * @@ -4139,7 +3877,7 @@ static void updateNumOfRowsInResultRows(SqlFunctionCtx* pCtx, int32_t numOfOutpu // if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) { // return; // } - +#if 0 for (int32_t i = 0; i < pResultRowInfo->size; ++i) { SResultRow* pResult = pResultRowInfo->pResult[i]; @@ -4153,6 +3891,8 @@ static void updateNumOfRowsInResultRows(SqlFunctionCtx* pCtx, int32_t numOfOutpu pResult->numOfRows = (uint16_t)(TMAX(pResult->numOfRows, pCell->numOfRes)); } } +#endif + } static int32_t compressQueryColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, int8_t compressed) { @@ -4630,73 +4370,6 @@ static int32_t setupQueryHandle(void* tsdb, STaskRuntimeEnv* pRuntimeEnv, int64_ return terrno; } -int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr, int32_t tbScanner, SArray* pOperator, - void* param) { - STaskRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; - - STaskAttr* pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; - pQueryAttr->tsdb = tsdb; - - if (tsdb != NULL) { - int32_t code = setupQueryHandle(tsdb, pRuntimeEnv, pQInfo->qId, pQueryAttr->stableQuery); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } - - pQueryAttr->interBufSize = getOutputInterResultBufSize(pQueryAttr); - - pRuntimeEnv->groupResInfo.totalGroup = (int32_t)(pQueryAttr->stableQuery ? GET_NUM_OF_TABLEGROUP(pRuntimeEnv) : 0); - pRuntimeEnv->enableGroupData = false; - - pRuntimeEnv->pQueryAttr = pQueryAttr; - pRuntimeEnv->pTsBuf = pTsBuf; - pRuntimeEnv->cur.vgroupIndex = -1; - setResultBufSize(pQueryAttr, &pRuntimeEnv->resultInfo); - - if (sourceOptr != NULL) { - assert(pRuntimeEnv->proot == NULL); - pRuntimeEnv->proot = sourceOptr; - } - - if (pTsBuf != NULL) { - int16_t order = (pQueryAttr->order.order == pRuntimeEnv->pTsBuf->tsOrder) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; - tsBufSetTraverseOrder(pRuntimeEnv->pTsBuf, order); - } - - int32_t ps = 4096; - getIntermediateBufInfo(pRuntimeEnv, &ps, &pQueryAttr->intermediateResultRowSize); - - int32_t TENMB = 1024 * 1024 * 10; - int32_t code = createDiskbasedBuf(&pRuntimeEnv->pResultBuf, ps, TENMB, "", "/tmp"); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - // create runtime environment - int32_t numOfTables = (int32_t)pQueryAttr->tableGroupInfo.numOfTables; - pQInfo->summary.tableInfoSize += (numOfTables * sizeof(STableQueryInfo)); - pQInfo->summary.queryProfEvents = taosArrayInit(512, sizeof(SQueryProfEvent)); - if (pQInfo->summary.queryProfEvents == NULL) { - // qDebug("QInfo:0x%"PRIx64" failed to allocate query prof events array", pQInfo->qId); - } - - pQInfo->summary.operatorProfResults = - taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_TINYINT), true, HASH_NO_LOCK); - - if (pQInfo->summary.operatorProfResults == NULL) { - // qDebug("QInfo:0x%"PRIx64" failed to allocate operator prof results hash", pQInfo->qId); - } - - code = setupQueryRuntimeEnv(pRuntimeEnv, (int32_t)pQueryAttr->tableGroupInfo.numOfTables, pOperator, param); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - // setTaskStatus(pOperator->pTaskInfo, QUERY_NOT_COMPLETED); - return TSDB_CODE_SUCCESS; -} - static void doTableQueryInfoTimeWindowCheck(SExecTaskInfo* pTaskInfo, STableQueryInfo* pTableQueryInfo, int32_t order) { #if 0 if (order == TSDB_ORDER_ASC) { @@ -4778,13 +4451,13 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { *newgroup = false; - while (tsdbNextDataBlock(pTableScanInfo->pTsdbReadHandle)) { + while (tsdbNextDataBlock(pTableScanInfo->dataReader)) { if (isTaskKilled(pOperator->pTaskInfo)) { longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED); } pTableScanInfo->numOfBlocks += 1; - tsdbRetrieveDataBlockInfo(pTableScanInfo->pTsdbReadHandle, &pBlock->info); + tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &pBlock->info); // todo opt // if (pTableGroupInfo->numOfTables > 1 || (pRuntimeEnv->current == NULL && pTableGroupInfo->numOfTables == 1)) { @@ -4794,7 +4467,6 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { // break; // } // - // pRuntimeEnv->current = *pTableQueryInfo; // doTableQueryInfoTimeWindowCheck(pTaskInfo, *pTableQueryInfo, pTableScanInfo->order); // } @@ -4822,7 +4494,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; // The read handle is not initialized yet, since no qualified tables exists - if (pTableScanInfo->pTsdbReadHandle == NULL) { + if (pTableScanInfo->dataReader == NULL) { return NULL; } @@ -4850,11 +4522,6 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; - // if (pTaskInfo->pTsBuf) { - // bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf); - // assert(ret); - // } - // if (pResultRowInfo->size > 0) { pResultRowInfo->curPos = 0; } @@ -4890,45 +4557,44 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) { STableScanInfo* pTableScanInfo = pOperator->info; *newgroup = false; -#if 0 - STableBlockDist tableBlockDist = {0}; - tableBlockDist.numOfTables = (int32_t)pOperator->pRuntimeEnv->tableqinfoGroupInfo.numOfTables; + + STableBlockDistInfo tableBlockDist = {0}; + tableBlockDist.numOfTables = 1; // TODO set the correct number of tables int32_t numRowSteps = TSDB_DEFAULT_MAX_ROW_FBLOCK / TSDB_BLOCK_DIST_STEP_ROWS; if (TSDB_DEFAULT_MAX_ROW_FBLOCK % TSDB_BLOCK_DIST_STEP_ROWS != 0) { ++numRowSteps; } + tableBlockDist.dataBlockInfos = taosArrayInit(numRowSteps, sizeof(SFileBlockInfo)); taosArraySetSize(tableBlockDist.dataBlockInfos, numRowSteps); + tableBlockDist.maxRows = INT_MIN; tableBlockDist.minRows = INT_MAX; - tsdbGetFileBlocksDistInfo(pTableScanInfo->pTsdbReadHandle, &tableBlockDist); - tableBlockDist.numOfRowsInMemTable = (int32_t) tsdbGetNumOfRowsInMemTable(pTableScanInfo->pTsdbReadHandle); + tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &tableBlockDist); + tableBlockDist.numOfRowsInMemTable = (int32_t) tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader); SSDataBlock* pBlock = &pTableScanInfo->block; pBlock->info.rows = 1; pBlock->info.numOfCols = 1; - SBufferWriter bw = tbufInitWriter(NULL, false); - blockDistInfoToBinary(&tableBlockDist, &bw); +// SBufferWriter bw = tbufInitWriter(NULL, false); +// blockDistInfoToBinary(&tableBlockDist, &bw); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0); - int32_t len = (int32_t) tbufTell(&bw); - pColInfo->pData = taosMemoryMalloc(len + sizeof(int32_t)); +// int32_t len = (int32_t) tbufTell(&bw); +// pColInfo->pData = taosMemoryMalloc(len + sizeof(int32_t)); +// *(int32_t*) pColInfo->pData = len; +// memcpy(pColInfo->pData + sizeof(int32_t), tbufGetData(&bw, false), len); +// +// tbufCloseWriter(&bw); - *(int32_t*) pColInfo->pData = len; - memcpy(pColInfo->pData + sizeof(int32_t), tbufGetData(&bw, false), len); - - tbufCloseWriter(&bw); - - SArray* g = GET_TABLEGROUP(pOperator->pRuntimeEnv, 0); - pOperator->pRuntimeEnv->current = taosArrayGetP(g, 0); +// SArray* g = GET_TABLEGROUP(pOperator->, 0); +// pOperator->pRuntimeEnv->current = taosArrayGetP(g, 0); pOperator->status = OP_EXEC_DONE; return pBlock; -#endif - return TSDB_CODE_SUCCESS; } static void doClearBufferedBlocks(SStreamBlockScanInfo* pInfo) { @@ -4976,7 +4642,20 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) return NULL; } - pInfo->pRes->pDataBlock = tqRetrieveDataBlock(pInfo->readerHandle); + SArray* pCols = tqRetrieveDataBlock(pInfo->readerHandle); + + int32_t numOfCols = pInfo->pRes->info.numOfCols; + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* p = taosArrayGet(pCols, i); + SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); + if (!pColMatchInfo->output) { + continue; + } + + ASSERT(pColMatchInfo->colId == p->info.colId); + taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, p); + } + if (pInfo->pRes->pDataBlock == NULL) { // TODO add log pTaskInfo->code = terrno; @@ -4996,12 +4675,16 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) int32_t loadRemoteDataCallback(void* param, const SDataBuf* pMsg, int32_t code) { SSourceDataInfo* pSourceDataInfo = (SSourceDataInfo*)param; - pSourceDataInfo->pRsp = pMsg->pData; + if (code == TSDB_CODE_SUCCESS) { + pSourceDataInfo->pRsp = pMsg->pData; - SRetrieveTableRsp* pRsp = pSourceDataInfo->pRsp; - pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->compLen = htonl(pRsp->compLen); + SRetrieveTableRsp* pRsp = pSourceDataInfo->pRsp; + pRsp->numOfRows = htonl(pRsp->numOfRows); + pRsp->compLen = htonl(pRsp->compLen); + pRsp->useconds = htobe64(pRsp->useconds); + } else { + pSourceDataInfo->code = code; + } pSourceDataInfo->status = EX_SOURCE_DATA_READY; tsem_post(&pSourceDataInfo->pEx->ready); @@ -5258,7 +4941,6 @@ static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo* pOperator) { totalSources, endTs - startTs); tsem_wait(&pExchangeInfo->ready); - pOperator->status = OP_RES_TO_RETURN; return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); } @@ -5302,18 +4984,22 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo* pOperator) { } doSendFetchDataRequest(pExchangeInfo, pTaskInfo, pExchangeInfo->current); - tsem_wait(&pExchangeInfo->ready); - SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, pExchangeInfo->current); + SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, pExchangeInfo->current); SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, pExchangeInfo->current); + if (pDataInfo->code != TSDB_CODE_SUCCESS) { + qError("%s vgId:%d, taskID:0x%" PRIx64 " error happens, code:%s", + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, tstrerror(pDataInfo->code)); + pOperator->pTaskInfo->code = pDataInfo->code; + return NULL; + } + SRetrieveTableRsp* pRsp = pDataInfo->pRsp; SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; - if (pRsp->numOfRows == 0) { - qDebug("%s vgId:%d, taskID:0x%" PRIx64 " %d of total completed, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 - " try next", + qDebug("%s vgId:%d, taskID:0x%" PRIx64 " %d of total completed, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 " try next", GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pExchangeInfo->current + 1, pDataInfo->totalRows, pLoadInfo->totalRows); @@ -5534,7 +5220,7 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, - SExecTaskInfo* pTaskInfo) { + SNode* pCondition, SExecTaskInfo* pTaskInfo) { assert(repeatTime > 0); STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); @@ -5553,21 +5239,22 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, taosArrayPush(pInfo->block.pDataBlock, &idata); } - pInfo->pTsdbReadHandle = pTsdbReadHandle; - pInfo->times = repeatTime; - pInfo->reverseTimes = reverseTime; - pInfo->order = order; - pInfo->current = 0; - pInfo->scanFlag = MAIN_SCAN; - pInfo->pColMatchInfo = pColMatchInfo; - pOperator->name = "TableScanOperator"; + pInfo->pFilterNode = pCondition; + pInfo->dataReader = pTsdbReadHandle; + pInfo->times = repeatTime; + pInfo->reverseTimes = reverseTime; + pInfo->order = order; + pInfo->current = 0; + pInfo->scanFlag = MAIN_SCAN; + pInfo->pColMatchInfo = pColMatchInfo; + pOperator->name = "TableScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = numOfOutput; - pOperator->getNextFn = doTableScan; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = numOfOutput; + pOperator->getNextFn = doTableScan; + pOperator->pTaskInfo = pTaskInfo; return pOperator; } @@ -5575,7 +5262,7 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); - pInfo->pTsdbReadHandle = pTsdbReadHandle; + pInfo->dataReader = pTsdbReadHandle; pInfo->times = 1; pInfo->reverseTimes = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; @@ -5596,32 +5283,42 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim return pOperator; } -SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) { - STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); +SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo) { + STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pInfo == NULL || pOperator == NULL) { + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } - pInfo->pTsdbReadHandle = pTsdbReadHandle; + pInfo->dataReader = dataReader; pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); - SColumnInfoData infoData = {{0}}; - infoData.info.type = TSDB_DATA_TYPE_BINARY; + SColumnInfoData infoData = {0}; + infoData.info.type = TSDB_DATA_TYPE_BINARY; infoData.info.bytes = 1024; infoData.info.colId = 0; taosArrayPush(pInfo->block.pDataBlock, &infoData); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "TableBlockInfoScanOperator"; + pOperator->name = "DataBlockInfoScanOperator"; // pOperator->operatorType = OP_TableBlockInfoScan; - pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - // pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols; - pOperator->getNextFn = doBlockInfoScan; + pOperator->blockingOptr = false; + pOperator->status = OP_NOT_OPENED; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doBlockInfoScan; + + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; return pOperator; + + _error: + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); + return NULL; } -SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, - SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -5631,8 +5328,18 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* return NULL; } + int32_t numOfOutput = taosArrayGetSize(pColList); + + SArray* pColIds = taosArrayInit(4, sizeof(int16_t)); + for(int32_t i = 0; i < numOfOutput; ++i) { + int16_t* id = taosArrayGet(pColList, i); + taosArrayPush(pColIds, id); + } + + pInfo->pColMatchInfo = pColList; + // set the extract column id to streamHandle - tqReadHandleSetColIdList((STqReadHandle*)streamReadHandle, pColList); + tqReadHandleSetColIdList((STqReadHandle*)streamReadHandle, pColIds); int32_t code = tqReadHandleSetTbUidList(streamReadHandle, pTableIdList); if (code != 0) { taosMemoryFreeClear(pInfo); @@ -5650,16 +5357,17 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pInfo->readerHandle = streamReadHandle; pInfo->pRes = pResBlock; - pOperator->name = "StreamBlockScanOperator"; + pOperator->name = "StreamBlockScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = pResBlock->info.numOfCols; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doStreamBlockScan; - pOperator->closeFn = operatorDummyCloseFn; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = pResBlock->info.numOfCols; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doStreamBlockScan; + pOperator->closeFn = operatorDummyCloseFn; + pOperator->pTaskInfo = pTaskInfo; + return pOperator; } @@ -5671,9 +5379,9 @@ static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t SRetrieveMetaTableRsp* pRsp = pScanResInfo->pRsp; pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->handle = htobe64(pRsp->handle); - pRsp->compLen = htonl(pRsp->compLen); + pRsp->useconds = htobe64(pRsp->useconds); + pRsp->handle = htobe64(pRsp->handle); + pRsp->compLen = htonl(pRsp->compLen); } else { operator->pTaskInfo->code = code; } @@ -5815,7 +5523,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { SColumnInfoData* pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, i); int64_t tmp = 0; char t[10] = {0}; - STR_TO_VARSTR(t, "_"); + STR_TO_VARSTR(t, "_"); //TODO if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { colDataAppend(pColInfoData, numOfRows, t, false); } else { @@ -5831,6 +5539,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { // pInfo->totalBytes; return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } else { // load the meta from mnode of the given epset + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + int64_t startTs = taosGetTimestampUs(); pInfo->req.type = pInfo->type; @@ -5870,6 +5582,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { SRetrieveMetaTableRsp* pRsp = pInfo->pRsp; pInfo->req.showId = pRsp->handle; + if (pRsp->numOfRows == 0 || pRsp->completed) { + pOperator->status = OP_EXEC_DONE; + } + if (pRsp->numOfRows == 0) { // qDebug("%s vgId:%d, taskID:0x%"PRIx64" %d of total completed, rowsOfSource:%"PRIu64", totalRows:%"PRIu64" // try next", @@ -5986,80 +5702,6 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB return pOperator; } -SArray* getOrderCheckColumns(STaskAttr* pQuery) { - int32_t numOfCols = (pQuery->pGroupbyExpr == NULL) ? 0 : taosArrayGetSize(pQuery->pGroupbyExpr->columnInfo); - - SArray* pOrderColumns = NULL; - if (numOfCols > 0) { - pOrderColumns = taosArrayDup(pQuery->pGroupbyExpr->columnInfo); - } else { - pOrderColumns = taosArrayInit(4, sizeof(SColIndex)); - } - - if (pQuery->interval.interval > 0) { - if (pOrderColumns == NULL) { - pOrderColumns = taosArrayInit(1, sizeof(SColIndex)); - } - - SColIndex colIndex = {.colIndex = 0, .colId = 0, .flag = TSDB_COL_NORMAL}; - taosArrayPush(pOrderColumns, &colIndex); - } - - { - numOfCols = (int32_t)taosArrayGetSize(pOrderColumns); - for (int32_t i = 0; i < numOfCols; ++i) { - SColIndex* index = taosArrayGet(pOrderColumns, i); - for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { - SExprBasicInfo* pExpr = &pQuery->pExpr1[j].base; - int32_t functionId = getExprFunctionId(&pQuery->pExpr1[j]); - - if (index->colId == pExpr->pParam[0].pCol->colId && - (functionId == FUNCTION_PRJ || functionId == FUNCTION_TAG || functionId == FUNCTION_TS)) { - index->colIndex = j; - index->colId = pExpr->resSchema.colId; - } - } - } - } - - return pOrderColumns; -} - -SArray* getResultGroupCheckColumns(STaskAttr* pQuery) { - int32_t numOfCols = (pQuery->pGroupbyExpr == NULL) ? 0 : taosArrayGetSize(pQuery->pGroupbyExpr->columnInfo); - - SArray* pOrderColumns = NULL; - if (numOfCols > 0) { - pOrderColumns = taosArrayDup(pQuery->pGroupbyExpr->columnInfo); - } else { - pOrderColumns = taosArrayInit(4, sizeof(SColIndex)); - } - - for (int32_t i = 0; i < numOfCols; ++i) { - SColIndex* index = taosArrayGet(pOrderColumns, i); - - bool found = false; - for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { - SExprBasicInfo* pExpr = &pQuery->pExpr1[j].base; - int32_t functionId = getExprFunctionId(&pQuery->pExpr1[j]); - - // FUNCTION_TAG_DUMMY function needs to be ignored - // if (index->colId == pExpr->pColumns->info.colId && - // ((TSDB_COL_IS_TAG(pExpr->pColumns->flag) && functionId == FUNCTION_TAG) || - // (TSDB_COL_IS_NORMAL_COL(pExpr->pColumns->flag) && functionId == FUNCTION_PRJ))) { - // index->colIndex = j; - // index->colId = pExpr->resSchema.colId; - // found = true; - // break; - // } - } - - assert(found && index->colIndex >= 0 && index->colIndex < pQuery->numOfOutput); - } - - return pOrderColumns; -} - static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey); static void cleanupAggSup(SAggSupporter* pAggSup); @@ -6775,7 +6417,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); - +#if 0 if (pProjectInfo->existDataBlock) { // TODO refactor SSDataBlock* pBlock = pProjectInfo->existDataBlock; pProjectInfo->existDataBlock = NULL; @@ -6797,6 +6439,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) return pRes; } } +#endif SOperatorInfo* downstream = pOperator->pDownstream[0]; @@ -6836,67 +6479,32 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput); + + if (pProjectInfo->curOffset < pInfo->pRes->info.rows && pProjectInfo->curOffset > 0) { + blockDataTrimFirstNRows(pInfo->pRes, pProjectInfo->curOffset); + pProjectInfo->curOffset = 0; + break; + } else if (pProjectInfo->curOffset >= pInfo->pRes->info.rows) { + pProjectInfo->curOffset -= pInfo->pRes->info.rows; + blockDataCleanup(pInfo->pRes); + continue; + } + if (pRes->info.rows >= pOperator->resultInfo.threshold) { break; } } + + if (pProjectInfo->limit.limit > 0 && pProjectInfo->curOutput + pInfo->pRes->info.rows >= pProjectInfo->limit.limit) { + pInfo->pRes->info.rows = (int32_t)(pProjectInfo->limit.limit - pProjectInfo->curOutput); + } + + pProjectInfo->curOutput += pInfo->pRes->info.rows; // copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); return (pInfo->pRes->info.rows > 0) ? pInfo->pRes : NULL; } -static SSDataBlock* doLimit(SOperatorInfo* pOperator, bool* newgroup) { - if (pOperator->status == OP_EXEC_DONE) { - return NULL; - } - - SLimitOperatorInfo* pInfo = pOperator->info; - - SSDataBlock* pBlock = NULL; - SOperatorInfo* pDownstream = pOperator->pDownstream[0]; - - while (1) { - publishOperatorProfEvent(pDownstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); - pBlock = pDownstream->getNextFn(pDownstream, newgroup); - publishOperatorProfEvent(pDownstream, QUERY_PROF_AFTER_OPERATOR_EXEC); - - if (pBlock == NULL) { - doSetOperatorCompleted(pOperator); - return NULL; - } - - if (pInfo->currentOffset == 0) { - break; - } else if (pInfo->currentOffset >= pBlock->info.rows) { - pInfo->currentOffset -= pBlock->info.rows; - } else { // TODO handle the data movement - int32_t remain = (int32_t)(pBlock->info.rows - pInfo->currentOffset); - pBlock->info.rows = remain; - - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); - - int16_t bytes = pColInfoData->info.bytes; - memmove(pColInfoData->pData, pColInfoData->pData + bytes * pInfo->currentOffset, remain * bytes); - } - - pInfo->currentOffset = 0; - break; - } - } - - if (pInfo->currentRows + pBlock->info.rows >= pInfo->limit.limit) { - pBlock->info.rows = (int32_t)(pInfo->limit.limit - pInfo->currentRows); - pInfo->currentRows = pInfo->limit.limit; - - doSetOperatorCompleted(pOperator); - } else { - pInfo->currentRows += pBlock->info.rows; - } - - return pBlock; -} - static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { if (OPTR_IS_OPENED(pOperator)) { return TSDB_CODE_SUCCESS; @@ -6975,7 +6583,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } - return pInfo->binfo.pRes; + return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; } // STimeWindow win = {0}; @@ -7004,6 +6612,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup finalizeUpdatedResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, pUpdated, pInfo->binfo.rowCellInfoOffset); + initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset); @@ -7145,9 +6754,6 @@ static SSDataBlock* doAllSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgr return pIntervalInfo->binfo.pRes; } - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { @@ -7163,14 +6769,14 @@ static SSDataBlock* doAllSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgr STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; // setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); - setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); +// setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey); hashAllIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); } pOperator->status = OP_RES_TO_RETURN; - pQueryAttr->order.order = order; // TODO : restore the order +// pQueryAttr->order.order = order; // TODO : restore the order doCloseAllTimeWindow(pRuntimeEnv); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); @@ -7266,22 +6872,22 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { } SStateWindowOperatorInfo* pWindowInfo = pOperator->info; - SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); - if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { - pOperator->status = OP_EXEC_DONE; - } +// if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { +// pOperator->status = OP_EXEC_DONE; +// } return pBInfo->pRes; } - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - STimeWindow win = pQueryAttr->window; + int32_t order = TSDB_ORDER_ASC; + STimeWindow win = pTaskInfo->window; + SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); @@ -7291,28 +6897,29 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { if (pBlock == NULL) { break; } - setInputDataBlock(pOperator, pBInfo->pCtx, pBlock, pQueryAttr->order.order); - if (pWindowInfo->colIndex == -1) { - pWindowInfo->colIndex = getGroupbyColumnIndex(pRuntimeEnv->pQueryAttr->pGroupbyExpr, pBlock); - } + +// setInputDataBlock(pOperator, pBInfo->pCtx, pDataBlock, TSDB_ORDER_ASC); +// 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; +// pQueryAttr->order.order = order; +// pQueryAttr->window = win; pOperator->status = OP_RES_TO_RETURN; closeAllResultRows(&pBInfo->resultRowInfo); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); finalizeQueryResult(pBInfo->pCtx, pOperator->numOfOutput); - initGroupResInfo(&pRuntimeEnv->groupResInfo, &pBInfo->resultRowInfo); +// initGroupResInfo(&pRuntimeEnv->groupResInfo, &pBInfo->resultRowInfo); // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); - if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { - pOperator->status = OP_EXEC_DONE; - } +// if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { +// pOperator->status = OP_EXEC_DONE; +// } return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; } @@ -7326,8 +6933,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) SOptrBasicInfo* pBInfo = &pInfo->binfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, - pBInfo->rowCellInfoOffset); + toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); return NULL; @@ -7355,14 +6961,11 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) // restore the value pOperator->status = OP_RES_TO_RETURN; closeAllResultRows(&pBInfo->resultRowInfo); - finalizeMultiTupleQueryResult(pBInfo->pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pBInfo->resultRowInfo, - pBInfo->rowCellInfoOffset); + finalizeMultiTupleQueryResult(pBInfo->pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pBInfo->resultRowInfo, pBInfo->rowCellInfoOffset); initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo); - blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, - pBInfo->rowCellInfoOffset); + toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } @@ -7567,10 +7170,10 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey) { _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); - pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput); - pAggSup->keyBuf = taosMemoryCalloc(1, sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES); + pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput); + pAggSup->keyBuf = taosMemoryCalloc(1, sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES); pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK); - pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); + pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell)); if (pAggSup->keyBuf == NULL || pAggSup->pResultRowArrayList == NULL || pAggSup->pResultRowListSet == NULL || @@ -7745,11 +7348,6 @@ static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { taosArrayDestroy(pInfo->pSortInfo); } -static void destroyConditionOperatorInfo(void* param, int32_t numOfOutput) { - SFilterOperatorInfo* pInfo = (SFilterOperatorInfo*)param; - doDestroyFilterInfo(pInfo->pFilterInfo, pInfo->numOfFilterCols); -} - static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) { SDistinctOperatorInfo* pInfo = (SDistinctOperatorInfo*)param; taosHashCleanup(pInfo->pSet); @@ -7819,19 +7417,20 @@ _error: } SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, - SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { + SSDataBlock* pResBlock, SLimit* pLimit, SExecTaskInfo* pTaskInfo) { SProjectOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SProjectOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } + pInfo->limit = *pLimit; + pInfo->curOffset = pLimit->offset; pInfo->binfo.pRes = pResBlock; pInfo->binfo.pCtx = createSqlFunctionCtx_rv(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset); if (pInfo->binfo.pCtx == NULL) { goto _error; } - // initResultRowInfo(&pBInfo->resultRowInfo, 8); // setFunctionResultOutput(pBInfo, MAIN_SCAN); @@ -7859,35 +7458,6 @@ _error: return NULL; } -SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo) { - SLimitOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SLimitOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL) { - goto _error; - } - - pInfo->limit = *pLimit; - pInfo->currentOffset = pLimit->offset; - - pOperator->name = "LimitOperator"; - // pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LIMIT; - pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doLimit; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - - int32_t code = appendDownstream(pOperator, &downstream, 1); - return pOperator; - -_error: - taosMemoryFreeClear(pInfo); - taosMemoryFreeClear(pOperator); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; -} - SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { @@ -7969,9 +7539,9 @@ SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, S return pOperator; } -SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, - int32_t numOfOutput) { +SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { SStateWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStateWindowOperatorInfo)); + pInfo->colIndex = -1; pInfo->reptScan = false; // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); @@ -7982,13 +7552,14 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper pOperator->name = "StateWindowOperator"; // pOperator->operatorType = OP_StateWindow; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; - pOperator->getNextFn = doStateWindowAgg; - pOperator->closeFn = destroyStateWindowOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfCols; + + pOperator->pTaskInfo = pTaskInfo; + pOperator->info = pInfo; + pOperator->getNextFn = doStateWindowAgg; + pOperator->closeFn = destroyStateWindowOperatorInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -8003,28 +7574,28 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo } int32_t numOfRows = 4096; - int32_t code = - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); + initExecTimeWindowInfo(&pInfo->timeWindowData, &pTaskInfo->window); - pInfo->gap = gap; - pInfo->binfo.pRes = pResBlock; - pInfo->prevTs = INT64_MIN; - pInfo->reptScan = false; - pOperator->name = "SessionWindowAggOperator"; + pInfo->gap = gap; + pInfo->binfo.pRes = pResBlock; + pInfo->prevTs = INT64_MIN; + pInfo->reptScan = false; + pOperator->name = "SessionWindowAggOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = numOfCols; - pOperator->info = pInfo; - pOperator->getNextFn = doSessionWindowAgg; - pOperator->closeFn = destroySWindowOperatorInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->getNextFn = doSessionWindowAgg; + pOperator->closeFn = destroySWindowOperatorInfo; + pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -8290,7 +7861,6 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator, bool* newgroup) { int32_t functionId = getExprFunctionId(&pOperator->pExpr[0]); if (functionId == FUNCTION_TID_TAG) { // return the tags & table Id - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; assert(pQueryAttr->numOfOutput == 1); SExprInfo* pExprInfo = &pOperator->pExpr[0]; @@ -8745,8 +8315,8 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* pExp->pExpr->_optrRoot.pRootNode = pTargetNode->pExpr; - pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; - pExp->base.pParam[0].pCol = createColumn(pTargetNode->dataBlockId, pTargetNode->slotId, pType); +// pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; +// pExp->base.pParam[0].pCol = createColumn(pTargetNode->dataBlockId, pTargetNode->slotId, pType); } else { ASSERT(0); } @@ -8792,7 +8362,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, - pScanPhyNode->reverse, pColList, pTaskInfo); + pScanPhyNode->reverse, pColList, pScanPhyNode->node.pConditions, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == nodeType(pPhyNode)) { SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode; SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc); @@ -8805,10 +8375,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SArray* tableIdList = extractTableIdList(pTableGroupInfo); SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc); - SArray* colList = extractScanColumnId(pScanPhyNode->pScanCols); - SOperatorInfo* pOperator = - createStreamScanOperatorInfo(pHandle->reader, pResBlock, colList, tableIdList, pTaskInfo); + int32_t numOfCols = 0; + SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); + SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pResBlock, pColList, tableIdList, pTaskInfo); taosArrayDestroy(tableIdList); return pOperator; } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == nodeType(pPhyNode)) { @@ -8835,9 +8405,13 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); int32_t num = 0; - SExprInfo* pExprInfo = createExprInfo(((SProjectPhysiNode*)pPhyNode)->pProjections, NULL, &num); + SProjectPhysiNode* pProjPhyNode = (SProjectPhysiNode*) pPhyNode; + SExprInfo* pExprInfo = createExprInfo(pProjPhyNode->pProjections, NULL, &num); + SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); - return createProjectOperatorInfo(op, pExprInfo, num, pResBlock, pTaskInfo); + SLimit limit = {.limit = pProjPhyNode->limit, .offset = pProjPhyNode->offset}; + + return createProjectOperatorInfo(op, pExprInfo, num, pResBlock, &limit, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_AGG == nodeType(pPhyNode)) { size_t size = LIST_LENGTH(pPhyNode->pChildren); assert(size == 1); @@ -9071,8 +8645,7 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod return pList; } -int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, - uint64_t queryId, uint64_t taskId) { +int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId) { int32_t code = 0; if (tableType == TSDB_SUPER_TABLE) { code = tsdbQuerySTableByTagCond(metaHandle, tableUid, 0, NULL, 0, 0, NULL, pGroupInfo, NULL, 0, queryId, taskId); @@ -9154,41 +8727,6 @@ _complete: return code; } -int32_t cloneExprFilterInfo(SColumnFilterInfo** dst, SColumnFilterInfo* src, int32_t filterNum) { - if (filterNum <= 0) { - return TSDB_CODE_SUCCESS; - } - - *dst = taosMemoryCalloc(filterNum, sizeof(*src)); - if (*dst == NULL) { - return TSDB_CODE_QRY_OUT_OF_MEMORY; - } - - memcpy(*dst, src, sizeof(*src) * filterNum); - - for (int32_t i = 0; i < filterNum; i++) { - if ((*dst)[i].filterstr && dst[i]->len > 0) { - void* pz = taosMemoryCalloc(1, (size_t)(*dst)[i].len + 1); - - if (pz == NULL) { - if (i == 0) { - taosMemoryFree(*dst); - } else { - freeColumnFilterInfo(*dst, i); - } - - return TSDB_CODE_QRY_OUT_OF_MEMORY; - } - - memcpy(pz, (void*)src->pz, (size_t)src->len + 1); - - (*dst)[i].pz = (int64_t)pz; - } - } - - return TSDB_CODE_SUCCESS; -} - static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SColumnInfo* pTagCols, SExprInfo* pExprs, int32_t numOfOutput, int32_t tagLen, bool superTable) { for (int32_t i = 0; i < numOfOutput; ++i) { @@ -9211,151 +8749,6 @@ static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SCol return TSDB_CODE_SUCCESS; } -// TODO tag length should be passed from client, refactor -int32_t createQueryFilter(char* data, uint16_t len, SFilterInfo** pFilters) { - tExprNode* expr = NULL; - - TRY(TSDB_MAX_TAG_CONDITIONS) { expr = exprTreeFromBinary(data, len); } - CATCH(code) { - CLEANUP_EXECUTE(); - return code; - } - END_TRY - - if (expr == NULL) { - // qError("failed to create expr tree"); - return TSDB_CODE_QRY_APP_ERROR; - } - - // int32_t ret = filterInitFromTree(expr, pFilters, 0); - // tExprTreeDestroy(expr, NULL); - - // return ret; - return TSDB_CODE_SUCCESS; -} - -// int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** -// pFilterInfo, uint64_t qId) { -// *pFilterInfo = taosMemoryCalloc(1, sizeof(SSingleColumnFilterInfo) * numOfFilterCols); -// if (*pFilterInfo == NULL) { -// return TSDB_CODE_QRY_OUT_OF_MEMORY; -// } -// -// for (int32_t i = 0, j = 0; i < numOfCols; ++i) { -// if (pCols[i].flist.numOfFilters > 0) { -// SSingleColumnFilterInfo* pFilter = &((*pFilterInfo)[j]); -// -// memcpy(&pFilter->info, &pCols[i], sizeof(SColumnInfo)); -// pFilter->info = pCols[i]; -// -// pFilter->numOfFilters = pCols[i].flist.numOfFilters; -// pFilter->pFilters = taosMemoryCalloc(pFilter->numOfFilters, sizeof(SColumnFilterElem)); -// if (pFilter->pFilters == NULL) { -// return TSDB_CODE_QRY_OUT_OF_MEMORY; -// } -// -// for (int32_t f = 0; f < pFilter->numOfFilters; ++f) { -// SColumnFilterElem* pSingleColFilter = &pFilter->pFilters[f]; -// pSingleColFilter->filterInfo = pCols[i].flist.filterInfo[f]; -// -// int32_t lower = pSingleColFilter->filterInfo.lowerRelOptr; -// int32_t upper = pSingleColFilter->filterInfo.upperRelOptr; -// if (lower == TSDB_RELATION_INVALID && upper == TSDB_RELATION_INVALID) { -// //qError("QInfo:0x%"PRIx64" invalid filter info", qId); -// return TSDB_CODE_QRY_INVALID_MSG; -// } -// -// pSingleColFilter->fp = getFilterOperator(lower, upper); -// if (pSingleColFilter->fp == NULL) { -// //qError("QInfo:0x%"PRIx64" invalid filter info", qId); -// return TSDB_CODE_QRY_INVALID_MSG; -// } -// -// pSingleColFilter->bytes = pCols[i].bytes; -// -// if (lower == TSDB_RELATION_IN) { -//// buildFilterSetFromBinary(&pSingleColFilter->q, (char *)(pSingleColFilter->filterInfo.pz), -///(int32_t)(pSingleColFilter->filterInfo.len)); -// } -// } -// -// j++; -// } -// } -// -// return TSDB_CODE_SUCCESS; -//} - -void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols) { - // for (int32_t i = 0; i < numOfFilterCols; ++i) { - // if (pFilterInfo[i].numOfFilters > 0) { - // if (pFilterInfo[i].pFilters->filterInfo.lowerRelOptr == TSDB_RELATION_IN) { - // taosHashCleanup((SHashObj *)(pFilterInfo[i].pFilters->q)); - // } - // taosMemoryFreeClear(pFilterInfo[i].pFilters); - // } - // } - // - // taosMemoryFreeClear(pFilterInfo); - return NULL; -} - -int32_t createFilterInfo(STaskAttr* pQueryAttr, uint64_t qId) { - for (int32_t i = 0; i < pQueryAttr->numOfCols; ++i) { - // if (pQueryAttr->tableCols[i].flist.numOfFilters > 0 && pQueryAttr->tableCols[i].flist.filterInfo != NULL) { - // pQueryAttr->numOfFilterCols++; - // } - } - - if (pQueryAttr->numOfFilterCols == 0) { - return TSDB_CODE_SUCCESS; - } - - // doCreateFilterInfo(pQueryAttr->tableCols, pQueryAttr->numOfCols, pQueryAttr->numOfFilterCols, - // &pQueryAttr->pFilterInfo, qId); - - pQueryAttr->createFilterOperator = true; - - return TSDB_CODE_SUCCESS; -} - -static void doUpdateExprColumnIndex(STaskAttr* pQueryAttr) { - assert(pQueryAttr->pExpr1 != NULL && pQueryAttr != NULL); - - for (int32_t k = 0; k < pQueryAttr->numOfOutput; ++k) { - SExprBasicInfo* pSqlExprMsg = &pQueryAttr->pExpr1[k].base; - // if (pSqlExprMsg->functionId == FUNCTION_ARITHM) { - // continue; - // } - - // todo opt performance - SColIndex* pColIndex = NULL; /*&pSqlExprMsg->colInfo;*/ - if (TSDB_COL_IS_NORMAL_COL(pColIndex->flag)) { - int32_t f = 0; - for (f = 0; f < pQueryAttr->numOfCols; ++f) { - if (pColIndex->colId == pQueryAttr->tableCols[f].colId) { - pColIndex->colIndex = f; - break; - } - } - - assert(f < pQueryAttr->numOfCols); - } else if (pColIndex->colId <= TSDB_UD_COLUMN_INDEX) { - // do nothing for user-defined constant value result columns - } else { - int32_t f = 0; - for (f = 0; f < pQueryAttr->numOfTags; ++f) { - if (pColIndex->colId == pQueryAttr->tagColList[f].colId) { - pColIndex->colIndex = f; - break; - } - } - - assert(f < pQueryAttr->numOfTags || pColIndex->colId == TSDB_TBNAME_COLUMN_INDEX); - } - } -} - void setResultBufSize(STaskAttr* pQueryAttr, SResultInfo* pResultInfo) { const int32_t DEFAULT_RESULT_MSG_SIZE = 1024 * (1024 + 512); @@ -9365,16 +8758,16 @@ void setResultBufSize(STaskAttr* pQueryAttr, SResultInfo* pResultInfo) { const float THRESHOLD_RATIO = 0.85f; - if (isProjQuery(pQueryAttr)) { - int32_t numOfRes = DEFAULT_RESULT_MSG_SIZE / pQueryAttr->resultRowSize; - if (numOfRes < MIN_ROWS_FOR_PRJ_QUERY) { - numOfRes = MIN_ROWS_FOR_PRJ_QUERY; - } - - pResultInfo->capacity = numOfRes; - } else { // in case of non-prj query, a smaller output buffer will be used. - pResultInfo->capacity = DEFAULT_MIN_ROWS; - } +// if (isProjQuery(pQueryAttr)) { +// int32_t numOfRes = DEFAULT_RESULT_MSG_SIZE / pQueryAttr->resultRowSize; +// if (numOfRes < MIN_ROWS_FOR_PRJ_QUERY) { +// numOfRes = MIN_ROWS_FOR_PRJ_QUERY; +// } +// +// pResultInfo->capacity = numOfRes; +// } else { // in case of non-prj query, a smaller output buffer will be used. +// pResultInfo->capacity = DEFAULT_MIN_ROWS; +// } pResultInfo->threshold = (int32_t)(pResultInfo->capacity * THRESHOLD_RATIO); pResultInfo->totalRows = 0; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index f7fccb29f7..ab7bfc7767 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -38,9 +38,14 @@ void minFunction(SqlFunctionCtx* pCtx); void maxFunction(SqlFunctionCtx *pCtx); bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); void stddevFunction(SqlFunctionCtx* pCtx); void stddevFinalize(SqlFunctionCtx* pCtx); +bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +void percentileFunction(SqlFunctionCtx *pCtx); + bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); void firstFunction(SqlFunctionCtx *pCtx); void lastFunction(SqlFunctionCtx *pCtx); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 024da4e04b..0048cc6f29 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -68,9 +68,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .classification = FUNC_MGT_AGG_FUNC, .checkFunc = stubCheckAndGetResultType, .getEnvFunc = getStddevFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize + .initFunc = stddevFunctionSetup, + .processFunc = stddevFunction, + .finalizeFunc = stddevFinalize }, { .name = "percentile", @@ -282,6 +282,26 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .sprocessFunc = atanFunction, .finalizeFunc = NULL }, + { + .name = "length", + .type = FUNCTION_TYPE_LENGTH, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = lengthFunction, + .finalizeFunc = NULL + }, + { + .name = "char_length", + .type = FUNCTION_TYPE_CHAR_LENGTH, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = charLengthFunction, + .finalizeFunc = NULL + }, { .name = "concat", .type = FUNCTION_TYPE_CONCAT, @@ -289,7 +309,67 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .checkFunc = stubCheckAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = concatFunction, + .finalizeFunc = NULL + }, + { + .name = "concat_ws", + .type = FUNCTION_TYPE_CONCAT_WS, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = concatWsFunction, + .finalizeFunc = NULL + }, + { + .name = "lower", + .type = FUNCTION_TYPE_LOWER, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = lowerFunction, + .finalizeFunc = NULL + }, + { + .name = "upper", + .type = FUNCTION_TYPE_UPPER, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = upperFunction, + .finalizeFunc = NULL + }, + { + .name = "ltrim", + .type = FUNCTION_TYPE_LTRIM, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = ltrimFunction, + .finalizeFunc = NULL + }, + { + .name = "rtrim", + .type = FUNCTION_TYPE_RTRIM, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = rtrimFunction, + .finalizeFunc = NULL + }, + { + .name = "substr", + .type = FUNCTION_TYPE_SUBSTR, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = substrFunction, .finalizeFunc = NULL }, { @@ -361,6 +441,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .initFunc = NULL, .sprocessFunc = winDurFunction, .finalizeFunc = NULL + }, + { + .name = "now", + .type = FUNCTION_TYPE_NOW, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winDurFunction, + .finalizeFunc = NULL } }; @@ -399,12 +489,6 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; break; } - case FUNCTION_TYPE_CONCAT: - case FUNCTION_TYPE_ROWTS: - case FUNCTION_TYPE_TBNAME: { - // todo - break; - } case FUNCTION_TYPE_QENDTS: case FUNCTION_TYPE_QSTARTTS: @@ -424,6 +508,7 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { break; } + case FUNCTION_TYPE_STDDEV: case FUNCTION_TYPE_SIN: case FUNCTION_TYPE_COS: case FUNCTION_TYPE_TAN: @@ -437,6 +522,67 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { break; } + case FUNCTION_TYPE_LENGTH: + case FUNCTION_TYPE_CHAR_LENGTH: { + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT }; + break; + } + + case FUNCTION_TYPE_CONCAT: + case FUNCTION_TYPE_CONCAT_WS: { + int32_t paraType, paraBytes = 0; + for (int32_t i = 0; i < pFunc->pParameterList->length; ++i) { + SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i); + paraBytes += pParam->node.resType.bytes; + paraType = pParam->node.resType.type; + } + pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType }; + break; + //int32_t paraTypeFirst, totalBytes = 0, sepBytes = 0; + //int32_t firstParamIndex = 0; + //if (pFunc->funcType == FUNCTION_TYPE_CONCAT_WS) { + // firstParamIndex = 1; + // SColumnNode* pSep = nodesListGetNode(pFunc->pParameterList, 0); + // sepBytes = pSep->node.resType.type; + //} + //for (int32_t i = firstParamIndex; i < pFunc->pParameterList->length; ++i) { + // SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i); + // int32_t paraType = pParam->node.resType.type; + // if (i == firstParamIndex) { + // paraTypeFirst = paraType; + // } + // if (paraType != paraTypeFirst) { + // return TSDB_CODE_FAILED; + // } + // //TODO: for constants also needs numOfRows + // totalBytes += pParam->node.resType.bytes; + //} + ////TODO: need to get numOfRows to decide how much space separator needed. Currently set to 100. + //totalBytes += sepBytes * (pFunc->pParameterList->length - 2) * 100; + //pFunc->node.resType = (SDataType) { .bytes = totalBytes, .type = paraTypeFirst }; + //break; + } + case FUNCTION_TYPE_LOWER: + case FUNCTION_TYPE_UPPER: + case FUNCTION_TYPE_LTRIM: + case FUNCTION_TYPE_RTRIM: + case FUNCTION_TYPE_SUBSTR: { + SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); + int32_t paraType = pParam->node.resType.type; + int32_t paraBytes = pParam->node.resType.bytes; + pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType }; + break; + } + + case FUNCTION_TYPE_ROWTS: + case FUNCTION_TYPE_TBNAME: { + // todo + break; + } + + case FUNCTION_TYPE_NOW: + // todo + break; default: ASSERT(0); // to found the fault ASAP. } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 610e5a0bb2..0dc2989f77 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -14,6 +14,7 @@ */ #include "builtinsimpl.h" +#include "tpercentile.h" #include "querynodes.h" #include "taggfunction.h" #include "tdatablock.h" @@ -453,6 +454,7 @@ bool getTopBotFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { } typedef struct SStddevRes { + double result; int64_t count; union {double quadraticDSum; int64_t quadraticISum;}; union {double dsum; int64_t isum;}; @@ -463,38 +465,129 @@ bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { return true; } +bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { + if (!functionSetup(pCtx, pResultInfo)) { + return false; + } + + SStddevRes* pRes = GET_ROWCELL_INTERBUF(pResultInfo); + memset(pRes, 0, sizeof(SStddevRes)); + return true; +} + void stddevFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; // Only the pre-computing information loaded and actual data does not loaded SInputColumnInfoData* pInput = &pCtx->input; - SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0]; - int32_t type = pInput->pData[0]->info.type; + SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0]; + int32_t type = pInput->pData[0]->info.type; SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); -// } else { // computing based on the true data block - SColumnInfoData* pCol = pInput->pData[0]; + // computing based on the true data block + SColumnInfoData* pCol = pInput->pData[0]; - int32_t start = pInput->startRowIndex; - int32_t numOfRows = pInput->numOfRows; + int32_t start = pInput->startRowIndex; + int32_t numOfRows = pInput->numOfRows; - switch(type) { - case TSDB_DATA_TYPE_INT: { - int32_t* plist = (int32_t*)pCol->pData; + switch (type) { + case TSDB_DATA_TYPE_TINYINT: { + int8_t* plist = (int8_t*)pCol->pData; for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { continue; } + numOfElem += 1; pStddevRes->count += 1; - pStddevRes->isum += plist[i]; + pStddevRes->isum += plist[i]; pStddevRes->quadraticISum += plist[i] * plist[i]; } + + break; + } + + case TSDB_DATA_TYPE_SMALLINT: { + int16_t* plist = (int16_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->isum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; } break; } + case TSDB_DATA_TYPE_INT: { + int32_t* plist = (int32_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->isum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + + break; + } + + case TSDB_DATA_TYPE_BIGINT: { + int64_t* plist = (int64_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->isum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + break; + } + + case TSDB_DATA_TYPE_FLOAT: { + float* plist = (float*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->isum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + break; + } + + case TSDB_DATA_TYPE_DOUBLE: { + double* plist = (double*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->isum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + break; + } + + default: + break; + } + // data in the check operation are all null, not output SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1); } @@ -503,11 +596,122 @@ void stddevFinalize(SqlFunctionCtx* pCtx) { functionFinalize(pCtx); SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - double res = pStddevRes->quadraticISum/pStddevRes->count - (pStddevRes->isum / pStddevRes->count) * (pStddevRes->isum / pStddevRes->count); + double avg = pStddevRes->isum / ((double) pStddevRes->count); + pStddevRes->result = sqrt(pStddevRes->quadraticISum/((double)pStddevRes->count) - avg*avg); } +typedef struct SPercentileInfo { + tMemBucket *pMemBucket; + int32_t stage; + double minval; + double maxval; + int64_t numOfElems; +} SPercentileInfo; +bool getPercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { + pEnv->calcMemSize = sizeof(SPercentileInfo); + return true; +} +bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { + if (!functionSetup(pCtx, pResultInfo)) { + return false; + } + + // in the first round, get the min-max value of all involved data + SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResultInfo); + SET_DOUBLE_VAL(&pInfo->minval, DBL_MAX); + SET_DOUBLE_VAL(&pInfo->maxval, -DBL_MAX); + pInfo->numOfElems = 0; + + return true; +} + +void percentileFunction(SqlFunctionCtx *pCtx) { + int32_t notNullElems = 0; +#if 0 + SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); + + if (pCtx->currentStage == REPEAT_SCAN && pInfo->stage == 0) { + pInfo->stage += 1; + + // all data are null, set it completed + if (pInfo->numOfElems == 0) { + pResInfo->complete = true; + return; + } else { + pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, pInfo->minval, pInfo->maxval); + } + } + + // the first stage, only acquire the min/max value + if (pInfo->stage == 0) { + if (pCtx->preAggVals.isSet) { + double tmin = 0.0, tmax = 0.0; + if (IS_SIGNED_NUMERIC_TYPE(pCtx->inputType)) { + tmin = (double)GET_INT64_VAL(&pCtx->preAggVals.statis.min); + tmax = (double)GET_INT64_VAL(&pCtx->preAggVals.statis.max); + } else if (IS_FLOAT_TYPE(pCtx->inputType)) { + tmin = GET_DOUBLE_VAL(&pCtx->preAggVals.statis.min); + tmax = GET_DOUBLE_VAL(&pCtx->preAggVals.statis.max); + } else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->inputType)) { + tmin = (double)GET_UINT64_VAL(&pCtx->preAggVals.statis.min); + tmax = (double)GET_UINT64_VAL(&pCtx->preAggVals.statis.max); + } else { + assert(true); + } + + if (GET_DOUBLE_VAL(&pInfo->minval) > tmin) { + SET_DOUBLE_VAL(&pInfo->minval, tmin); + } + + if (GET_DOUBLE_VAL(&pInfo->maxval) < tmax) { + SET_DOUBLE_VAL(&pInfo->maxval, tmax); + } + + pInfo->numOfElems += (pCtx->size - pCtx->preAggVals.statis.numOfNull); + } else { + for (int32_t i = 0; i < pCtx->size; ++i) { + char *data = GET_INPUT_DATA(pCtx, i); + if (pCtx->hasNull && isNull(data, pCtx->inputType)) { + continue; + } + + double v = 0; + GET_TYPED_DATA(v, double, pCtx->inputType, data); + + if (v < GET_DOUBLE_VAL(&pInfo->minval)) { + SET_DOUBLE_VAL(&pInfo->minval, v); + } + + if (v > GET_DOUBLE_VAL(&pInfo->maxval)) { + SET_DOUBLE_VAL(&pInfo->maxval, v); + } + + pInfo->numOfElems += 1; + } + } + + return; + } + + // the second stage, calculate the true percentile value + for (int32_t i = 0; i < pCtx->size; ++i) { + char *data = GET_INPUT_DATA(pCtx, i); + if (pCtx->hasNull && isNull(data, pCtx->inputType)) { + continue; + } + + notNullElems += 1; + tMemBucketPut(pInfo->pMemBucket, data, 1); + } + + SET_VAL(pCtx, notNullElems, 1); + pResInfo->hasResult = DATA_SET_FLAG; +#endif + +} bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { SColumnNode* pNode = nodesListGetNode(pFunc->pParameterList, 0); diff --git a/source/libs/function/src/taggfunction.c b/source/libs/function/src/taggfunction.c index af24906c9e..9174420ff4 100644 --- a/source/libs/function/src/taggfunction.c +++ b/source/libs/function/src/taggfunction.c @@ -176,26 +176,6 @@ typedef struct SResPair { double avg; } SResPair; -#define TSDB_BLOCK_DIST_STEP_ROWS 16 - -typedef struct STableBlockDist { - uint16_t rowSize; - uint16_t numOfFiles; - uint32_t numOfTables; - uint64_t totalSize; - uint64_t totalRows; - int32_t maxRows; - int32_t minRows; - int32_t firstSeekTimeUs; - uint32_t numOfRowsInMemTable; - uint32_t numOfSmallBlocks; - SArray *dataBlockInfos; -} STableBlockDist; - -typedef struct SFileBlockInfo { - int32_t numBlocksOfStep; -} SFileBlockInfo; - void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell) { pCell->initialized = false; } @@ -3984,7 +3964,7 @@ static void irate_function(SqlFunctionCtx *pCtx) { } } -static void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDist* pDist) { +static void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDistInfo* pDist) { SBufferReader br = tbufInitReader(data, len, false); pDist->numOfTables = tbufReadUint32(&br); @@ -4024,7 +4004,7 @@ static void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDi static void blockInfo_func(SqlFunctionCtx* pCtx) { SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - STableBlockDist* pDist = (STableBlockDist*) GET_ROWCELL_INTERBUF(pResInfo); + STableBlockDistInfo* pDist = (STableBlockDistInfo*) GET_ROWCELL_INTERBUF(pResInfo); int32_t len = *(int32_t*) pCtx->pInput; blockDistInfoFromBinary((char*)pCtx->pInput + sizeof(int32_t), len, pDist); @@ -4036,8 +4016,8 @@ static void blockInfo_func(SqlFunctionCtx* pCtx) { //pResInfo->hasResult = DATA_SET_FLAG; } -static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlockDist* pSrc) { - STableBlockDist* pDist = (STableBlockDist*) GET_ROWCELL_INTERBUF(pResInfo); +static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlockDistInfo* pSrc) { + STableBlockDistInfo* pDist = (STableBlockDistInfo*) GET_ROWCELL_INTERBUF(pResInfo); assert(pDist != NULL && pSrc != NULL); pDist->numOfTables += pSrc->numOfTables; @@ -4071,7 +4051,7 @@ static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlock } void block_func_merge(SqlFunctionCtx* pCtx) { - STableBlockDist info = {0}; + STableBlockDistInfo info = {0}; int32_t len = *(int32_t*) pCtx->pInput; blockDistInfoFromBinary(((char*)pCtx->pInput) + sizeof(int32_t), len, &info); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); @@ -4082,7 +4062,7 @@ void block_func_merge(SqlFunctionCtx* pCtx) { //pResInfo->hasResult = DATA_SET_FLAG; } -void getPercentiles(STableBlockDist *pTableBlockDist, int64_t totalBlocks, int32_t numOfPercents, +void getPercentiles(STableBlockDistInfo *pTableBlockDist, int64_t totalBlocks, int32_t numOfPercents, double* percents, int32_t* percentiles) { if (totalBlocks == 0) { for (int32_t i = 0; i < numOfPercents; ++i) { @@ -4117,7 +4097,7 @@ void getPercentiles(STableBlockDist *pTableBlockDist, int64_t totalBlocks, int32 } } -void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) { +void generateBlockDistResult(STableBlockDistInfo *pTableBlockDist, char* result) { if (pTableBlockDist == NULL) { return; } @@ -4178,7 +4158,7 @@ void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) { void blockinfo_func_finalizer(SqlFunctionCtx* pCtx) { SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - STableBlockDist* pDist = (STableBlockDist*) GET_ROWCELL_INTERBUF(pResInfo); + STableBlockDistInfo* pDist = (STableBlockDistInfo*) GET_ROWCELL_INTERBUF(pResInfo); pDist->rowSize = (uint16_t)pCtx->param[0].i; generateBlockDistResult(pDist, pCtx->pOutput); diff --git a/source/libs/index/inc/indexFstRegex.h b/source/libs/index/inc/indexFstRegex.h index 50b9cae7ff..8fb5455336 100644 --- a/source/libs/index/inc/indexFstRegex.h +++ b/source/libs/index/inc/indexFstRegex.h @@ -63,9 +63,10 @@ typedef struct { FstRegex *regexCreate(const char *str); -void regexSetup(FstRegex *regex, uint32_t size, const char *str); - -// uint32_t regexStart() +uint32_t regexAutomStart(FstRegex *regex); +bool regexAutomIsMatch(FstRegex *regex, uint32_t state); +bool regexAutomCanMatch(FstRegex *regex, uint32_t state, bool null); +bool regexAutomAccept(FstRegex *regex, uint32_t state, uint8_t byte, uint32_t *result); #ifdef __cplusplus } diff --git a/source/libs/index/inc/indexFstSparse.h b/source/libs/index/inc/indexFstSparse.h index 69b33c82d9..665fb2ba5c 100644 --- a/source/libs/index/inc/indexFstSparse.h +++ b/source/libs/index/inc/indexFstSparse.h @@ -23,9 +23,9 @@ extern "C" { #endif typedef struct FstSparseSet { - SArray *dense; - SArray *sparse; - int32_t size; + uint32_t *dense; + uint32_t *sparse; + int32_t size; } FstSparseSet; FstSparseSet *sparSetCreate(int32_t sz); diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index d3ca3a1acf..7d52abcd1b 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -27,7 +27,7 @@ #endif #define INDEX_NUM_OF_THREADS 4 -#define INDEX_QUEUE_SIZE 200 +#define INDEX_QUEUE_SIZE 200 void* indexQhandle = NULL; diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index ca26cf38e5..df3c0b6e7b 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -21,8 +21,8 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later -#define MEM_TERM_LIMIT 10 * 10000 -#define MEM_THRESHOLD 1024 * 1024 +#define MEM_TERM_LIMIT 10 * 10000 +#define MEM_THRESHOLD 1024 * 1024 #define MEM_ESTIMATE_RADIO 1.5 static void indexMemRef(MemTable* tbl); diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index 24bc7a93a2..bc3ecea7a5 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -642,6 +642,9 @@ static const char* fstNodeState(FstNode* node) { } void fstNodeDestroy(FstNode* node) { + if (node == NULL) { + return; + } fstSliceDestroy(&node->data); taosMemoryFree(node); } @@ -1247,11 +1250,13 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) { // autState = sws->aut->accept(preState, b); autState = automFuncs[aut->type].accept(aut, preState, b); taosArrayPush(sws->inp, &b); + StreamState s = {.node = node, .trans = res + 1, .out = {.null = false, .out = out}, .autState = preState}; + node = NULL; + taosArrayPush(sws->stack, &s); out += trn.out; node = fstGetNode(sws->fst, trn.addr); - fstNodeDestroy(node); } else { // This is a little tricky. We're in this case if the // given bound is not a prefix of any key in the FST. @@ -1272,6 +1277,9 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) { return true; } } + + fstNodeDestroy(node); + uint32_t sz = taosArrayGetSize(sws->stack); if (sz != 0) { StreamState* s = taosArrayGet(sws->stack, sz - 1); @@ -1349,7 +1357,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb for (uint32_t i = 0; i < isz; i++) { buf[i] = *(uint8_t*)taosArrayGet(sws->inp, i); } - FstSlice slice = fstSliceCreate(buf, taosArrayGetSize(sws->inp)); + FstSlice slice = fstSliceCreate(buf, isz); if (fstBoundWithDataExceededBy(sws->endAt, &slice)) { taosArrayDestroyEx(sws->stack, streamStateDestroy); sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); diff --git a/source/libs/index/src/indexFstCommon.c b/source/libs/index/src/indexFstCommon.c index e2544c7ac3..902e68ce09 100644 --- a/source/libs/index/src/indexFstCommon.c +++ b/source/libs/index/src/indexFstCommon.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 TAOS Data, Inc. +YAML:9:25: error: unknown key 'AlignConsecutiveMacros' * 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 diff --git a/source/libs/index/src/indexFstRegex.c b/source/libs/index/src/indexFstRegex.c index e89c94079e..33eeae802e 100644 --- a/source/libs/index/src/indexFstRegex.c +++ b/source/libs/index/src/indexFstRegex.c @@ -14,6 +14,7 @@ */ #include "indexFstRegex.h" +#include "indexFstDfa.h" #include "indexFstSparse.h" FstRegex *regexCreate(const char *str) { @@ -26,10 +27,35 @@ FstRegex *regexCreate(const char *str) { memcpy(orig, str, sz); regex->orig = orig; + + // construct insts based on str + SArray *insts = NULL; + + FstDfaBuilder *builder = dfaBuilderCreate(insts); + regex->dfa = dfaBuilderBuild(builder); return regex; } -void regexSetup(FstRegex *regex, uint32_t size, const char *str) { - // return - // return; +uint32_t regexAutomStart(FstRegex *regex) { + ///// no nothing + return 0; +} +bool regexAutomIsMatch(FstRegex *regex, uint32_t state) { + if (regex->dfa != NULL && dfaIsMatch(regex->dfa, state)) { + return true; + } else { + return false; + } +} + +bool regexAutomCanMatch(FstRegex *regex, uint32_t state, bool null) { + // make frame happy + return null; +} + +bool regexAutomAccept(FstRegex *regex, uint32_t state, uint8_t byte, uint32_t *result) { + if (regex->dfa == NULL) { + return false; + } + return dfaAccept(regex->dfa, state, byte, result); } diff --git a/source/libs/index/src/indexSparse.c b/source/libs/index/src/indexFstSparse.c similarity index 65% rename from source/libs/index/src/indexSparse.c rename to source/libs/index/src/indexFstSparse.c index 9d228e71ff..e8ab3be2fe 100644 --- a/source/libs/index/src/indexSparse.c +++ b/source/libs/index/src/indexFstSparse.c @@ -21,47 +21,44 @@ FstSparseSet *sparSetCreate(int32_t sz) { return NULL; } - ss->dense = taosArrayInit(sz, sizeof(uint32_t)); - ss->sparse = taosArrayInit(sz, sizeof(uint32_t)); - ss->size = sz; + ss->dense = (uint32_t *)taosMemoryCalloc(sz, sizeof(uint32_t)); + ss->sparse = (uint32_t *)taosMemoryCalloc(sz, sizeof(uint32_t)); + ss->size = 0; return ss; } void sparSetDestroy(FstSparseSet *ss) { if (ss == NULL) { return; } - taosArrayDestroy(ss->dense); - taosArrayDestroy(ss->sparse); + taosMemoryFree(ss->dense); + taosMemoryFree(ss->sparse); taosMemoryFree(ss); } -uint32_t sparSetLen(FstSparseSet *ss) { return ss == NULL ? 0 : ss->size; } +uint32_t sparSetLen(FstSparseSet *ss) { + // Get occupied size + return ss == NULL ? 0 : ss->size; +} uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip) { if (ss == NULL) { return 0; } uint32_t i = ss->size; - taosArraySet(ss->dense, i, &ip); - taosArraySet(ss->sparse, ip, &i); + ss->dense[i] = ip; + ss->sparse[ip] = i; ss->size += 1; return i; } uint32_t sparSetGet(FstSparseSet *ss, uint32_t i) { - if (i >= taosArrayGetSize(ss->dense)) { - return 0; - } - uint32_t *v = taosArrayGet(ss->dense, i); - return *v; + // check later + return ss->dense[i]; } bool sparSetContains(FstSparseSet *ss, uint32_t ip) { - if (ip >= taosArrayGetSize(ss->sparse)) { + uint32_t i = ss->sparse[ip]; + if (i < ss->size && ss->dense[i] == ip) { + return true; + } else { return false; } - uint32_t i = *(uint32_t *)taosArrayGet(ss->sparse, ip); - if (i >= taosArrayGetSize(ss->dense)) { - return false; - } - uint32_t v = *(uint32_t *)taosArrayGet(ss->dense, i); - return v == ip; } void sparSetClear(FstSparseSet *ss) { if (ss == NULL) { diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index eff53108cd..bfe1bb21bf 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -480,6 +480,15 @@ void checkFstCheckIteratorRange2() { assert(result.size() == 4); automCtxDestroy(ctx); } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "bb", GE, "ed", LT, result); + assert(result.size() == 3); + automCtxDestroy(ctx); + } { // range search std::vector result; @@ -510,6 +519,68 @@ void checkFstCheckIteratorRange2() { } delete m; } +void checkFstCheckIteratorRange3() { + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("ab", 1); + fw->Put("b", 2); + fw->Put("cdd", 3); + fw->Put("cde", 3); + fw->Put("ddd", 4); + fw->Put("ed", 5); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GE, "", (RangeType)10, result); + assert(result.size() == 5); + automCtxDestroy(ctx); + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "", (RangeType)20, "ab", LE, result); + assert(result.size() == 1); + automCtxDestroy(ctx); + // taosMemoryFree(ctx); + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "", (RangeType)30, "ab", LT, result); + assert(result.size() == 0); + automCtxDestroy(ctx); + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "ed", GT, "ed", (RangeType)40, result); + assert(result.size() == 0); + automCtxDestroy(ctx); + } + delete m; +} void fst_get(Fst* fst) { for (int i = 0; i < 10000; i++) { @@ -578,6 +649,7 @@ int main(int argc, char* argv[]) { checkFstCheckIteratorPrefix(); checkFstCheckIteratorRange1(); checkFstCheckIteratorRange2(); + checkFstCheckIteratorRange3(); // checkFstLongTerm(); // checkFstPrefixSearch(); diff --git a/source/libs/nodes/inc/nodesUtil.h b/source/libs/nodes/inc/nodesUtil.h index de00b6bca4..976044c16f 100644 --- a/source/libs/nodes/inc/nodesUtil.h +++ b/source/libs/nodes/inc/nodesUtil.h @@ -20,12 +20,16 @@ extern "C" { #endif -#define nodesFatal(param, ...) qFatal("NODES: " param, __VA_ARGS__) -#define nodesError(param, ...) qError("NODES: " param, __VA_ARGS__) -#define nodesWarn(param, ...) qWarn("NODES: " param, __VA_ARGS__) -#define nodesInfo(param, ...) qInfo("NODES: " param, __VA_ARGS__) -#define nodesDebug(param, ...) qDebug("NODES: " param, __VA_ARGS__) -#define nodesTrace(param, ...) qTrace("NODES: " param, __VA_ARGS__) +#define nodesFatal(...) qFatal("NODES: " __VA_ARGS__) +#define nodesError(...) qError("NODES: " __VA_ARGS__) +#define nodesWarn(...) qWarn("NODES: " __VA_ARGS__) +#define nodesInfo(...) qInfo("NODES: " __VA_ARGS__) +#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__) +#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__) + +#define NODES_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) +#define NODES_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) +#define NODES_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) #ifdef __cplusplus } diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index e728078a38..f8bc99b975 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -206,6 +206,12 @@ static SNode* orderByExprNodeCopy(const SOrderByExprNode* pSrc, SOrderByExprNode return (SNode*)pDst; } +static SNode* nodeListNodeCopy(const SNodeListNode* pSrc, SNodeListNode* pDst) { + COPY_ALL_SCALAR_FIELDS; + CLONE_NODE_LIST_FIELD(pNodeList); + return (SNode*)pDst; +} + static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) { COPY_SCALAR_FIELD(mode); CLONE_NODE_FIELD(pValues); @@ -360,6 +366,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { return orderByExprNodeCopy((const SOrderByExprNode*)pNode, (SOrderByExprNode*)pDst); case QUERY_NODE_LIMIT: break; + case QUERY_NODE_NODE_LIST: + return nodeListNodeCopy((const SNodeListNode*)pNode, (SNodeListNode*)pDst); case QUERY_NODE_FILL: return fillNodeCopy((const SFillNode*)pNode, (SFillNode*)pDst); case QUERY_NODE_DATABLOCK_DESC: diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 32040a2e3f..5337965164 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2015,6 +2015,31 @@ static int32_t jsonToNodeListNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkFillMode = "Mode"; +static const char* jkFillValues = "Values"; + +static int32_t fillNodeToJson(const void* pObj, SJson* pJson) { + const SFillNode* pNode = (const SFillNode*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkFillMode, pNode->mode); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkFillValues, nodeToJson, pNode->pValues); + } + + return code; +} + +static int32_t jsonToFillNode(const SJson* pJson, void* pObj) { + SFillNode* pNode = (SFillNode*)pObj; + + int32_t code = tjsonGetNumberValue(pJson, jkFillMode, pNode->mode); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkFillValues, &pNode->pValues); + } + + return code; +} + static const char* jkTargetDataBlockId = "DataBlockId"; static const char* jkTargetSlotId = "SlotId"; static const char* jkTargetExpr = "Expr"; @@ -2328,6 +2353,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { case QUERY_NODE_NODE_LIST: return nodeListNodeToJson(pObj, pJson); case QUERY_NODE_FILL: + return fillNodeToJson(pObj, pJson); case QUERY_NODE_RAW_EXPR: break; case QUERY_NODE_TARGET: @@ -2431,7 +2457,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToIntervalWindowNode(pJson, pObj); case QUERY_NODE_NODE_LIST: return jsonToNodeListNode(pJson, pObj); - // case QUERY_NODE_FILL: + case QUERY_NODE_FILL: + return jsonToFillNode(pJson, pObj); case QUERY_NODE_TARGET: return jsonToTargetNode(pJson, pObj); // case QUERY_NODE_RAW_EXPR: diff --git a/source/libs/nodes/src/nodesToSQLFuncs.c b/source/libs/nodes/src/nodesToSQLFuncs.c new file mode 100644 index 0000000000..68f38bb6a7 --- /dev/null +++ b/source/libs/nodes/src/nodesToSQLFuncs.c @@ -0,0 +1,145 @@ +/* + * 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 "cmdnodes.h" +#include "nodesUtil.h" +#include "plannodes.h" +#include "querynodes.h" +#include "taos.h" +#include "taoserror.h" +#include "thash.h" + +char *gOperatorStr[] = {NULL, "+", "-", "*", "/", "%", "&", "|", ">", ">=", "<", "<=", "=", "<>", + "IN", "NOT IN", "LIKE", "NOT LIKE", "MATCH", "NMATCH", "IS NULL", "IS NOT NULL", + "IS TRUE", "IS FALSE", "IS UNKNOWN", "IS NOT TRUE", "IS NOT FALSE", "IS NOT UNKNOWN"}; +char *gLogicConditionStr[] = {"AND", "OR", "NOT"}; + +int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { + switch (pNode->type) { + case QUERY_NODE_COLUMN: { + SColumnNode *colNode = (SColumnNode *)pNode; + if (colNode->dbName[0]) { + *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName); + } + + if (colNode->tableAlias[0]) { + *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias); + } else if (colNode->tableName[0]) { + *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName); + } + + *len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->colName); + + return TSDB_CODE_SUCCESS; + } + case QUERY_NODE_VALUE:{ + SValueNode *colNode = (SValueNode *)pNode; + char *t = nodesGetStrValueFromNode(colNode); + if (NULL == t) { + nodesError("fail to get str value from valueNode"); + NODES_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + *len += snprintf(buf + *len, bufSize - *len, "%s", t); + taosMemoryFree(t); + + return TSDB_CODE_SUCCESS; + } + case QUERY_NODE_OPERATOR: { + SOperatorNode* pOpNode = (SOperatorNode*)pNode; + *len += snprintf(buf + *len, bufSize - *len, "("); + if (pOpNode->pLeft) { + NODES_ERR_RET(nodesNodeToSQL(pOpNode->pLeft, buf, bufSize, len)); + } + + if (pOpNode->opType >= (sizeof(gOperatorStr) / sizeof(gOperatorStr[0]))) { + nodesError("unknown operation type:%d", pOpNode->opType); + NODES_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + *len += snprintf(buf + *len, bufSize - *len, " %s ", gOperatorStr[pOpNode->opType]); + + if (pOpNode->pRight) { + NODES_ERR_RET(nodesNodeToSQL(pOpNode->pRight, buf, bufSize, len)); + } + + *len += snprintf(buf + *len, bufSize - *len, ")"); + + return TSDB_CODE_SUCCESS; + } + case QUERY_NODE_LOGIC_CONDITION:{ + SLogicConditionNode* pLogicNode = (SLogicConditionNode*)pNode; + SNode* node = NULL; + bool first = true; + + *len += snprintf(buf + *len, bufSize - *len, "("); + + FOREACH(node, pLogicNode->pParameterList) { + if (!first) { + *len += snprintf(buf + *len, bufSize - *len, " %s ", gLogicConditionStr[pLogicNode->condType]); + } + NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len)); + first = false; + } + + *len += snprintf(buf + *len, bufSize - *len, ")"); + + return TSDB_CODE_SUCCESS; + } + case QUERY_NODE_FUNCTION:{ + SFunctionNode* pFuncNode = (SFunctionNode*)pNode; + SNode* node = NULL; + bool first = true; + + *len += snprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName); + + FOREACH(node, pFuncNode->pParameterList) { + if (!first) { + *len += snprintf(buf + *len, bufSize - *len, ", "); + } + NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len)); + first = false; + } + + *len += snprintf(buf + *len, bufSize - *len, ")"); + + return TSDB_CODE_SUCCESS; + } + case QUERY_NODE_NODE_LIST:{ + SNodeListNode* pListNode = (SNodeListNode *)pNode; + SNode* node = NULL; + bool first = true; + + *len += snprintf(buf + *len, bufSize - *len, "("); + + FOREACH(node, pListNode->pNodeList) { + if (!first) { + *len += snprintf(buf + *len, bufSize - *len, ", "); + } + NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len)); + first = false; + } + + *len += snprintf(buf + *len, bufSize - *len, ")"); + + return TSDB_CODE_SUCCESS; + } + default: + break; + } + + nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type)); + NODES_RET(TSDB_CODE_QRY_APP_ERROR); +} diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index 7eaa049946..bbd0473edd 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -17,7 +17,8 @@ typedef enum ETraversalOrder { TRAVERSAL_PREORDER = 1, - TRAVERSAL_POSTORDER + TRAVERSAL_INORDER, + TRAVERSAL_POSTORDER, } ETraversalOrder; static EDealRes walkList(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 89b4476899..90f06c6c9c 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -136,6 +136,10 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SDropTopicStmt)); case QUERY_NODE_EXPLAIN_STMT: return makeNode(type, sizeof(SExplainStmt)); + case QUERY_NODE_DESCRIBE_STMT: + return makeNode(type, sizeof(SDescribeStmt)); + case QUERY_NODE_RESET_QUERY_CACHE_STMT: + return makeNode(type, sizeof(SNode)); case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_TABLES_STMT: case QUERY_NODE_SHOW_STABLES_STMT: @@ -786,11 +790,94 @@ void* nodesGetValueFromNode(SValueNode *pNode) { return NULL; } +char* nodesGetStrValueFromNode(SValueNode *pNode) { + switch (pNode->node.resType.type) { + case TSDB_DATA_TYPE_BOOL: { + void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + if (NULL == buf) { + return NULL; + } + + sprintf(buf, "%s", pNode->datum.b ? "true" : "false"); + return buf; + } + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TIMESTAMP: { + void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + if (NULL == buf) { + return NULL; + } + + sprintf(buf, "%" PRId64, pNode->datum.i); + return buf; + } + case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_USMALLINT: + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_UBIGINT: { + void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + if (NULL == buf) { + return NULL; + } + + sprintf(buf, "%" PRIu64, pNode->datum.u); + return buf; + } + case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_DOUBLE: { + void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + if (NULL == buf) { + return NULL; + } + + sprintf(buf, "%e", pNode->datum.d); + return buf; + } + case TSDB_DATA_TYPE_NCHAR: + case TSDB_DATA_TYPE_VARCHAR: + case TSDB_DATA_TYPE_VARBINARY: { + int32_t bufSize = varDataLen(pNode->datum.p) + 2 + 1; + void *buf = taosMemoryMalloc(bufSize); + if (NULL == buf) { + return NULL; + } + + snprintf(buf, bufSize, "'%s'", varDataVal(pNode->datum.p)); + return buf; + } + default: + break; + } + + return NULL; +} + bool nodesIsExprNode(const SNode* pNode) { ENodeType type = nodeType(pNode); return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || QUERY_NODE_FUNCTION == type); } +bool nodesIsUnaryOp(const SOperatorNode* pOp) { + switch (pOp->opType) { + case OP_TYPE_MINUS: + case OP_TYPE_IS_NULL: + case OP_TYPE_IS_NOT_NULL: + case OP_TYPE_IS_TRUE: + case OP_TYPE_IS_FALSE: + case OP_TYPE_IS_UNKNOWN: + case OP_TYPE_IS_NOT_TRUE: + case OP_TYPE_IS_NOT_FALSE: + case OP_TYPE_IS_NOT_UNKNOWN: + return true; + default: + break; + } + return false; +} + bool nodesIsArithmeticOp(const SOperatorNode* pOp) { switch (pOp->opType) { case OP_TYPE_ADD: diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 029ae7e91f..1fce11acdf 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -71,6 +71,7 @@ typedef enum ETableOptionType { typedef struct SAlterOption { int32_t type; SToken val; + SNodeList* pKeep; } SAlterOption; extern SToken nil_token; @@ -121,6 +122,8 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt); SNode* createDefaultAlterDatabaseOptions(SAstCreateContext* pCxt); SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, const SToken* pVal); +SNode* setDatabaseKeepOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pKeep); +SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); @@ -129,6 +132,8 @@ SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt); SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, const SToken* pVal); SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pSma); SNode* setTableRollupOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pFuncs); +SNode* setTableKeepOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pKeep); +SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); SNode* createColumnDefNode(SAstCreateContext* pCxt, const SToken* pColName, SDataType dataType, const SToken* pComment); SDataType createDataType(uint8_t type); SDataType createVarLenDataType(uint8_t type, const SToken* pLen); @@ -145,6 +150,8 @@ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern); +SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName); +SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable); SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword); SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal); SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName); @@ -163,6 +170,18 @@ SNode* createDefaultExplainOptions(SAstCreateContext* pCxt); SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal); SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal); SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery); +SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable); +SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt); +SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups); +SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize); +SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName); +SNode* createCreateStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName, const SToken* pTableName, SNode* pQuery); +SNode* createDropStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName); +SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId); +SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2); +SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes); +SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId); +SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index a38d64c58c..ee17de50e0 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -77,10 +77,7 @@ typedef struct STableDataBlocks { STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache char *pData; bool cloned; - STagData tagData; - char tableName[TSDB_TABLE_NAME_LEN]; - char dbFName[TSDB_DB_FNAME_LEN]; - + int32_t createTbReqLen; SParsedDataColInfo boundColumnInfo; SRowBuilder rowBuilder; } STableDataBlocks; @@ -121,6 +118,7 @@ static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks* pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid); pBlocks->uid = dataBuf->pTableMeta->uid; pBlocks->sversion = dataBuf->pTableMeta->sversion; + pBlocks->schemaLen = dataBuf->createTbReqLen; if (pBlocks->numOfRows + numOfRows >= INT16_MAX) { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -139,7 +137,7 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash); int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo); int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t * numOfRows); int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList); -int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t payloadType, SArray** pVgDataBlocks); + const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq); +int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** pVgDataBlocks); #endif // TDENGINE_DATABLOCKMGT_H diff --git a/source/libs/parser/inc/parInt.h b/source/libs/parser/inc/parInt.h index af0d78717e..9bad3e9eb9 100644 --- a/source/libs/parser/inc/parInt.h +++ b/source/libs/parser/inc/parInt.h @@ -25,6 +25,7 @@ extern "C" { int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery); int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery); int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery); +int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 5e2f8e4241..4ae33e5c5c 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -137,7 +137,7 @@ db_options(A) ::= db_options(B) DAYS NK_INTEGER(C). db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FSYNC, &C); } db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MAXROWS, &C); } db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MINROWS, &C); } -db_options(A) ::= db_options(B) KEEP NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, &C); } +db_options(A) ::= db_options(B) KEEP integer_list(C). { A = setDatabaseKeepOption(pCxt, B, C); } db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PRECISION, &C); } db_options(A) ::= db_options(B) QUORUM NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_QUORUM, &C); } db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_REPLICA, &C); } @@ -148,17 +148,23 @@ db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAM_MODE, &C); } db_options(A) ::= db_options(B) RETENTIONS NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, &C); } -alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabaseOption(pCxt, A, B.type, &B.val); } -alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseOption(pCxt, B, C.type, &C.val); } +alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabaseAlterOption(pCxt, A, &B); } +alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseAlterOption(pCxt, B, &C); } %type alter_db_option { SAlterOption } %destructor alter_db_option { } alter_db_option(A) ::= BLOCKS NK_INTEGER(B). { A.type = DB_OPTION_BLOCKS; A.val = B; } alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.val = B; } -alter_db_option(A) ::= KEEP NK_INTEGER(B). { A.type = DB_OPTION_KEEP; A.val = B; } +alter_db_option(A) ::= KEEP integer_list(B). { A.type = DB_OPTION_KEEP; A.pKeep = B; } alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; } alter_db_option(A) ::= QUORUM NK_INTEGER(B). { A.type = DB_OPTION_QUORUM; A.val = B; } alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.val = B; } +alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.val = B; } + +%type integer_list { SNodeList* } +%destructor integer_list { nodesDestroyList($$); } +integer_list(A) ::= NK_INTEGER(B). { A = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); } +integer_list(A) ::= integer_list(B) NK_COMMA NK_INTEGER(C). { A = addNodeToList(pCxt, B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C)); } /************************************************ create/drop table/stable ********************************************/ cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B) @@ -259,20 +265,20 @@ tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. table_options(A) ::= . { A = createDefaultTableOptions(pCxt); } table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); } -table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &C); } +table_options(A) ::= table_options(B) KEEP integer_list(C). { A = setTableKeepOption(pCxt, B, C); } table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); } table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); } table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableRollupOption(pCxt, B, C); } table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { A = setTableOption(pCxt, B, TABLE_OPTION_FILE_FACTOR, &C); } table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_DELAY, &C); } -alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); } -alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableOption(pCxt, B, C.type, &C.val); } +alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTableAlterOption(pCxt, A, &B); } +alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableAlterOption(pCxt, B, &C); } %type alter_table_option { SAlterOption } %destructor alter_table_option { } alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.val = B; } -alter_table_option(A) ::= KEEP NK_INTEGER(B). { A.type = TABLE_OPTION_KEEP; A.val = B; } +alter_table_option(A) ::= KEEP integer_list(B). { A.type = TABLE_OPTION_KEEP; A.pKeep = B; } alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.val = B; } %type col_name_list { SNodeList* } @@ -295,6 +301,17 @@ cmd ::= SHOW QNODES. cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, A, B); } cmd ::= SHOW STREAMS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } +cmd ::= SHOW ACCOUNTS. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } +cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } +cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } +cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } +cmd ::= SHOW CREATE DATABASE db_name(A). { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &A); } +cmd ::= SHOW CREATE TABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, A); } +cmd ::= SHOW CREATE STABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, A); } +cmd ::= SHOW QUERIES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } +cmd ::= SHOW SCORES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } +cmd ::= SHOW TOPICS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } +cmd ::= SHOW VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } db_name_cond_opt(A) ::= . { A = createDefaultDatabaseCondValue(pCxt); } db_name_cond_opt(A) ::= db_name(B) NK_DOT. { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } @@ -339,7 +356,14 @@ cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C). cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C); } cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); } -/************************************************ select **************************************************************/ +/************************************************ desc/describe *******************************************************/ +cmd ::= DESC full_table_name(A). { pCxt->pRootNode = createDescribeStmt(pCxt, A); } +cmd ::= DESCRIBE full_table_name(A). { pCxt->pRootNode = createDescribeStmt(pCxt, A); } + +/************************************************ reset query cache ***************************************************/ +cmd ::= RESET QUERY CACHE. { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } + +/************************************************ explain *************************************************************/ cmd ::= EXPLAIN analyze_opt(A) explain_options(B) query_expression(C). { pCxt->pRootNode = createExplainStmt(pCxt, A, B, C); } %type analyze_opt { bool } @@ -351,6 +375,45 @@ explain_options(A) ::= . explain_options(A) ::= explain_options(B) VERBOSE NK_BOOL(C). { A = setExplainVerbose(pCxt, B, &C); } explain_options(A) ::= explain_options(B) RATIO NK_FLOAT(C). { A = setExplainRatio(pCxt, B, &C); } +/************************************************ compact *************************************************************/ +cmd ::= COMPACT VNODES IN NK_LP integer_list(A) NK_RP. { pCxt->pRootNode = createCompactStmt(pCxt, A); } + +/************************************************ create/drop function ************************************************/ +cmd ::= CREATE agg_func_opt(A) FUNCTION function_name(B) + AS NK_STRING(C) OUTPUTTYPE type_name(D) bufsize_opt(E). { pCxt->pRootNode = createCreateFunctionStmt(pCxt, A, &B, &C, D, E); } +cmd ::= DROP FUNCTION function_name(A). { pCxt->pRootNode = createDropFunctionStmt(pCxt, &A); } + +%type agg_func_opt { bool } +%destructor agg_func_opt { } +agg_func_opt(A) ::= . { A = false; } +agg_func_opt(A) ::= AGGREGATE. { A = true; } + +%type bufsize_opt { int32_t } +%destructor bufsize_opt { } +bufsize_opt(A) ::= . { A = 0; } +bufsize_opt(A) ::= BUFSIZE NK_INTEGER(B). { A = strtol(B.z, NULL, 10); } + +/************************************************ create/drop stream **************************************************/ +cmd ::= CREATE STREAM stream_name(A) INTO table_name(B) AS query_expression(C). { pCxt->pRootNode = createCreateStreamStmt(pCxt, &A, &B, C); } +cmd ::= DROP STREAM stream_name(A). { pCxt->pRootNode = createDropStreamStmt(pCxt, &A); } + +/************************************************ kill connection/query ***********************************************/ +cmd ::= KILL CONNECTION NK_INTEGER(A). { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &A); } +cmd ::= KILL QUERY NK_INTEGER(A). { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_QUERY_STMT, &A); } + +/************************************************ merge/redistribute/ vgroup ******************************************/ +cmd ::= MERGE VGROUP NK_INTEGER(A) NK_INTEGER(B). { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &A, &B); } +cmd ::= REDISTRIBUTE VGROUP NK_INTEGER(A) dnode_list(B). { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &A, B); } +cmd ::= SPLIT VGROUP NK_INTEGER(A). { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &A); } + +%type dnode_list { SNodeList* } +%destructor dnode_list { nodesDestroyList($$); } +dnode_list(A) ::= DNODE NK_INTEGER(B). { A = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); } +dnode_list(A) ::= dnode_list(B) DNODE NK_INTEGER(C). { A = addNodeToList(pCxt, B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C)); } + +/************************************************ syncdb **************************************************************/ +cmd ::= SYNCDB db_name(A) REPLICA. { pCxt->pRootNode = createSyncdbStmt(pCxt, &A); } + /************************************************ select **************************************************************/ cmd ::= query_expression(A). { pCxt->pRootNode = A; } @@ -429,6 +492,10 @@ index_name(A) ::= NK_ID(B). %destructor topic_name { } topic_name(A) ::= NK_ID(B). { A = B; } +%type stream_name { SToken } +%destructor stream_name { } +stream_name(A) ::= NK_ID(B). { A = B; } + /************************************************ expression **********************************************************/ expression(A) ::= literal(B). { A = B; } //expression(A) ::= NK_QUESTION(B). { A = B; } @@ -446,7 +513,7 @@ expression(A) ::= NK_PLUS(B) expression(C). } expression(A) ::= NK_MINUS(B) expression(C). { SToken t = getTokenFromRawExprNode(pCxt, C); - A = createRawExprNodeExt(pCxt, &B, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, C), NULL)); + A = createRawExprNodeExt(pCxt, &B, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, C), NULL)); } expression(A) ::= expression(B) NK_PLUS expression(C). { SToken s = getTokenFromRawExprNode(pCxt, B); @@ -482,38 +549,14 @@ expression_list(A) ::= expression_list(B) NK_COMMA expression(C). column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); } column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); } -//pseudo_column(A) ::= NK_NOW. { A = createFunctionNode(pCxt, NULL, NULL); } -pseudo_column(A) ::= NK_UNDERLINE(B) ROWTS(C). { - SToken t = B; - t.n = (C.z + C.n) - B.z; - A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); - } +pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } -pseudo_column(A) ::= NK_UNDERLINE(B) QSTARTTS(C). { - SToken t = B; - t.n = (C.z + C.n) - B.z; - A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); - } -pseudo_column(A) ::= NK_UNDERLINE(B) QENDTS(C). { - SToken t = B; - t.n = (C.z + C.n) - B.z; - A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); - } -pseudo_column(A) ::= NK_UNDERLINE(B) WSTARTTS(C). { - SToken t = B; - t.n = (C.z + C.n) - B.z; - A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); - } -pseudo_column(A) ::= NK_UNDERLINE(B) WENDTS(C). { - SToken t = B; - t.n = (C.z + C.n) - B.z; - A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); - } -pseudo_column(A) ::= NK_UNDERLINE(B) WDURATION(C). { - SToken t = B; - t.n = (C.z + C.n) - B.z; - A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); - } +pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= QENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= WSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= WENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= WDURATION(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } /************************************************ predicate ***********************************************************/ predicate(A) ::= expression(B) compare_op(C) expression(D). { diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 8783872ad8..18a0ae8cfa 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -138,18 +138,6 @@ static SDatabaseOptions* setDbMinRows(SAstCreateContext* pCxt, SDatabaseOptions* return pOptions; } -static SDatabaseOptions* setDbKeep(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { - int64_t val = strtol(pVal->z, NULL, 10); - if (val < TSDB_MIN_KEEP || val > TSDB_MAX_KEEP) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, - "invalid db option keep: %"PRId64" valid range: [%d, %d]", val, TSDB_MIN_KEEP, TSDB_MAX_KEEP); - pCxt->valid = false; - return pOptions; - } - pOptions->keep = val; - return pOptions; -} - static SDatabaseOptions* setDbPrecision(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { char val[10] = {0}; trimString(pVal->z, pVal->n, val, sizeof(val)); @@ -180,9 +168,9 @@ static SDatabaseOptions* setDbQuorum(SAstCreateContext* pCxt, SDatabaseOptions* static SDatabaseOptions* setDbReplica(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { int64_t val = strtol(pVal->z, NULL, 10); - if (val < TSDB_MIN_DB_REPLICA_OPTION || val > TSDB_MAX_DB_REPLICA_OPTION) { + if (!(val == TSDB_MIN_DB_REPLICA_OPTION || val == TSDB_MAX_DB_REPLICA_OPTION)) { snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, - "invalid db option replications: %"PRId64" valid range: [%d, %d]", val, TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION); + "invalid db option replications: %"PRId64", only 1, 3 allowed", val); pCxt->valid = false; return pOptions; } @@ -291,7 +279,6 @@ static void initSetDatabaseOptionFp() { setDbOptionFuncs[DB_OPTION_FSYNC] = setDbFsync; setDbOptionFuncs[DB_OPTION_MAXROWS] = setDbMaxRows; setDbOptionFuncs[DB_OPTION_MINROWS] = setDbMinRows; - setDbOptionFuncs[DB_OPTION_KEEP] = setDbKeep; setDbOptionFuncs[DB_OPTION_PRECISION] = setDbPrecision; setDbOptionFuncs[DB_OPTION_QUORUM] = setDbQuorum; setDbOptionFuncs[DB_OPTION_REPLICA] = setDbReplica; @@ -303,18 +290,6 @@ static void initSetDatabaseOptionFp() { setDbOptionFuncs[DB_OPTION_RETENTIONS] = setDbRetentions; } -static STableOptions* setTableKeep(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { - int64_t val = strtol(pVal->z, NULL, 10); - if (val < TSDB_MIN_KEEP || val > TSDB_MAX_KEEP) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, - "invalid table option keep: %"PRId64" valid range: [%d, %d]", val, TSDB_MIN_KEEP, TSDB_MAX_KEEP); - pCxt->valid = false; - return pOptions; - } - pOptions->keep = val; - return pOptions; -} - static STableOptions* setTableTtl(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { int64_t val = strtol(pVal->z, NULL, 10); if (val < TSDB_MIN_DB_TTL_OPTION) { @@ -363,7 +338,6 @@ static STableOptions* setTableDelay(SAstCreateContext* pCxt, STableOptions* pOpt } static void initSetTableOptionFp() { - setTableOptionFuncs[TABLE_OPTION_KEEP] = setTableKeep; setTableOptionFuncs[TABLE_OPTION_TTL] = setTableTtl; setTableOptionFuncs[TABLE_OPTION_COMMENT] = setTableComment; setTableOptionFuncs[TABLE_OPTION_FILE_FACTOR] = setTableFileFactor; @@ -397,7 +371,9 @@ static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) { pCxt->valid = false; } } - trimEscape(pUserName); + if (pCxt->valid) { + trimEscape(pUserName); + } return pCxt->valid; } @@ -472,42 +448,50 @@ static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool query) { if (NULL == pDbName) { - pCxt->valid = (query ? NULL != pCxt->pQueryCxt->db : true); + if (query && NULL == pCxt->pQueryCxt->db) { + generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DB_NOT_SPECIFIED); + pCxt->valid = false; + } } else { - pCxt->valid = pDbName->n < TSDB_DB_NAME_LEN ? true : false; + if (pDbName->n >= TSDB_DB_NAME_LEN) { + generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pDbName->z); + pCxt->valid = false; + } + } + if (pCxt->valid) { + trimEscape(pDbName); } - trimEscape(pDbName); return pCxt->valid; } static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) { - if (NULL == pTableName) { - pCxt->valid = true; - } else { - pCxt->valid = pTableName->n < TSDB_TABLE_NAME_LEN ? true : false; + if (NULL != pTableName && pTableName->n >= TSDB_TABLE_NAME_LEN) { + generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTableName->z); + pCxt->valid = false; + return false; } trimEscape(pTableName); - return pCxt->valid; + return true; } static bool checkColumnName(SAstCreateContext* pCxt, SToken* pColumnName) { - if (NULL == pColumnName) { - pCxt->valid = true; - } else { - pCxt->valid = pColumnName->n < TSDB_COL_NAME_LEN ? true : false; + if (NULL != pColumnName && pColumnName->n >= TSDB_COL_NAME_LEN) { + generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pColumnName->z); + pCxt->valid = false; + return false; } trimEscape(pColumnName); - return pCxt->valid; + return true; } static bool checkIndexName(SAstCreateContext* pCxt, SToken* pIndexName) { - if (NULL == pIndexName) { + if (NULL != pIndexName && pIndexName->n >= TSDB_INDEX_NAME_LEN) { + generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pIndexName->z); pCxt->valid = false; - } else { - pCxt->valid = pIndexName->n < TSDB_INDEX_NAME_LEN ? true : false; + return false; } trimEscape(pIndexName); - return pCxt->valid; + return true; } SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode) { @@ -882,7 +866,9 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) { pOptions->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; pOptions->maxRowsPerBlock = TSDB_DEFAULT_MAX_ROW_FBLOCK; pOptions->minRowsPerBlock = TSDB_DEFAULT_MIN_ROW_FBLOCK; - pOptions->keep = TSDB_DEFAULT_KEEP; + pOptions->keep0 = TSDB_DEFAULT_KEEP; + pOptions->keep1 = TSDB_DEFAULT_KEEP; + pOptions->keep2 = TSDB_DEFAULT_KEEP; pOptions->precision = TSDB_TIME_PRECISION_MILLI; pOptions->quorum = TSDB_DEFAULT_DB_QUORUM_OPTION; pOptions->replica = TSDB_DEFAULT_DB_REPLICA_OPTION; @@ -905,7 +891,9 @@ SNode* createDefaultAlterDatabaseOptions(SAstCreateContext* pCxt) { pOptions->fsyncPeriod = -1; pOptions->maxRowsPerBlock = -1; pOptions->minRowsPerBlock = -1; - pOptions->keep = -1; + pOptions->keep0 = -1; + pOptions->keep1 = -1; + pOptions->keep2= -1; pOptions->precision = -1; pOptions->quorum = -1; pOptions->replica = -1; @@ -921,6 +909,48 @@ SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOpti return (SNode*)setDbOptionFuncs[type](pCxt, (SDatabaseOptions*)pOptions, pVal); } +static bool checkAndSetKeepOption(SAstCreateContext* pCxt, SNodeList* pKeep, int32_t* pKeep0, int32_t* pKeep1, int32_t* pKeep2) { + int32_t numOfKeep = LIST_LENGTH(pKeep); + if (numOfKeep > 3 || numOfKeep < 1) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid number of keep options"); + return false; + } + + int32_t daysToKeep0 = strtol(((SValueNode*)nodesListGetNode(pKeep, 0))->literal, NULL, 10); + int32_t daysToKeep1 = numOfKeep > 1 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 1))->literal, NULL, 10) : daysToKeep0; + int32_t daysToKeep2 = numOfKeep > 2 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 2))->literal, NULL, 10) : daysToKeep1; + if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP || + daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, + "invalid option keep: %d, %d, %d valid range: [%d, %d]", daysToKeep0, daysToKeep1, daysToKeep2, TSDB_MIN_KEEP, TSDB_MAX_KEEP); + return false; + } + + if (!((daysToKeep0 <= daysToKeep1) && (daysToKeep1 <= daysToKeep2))) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid keep value, should be keep0 <= keep1 <= keep2"); + return false; + } + + *pKeep0 = daysToKeep0; + *pKeep1 = daysToKeep1; + *pKeep2 = daysToKeep2; + return true; +} + +SNode* setDatabaseKeepOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pKeep) { + SDatabaseOptions* pOp = (SDatabaseOptions*)pOptions; + pCxt->valid = checkAndSetKeepOption(pCxt, pKeep, &pOp->keep0, &pOp->keep1, &pOp->keep2); + return pOptions; +} + +SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { + if (DB_OPTION_KEEP == pAlterOption->type) { + return setDatabaseKeepOption(pCxt, pOptions, pAlterOption->pKeep); + } else { + return setDatabaseOption(pCxt, pOptions, pAlterOption->type, &pAlterOption->val); + } +} + SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions) { if (!checkDbName(pCxt, pDbName, false)) { return NULL; @@ -958,7 +988,9 @@ SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); CHECK_OUT_OF_MEM(pOptions); - pOptions->keep = TSDB_DEFAULT_KEEP; + pOptions->keep0 = TSDB_DEFAULT_KEEP; + pOptions->keep1 = TSDB_DEFAULT_KEEP; + pOptions->keep2 = TSDB_DEFAULT_KEEP; pOptions->ttl = TSDB_DEFAULT_DB_TTL_OPTION; pOptions->filesFactor = TSDB_DEFAULT_DB_FILE_FACTOR; pOptions->delay = TSDB_DEFAULT_DB_DELAY; @@ -968,7 +1000,9 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt) { STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); CHECK_OUT_OF_MEM(pOptions); - pOptions->keep = -1; + pOptions->keep0 = -1; + pOptions->keep1 = -1; + pOptions->keep2 = -1; pOptions->ttl = -1; pOptions->filesFactor = -1; pOptions->delay = -1; @@ -994,6 +1028,20 @@ SNode* setTableRollupOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* return pOptions; } +SNode* setTableKeepOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pKeep) { + STableOptions* pOp = (STableOptions*)pOptions; + pCxt->valid = checkAndSetKeepOption(pCxt, pKeep, &pOp->keep0, &pOp->keep1, &pOp->keep2); + return pOptions; +} + +SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { + if (TABLE_OPTION_KEEP == pAlterOption->type) { + return setTableKeepOption(pCxt, pOptions, pAlterOption->pKeep); + } else { + return setTableOption(pCxt, pOptions, pAlterOption->type, &pAlterOption->val); + } +} + SNode* createColumnDefNode(SAstCreateContext* pCxt, const SToken* pColName, SDataType dataType, const SToken* pComment) { SColumnDefNode* pCol = (SColumnDefNode*)nodesMakeNode(QUERY_NODE_COLUMN_DEF); CHECK_OUT_OF_MEM(pCol); @@ -1017,6 +1065,9 @@ SDataType createVarLenDataType(uint8_t type, const SToken* pLen) { SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions) { + if (NULL == pRealTable) { + return NULL; + } SCreateTableStmt* pStmt = (SCreateTableStmt*)nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT); CHECK_OUT_OF_MEM(pStmt); strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); @@ -1031,6 +1082,9 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags) { + if (NULL == pRealTable) { + return NULL; + } SCreateSubTableClause* pStmt = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE); CHECK_OUT_OF_MEM(pStmt); strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); @@ -1053,6 +1107,9 @@ SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables } SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) { + if (NULL == pRealTable) { + return NULL; + } SDropTableClause* pStmt = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE); CHECK_OUT_OF_MEM(pStmt); strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); @@ -1080,6 +1137,9 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S } SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) { + if (NULL == pRealTable) { + return NULL; + } SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_OPTIONS; @@ -1088,6 +1148,9 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* } SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType) { + if (NULL == pRealTable) { + return NULL; + } SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->alterType = alterType; @@ -1097,6 +1160,9 @@ SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, } SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName) { + if (NULL == pRealTable) { + return NULL; + } SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->alterType = alterType; @@ -1105,6 +1171,9 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_ } SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName) { + if (NULL == pRealTable) { + return NULL; + } SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->alterType = alterType; @@ -1114,6 +1183,9 @@ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int } SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal) { + if (NULL == pRealTable) { + return NULL; + } SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL; @@ -1149,6 +1221,18 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S return (SNode*)pStmt; } +SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_SHOW_CREATE_DATABASE_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) { + SNode* pStmt = nodesMakeNode(type); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword) { char password[TSDB_USET_PASSWORD_LEN] = {0}; if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) { @@ -1343,3 +1427,81 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, pStmt->pQuery = pQuery; return (SNode*)pStmt; } + +SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable) { + if (NULL == pRealTable) { + return NULL; + } + SDescribeStmt* pStmt = nodesMakeNode(QUERY_NODE_DESCRIBE_STMT); + CHECK_OUT_OF_MEM(pStmt); + strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); + strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); + nodesDestroyNode(pRealTable); + return (SNode*)pStmt; +} + +SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_RESET_QUERY_CACHE_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_COMPACT_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_CREATE_FUNCTION_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_DROP_FUNCTION_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createCreateStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName, const SToken* pTableName, SNode* pQuery) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createDropStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_DROP_STREAM_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId) { + SNode* pStmt = nodesMakeNode(type); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_MERGE_VGROUP_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_REDISTRIBUTE_VGROUP_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_SPLIT_VGROUP_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} + +SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName) { + SNode* pStmt = nodesMakeNode(QUERY_NODE_SYNCDB_STMT); + CHECK_OUT_OF_MEM(pStmt); + return pStmt; +} diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index ed67de17e0..d9cf0b39b5 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -52,20 +52,20 @@ typedef struct SInsertParseContext { SParseContext* pComCxt; // input char *pSql; // input SMsgBuf msg; // input - char dbFName[TSDB_DB_FNAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; STableMeta* pTableMeta; // each table SParsedDataColInfo tags; // each table SKVRowBuilder tagsBuilder; // each table + SVCreateTbReq createTblReq; // each table SHashObj* pVgroupsHashObj; // global SHashObj* pTableBlockHashObj; // global + SHashObj* pSubTableHashObj; // global SArray* pTableDataBlocks; // global SArray* pVgDataBlocks; // global int32_t totalNum; SVnodeModifOpStmt* pOutput; } SInsertParseContext; -typedef int32_t (*_row_append_fn_t)(const void *value, int32_t len, void *param); +typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void *value, int32_t len, void *param); static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; @@ -231,9 +231,6 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { SVgroupInfo vg; CHECK_CODE(catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg)); CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); - pCxt->pTableMeta->vgId = vg.vgId; // todo remove - strcpy(pCxt->tableName, name.tname); - tNameGetFullDbName(&name, pCxt->dbFName); return TSDB_CODE_SUCCESS; } @@ -444,26 +441,26 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int if (isNullStr(pToken)) { if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { int64_t tmpVal = 0; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } - return func(NULL, 0, param); + return func(pMsgBuf, NULL, 0, param); } switch (pSchema->type) { case TSDB_DATA_TYPE_BOOL: { if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) { if (strncmp(pToken->z, "true", pToken->n) == 0) { - return func(&TRUE_VALUE, pSchema->bytes, param); + return func(pMsgBuf, &TRUE_VALUE, pSchema->bytes, param); } else if (strncmp(pToken->z, "false", pToken->n) == 0) { - return func(&FALSE_VALUE, pSchema->bytes, param); + return func(pMsgBuf, &FALSE_VALUE, pSchema->bytes, param); } else { return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); } } else if (pToken->type == TK_NK_INTEGER) { - return func(((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); + return func(pMsgBuf, ((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); } else if (pToken->type == TK_NK_FLOAT) { - return func(((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); + return func(pMsgBuf, ((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); } else { return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); } @@ -477,7 +474,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } uint8_t tmpVal = (uint8_t)iv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_UTINYINT:{ @@ -487,7 +484,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "unsigned tinyint data overflow", pToken->z); } uint8_t tmpVal = (uint8_t)iv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_SMALLINT: { @@ -497,7 +494,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "smallint data overflow", pToken->z); } int16_t tmpVal = (int16_t)iv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_USMALLINT: { @@ -507,7 +504,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "unsigned smallint data overflow", pToken->z); } uint16_t tmpVal = (uint16_t)iv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_INT: { @@ -517,7 +514,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "int data overflow", pToken->z); } int32_t tmpVal = (int32_t)iv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_UINT: { @@ -527,7 +524,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "unsigned int data overflow", pToken->z); } uint32_t tmpVal = (uint32_t)iv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_BIGINT: { @@ -536,7 +533,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } else if (!IS_VALID_BIGINT(iv)) { return buildSyntaxErrMsg(pMsgBuf, "bigint data overflow", pToken->z); } - return func(&iv, pSchema->bytes, param); + return func(pMsgBuf, &iv, pSchema->bytes, param); } case TSDB_DATA_TYPE_UBIGINT: { @@ -546,7 +543,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "unsigned bigint data overflow", pToken->z); } uint64_t tmpVal = (uint64_t)iv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_FLOAT: { @@ -558,7 +555,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "illegal float data", pToken->z); } float tmpVal = (float)dv; - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_DOUBLE: { @@ -569,7 +566,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) { return buildSyntaxErrMsg(pMsgBuf, "illegal double data", pToken->z); } - return func(&dv, pSchema->bytes, param); + return func(pMsgBuf, &dv, pSchema->bytes, param); } case TSDB_DATA_TYPE_BINARY: { @@ -578,11 +575,11 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "string data overflow", pToken->z); } - return func(pToken->z, pToken->n, param); + return func(pMsgBuf, pToken->z, pToken->n, param); } case TSDB_DATA_TYPE_NCHAR: { - return func(pToken->z, pToken->n, param); + return func(pMsgBuf, pToken->z, pToken->n, param); } case TSDB_DATA_TYPE_TIMESTAMP: { @@ -591,7 +588,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp", pToken->z); } - return func(&tmpVal, pSchema->bytes, param); + return func(pMsgBuf, &tmpVal, pSchema->bytes, param); } } @@ -605,7 +602,7 @@ typedef struct SMemParam { col_id_t colIdx; } SMemParam; -static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* param) { +static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) { SMemParam* pa = (SMemParam*)param; SRowBuilder* rb = pa->rb; if (TSDB_DATA_TYPE_BINARY == pa->schema->type) { @@ -617,7 +614,9 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p int32_t output = 0; const char* rowEnd = tdRowEnd(rb->pBuf); if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(rowEnd), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) { - return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; + char buf[512] = {0}; + snprintf(buf, tListLen(buf), "%s", strerror(errno)); + return buildSyntaxErrMsg(pMsgBuf, buf, value); } varDataSetLen(rowEnd, output); tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx); @@ -714,7 +713,7 @@ typedef struct SKvParam { char buf[TSDB_MAX_TAGS_LEN]; } SKvParam; -static int32_t KvRowAppend(const void *value, int32_t len, void *param) { +static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, void *param) { SKvParam* pa = (SKvParam*) param; int8_t type = pa->schema->type; @@ -727,7 +726,9 @@ static int32_t KvRowAppend(const void *value, int32_t len, void *param) { // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' int32_t output = 0; if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(pa->buf), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) { - return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; + char buf[512] = {0}; + snprintf(buf, tListLen(buf), "%s", strerror(errno)); + return buildSyntaxErrMsg(pMsgBuf, buf, value);; } varDataSetLen(pa->buf, output); @@ -739,8 +740,20 @@ static int32_t KvRowAppend(const void *value, int32_t len, void *param) { return TSDB_CODE_SUCCESS; } +static int32_t buildCreateTbReq(SInsertParseContext* pCxt, const SName* pName, SKVRow row) { + char dbFName[TSDB_DB_FNAME_LEN] = {0}; + tNameGetFullDbName(pName, dbFName); + pCxt->createTblReq.type = TD_CHILD_TABLE; + pCxt->createTblReq.dbFName = strdup(dbFName); + pCxt->createTblReq.name = strdup(pName->tname); + pCxt->createTblReq.ctbCfg.suid = pCxt->pTableMeta->suid; + pCxt->createTblReq.ctbCfg.pTag = row; + + return TSDB_CODE_SUCCESS; +} + // pSql -> tag1_value, ...) -static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema, uint8_t precision) { +static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint8_t precision, const SName* pName) { if (tdInitKVRowBuilder(&pCxt->tagsBuilder) < 0) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -750,9 +763,9 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema, char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" for (int i = 0; i < pCxt->tags.numOfBound; ++i) { NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); - SSchema* pSchema = &pTagsSchema[pCxt->tags.boundColumns[i]]; - param.schema = pSchema; - CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, precision, tmpTokenBuf, KvRowAppend, ¶m, &pCxt->msg)); + SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i] - 1]; // colId starts with 1 + param.schema = pTagSchema; + CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pTagSchema, precision, tmpTokenBuf, KvRowAppend, ¶m, &pCxt->msg)); } SKVRow row = tdGetKVRowFromBuilder(&pCxt->tagsBuilder); @@ -761,23 +774,47 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema, } tdSortKVRowByColIdx(row); - // todo construct payload + return buildCreateTbReq(pCxt, pName, row); +} - taosMemoryFreeClear(row); +static int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) { + *pDst = taosMemoryMalloc(TABLE_META_SIZE(pSrc)); + if (NULL == *pDst) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + memcpy(*pDst, pSrc, TABLE_META_SIZE(pSrc)); + return TSDB_CODE_SUCCESS; +} - return 0; +static int32_t storeTableMeta(SHashObj* pHash, const char* pName, int32_t len, STableMeta* pMeta) { + STableMeta* pBackup = NULL; + if (TSDB_CODE_SUCCESS != cloneTableMeta(pMeta, &pBackup)) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + pBackup->uid = tGenIdPI64(); + return taosHashPut(pHash, pName, len, &pBackup, POINTER_BYTES); } // pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken) { - SToken sToken; + SName name; + createSName(&name, pTbnameToken, pCxt->pComCxt, &pCxt->msg); + char tbFName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(&name, tbFName); + int32_t len = strlen(tbFName); + STableMeta** pMeta = taosHashGet(pCxt->pSubTableHashObj, tbFName, len); + if (NULL != pMeta) { + return cloneTableMeta(*pMeta, &pCxt->pTableMeta); + } + SToken sToken; // pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) NEXT_TOKEN(pCxt->pSql, sToken); CHECK_CODE(getTableMeta(pCxt, &sToken)); if (TSDB_SUPER_TABLE != pCxt->pTableMeta->tableType) { return buildInvalidOperationMsg(&pCxt->msg, "create table only from super table is allowed"); } + CHECK_CODE(storeTableMeta(pCxt->pSubTableHashObj, tbFName, len, pCxt->pTableMeta)); SSchema* pTagsSchema = getTableTagSchema(pCxt->pTableMeta); setBoundColumnInfo(&pCxt->tags, pTagsSchema, getNumOfTags(pCxt->pTableMeta)); @@ -797,7 +834,11 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken) if (TK_NK_LP != sToken.type) { return buildSyntaxErrMsg(&pCxt->msg, "( is expected", sToken.z); } - CHECK_CODE(parseTagsClause(pCxt, pTagsSchema, getTableInfo(pCxt->pTableMeta).precision)); + CHECK_CODE(parseTagsClause(pCxt, pCxt->pTableMeta->schema, getTableInfo(pCxt->pTableMeta).precision, &name)); + NEXT_TOKEN(pCxt->pSql, sToken); + if (TK_NK_RP != sToken.type) { + return buildSyntaxErrMsg(&pCxt->msg, ") is expected", sToken.z); + } return TSDB_CODE_SUCCESS; } @@ -905,10 +946,17 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* da return TSDB_CODE_SUCCESS; } +static void destroyCreateSubTbReq(SVCreateTbReq* pReq) { + taosMemoryFreeClear(pReq->dbFName); + taosMemoryFreeClear(pReq->name); + taosMemoryFreeClear(pReq->ctbCfg.pTag); +} + static void destroyInsertParseContextForTable(SInsertParseContext* pCxt) { taosMemoryFreeClear(pCxt->pTableMeta); destroyBoundColumnInfo(&pCxt->tags); tdDestroyKVRowBuilder(&pCxt->tagsBuilder); + destroyCreateSubTbReq(&pCxt->createTblReq); } static void destroyDataBlock(STableDataBlocks* pDataBlock) { @@ -972,10 +1020,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { STableDataBlocks *dataBuf = NULL; CHECK_CODE(getDataBlockFromList(pCxt->pTableBlockHashObj, pCxt->pTableMeta->uid, TSDB_DEFAULT_PAYLOAD_SIZE, - sizeof(SSubmitBlk), getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta, &dataBuf, NULL)); - strcpy(dataBuf->tableName, pCxt->tableName); - strcpy(dataBuf->dbFName, pCxt->dbFName); - + sizeof(SSubmitBlk), getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta, &dataBuf, NULL, &pCxt->createTblReq)); + if (TK_NK_LP == sToken.type) { // pSql -> field1_name, ...) CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta))); @@ -1005,7 +1051,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { } // merge according to vgId if (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { - CHECK_CODE(mergeTableDataBlocks(pCxt->pTableBlockHashObj, pCxt->pOutput->schemaAttache, pCxt->pOutput->payloadType, &pCxt->pVgDataBlocks)); + CHECK_CODE(mergeTableDataBlocks(pCxt->pTableBlockHashObj, pCxt->pOutput->payloadType, &pCxt->pVgDataBlocks)); } return buildOutput(pCxt); } @@ -1024,11 +1070,13 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { .pTableMeta = NULL, .pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false), .pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false), + .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false), .totalNum = 0, .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT) }; - if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pOutput) { + if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || + NULL == context.pSubTableHashObj || NULL == context.pOutput) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index f70e514b5a..088b25d544 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -149,8 +149,28 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star return TSDB_CODE_SUCCESS; } +static int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) { + int32_t len = tSerializeSVCreateTbReq(NULL, pCreateTbReq); + if (pBlocks->nAllocSize - pBlocks->size < len) { + pBlocks->nAllocSize += len + pBlocks->rowSize; + char* pTmp = taosMemoryRealloc(pBlocks->pData, pBlocks->nAllocSize); + if (pTmp != NULL) { + pBlocks->pData = pTmp; + memset(pBlocks->pData + pBlocks->size, 0, pBlocks->nAllocSize - pBlocks->size); + } else { + pBlocks->nAllocSize -= len + pBlocks->rowSize; + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + } + char* pBuf = pBlocks->pData + pBlocks->size; + tSerializeSVCreateTbReq((void**)&pBuf, pCreateTbReq); + pBlocks->size += len; + pBlocks->createTbReqLen = len; + return TSDB_CODE_SUCCESS; +} + int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList) { + const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq) { *dataBlocks = NULL; STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id)); if (t1 != NULL) { @@ -163,6 +183,13 @@ int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int3 return ret; } + if (NULL != pCreateTbReq && NULL != pCreateTbReq->ctbCfg.pTag) { + ret = buildCreateTbMsg(*dataBlocks, pCreateTbReq); + if (ret != TSDB_CODE_SUCCESS) { + return ret; + } + } + taosHashPut(pHashList, (const char*)&id, sizeof(int64_t), (char*)dataBlocks, POINTER_BYTES); if (pBlockList) { taosArrayPush(pBlockList, dataBlocks); @@ -294,7 +321,7 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey int32_t extendedRowSize = getExtendedRowSize(dataBuf); SBlockKeyTuple *pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; - char * pBlockData = pBlocks->data; + char * pBlockData = pBlocks->data + pBlocks->schemaLen; int n = 0; while (n < nRows) { pBlkKeyTuple->skey = TD_ROW_KEY((STSRow *)pBlockData); @@ -340,44 +367,26 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey } // Erase the empty space reserved for binary data -static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, int8_t schemaAttached, bool isRawPayload) { +static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, bool isRawPayload) { // TODO: optimize this function, handle the case while binary is not presented STableMeta* pTableMeta = pTableDataBlock->pTableMeta; STableComInfo tinfo = getTableInfo(pTableMeta); SSchema* pSchema = getTableColumnSchema(pTableMeta); + int32_t nonDataLen = sizeof(SSubmitBlk) + pTableDataBlock->createTbReqLen; SSubmitBlk* pBlock = pDataBlock; - memcpy(pDataBlock, pTableDataBlock->pData, sizeof(SSubmitBlk)); - pDataBlock = (char*)pDataBlock + sizeof(SSubmitBlk); + memcpy(pDataBlock, pTableDataBlock->pData, nonDataLen); + pDataBlock = (char*)pDataBlock + nonDataLen; int32_t flen = 0; // original total length of row - - // schema needs to be included into the submit data block - if (schemaAttached) { - int32_t numOfCols = getNumOfColumns(pTableDataBlock->pTableMeta); - for(int32_t j = 0; j < numOfCols; ++j) { - STColumn* pCol = (STColumn*) pDataBlock; - pCol->colId = htons(pSchema[j].colId); - pCol->type = pSchema[j].type; - pCol->bytes = htons(pSchema[j].bytes); - pCol->offset = 0; - - pDataBlock = (char*)pDataBlock + sizeof(STColumn); + if (isRawPayload) { + for (int32_t j = 0; j < tinfo.numOfColumns; ++j) { flen += TYPE_BYTES[pSchema[j].type]; } - - int32_t schemaSize = sizeof(STColumn) * numOfCols; - pBlock->schemaLen = schemaSize; - } else { - if (isRawPayload) { - for (int32_t j = 0; j < tinfo.numOfColumns; ++j) { - flen += TYPE_BYTES[pSchema[j].type]; - } - } - pBlock->schemaLen = 0; } + pBlock->schemaLen = pTableDataBlock->createTbReqLen; - char* p = pTableDataBlock->pData + sizeof(SSubmitBlk); + char* p = pTableDataBlock->pData + nonDataLen; pBlock->dataLen = 0; int32_t numOfRows = pBlock->numOfRows; @@ -414,7 +423,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB return pBlock->dataLen + pBlock->schemaLen; } -int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t payloadType, SArray** pVgDataBlocks) { +int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** pVgDataBlocks) { const int INSERT_HEAD_SIZE = sizeof(SSubmitReq); int code = 0; bool isRawPayload = IS_RAW_PAYLOAD(payloadType); @@ -429,7 +438,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t if (pBlocks->numOfRows > 0) { STableDataBlocks* dataBuf = NULL; int32_t ret = getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE, - INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList); + INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL); if (ret != TSDB_CODE_SUCCESS) { taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); @@ -474,7 +483,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta); // erase the empty space reserved for binary data - int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, schemaAttached, isRawPayload); + int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload); assert(finalLen <= len); dataBuf->size += (finalLen + sizeof(SSubmitBlk)); diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 213b14ae5d..21191563e1 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -29,10 +29,14 @@ typedef struct SKeyword { // keywords in sql string static SKeyword keywordTable[] = { {"ACCOUNT", TK_ACCOUNT}, + {"ACCOUNTS", TK_ACCOUNTS}, + {"ADD", TK_ADD}, + {"AGGREGATE", TK_AGGREGATE}, {"ALL", TK_ALL}, {"ALTER", TK_ALTER}, {"ANALYZE", TK_ANALYZE}, {"AND", TK_AND}, + {"APPS", TK_APPS}, {"AS", TK_AS}, {"ASC", TK_ASC}, {"BETWEEN", TK_BETWEEN}, @@ -40,17 +44,25 @@ static SKeyword keywordTable[] = { {"BIGINT", TK_BIGINT}, {"BLOCKS", TK_BLOCKS}, {"BOOL", TK_BOOL}, + {"BUFSIZE", TK_BUFSIZE}, {"BY", TK_BY}, {"CACHE", TK_CACHE}, {"CACHELAST", TK_CACHELAST}, + {"COLUMN", TK_COLUMN}, {"COMMENT", TK_COMMENT}, {"COMP", TK_COMP}, + {"COMPACT", TK_COMPACT}, + {"CONNS", TK_CONNS}, + {"CONNECTION", TK_CONNECTION}, + {"CONNECTIONS", TK_CONNECTIONS}, {"CREATE", TK_CREATE}, {"DATABASE", TK_DATABASE}, {"DATABASES", TK_DATABASES}, {"DAYS", TK_DAYS}, + {"DBS", TK_DBS}, {"DELAY", TK_DELAY}, {"DESC", TK_DESC}, + {"DESCRIBE", TK_DESCRIBE}, {"DISTINCT", TK_DISTINCT}, {"DNODE", TK_DNODE}, {"DNODES", TK_DNODES}, @@ -82,14 +94,18 @@ static SKeyword keywordTable[] = { {"JOIN", TK_JOIN}, {"JSON", TK_JSON}, {"KEEP", TK_KEEP}, + {"KILL", TK_KILL}, + {"LICENCE", TK_LICENCE}, {"LIKE", TK_LIKE}, {"LIMIT", TK_LIMIT}, {"LINEAR", TK_LINEAR}, + {"LOCAL", TK_LOCAL}, {"MATCH", TK_MATCH}, {"MAXROWS", TK_MAXROWS}, {"MINROWS", TK_MINROWS}, {"MINUS", TK_MINUS}, {"MNODES", TK_MNODES}, + {"MODIFY", TK_MODIFY}, {"MODULES", TK_MODULES}, {"NCHAR", TK_NCHAR}, {"NMATCH", TK_NMATCH}, @@ -101,24 +117,32 @@ static SKeyword keywordTable[] = { {"ON", TK_ON}, {"OR", TK_OR}, {"ORDER", TK_ORDER}, + {"OUTPUTTYPE", TK_OUTPUTTYPE}, {"PARTITION", TK_PARTITION}, {"PASS", TK_PASS}, {"PORT", TK_PORT}, + {"PPS", TK_PPS}, {"PRECISION", TK_PRECISION}, {"PRIVILEGE", TK_PRIVILEGE}, {"PREV", TK_PREV}, - {"QENDTS", TK_QENDTS}, + {"_QENDTS", TK_QENDTS}, {"QNODE", TK_QNODE}, {"QNODES", TK_QNODES}, - {"QSTARTTS", TK_QSTARTTS}, + {"_QSTARTTS", TK_QSTARTTS}, + {"QTIME", TK_QTIME}, + {"QUERIES", TK_QUERIES}, + {"QUERY", TK_QUERY}, {"QUORUM", TK_QUORUM}, {"RATIO", TK_RATIO}, {"REPLICA", TK_REPLICA}, + {"RESET", TK_RESET}, {"RETENTIONS", TK_RETENTIONS}, {"ROLLUP", TK_ROLLUP}, - {"ROWTS", TK_ROWTS}, + {"_ROWTS", TK_ROWTS}, + {"SCORES", TK_SCORES}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, + {"SET", TK_SET}, {"SHOW", TK_SHOW}, {"SINGLE_STABLE", TK_SINGLE_STABLE}, {"SLIDING", TK_SLIDING}, @@ -128,16 +152,23 @@ static SKeyword keywordTable[] = { {"SOFFSET", TK_SOFFSET}, {"STABLE", TK_STABLE}, {"STABLES", TK_STABLES}, + {"STATE", TK_STATE}, {"STATE_WINDOW", TK_STATE_WINDOW}, + {"STORAGE", TK_STORAGE}, + {"STREAM", TK_STREAM}, {"STREAMS", TK_STREAMS}, {"STREAM_MODE", TK_STREAM_MODE}, + {"SYNCDB", TK_SYNCDB}, {"TABLE", TK_TABLE}, {"TABLES", TK_TABLES}, + {"TAG", TK_TAG}, {"TAGS", TK_TAGS}, {"TBNAME", TK_TBNAME}, {"TIMESTAMP", TK_TIMESTAMP}, {"TINYINT", TK_TINYINT}, {"TOPIC", TK_TOPIC}, + {"TOPICS", TK_TOPICS}, + {"TSERIES", TK_TSERIES}, {"TTL", TK_TTL}, {"UNION", TK_UNION}, {"UNSIGNED", TK_UNSIGNED}, @@ -145,15 +176,18 @@ static SKeyword keywordTable[] = { {"USER", TK_USER}, {"USERS", TK_USERS}, {"USING", TK_USING}, + {"VALUE", TK_VALUE}, {"VALUES", TK_VALUES}, {"VARCHAR", TK_VARCHAR}, + {"VARIABLES", TK_VARIABLES}, {"VERBOSE", TK_VERBOSE}, {"VGROUPS", TK_VGROUPS}, + {"VNODES", TK_VNODES}, {"WAL", TK_WAL}, - {"WDURATION", TK_WDURATION}, - {"WENDTS", TK_WENDTS}, + {"_WDURATION", TK_WDURATION}, + {"_WENDTS", TK_WENDTS}, {"WHERE", TK_WHERE}, - {"WSTARTTS", TK_WSTARTTS}, + {"_WSTARTTS", TK_WSTARTTS}, // {"ID", TK_ID}, // {"STRING", TK_STRING}, // {"EQ", TK_EQ}, @@ -179,23 +213,8 @@ static SKeyword keywordTable[] = { // {"UMINUS", TK_UMINUS}, // {"UPLUS", TK_UPLUS}, // {"BITNOT", TK_BITNOT}, - // {"ACCOUNTS", TK_ACCOUNTS}, - // {"QUERIES", TK_QUERIES}, - // {"CONNECTIONS", TK_CONNECTIONS}, - // {"VARIABLES", TK_VARIABLES}, - // {"SCORES", TK_SCORES}, // {"GRANTS", TK_GRANTS}, // {"DOT", TK_DOT}, - // {"DESCRIBE", TK_DESCRIBE}, - // {"SYNCDB", TK_SYNCDB}, - // {"LOCAL", TK_LOCAL}, - // {"PPS", TK_PPS}, - // {"TSERIES", TK_TSERIES}, - // {"DBS", TK_DBS}, - // {"STORAGE", TK_STORAGE}, - // {"QTIME", TK_QTIME}, - // {"CONNS", TK_CONNS}, - // {"STATE", TK_STATE}, // {"CTIME", TK_CTIME}, // {"LP", TK_LP}, // {"RP", TK_RP}, @@ -203,17 +222,8 @@ static SKeyword keywordTable[] = { // {"EVERY", TK_EVERY}, // {"VARIABLE", TK_VARIABLE}, // {"UPDATE", TK_UPDATE}, - // {"RESET", TK_RESET}, - // {"QUERY", TK_QUERY}, - // {"ADD", TK_ADD}, - // {"COLUMN", TK_COLUMN}, - // {"TAG", TK_TAG}, // {"CHANGE", TK_CHANGE}, - // {"SET", TK_SET}, - // {"KILL", TK_KILL}, - // {"CONNECTION", TK_CONNECTION}, // {"COLON", TK_COLON}, - // {"STREAM", TK_STREAM}, // {"ABORT", TK_ABORT}, // {"AFTER", TK_AFTER}, // {"ATTACH", TK_ATTACH}, @@ -244,14 +254,7 @@ static SKeyword keywordTable[] = { // {"TRIGGER", TK_TRIGGER}, // {"VIEW", TK_VIEW}, // {"SEMI", TK_SEMI}, - // {"VNODES", TK_VNODES}, -// {"PARTITIONS", TK_PARTITIONS}, - // {"TOPICS", TK_TOPICS}, - // {"COMPACT", TK_COMPACT}, - // {"MODIFY", TK_MODIFY}, - // {"OUTPUTTYPE", TK_OUTPUTTYPE}, - // {"AGGREGATE", TK_AGGREGATE}, - // {"BUFSIZE", TK_BUFSIZE}, + // {"PARTITIONS", TK_PARTITIONS}, // {"MODE", TK_MODE}, }; @@ -437,10 +440,6 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { *tokenId = TK_NK_QUESTION; return 1; } - case '_': { - *tokenId = TK_NK_UNDERLINE; - return 1; - } case '`': case '\'': case '"': { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index d453193d0f..773060beab 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -240,7 +240,11 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol if (NULL != pTable) { strcpy(pCol->tableAlias, pTable->tableAlias); } else if (QUERY_NODE_COLUMN == nodeType(pExpr)) { - strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias); + SColumnNode* pProjCol = (SColumnNode*)pExpr; + strcpy(pCol->tableAlias, pProjCol->tableAlias); + pCol->tableId = pProjCol->tableId; + pCol->colId = pProjCol->colId; + pCol->colType = pProjCol->colType; } strcpy(pCol->colName, pExpr->aliasName); pCol->node.resType = pExpr->resType; @@ -435,6 +439,9 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { } static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { + if (nodesIsUnaryOp(pOp)) { + return DEAL_RES_CONTINUE; + } SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; if (nodesIsArithmeticOp(pOp)) { @@ -956,9 +963,9 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS pReq->cacheBlockSize = pStmt->pOptions->cacheBlockSize; pReq->totalBlocks = pStmt->pOptions->numOfBlocks; pReq->daysPerFile = pStmt->pOptions->daysPerFile; - pReq->daysToKeep0 = pStmt->pOptions->keep; - pReq->daysToKeep1 = -1; - pReq->daysToKeep2 = -1; + pReq->daysToKeep0 = pStmt->pOptions->keep0; + pReq->daysToKeep1 = pStmt->pOptions->keep1; + pReq->daysToKeep2 = pStmt->pOptions->keep2; pReq->minRows = pStmt->pOptions->minRowsPerBlock; pReq->maxRows = pStmt->pOptions->maxRowsPerBlock; pReq->commitTime = -1; @@ -1041,13 +1048,14 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameGetFullDbName(&name, pReq->db); pReq->totalBlocks = pStmt->pOptions->numOfBlocks; - pReq->daysToKeep0 = pStmt->pOptions->keep; - pReq->daysToKeep1 = -1; - pReq->daysToKeep2 = -1; + pReq->daysToKeep0 = pStmt->pOptions->keep0; + pReq->daysToKeep1 = pStmt->pOptions->keep1; + pReq->daysToKeep2 = pStmt->pOptions->keep2; pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod; pReq->walLevel = pStmt->pOptions->walLevel; pReq->quorum = pStmt->pOptions->quorum; pReq->cacheLastRow = pStmt->pOptions->cachelast; + pReq->replications = pStmt->pOptions->replica; return; } @@ -1094,10 +1102,6 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray) { } static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { - if (NULL == pList) { - return TSDB_CODE_SUCCESS; - } - *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); SNode* pNode; FOREACH(pNode, pList) { @@ -1119,7 +1123,7 @@ static const SColumnDefNode* findColDef(const SNodeList* pCols, const SColumnNod return NULL; } -static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { +static int32_t checkCreateSuperTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { if (NULL != pStmt->pOptions->pSma) { SNode* pNode = NULL; FOREACH(pNode, pStmt->pOptions->pSma) { @@ -1148,7 +1152,7 @@ static int32_t getAggregationMethod(SNodeList* pFuncs) { } static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { - int32_t code = checkCreateTable(pCxt, pStmt); + int32_t code = checkCreateSuperTable(pCxt, pStmt); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -1160,10 +1164,15 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt createReq.delay = pStmt->pOptions->delay; columnDefNodeToField(pStmt->pCols, &createReq.pColumns); columnDefNodeToField(pStmt->pTags, &createReq.pTags); - columnNodeToField(pStmt->pOptions->pSma, &createReq.pSmas); createReq.numOfColumns = LIST_LENGTH(pStmt->pCols); createReq.numOfTags = LIST_LENGTH(pStmt->pTags); - createReq.numOfSmas = LIST_LENGTH(pStmt->pOptions->pSma); + if (NULL == pStmt->pOptions->pSma) { + columnDefNodeToField(pStmt->pCols, &createReq.pSmas); + createReq.numOfSmas = createReq.numOfColumns; + } else { + columnNodeToField(pStmt->pOptions->pSma, &createReq.pSmas); + createReq.numOfSmas = LIST_LENGTH(pStmt->pOptions->pSma); + } SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; strcpy(tableName.dbname, pStmt->dbName); @@ -1217,6 +1226,9 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt SName tableName; int32_t code = getTableMetaImpl( pCxt, toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName), &pTableMeta); + if ((TSDB_CODE_TDB_INVALID_TABLE_ID == code || TSDB_CODE_VND_TB_NOT_EXIST == code) && pClause->ignoreNotExists) { + return TSDB_CODE_SUCCESS; + } if (TSDB_CODE_SUCCESS == code) { if (TSDB_SUPER_TABLE == pTableMeta->tableType) { code = doTranslateDropSuperTable(pCxt, &tableName, pClause->ignoreNotExists); @@ -1466,20 +1478,20 @@ static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pSt static int32_t nodeTypeToShowType(ENodeType nt) { switch (nt) { - case QUERY_NODE_SHOW_DATABASES_STMT: - return TSDB_MGMT_TABLE_DB; - case QUERY_NODE_SHOW_STABLES_STMT: - return TSDB_MGMT_TABLE_STB; - case QUERY_NODE_SHOW_USERS_STMT: - return TSDB_MGMT_TABLE_USER; - case QUERY_NODE_SHOW_DNODES_STMT: - return TSDB_MGMT_TABLE_DNODE; - case QUERY_NODE_SHOW_VGROUPS_STMT: - return TSDB_MGMT_TABLE_VGROUP; - case QUERY_NODE_SHOW_MNODES_STMT: - return TSDB_MGMT_TABLE_MNODE; - case QUERY_NODE_SHOW_QNODES_STMT: - return TSDB_MGMT_TABLE_QNODE; + case QUERY_NODE_SHOW_APPS_STMT: + return 0; // todo + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + return TSDB_MGMT_TABLE_CONNS; + case QUERY_NODE_SHOW_LICENCE_STMT: + return 0; // todo + case QUERY_NODE_SHOW_QUERIES_STMT: + return TSDB_MGMT_TABLE_QUERIES; + case QUERY_NODE_SHOW_SCORES_STMT: + return 0; // todo + case QUERY_NODE_SHOW_TOPICS_STMT: + return 0; // todo + case QUERY_NODE_SHOW_VARIABLE_STMT: + return TSDB_MGMT_TABLE_VARIABLES; default: break; } @@ -1505,30 +1517,6 @@ static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { return TSDB_CODE_SUCCESS; } -static int32_t translateShowTables(STranslateContext* pCxt) { - SVShowTablesReq* pShowReq = taosMemoryCalloc(1, sizeof(SVShowTablesReq)); - - SArray* array = NULL; - int32_t code = getDBVgInfo(pCxt, pCxt->pParseCxt->db, &array); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - SVgroupInfo* info = taosArrayGet(array, 0); - pShowReq->head.vgId = htonl(info->vgId); - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = info->epSet; - pCxt->pCmdMsg->msgType = TDMT_VND_SHOW_TABLES; - pCxt->pCmdMsg->msgLen = sizeof(SVShowTablesReq); - pCxt->pCmdMsg->pMsg = pShowReq; - pCxt->pCmdMsg->pExtension = array; - - return TSDB_CODE_SUCCESS; -} - static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, char* pTableName, int32_t* pVgId) { SVgroupInfo vg = {0}; int32_t code = getTableHashVgroup(pCxt, pCxt->pParseCxt->db, pTableName, &vg); @@ -1812,6 +1800,10 @@ static int32_t translateExplain(STranslateContext* pCxt, SExplainStmt* pStmt) { return translateQuery(pCxt, pStmt->pQuery); } +static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) { + return getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta); +} + static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { @@ -1860,17 +1852,19 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_ALTER_DNODE_STMT: code = translateAlterDnode(pCxt, (SAlterDnodeStmt*)pNode); break; - case QUERY_NODE_SHOW_DATABASES_STMT: - case QUERY_NODE_SHOW_STABLES_STMT: - case QUERY_NODE_SHOW_USERS_STMT: - case QUERY_NODE_SHOW_DNODES_STMT: - case QUERY_NODE_SHOW_VGROUPS_STMT: - case QUERY_NODE_SHOW_MNODES_STMT: - case QUERY_NODE_SHOW_QNODES_STMT: + case QUERY_NODE_SHOW_APPS_STMT: + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_LICENCE_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + case QUERY_NODE_SHOW_SCORES_STMT: + case QUERY_NODE_SHOW_TOPICS_STMT: + case QUERY_NODE_SHOW_VARIABLE_STMT: code = translateShow(pCxt, (SShowStmt*)pNode); break; - case QUERY_NODE_SHOW_TABLES_STMT: - code = translateShowTables(pCxt); + case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: + case QUERY_NODE_SHOW_CREATE_TABLE_STMT: + case QUERY_NODE_SHOW_CREATE_STABLE_STMT: + // todo break; case QUERY_NODE_CREATE_INDEX_STMT: code = translateCreateIndex(pCxt, (SCreateIndexStmt*)pNode); @@ -1896,6 +1890,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_EXPLAIN_STMT: code = translateExplain(pCxt, (SExplainStmt*)pNode); break; + case QUERY_NODE_DESCRIBE_STMT: + code = translateDescribe(pCxt, (SDescribeStmt*)pNode); + break; default: break; } @@ -1913,40 +1910,82 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) { return code; } -int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { +static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* numOfCols, SSchema** pSchema) { + *numOfCols = LIST_LENGTH(pSelect->pProjectionList); + *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); + if (NULL == (*pSchema)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + SNode* pNode; + int32_t index = 0; + FOREACH(pNode, pSelect->pProjectionList) { + SExprNode* pExpr = (SExprNode*)pNode; + (*pSchema)[index].type = pExpr->resType.type; + (*pSchema)[index].bytes = pExpr->resType.bytes; + (*pSchema)[index].colId = index + 1; + strcpy((*pSchema)[index].name, pExpr->aliasName); + index +=1; + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t extractExplainResultSchema(int32_t* numOfCols, SSchema** pSchema) { + *numOfCols = 1; + *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); + if (NULL == (*pSchema)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[0].bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE; + strcpy((*pSchema)[0].name, TSDB_EXPLAIN_RESULT_COLUMN_NAME); + return TSDB_CODE_SUCCESS; +} + +static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema) { + *numOfCols = DESCRIBE_RESULT_COLS; + *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); + if (NULL == (*pSchema)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[0].bytes = DESCRIBE_RESULT_FIELD_LEN; + strcpy((*pSchema)[0].name, "Field"); + + (*pSchema)[1].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[1].bytes = DESCRIBE_RESULT_TYPE_LEN; + strcpy((*pSchema)[1].name, "Type"); + + (*pSchema)[2].type = TSDB_DATA_TYPE_INT; + (*pSchema)[2].bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; + strcpy((*pSchema)[2].name, "Length"); + + (*pSchema)[3].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[3].bytes = DESCRIBE_RESULT_NOTE_LEN; + strcpy((*pSchema)[3].name, "Note"); + + return TSDB_CODE_SUCCESS; +} + +int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { if (NULL == pRoot) { return TSDB_CODE_SUCCESS; } - if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) { - SSelectStmt* pSelect = (SSelectStmt*) pRoot; - *numOfCols = LIST_LENGTH(pSelect->pProjectionList); - *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); - if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - SNode* pNode; - int32_t index = 0; - FOREACH(pNode, pSelect->pProjectionList) { - SExprNode* pExpr = (SExprNode*)pNode; - (*pSchema)[index].type = pExpr->resType.type; - (*pSchema)[index].bytes = pExpr->resType.bytes; - (*pSchema)[index].colId = index + 1; - strcpy((*pSchema)[index].name, pExpr->aliasName); - index +=1; - } - } else if (QUERY_NODE_EXPLAIN_STMT == nodeType(pRoot)) { - *numOfCols = 1; - *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); - if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; - (*pSchema)[0].bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE; + switch (nodeType(pRoot)) { + case QUERY_NODE_SELECT_STMT: + return extractSelectResultSchema((SSelectStmt*)pRoot, numOfCols, pSchema); + case QUERY_NODE_EXPLAIN_STMT: + return extractExplainResultSchema(numOfCols, pSchema); + case QUERY_NODE_DESCRIBE_STMT: + return extractDescribeResultSchema(numOfCols, pSchema); + default: + break; } - return TSDB_CODE_SUCCESS; + return TSDB_CODE_FAILED; } static void destroyTranslateContext(STranslateContext* pCxt) { @@ -2116,10 +2155,11 @@ typedef struct SVgroupTablesBatch { char dbName[TSDB_DB_NAME_LEN]; } SVgroupTablesBatch; -static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) { +static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchemaEx* pSchema) { pSchema->colId = colId; pSchema->type = pCol->dataType.type; - pSchema->bytes = pCol->dataType.bytes; + pSchema->bytes = calcTypeBytes(pCol->dataType); + pSchema->sma = TSDB_BSMA_TYPE_LATEST; // TODO: use default value currently, and use the real value later. strcpy(pSchema->name, pCol->colName); } @@ -2141,7 +2181,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const char* pDbName, con req.dbFName = strdup(dbFName); req.name = strdup(pTableName); req.ntbCfg.nCols = LIST_LENGTH(pColumns); - req.ntbCfg.pSchema = taosMemoryCalloc(req.ntbCfg.nCols, sizeof(SSchema)); + req.ntbCfg.pSchema = taosMemoryCalloc(req.ntbCfg.nCols, sizeof(SSchemaEx)); if (NULL == req.name || NULL == req.ntbCfg.pSchema) { destroyCreateTbReq(&req); return TSDB_CODE_OUT_OF_MEMORY; @@ -2152,6 +2192,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const char* pDbName, con toSchema((SColumnDefNode*)pCol, index + 1, req.ntbCfg.pSchema + index); ++index; } + // TODO: use the real sma for normal table. pBatch->info = *pVgroupInfo; strcpy(pBatch->dbName, pDbName); @@ -2396,9 +2437,19 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau return TSDB_CODE_SUCCESS; } +static int32_t checkCreateSubTable(STranslateContext* pCxt, SCreateSubTableClause* pStmt) { + if (0 != strcmp(pStmt->dbName, pStmt->useDbName)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR);; + } + return TSDB_CODE_SUCCESS; +} static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableClause* pStmt, SHashObj* pVgroupHashmap) { + int32_t code = checkCreateSubTable(pCxt, pStmt); + STableMeta* pSuperTableMeta = NULL; - int32_t code = getTableMeta(pCxt, pStmt->useDbName, pStmt->useTableName, &pSuperTableMeta); + if (TSDB_CODE_SUCCESS == code) { + code = getTableMeta(pCxt, pStmt->useDbName, pStmt->useTableName, &pSuperTableMeta); + } SKVRowBuilder kvRowBuilder = {0}; if (TSDB_CODE_SUCCESS == code) { @@ -2530,24 +2581,31 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SELECT_STMT: case QUERY_NODE_EXPLAIN_STMT: pQuery->haveResultSet = true; - pQuery->directRpc = false; pQuery->msgType = TDMT_VND_QUERY; - if (TSDB_CODE_SUCCESS != qExtractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; - } break; case QUERY_NODE_VNODE_MODIF_STMT: - pQuery->haveResultSet = false; - pQuery->directRpc = false; pQuery->msgType = TDMT_VND_CREATE_TABLE; break; - default: - pQuery->haveResultSet = false; - pQuery->directRpc = true; - pQuery->pCmdMsg = pCxt->pCmdMsg; - pCxt->pCmdMsg = NULL; - pQuery->msgType = pQuery->pCmdMsg->msgType; + case QUERY_NODE_DESCRIBE_STMT: + pQuery->localCmd = true; + pQuery->haveResultSet = true; break; + case QUERY_NODE_RESET_QUERY_CACHE_STMT: + pQuery->localCmd = true; + break; + default: + pQuery->directRpc = true; + if (NULL != pCxt->pCmdMsg) { + TSWAP(pQuery->pCmdMsg, pCxt->pCmdMsg, SCmdMsgInfo*); + pQuery->msgType = pQuery->pCmdMsg->msgType; + } + break; + } + + if (pQuery->haveResultSet) { + if (TSDB_CODE_SUCCESS != extractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema)) { + return TSDB_CODE_OUT_OF_MEMORY; + } } if (NULL != pCxt->pDbs) { diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 80d04c5ee4..aeed7719f3 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -61,6 +61,12 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "This statement is no longer supported"; case TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL: return "This interval value is too small : %s"; + case TSDB_CODE_PAR_DB_NOT_SPECIFIED: + return "db not specified"; + case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME: + return "Invalid identifier name : %s"; + case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR: + return "corresponding super table not in this db"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index d9bff4b9ef..d410aa2e17 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -62,3 +62,7 @@ void qDestroyQuery(SQuery* pQueryNode) { taosArrayDestroy(pQueryNode->pTableList); taosMemoryFreeClear(pQueryNode); } + +int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { + return extractResultSchema(pRoot, numOfCols, pSchema); +} \ No newline at end of file diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 154b87ba4b..86e564adab 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -100,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 274 +#define YYNOCODE 304 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SAlterOption yy29; - SNodeList* yy40; - ENullOrder yy177; - EOrder yy210; - EOperatorType yy328; - SNode* yy364; - EJoinType yy392; - SDataType yy420; - SToken yy437; - int32_t yy460; - EFillMode yy478; - bool yy493; + EOperatorType yy60; + SNode* yy104; + SToken yy129; + bool yy185; + int32_t yy196; + SAlterOption yy253; + SNodeList* yy312; + SDataType yy336; + EOrder yy354; + ENullOrder yy489; + EJoinType yy532; + EFillMode yy550; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -132,17 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 438 -#define YYNRULE 354 -#define YYNTOKEN 176 -#define YY_MAX_SHIFT 437 -#define YY_MIN_SHIFTREDUCE 684 -#define YY_MAX_SHIFTREDUCE 1037 -#define YY_ERROR_ACTION 1038 -#define YY_ACCEPT_ACTION 1039 -#define YY_NO_ACTION 1040 -#define YY_MIN_REDUCE 1041 -#define YY_MAX_REDUCE 1394 +#define YYNSTATE 511 +#define YYNRULE 390 +#define YYNTOKEN 201 +#define YY_MAX_SHIFT 510 +#define YY_MIN_SHIFTREDUCE 762 +#define YY_MAX_SHIFTREDUCE 1151 +#define YY_ERROR_ACTION 1152 +#define YY_ACCEPT_ACTION 1153 +#define YY_NO_ACTION 1154 +#define YY_MIN_REDUCE 1155 +#define YY_MAX_REDUCE 1544 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -209,408 +209,458 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1305) +#define YY_ACTTAB_COUNT (1448) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1251, 337, 24, 172, 356, 356, 256, 241, 1247, 1254, - /* 10 */ 1220, 1221, 31, 29, 27, 26, 25, 1264, 369, 369, - /* 20 */ 9, 8, 93, 67, 67, 31, 29, 27, 26, 25, - /* 30 */ 286, 292, 337, 1373, 106, 60, 1053, 1280, 369, 1144, - /* 40 */ 1144, 341, 1135, 276, 353, 94, 118, 215, 1084, 249, - /* 50 */ 1371, 91, 1136, 93, 355, 979, 1211, 1213, 1238, 1144, - /* 60 */ 215, 165, 1319, 336, 110, 335, 1087, 44, 1373, 913, - /* 70 */ 63, 1265, 1266, 1269, 1312, 1184, 90, 943, 231, 1308, - /* 80 */ 1385, 118, 91, 1238, 1139, 1371, 107, 1111, 956, 1346, - /* 90 */ 943, 339, 114, 1319, 1320, 257, 1324, 422, 421, 420, - /* 100 */ 419, 418, 417, 416, 415, 414, 413, 412, 411, 410, - /* 110 */ 409, 408, 407, 406, 405, 298, 944, 293, 105, 242, - /* 120 */ 297, 213, 898, 296, 368, 294, 1147, 105, 295, 944, - /* 130 */ 31, 29, 27, 26, 25, 1146, 368, 1122, 23, 236, - /* 140 */ 938, 939, 940, 941, 942, 946, 947, 948, 27, 26, - /* 150 */ 25, 23, 236, 938, 939, 940, 941, 942, 946, 947, - /* 160 */ 948, 793, 392, 391, 390, 797, 389, 799, 800, 388, - /* 170 */ 802, 385, 1264, 808, 382, 810, 811, 379, 376, 229, - /* 180 */ 30, 28, 337, 277, 12, 30, 28, 980, 238, 277, - /* 190 */ 878, 246, 1280, 238, 1264, 878, 1251, 310, 255, 353, - /* 200 */ 254, 1191, 978, 93, 1247, 1253, 876, 228, 1251, 355, - /* 210 */ 308, 876, 1189, 1238, 1280, 11, 1247, 1253, 341, 369, - /* 220 */ 11, 340, 248, 119, 1141, 62, 1265, 1266, 1269, 1312, - /* 230 */ 105, 355, 91, 214, 1308, 1238, 1, 265, 1146, 1120, - /* 240 */ 1144, 1, 115, 1319, 1320, 1373, 1324, 63, 1265, 1266, - /* 250 */ 1269, 1312, 119, 1191, 720, 231, 1308, 113, 118, 243, - /* 260 */ 434, 6, 1371, 902, 1189, 434, 119, 430, 429, 168, - /* 270 */ 284, 312, 877, 1280, 1280, 319, 1339, 877, 30, 28, - /* 280 */ 353, 353, 124, 123, 222, 404, 238, 1264, 878, 1033, - /* 290 */ 1034, 326, 1331, 975, 879, 53, 882, 883, 204, 879, - /* 300 */ 926, 882, 883, 204, 876, 926, 290, 1280, 327, 330, - /* 310 */ 289, 313, 1137, 11, 340, 721, 1373, 720, 119, 1264, - /* 320 */ 223, 1191, 221, 220, 355, 288, 332, 328, 1238, 1372, - /* 330 */ 1064, 291, 1212, 1371, 1, 722, 119, 368, 1373, 1280, - /* 340 */ 63, 1265, 1266, 1269, 1312, 404, 353, 369, 231, 1308, - /* 350 */ 113, 118, 366, 30, 28, 1371, 355, 369, 434, 900, - /* 360 */ 1238, 238, 367, 878, 395, 167, 1264, 975, 1144, 1340, - /* 370 */ 877, 1238, 63, 1265, 1266, 1269, 1312, 1191, 1144, 876, - /* 380 */ 231, 1308, 1385, 250, 1063, 12, 1280, 192, 1189, 331, - /* 390 */ 1174, 1369, 879, 353, 882, 883, 204, 337, 926, 139, - /* 400 */ 251, 1062, 137, 355, 30, 28, 354, 1238, 105, 7, - /* 410 */ 369, 303, 238, 348, 878, 186, 1146, 44, 93, 63, - /* 420 */ 1265, 1266, 1269, 1312, 1061, 1238, 311, 231, 1308, 1385, - /* 430 */ 876, 1144, 945, 434, 1140, 987, 30, 28, 1330, 345, - /* 440 */ 147, 900, 1238, 306, 238, 877, 878, 91, 300, 1060, - /* 450 */ 1326, 146, 1264, 1059, 21, 1191, 901, 116, 1319, 1320, - /* 460 */ 7, 1324, 876, 949, 899, 1238, 1190, 879, 1323, 882, - /* 470 */ 883, 204, 1280, 926, 41, 30, 28, 40, 1004, 353, - /* 480 */ 1121, 1326, 369, 238, 434, 878, 1058, 252, 1208, 355, - /* 490 */ 1238, 119, 7, 1238, 1238, 122, 877, 1039, 341, 1322, - /* 500 */ 344, 876, 349, 1144, 1057, 205, 1265, 1266, 1269, 323, - /* 510 */ 1002, 1003, 1005, 1006, 1326, 290, 434, 1056, 879, 289, - /* 520 */ 882, 883, 204, 1055, 926, 1373, 346, 1238, 877, 898, - /* 530 */ 1052, 1, 1321, 9, 8, 903, 258, 401, 118, 270, - /* 540 */ 291, 400, 1371, 1264, 141, 1238, 253, 140, 271, 1133, - /* 550 */ 879, 352, 882, 883, 204, 434, 926, 143, 1238, 886, - /* 560 */ 142, 1051, 402, 1280, 1238, 20, 1050, 877, 1049, 1112, - /* 570 */ 353, 1238, 1129, 1373, 1264, 31, 29, 27, 26, 25, - /* 580 */ 355, 399, 398, 397, 1238, 396, 118, 1036, 1037, 879, - /* 590 */ 1371, 882, 883, 204, 1280, 926, 64, 1265, 1266, 1269, - /* 600 */ 1312, 353, 1238, 145, 1311, 1308, 144, 1238, 1131, 1238, - /* 610 */ 1048, 355, 1047, 1264, 315, 1238, 269, 1046, 1264, 264, - /* 620 */ 263, 262, 261, 260, 1045, 889, 99, 64, 1265, 1266, - /* 630 */ 1269, 1312, 935, 1280, 1001, 351, 1308, 153, 1280, 298, - /* 640 */ 353, 293, 1080, 1127, 297, 353, 42, 296, 1075, 294, - /* 650 */ 355, 1238, 295, 1238, 1238, 355, 1264, 1119, 1238, 1238, - /* 660 */ 1042, 885, 1044, 343, 299, 1238, 108, 1265, 1266, 1269, - /* 670 */ 301, 64, 1265, 1266, 1269, 1312, 1280, 169, 394, 1054, - /* 680 */ 1309, 78, 158, 353, 77, 76, 75, 74, 73, 72, - /* 690 */ 71, 70, 69, 355, 156, 324, 1264, 1238, 1073, 878, - /* 700 */ 237, 1264, 1185, 1238, 342, 1386, 162, 950, 283, 209, - /* 710 */ 1265, 1266, 1269, 1258, 401, 876, 1280, 1342, 400, 32, - /* 720 */ 304, 1280, 910, 353, 865, 1256, 338, 888, 353, 1281, - /* 730 */ 171, 871, 177, 355, 32, 361, 32, 1238, 355, 402, - /* 740 */ 320, 183, 1238, 1264, 175, 2, 190, 96, 898, 209, - /* 750 */ 1265, 1266, 1269, 97, 208, 1265, 1266, 1269, 399, 398, - /* 760 */ 397, 1210, 396, 1280, 121, 22, 259, 267, 266, 434, - /* 770 */ 353, 786, 268, 1264, 272, 31, 29, 27, 26, 25, - /* 780 */ 355, 877, 781, 99, 1238, 906, 333, 126, 31, 29, - /* 790 */ 27, 26, 25, 1280, 42, 1264, 108, 1265, 1266, 1269, - /* 800 */ 353, 273, 274, 879, 814, 882, 883, 818, 905, 824, - /* 810 */ 355, 823, 100, 129, 1238, 1280, 374, 235, 275, 97, - /* 820 */ 437, 98, 353, 99, 97, 278, 209, 1265, 1266, 1269, - /* 830 */ 43, 132, 355, 904, 189, 1387, 1238, 89, 287, 239, - /* 840 */ 285, 314, 227, 426, 317, 188, 59, 88, 209, 1265, - /* 850 */ 1266, 1269, 1041, 1134, 78, 136, 55, 77, 76, 75, - /* 860 */ 74, 73, 72, 71, 70, 69, 1130, 138, 61, 101, - /* 870 */ 1264, 184, 102, 1132, 1128, 103, 87, 86, 85, 84, - /* 880 */ 83, 82, 81, 80, 79, 104, 316, 148, 151, 925, - /* 890 */ 1280, 927, 928, 929, 930, 931, 903, 353, 1353, 325, - /* 900 */ 197, 1264, 365, 359, 154, 199, 883, 355, 322, 1343, - /* 910 */ 157, 1238, 1352, 230, 329, 5, 161, 198, 334, 318, - /* 920 */ 321, 1280, 149, 207, 1265, 1266, 1269, 125, 353, 975, - /* 930 */ 1333, 1264, 31, 29, 27, 26, 25, 111, 355, 4, - /* 940 */ 163, 902, 1238, 92, 1327, 33, 232, 17, 164, 347, - /* 950 */ 350, 1280, 1388, 1264, 210, 1265, 1266, 1269, 353, 1294, - /* 960 */ 1370, 362, 170, 179, 191, 1219, 1218, 357, 355, 358, - /* 970 */ 364, 240, 1238, 1280, 363, 1264, 181, 52, 1145, 54, - /* 980 */ 353, 372, 193, 187, 202, 1265, 1266, 1269, 65, 913, - /* 990 */ 355, 433, 195, 39, 1238, 1280, 200, 1264, 201, 196, - /* 1000 */ 1232, 874, 353, 873, 1226, 120, 211, 1265, 1266, 1269, - /* 1010 */ 848, 1203, 355, 1202, 95, 1201, 1238, 1280, 1200, 1264, - /* 1020 */ 1199, 1198, 1197, 1196, 353, 850, 1195, 1194, 203, 1265, - /* 1030 */ 1266, 1269, 119, 1193, 355, 1192, 1086, 1225, 1238, 1280, - /* 1040 */ 1216, 1264, 128, 1123, 733, 1085, 353, 1083, 279, 281, - /* 1050 */ 212, 1265, 1266, 1269, 1072, 280, 355, 1071, 1068, 1125, - /* 1060 */ 1238, 1280, 68, 1264, 135, 1124, 831, 830, 353, 761, - /* 1070 */ 829, 1081, 1277, 1265, 1266, 1269, 760, 759, 355, 758, - /* 1080 */ 757, 1076, 1238, 1280, 756, 224, 225, 1264, 302, 1074, - /* 1090 */ 353, 226, 1067, 305, 1276, 1265, 1266, 1269, 307, 1066, - /* 1100 */ 355, 309, 66, 1224, 1238, 1223, 36, 1280, 152, 150, - /* 1110 */ 14, 1264, 1215, 3, 353, 32, 1275, 1265, 1266, 1269, - /* 1120 */ 245, 244, 155, 15, 355, 37, 34, 10, 1238, 46, - /* 1130 */ 891, 1280, 160, 1264, 49, 1022, 1000, 994, 353, 993, - /* 1140 */ 218, 1265, 1266, 1269, 972, 109, 884, 1021, 355, 233, - /* 1150 */ 8, 159, 1238, 1280, 47, 1264, 48, 1026, 1256, 971, - /* 1160 */ 353, 19, 1025, 1027, 217, 1265, 1266, 1269, 35, 234, - /* 1170 */ 355, 166, 13, 117, 1238, 1280, 16, 1264, 936, 911, - /* 1180 */ 173, 18, 353, 174, 998, 176, 219, 1265, 1266, 1269, - /* 1190 */ 178, 50, 355, 360, 1214, 180, 1238, 1280, 55, 893, - /* 1200 */ 370, 182, 51, 38, 353, 1255, 185, 371, 216, 1265, - /* 1210 */ 1266, 1269, 887, 815, 355, 375, 134, 373, 1238, 112, - /* 1220 */ 247, 807, 812, 377, 378, 282, 809, 133, 380, 381, - /* 1230 */ 206, 1265, 1266, 1269, 892, 803, 895, 883, 383, 384, - /* 1240 */ 386, 801, 387, 806, 805, 804, 792, 393, 56, 826, - /* 1250 */ 45, 822, 57, 131, 58, 821, 820, 731, 825, 403, - /* 1260 */ 753, 752, 745, 751, 750, 749, 748, 747, 746, 744, - /* 1270 */ 743, 742, 1082, 741, 740, 739, 1070, 738, 1069, 737, - /* 1280 */ 736, 423, 424, 427, 428, 1065, 431, 425, 432, 1040, - /* 1290 */ 880, 194, 435, 436, 1040, 1040, 1040, 1040, 1040, 1040, - /* 1300 */ 130, 1040, 1040, 1040, 127, + /* 0 */ 1250, 441, 441, 265, 441, 1246, 1413, 72, 304, 306, + /* 10 */ 72, 111, 30, 28, 348, 409, 252, 354, 20, 1263, + /* 20 */ 261, 1153, 990, 1261, 1261, 269, 1261, 1429, 31, 29, + /* 30 */ 27, 26, 25, 1399, 412, 441, 233, 98, 988, 117, + /* 40 */ 409, 305, 1399, 1014, 427, 1395, 1401, 11, 1386, 1429, + /* 50 */ 1301, 30, 28, 1094, 1395, 1401, 425, 1261, 799, 261, + /* 60 */ 798, 990, 98, 409, 69, 1414, 1415, 1418, 1462, 1, + /* 70 */ 96, 276, 254, 1458, 120, 1413, 1308, 988, 800, 411, + /* 80 */ 121, 1469, 1470, 1308, 1474, 98, 11, 1340, 399, 251, + /* 90 */ 30, 28, 507, 1490, 1306, 96, 1429, 1252, 261, 325, + /* 100 */ 990, 440, 1523, 425, 989, 122, 1469, 1470, 1, 1474, + /* 110 */ 22, 24, 191, 427, 1399, 125, 988, 1386, 96, 1521, + /* 120 */ 31, 29, 27, 26, 25, 11, 1395, 1402, 123, 1469, + /* 130 */ 1470, 507, 1474, 70, 1414, 1415, 1418, 1462, 991, 1386, + /* 140 */ 440, 1461, 1458, 989, 135, 134, 1413, 1, 31, 29, + /* 150 */ 27, 26, 25, 186, 65, 994, 995, 1038, 1039, 1040, + /* 160 */ 1041, 1042, 1043, 1044, 1045, 99, 232, 1429, 1010, 1406, + /* 170 */ 507, 299, 1253, 298, 425, 318, 126, 991, 330, 1010, + /* 180 */ 428, 1404, 989, 264, 427, 1429, 1348, 331, 1386, 12, + /* 190 */ 1413, 398, 425, 131, 994, 995, 1038, 1039, 1040, 1041, + /* 200 */ 1042, 1043, 1044, 1045, 69, 1414, 1415, 1418, 1462, 441, + /* 210 */ 126, 1429, 254, 1458, 1535, 311, 991, 47, 425, 1308, + /* 220 */ 46, 441, 1336, 1496, 402, 266, 440, 312, 427, 133, + /* 230 */ 1306, 1261, 1386, 994, 995, 1038, 1039, 1040, 1041, 1042, + /* 240 */ 1043, 1044, 1045, 1261, 404, 400, 30, 28, 70, 1414, + /* 250 */ 1415, 1418, 1462, 64, 261, 329, 990, 1459, 324, 323, + /* 260 */ 322, 321, 320, 60, 317, 316, 315, 314, 310, 309, + /* 270 */ 308, 307, 988, 84, 1118, 12, 83, 82, 81, 80, + /* 280 */ 79, 78, 77, 76, 75, 30, 28, 426, 1156, 361, + /* 290 */ 111, 356, 300, 261, 360, 990, 126, 160, 1264, 357, + /* 300 */ 355, 126, 358, 7, 395, 1116, 1117, 1119, 1120, 84, + /* 310 */ 6, 988, 83, 82, 81, 80, 79, 78, 77, 76, + /* 320 */ 75, 441, 1308, 1523, 30, 28, 507, 338, 273, 503, + /* 330 */ 502, 441, 261, 1306, 990, 126, 125, 1258, 989, 114, + /* 340 */ 1521, 1225, 7, 1261, 272, 31, 29, 27, 26, 25, + /* 350 */ 988, 1339, 1341, 1261, 874, 464, 463, 462, 878, 461, + /* 360 */ 880, 881, 460, 883, 457, 507, 889, 454, 891, 892, + /* 370 */ 451, 448, 991, 27, 26, 25, 113, 989, 1167, 213, + /* 380 */ 1413, 7, 1291, 1375, 31, 29, 27, 26, 25, 994, + /* 390 */ 995, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 441, + /* 400 */ 1523, 1429, 1201, 1026, 507, 438, 339, 384, 425, 1239, + /* 410 */ 126, 991, 1178, 1522, 428, 1012, 989, 1521, 427, 283, + /* 420 */ 1349, 1261, 1386, 31, 29, 27, 26, 25, 994, 995, + /* 430 */ 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 115, 1414, + /* 440 */ 1415, 1418, 1089, 31, 29, 27, 26, 25, 385, 271, + /* 450 */ 991, 361, 1015, 356, 1386, 339, 360, 111, 235, 160, + /* 460 */ 245, 357, 355, 1177, 358, 1263, 1413, 994, 995, 1038, + /* 470 */ 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1537, 235, 1523, + /* 480 */ 30, 28, 159, 9, 8, 403, 351, 1429, 261, 1057, + /* 490 */ 990, 1155, 125, 49, 425, 291, 1521, 246, 375, 244, + /* 500 */ 243, 1026, 350, 1148, 427, 1386, 988, 353, 1386, 1057, + /* 510 */ 293, 1257, 1176, 413, 1175, 93, 92, 91, 90, 89, + /* 520 */ 88, 87, 86, 85, 68, 1414, 1415, 1418, 1462, 1523, + /* 530 */ 49, 274, 234, 1458, 159, 1058, 416, 1, 351, 111, + /* 540 */ 95, 1093, 125, 1174, 1523, 441, 1521, 1263, 1256, 1013, + /* 550 */ 1059, 439, 1070, 1062, 1386, 1058, 1386, 125, 476, 353, + /* 560 */ 507, 1521, 172, 1308, 441, 441, 1173, 1261, 1063, 1147, + /* 570 */ 205, 275, 989, 1062, 1307, 1172, 23, 259, 1052, 1053, + /* 580 */ 1054, 1055, 1056, 1060, 1061, 1386, 1261, 1261, 1011, 1476, + /* 590 */ 1194, 21, 1171, 1170, 1169, 1166, 23, 259, 1052, 1053, + /* 600 */ 1054, 1055, 1056, 1060, 1061, 1198, 991, 1473, 1386, 1101, + /* 610 */ 1165, 147, 362, 1248, 119, 1012, 112, 1386, 1481, 1089, + /* 620 */ 344, 219, 146, 994, 995, 1038, 1039, 1040, 1041, 1042, + /* 630 */ 1043, 1044, 1045, 217, 1386, 1386, 1386, 1386, 1164, 1163, + /* 640 */ 1162, 1161, 1160, 136, 1159, 1158, 50, 9, 8, 144, + /* 650 */ 1237, 1413, 1386, 420, 495, 494, 493, 492, 491, 490, + /* 660 */ 489, 488, 207, 485, 484, 483, 482, 481, 480, 479, + /* 670 */ 478, 477, 1429, 1476, 1476, 486, 58, 467, 294, 425, + /* 680 */ 1386, 1386, 1386, 1386, 1386, 798, 1386, 1386, 417, 427, + /* 690 */ 424, 1472, 1471, 1386, 1254, 152, 476, 154, 150, 1413, + /* 700 */ 153, 346, 373, 143, 67, 138, 998, 140, 383, 69, + /* 710 */ 1414, 1415, 1418, 1462, 1092, 371, 1244, 254, 1458, 1535, + /* 720 */ 1429, 1150, 1151, 165, 137, 415, 466, 412, 1519, 45, + /* 730 */ 44, 303, 156, 130, 1189, 155, 104, 427, 297, 387, + /* 740 */ 158, 1386, 1413, 157, 1168, 1226, 241, 1187, 289, 396, + /* 750 */ 285, 281, 127, 188, 1302, 345, 364, 69, 1414, 1415, + /* 760 */ 1418, 1462, 181, 1429, 1492, 254, 1458, 120, 43, 367, + /* 770 */ 425, 1115, 1001, 175, 126, 997, 177, 1430, 1413, 187, + /* 780 */ 427, 410, 421, 190, 1386, 391, 1489, 32, 32, 32, + /* 790 */ 1064, 1023, 957, 194, 2, 1010, 196, 278, 1049, 1429, + /* 800 */ 69, 1414, 1415, 1418, 1462, 1413, 425, 282, 254, 1458, + /* 810 */ 1535, 101, 240, 242, 433, 418, 427, 841, 102, 1480, + /* 820 */ 1386, 202, 966, 211, 313, 413, 1429, 409, 510, 1338, + /* 830 */ 132, 104, 319, 425, 867, 327, 224, 1414, 1415, 1418, + /* 840 */ 326, 1000, 210, 427, 328, 94, 332, 1386, 1019, 98, + /* 850 */ 333, 499, 43, 209, 446, 862, 1523, 895, 102, 103, + /* 860 */ 1413, 899, 905, 70, 1414, 1415, 1418, 1462, 413, 125, + /* 870 */ 334, 423, 1458, 1521, 1018, 335, 139, 66, 1017, 336, + /* 880 */ 203, 1429, 96, 104, 102, 337, 904, 105, 425, 142, + /* 890 */ 48, 145, 184, 1469, 408, 340, 407, 1016, 427, 1523, + /* 900 */ 347, 349, 1386, 74, 1413, 1251, 376, 149, 1247, 1413, + /* 910 */ 437, 377, 125, 151, 106, 107, 1521, 1249, 115, 1414, + /* 920 */ 1415, 1418, 1245, 108, 109, 1429, 352, 359, 378, 250, + /* 930 */ 1429, 1015, 425, 382, 167, 390, 388, 425, 168, 379, + /* 940 */ 170, 397, 427, 1503, 431, 386, 1386, 427, 1493, 260, + /* 950 */ 389, 1386, 995, 974, 392, 164, 414, 1536, 1502, 5, + /* 960 */ 1483, 173, 228, 1414, 1415, 1418, 1413, 228, 1414, 1415, + /* 970 */ 1418, 1413, 406, 394, 393, 176, 253, 4, 401, 1089, + /* 980 */ 97, 1014, 33, 183, 180, 422, 255, 1429, 118, 1477, + /* 990 */ 419, 429, 1429, 182, 425, 17, 1347, 1346, 430, 425, + /* 1000 */ 263, 434, 1444, 435, 427, 198, 1538, 1413, 1386, 427, + /* 1010 */ 200, 57, 436, 1386, 1520, 1413, 258, 59, 1262, 212, + /* 1020 */ 473, 189, 444, 214, 227, 1414, 1415, 1418, 1429, 228, + /* 1030 */ 1414, 1415, 1418, 487, 208, 425, 1429, 506, 216, 220, + /* 1040 */ 221, 1413, 39, 425, 218, 427, 1380, 1379, 277, 1386, + /* 1050 */ 1413, 279, 262, 427, 1376, 280, 405, 1386, 984, 985, + /* 1060 */ 128, 284, 1429, 1374, 286, 228, 1414, 1415, 1418, 425, + /* 1070 */ 287, 1429, 288, 226, 1414, 1415, 1418, 1413, 425, 427, + /* 1080 */ 1373, 290, 1372, 1386, 1363, 1413, 292, 129, 427, 295, + /* 1090 */ 296, 969, 1386, 968, 1357, 1356, 302, 1355, 1429, 229, + /* 1100 */ 1414, 1415, 1418, 301, 1354, 425, 1429, 1331, 222, 1414, + /* 1110 */ 1415, 1418, 940, 425, 1330, 427, 1329, 1328, 1327, 1386, + /* 1120 */ 1326, 1413, 1325, 427, 1324, 1323, 1413, 1386, 1322, 1321, + /* 1130 */ 1320, 1319, 100, 1318, 1317, 230, 1414, 1415, 1418, 1316, + /* 1140 */ 1315, 1314, 1429, 223, 1414, 1415, 1418, 1429, 1313, 425, + /* 1150 */ 1312, 1311, 1310, 1309, 425, 1200, 1371, 942, 1365, 427, + /* 1160 */ 1353, 1344, 1413, 1386, 427, 1240, 141, 1413, 1386, 811, + /* 1170 */ 1199, 1197, 1186, 1413, 341, 343, 1185, 1182, 342, 231, + /* 1180 */ 1414, 1415, 1418, 1429, 1426, 1414, 1415, 1418, 1429, 1242, + /* 1190 */ 425, 73, 912, 486, 1429, 425, 910, 1241, 1195, 1190, + /* 1200 */ 427, 425, 1238, 148, 1386, 427, 840, 839, 247, 1386, + /* 1210 */ 248, 427, 365, 838, 1413, 1386, 837, 835, 834, 1188, + /* 1220 */ 1425, 1414, 1415, 1418, 1236, 1424, 1414, 1415, 1418, 1413, + /* 1230 */ 249, 238, 1414, 1415, 1418, 1429, 1181, 370, 268, 267, + /* 1240 */ 1413, 368, 425, 1180, 372, 71, 1370, 163, 1003, 42, + /* 1250 */ 1429, 976, 427, 1364, 990, 1413, 1386, 425, 110, 206, + /* 1260 */ 380, 1429, 1352, 472, 996, 166, 1351, 427, 425, 1343, + /* 1270 */ 988, 1386, 237, 1414, 1415, 1418, 1429, 381, 427, 36, + /* 1280 */ 366, 206, 1386, 425, 474, 472, 51, 239, 1414, 1415, + /* 1290 */ 1418, 169, 171, 427, 3, 374, 32, 1386, 236, 1414, + /* 1300 */ 1415, 1418, 37, 471, 470, 469, 474, 468, 116, 162, + /* 1310 */ 174, 1114, 369, 225, 1414, 1415, 1418, 363, 442, 178, + /* 1320 */ 161, 1108, 1107, 14, 507, 471, 470, 469, 52, 468, + /* 1330 */ 999, 179, 53, 34, 19, 1404, 989, 15, 1086, 185, + /* 1340 */ 1085, 35, 124, 1141, 41, 16, 10, 40, 54, 1136, + /* 1350 */ 1135, 256, 1140, 1139, 257, 8, 1050, 1024, 192, 13, + /* 1360 */ 18, 432, 193, 1112, 1004, 195, 197, 55, 1342, 199, + /* 1370 */ 991, 56, 201, 60, 1005, 38, 1403, 896, 445, 270, + /* 1380 */ 204, 1007, 995, 443, 449, 452, 447, 994, 995, 893, + /* 1390 */ 450, 873, 890, 453, 455, 884, 456, 458, 882, 459, + /* 1400 */ 61, 907, 888, 887, 886, 465, 62, 63, 906, 903, + /* 1410 */ 901, 475, 885, 809, 831, 830, 829, 828, 827, 826, + /* 1420 */ 825, 824, 823, 842, 821, 820, 1196, 819, 818, 817, + /* 1430 */ 1184, 816, 815, 814, 496, 497, 500, 1183, 501, 1179, + /* 1440 */ 498, 504, 505, 1154, 992, 215, 508, 509, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 220, 185, 237, 238, 216, 216, 225, 219, 228, 229, - /* 10 */ 222, 222, 12, 13, 14, 15, 16, 179, 185, 185, - /* 20 */ 1, 2, 206, 190, 190, 12, 13, 14, 15, 16, - /* 30 */ 197, 197, 185, 252, 178, 184, 180, 199, 185, 206, - /* 40 */ 206, 225, 179, 190, 206, 194, 265, 47, 0, 208, - /* 50 */ 269, 235, 201, 206, 216, 4, 215, 216, 220, 206, - /* 60 */ 47, 245, 246, 247, 198, 249, 0, 187, 252, 69, - /* 70 */ 232, 233, 234, 235, 236, 209, 196, 77, 240, 241, - /* 80 */ 242, 265, 235, 220, 204, 269, 188, 189, 69, 251, - /* 90 */ 77, 244, 245, 246, 247, 185, 249, 49, 50, 51, - /* 100 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - /* 110 */ 62, 63, 64, 65, 66, 49, 116, 51, 199, 191, - /* 120 */ 54, 211, 20, 57, 20, 59, 207, 199, 62, 116, - /* 130 */ 12, 13, 14, 15, 16, 207, 20, 0, 138, 139, - /* 140 */ 140, 141, 142, 143, 144, 145, 146, 147, 14, 15, - /* 150 */ 16, 138, 139, 140, 141, 142, 143, 144, 145, 146, - /* 160 */ 147, 83, 84, 85, 86, 87, 88, 89, 90, 91, - /* 170 */ 92, 93, 179, 95, 96, 97, 98, 99, 100, 203, - /* 180 */ 12, 13, 185, 46, 68, 12, 13, 14, 20, 46, - /* 190 */ 22, 203, 199, 20, 179, 22, 220, 21, 125, 206, - /* 200 */ 127, 199, 151, 206, 228, 229, 38, 205, 220, 216, - /* 210 */ 34, 38, 210, 220, 199, 47, 228, 229, 225, 185, - /* 220 */ 47, 206, 191, 150, 190, 232, 233, 234, 235, 236, - /* 230 */ 199, 216, 235, 240, 241, 220, 68, 63, 207, 0, - /* 240 */ 206, 68, 245, 246, 247, 252, 249, 232, 233, 234, - /* 250 */ 235, 236, 150, 199, 22, 240, 241, 242, 265, 205, - /* 260 */ 92, 43, 269, 20, 210, 92, 150, 182, 183, 254, - /* 270 */ 38, 185, 104, 199, 199, 260, 261, 104, 12, 13, - /* 280 */ 206, 206, 108, 109, 35, 46, 20, 179, 22, 171, - /* 290 */ 172, 120, 148, 149, 126, 184, 128, 129, 130, 126, - /* 300 */ 132, 128, 129, 130, 38, 132, 57, 199, 234, 234, - /* 310 */ 61, 225, 201, 47, 206, 20, 252, 22, 150, 179, - /* 320 */ 71, 199, 73, 74, 216, 76, 155, 156, 220, 265, - /* 330 */ 179, 82, 210, 269, 68, 40, 150, 20, 252, 199, - /* 340 */ 232, 233, 234, 235, 236, 46, 206, 185, 240, 241, - /* 350 */ 242, 265, 190, 12, 13, 269, 216, 185, 92, 20, - /* 360 */ 220, 20, 190, 22, 79, 122, 179, 149, 206, 261, - /* 370 */ 104, 220, 232, 233, 234, 235, 236, 199, 206, 38, - /* 380 */ 240, 241, 242, 205, 179, 68, 199, 192, 210, 20, - /* 390 */ 195, 251, 126, 206, 128, 129, 130, 185, 132, 72, - /* 400 */ 191, 179, 75, 216, 12, 13, 14, 220, 199, 68, - /* 410 */ 185, 4, 20, 81, 22, 190, 207, 187, 206, 232, - /* 420 */ 233, 234, 235, 236, 179, 220, 19, 240, 241, 242, - /* 430 */ 38, 206, 116, 92, 204, 14, 12, 13, 251, 81, - /* 440 */ 33, 20, 220, 36, 20, 104, 22, 235, 41, 179, - /* 450 */ 230, 44, 179, 179, 138, 199, 20, 245, 246, 247, - /* 460 */ 68, 249, 38, 147, 20, 220, 210, 126, 248, 128, - /* 470 */ 129, 130, 199, 132, 67, 12, 13, 70, 128, 206, - /* 480 */ 0, 230, 185, 20, 92, 22, 179, 190, 206, 216, - /* 490 */ 220, 150, 68, 220, 220, 213, 104, 176, 225, 248, - /* 500 */ 3, 38, 170, 206, 179, 232, 233, 234, 235, 159, - /* 510 */ 160, 161, 162, 163, 230, 57, 92, 179, 126, 61, - /* 520 */ 128, 129, 130, 179, 132, 252, 168, 220, 104, 20, - /* 530 */ 179, 68, 248, 1, 2, 20, 27, 57, 265, 30, - /* 540 */ 82, 61, 269, 179, 72, 220, 225, 75, 39, 200, - /* 550 */ 126, 47, 128, 129, 130, 92, 132, 72, 220, 38, - /* 560 */ 75, 179, 82, 199, 220, 2, 179, 104, 179, 189, - /* 570 */ 206, 220, 200, 252, 179, 12, 13, 14, 15, 16, - /* 580 */ 216, 101, 102, 103, 220, 105, 265, 174, 175, 126, - /* 590 */ 269, 128, 129, 130, 199, 132, 232, 233, 234, 235, - /* 600 */ 236, 206, 220, 72, 240, 241, 75, 220, 200, 220, - /* 610 */ 179, 216, 179, 179, 69, 220, 107, 179, 179, 110, - /* 620 */ 111, 112, 113, 114, 179, 104, 81, 232, 233, 234, - /* 630 */ 235, 236, 128, 199, 69, 240, 241, 122, 199, 49, - /* 640 */ 206, 51, 0, 200, 54, 206, 81, 57, 0, 59, - /* 650 */ 216, 220, 62, 220, 220, 216, 179, 0, 220, 220, - /* 660 */ 0, 38, 179, 166, 22, 220, 232, 233, 234, 235, - /* 670 */ 22, 232, 233, 234, 235, 236, 199, 272, 200, 180, - /* 680 */ 241, 21, 69, 206, 24, 25, 26, 27, 28, 29, - /* 690 */ 30, 31, 32, 216, 81, 263, 179, 220, 0, 22, - /* 700 */ 223, 179, 209, 220, 270, 271, 257, 69, 182, 232, - /* 710 */ 233, 234, 235, 68, 57, 38, 199, 231, 61, 81, - /* 720 */ 22, 199, 69, 206, 69, 80, 250, 104, 206, 199, - /* 730 */ 266, 124, 69, 216, 81, 69, 81, 220, 216, 82, - /* 740 */ 223, 69, 220, 179, 81, 253, 226, 81, 20, 232, - /* 750 */ 233, 234, 235, 81, 232, 233, 234, 235, 101, 102, - /* 760 */ 103, 185, 105, 199, 115, 2, 214, 116, 212, 92, - /* 770 */ 206, 69, 212, 179, 185, 12, 13, 14, 15, 16, - /* 780 */ 216, 104, 69, 81, 220, 20, 264, 187, 12, 13, - /* 790 */ 14, 15, 16, 199, 81, 179, 232, 233, 234, 235, - /* 800 */ 206, 224, 206, 126, 69, 128, 129, 69, 20, 69, - /* 810 */ 216, 69, 69, 187, 220, 199, 81, 223, 217, 81, - /* 820 */ 19, 81, 206, 81, 81, 185, 232, 233, 234, 235, - /* 830 */ 187, 187, 216, 20, 33, 271, 220, 36, 199, 223, - /* 840 */ 181, 224, 181, 42, 217, 44, 68, 185, 232, 233, - /* 850 */ 234, 235, 0, 199, 21, 199, 78, 24, 25, 26, - /* 860 */ 27, 28, 29, 30, 31, 32, 199, 199, 67, 199, - /* 870 */ 179, 70, 199, 199, 199, 199, 24, 25, 26, 27, - /* 880 */ 28, 29, 30, 31, 32, 199, 206, 184, 184, 131, - /* 890 */ 199, 133, 134, 135, 136, 137, 20, 206, 262, 158, - /* 900 */ 18, 179, 101, 157, 221, 23, 129, 216, 220, 231, - /* 910 */ 221, 220, 262, 220, 220, 165, 258, 35, 164, 118, - /* 920 */ 153, 199, 121, 232, 233, 234, 235, 45, 206, 149, - /* 930 */ 259, 179, 12, 13, 14, 15, 16, 256, 216, 152, - /* 940 */ 255, 20, 220, 206, 230, 115, 173, 68, 243, 167, - /* 950 */ 169, 199, 273, 179, 232, 233, 234, 235, 206, 239, - /* 960 */ 268, 119, 267, 206, 195, 221, 221, 220, 216, 220, - /* 970 */ 217, 220, 220, 199, 218, 179, 184, 184, 206, 68, - /* 980 */ 206, 202, 185, 184, 232, 233, 234, 235, 106, 69, - /* 990 */ 216, 181, 186, 227, 220, 199, 193, 179, 193, 177, - /* 1000 */ 0, 104, 206, 126, 0, 123, 232, 233, 234, 235, - /* 1010 */ 80, 0, 216, 0, 115, 0, 220, 199, 0, 179, - /* 1020 */ 0, 0, 0, 0, 206, 22, 0, 0, 232, 233, - /* 1030 */ 234, 235, 150, 0, 216, 0, 0, 0, 220, 199, - /* 1040 */ 0, 179, 43, 0, 48, 0, 206, 0, 38, 43, - /* 1050 */ 232, 233, 234, 235, 0, 36, 216, 0, 0, 0, - /* 1060 */ 220, 199, 77, 179, 75, 0, 38, 38, 206, 38, - /* 1070 */ 22, 0, 232, 233, 234, 235, 38, 38, 216, 38, - /* 1080 */ 38, 0, 220, 199, 38, 22, 22, 179, 39, 0, - /* 1090 */ 206, 22, 0, 38, 232, 233, 234, 235, 22, 0, - /* 1100 */ 216, 22, 20, 0, 220, 0, 122, 199, 117, 43, - /* 1110 */ 154, 179, 0, 81, 206, 81, 232, 233, 234, 235, - /* 1120 */ 12, 13, 69, 154, 216, 81, 148, 154, 220, 68, - /* 1130 */ 22, 199, 81, 179, 4, 38, 69, 69, 206, 69, - /* 1140 */ 232, 233, 234, 235, 69, 68, 38, 38, 216, 38, - /* 1150 */ 2, 68, 220, 199, 68, 179, 68, 38, 80, 69, - /* 1160 */ 206, 81, 38, 69, 232, 233, 234, 235, 81, 38, - /* 1170 */ 216, 80, 68, 80, 220, 199, 81, 179, 128, 69, - /* 1180 */ 80, 68, 206, 69, 69, 68, 232, 233, 234, 235, - /* 1190 */ 68, 68, 216, 120, 0, 43, 220, 199, 78, 22, - /* 1200 */ 92, 117, 68, 68, 206, 80, 80, 79, 232, 233, - /* 1210 */ 234, 235, 104, 69, 216, 68, 33, 38, 220, 36, - /* 1220 */ 38, 94, 69, 38, 68, 42, 69, 44, 38, 68, - /* 1230 */ 232, 233, 234, 235, 126, 69, 128, 129, 38, 68, - /* 1240 */ 38, 69, 68, 94, 94, 94, 22, 82, 68, 38, - /* 1250 */ 67, 38, 68, 70, 68, 38, 22, 48, 104, 47, - /* 1260 */ 22, 38, 22, 38, 38, 38, 38, 38, 38, 38, - /* 1270 */ 38, 38, 0, 38, 38, 38, 0, 38, 0, 38, - /* 1280 */ 38, 38, 36, 38, 37, 0, 22, 43, 21, 274, - /* 1290 */ 22, 22, 21, 20, 274, 274, 274, 274, 274, 274, - /* 1300 */ 117, 274, 274, 274, 121, 274, 274, 274, 274, 274, - /* 1310 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1320 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1330 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1340 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1350 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1360 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1370 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1380 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1390 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1400 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1410 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1420 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1430 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1440 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1450 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, - /* 1460 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 0 */ 226, 210, 210, 217, 210, 226, 204, 216, 216, 210, + /* 10 */ 216, 225, 12, 13, 223, 210, 229, 223, 2, 233, + /* 20 */ 20, 201, 22, 232, 232, 229, 232, 225, 12, 13, + /* 30 */ 14, 15, 16, 246, 232, 210, 237, 232, 38, 224, + /* 40 */ 210, 216, 246, 20, 242, 258, 259, 47, 246, 225, + /* 50 */ 235, 12, 13, 14, 258, 259, 232, 232, 20, 20, + /* 60 */ 22, 22, 232, 210, 262, 263, 264, 265, 266, 69, + /* 70 */ 265, 251, 270, 271, 272, 204, 225, 38, 40, 274, + /* 80 */ 275, 276, 277, 225, 279, 232, 47, 236, 264, 231, + /* 90 */ 12, 13, 92, 291, 236, 265, 225, 204, 20, 63, + /* 100 */ 22, 20, 282, 232, 104, 275, 276, 277, 69, 279, + /* 110 */ 2, 267, 268, 242, 246, 295, 38, 246, 265, 299, + /* 120 */ 12, 13, 14, 15, 16, 47, 258, 259, 275, 276, + /* 130 */ 277, 92, 279, 262, 263, 264, 265, 266, 138, 246, + /* 140 */ 20, 270, 271, 104, 108, 109, 204, 69, 12, 13, + /* 150 */ 14, 15, 16, 130, 209, 155, 156, 157, 158, 159, + /* 160 */ 160, 161, 162, 163, 164, 220, 18, 225, 20, 69, + /* 170 */ 92, 137, 227, 139, 232, 27, 176, 138, 30, 20, + /* 180 */ 242, 81, 104, 245, 242, 225, 248, 39, 246, 69, + /* 190 */ 204, 128, 232, 44, 155, 156, 157, 158, 159, 160, + /* 200 */ 161, 162, 163, 164, 262, 263, 264, 265, 266, 210, + /* 210 */ 176, 225, 270, 271, 272, 216, 138, 68, 232, 225, + /* 220 */ 71, 210, 232, 281, 264, 231, 20, 216, 242, 239, + /* 230 */ 236, 232, 246, 155, 156, 157, 158, 159, 160, 161, + /* 240 */ 162, 163, 164, 232, 181, 182, 12, 13, 262, 263, + /* 250 */ 264, 265, 266, 69, 20, 107, 22, 271, 110, 111, + /* 260 */ 112, 113, 114, 79, 116, 117, 118, 119, 120, 121, + /* 270 */ 122, 123, 38, 21, 155, 69, 24, 25, 26, 27, + /* 280 */ 28, 29, 30, 31, 32, 12, 13, 14, 0, 49, + /* 290 */ 225, 51, 251, 20, 54, 22, 176, 57, 233, 59, + /* 300 */ 60, 176, 62, 69, 185, 186, 187, 188, 189, 21, + /* 310 */ 43, 38, 24, 25, 26, 27, 28, 29, 30, 31, + /* 320 */ 32, 210, 225, 282, 12, 13, 92, 216, 231, 207, + /* 330 */ 208, 210, 20, 236, 22, 176, 295, 216, 104, 213, + /* 340 */ 299, 215, 69, 232, 234, 12, 13, 14, 15, 16, + /* 350 */ 38, 241, 242, 232, 83, 84, 85, 86, 87, 88, + /* 360 */ 89, 90, 91, 92, 93, 92, 95, 96, 97, 98, + /* 370 */ 99, 100, 138, 14, 15, 16, 203, 104, 205, 218, + /* 380 */ 204, 69, 221, 0, 12, 13, 14, 15, 16, 155, + /* 390 */ 156, 157, 158, 159, 160, 161, 162, 163, 164, 210, + /* 400 */ 282, 225, 0, 70, 92, 216, 46, 210, 232, 0, + /* 410 */ 176, 138, 204, 295, 242, 20, 104, 299, 242, 36, + /* 420 */ 248, 232, 246, 12, 13, 14, 15, 16, 155, 156, + /* 430 */ 157, 158, 159, 160, 161, 162, 163, 164, 262, 263, + /* 440 */ 264, 265, 175, 12, 13, 14, 15, 16, 251, 217, + /* 450 */ 138, 49, 20, 51, 246, 46, 54, 225, 47, 57, + /* 460 */ 35, 59, 60, 204, 62, 233, 204, 155, 156, 157, + /* 470 */ 158, 159, 160, 161, 162, 163, 164, 301, 47, 282, + /* 480 */ 12, 13, 57, 1, 2, 20, 61, 225, 20, 78, + /* 490 */ 22, 0, 295, 212, 232, 134, 299, 72, 251, 74, + /* 500 */ 75, 70, 77, 131, 242, 246, 38, 82, 246, 78, + /* 510 */ 149, 230, 204, 251, 204, 24, 25, 26, 27, 28, + /* 520 */ 29, 30, 31, 32, 262, 263, 264, 265, 266, 282, + /* 530 */ 212, 217, 270, 271, 57, 124, 3, 69, 61, 225, + /* 540 */ 222, 4, 295, 204, 282, 210, 299, 233, 230, 20, + /* 550 */ 124, 216, 70, 142, 246, 124, 246, 295, 46, 82, + /* 560 */ 92, 299, 130, 225, 210, 210, 204, 232, 142, 197, + /* 570 */ 216, 216, 104, 142, 236, 204, 165, 166, 167, 168, + /* 580 */ 169, 170, 171, 172, 173, 246, 232, 232, 20, 260, + /* 590 */ 0, 165, 204, 204, 204, 204, 165, 166, 167, 168, + /* 600 */ 169, 170, 171, 172, 173, 0, 138, 278, 246, 14, + /* 610 */ 204, 33, 22, 226, 36, 20, 18, 246, 174, 175, + /* 620 */ 42, 23, 44, 155, 156, 157, 158, 159, 160, 161, + /* 630 */ 162, 163, 164, 35, 246, 246, 246, 246, 204, 204, + /* 640 */ 204, 204, 204, 45, 204, 204, 68, 1, 2, 71, + /* 650 */ 0, 204, 246, 67, 49, 50, 51, 52, 53, 54, + /* 660 */ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + /* 670 */ 65, 66, 225, 260, 260, 67, 209, 80, 70, 232, + /* 680 */ 246, 246, 246, 246, 246, 22, 246, 246, 67, 242, + /* 690 */ 47, 278, 278, 246, 227, 73, 46, 73, 76, 204, + /* 700 */ 76, 38, 21, 125, 106, 127, 38, 129, 254, 262, + /* 710 */ 263, 264, 265, 266, 177, 34, 226, 270, 271, 272, + /* 720 */ 225, 199, 200, 226, 146, 192, 226, 232, 281, 131, + /* 730 */ 132, 133, 73, 135, 0, 76, 67, 242, 140, 70, + /* 740 */ 73, 246, 204, 76, 205, 215, 148, 0, 150, 293, + /* 750 */ 152, 153, 154, 302, 235, 207, 22, 262, 263, 264, + /* 760 */ 265, 266, 287, 225, 261, 270, 271, 272, 67, 22, + /* 770 */ 232, 70, 104, 67, 176, 38, 70, 225, 204, 284, + /* 780 */ 242, 280, 196, 296, 246, 290, 291, 67, 67, 67, + /* 790 */ 70, 70, 70, 67, 283, 20, 70, 210, 155, 225, + /* 800 */ 262, 263, 264, 265, 266, 204, 232, 36, 270, 271, + /* 810 */ 272, 67, 257, 214, 70, 194, 242, 38, 67, 281, + /* 820 */ 246, 70, 136, 252, 210, 251, 225, 210, 19, 210, + /* 830 */ 115, 67, 240, 232, 70, 124, 262, 263, 264, 265, + /* 840 */ 238, 104, 33, 242, 238, 36, 210, 246, 20, 232, + /* 850 */ 256, 42, 67, 44, 67, 70, 282, 70, 67, 67, + /* 860 */ 204, 70, 70, 262, 263, 264, 265, 266, 251, 295, + /* 870 */ 242, 270, 271, 299, 20, 250, 212, 68, 20, 232, + /* 880 */ 71, 225, 265, 67, 67, 243, 70, 70, 232, 212, + /* 890 */ 212, 212, 275, 276, 277, 210, 279, 20, 242, 282, + /* 900 */ 206, 225, 246, 210, 204, 225, 232, 225, 225, 204, + /* 910 */ 101, 256, 295, 225, 225, 225, 299, 225, 262, 263, + /* 920 */ 264, 265, 225, 225, 225, 225, 214, 214, 145, 206, + /* 930 */ 225, 20, 232, 242, 209, 126, 232, 232, 129, 255, + /* 940 */ 209, 184, 242, 292, 183, 250, 246, 242, 261, 249, + /* 950 */ 243, 246, 156, 144, 249, 146, 300, 301, 292, 191, + /* 960 */ 289, 247, 262, 263, 264, 265, 204, 262, 263, 264, + /* 970 */ 265, 204, 190, 246, 179, 247, 246, 178, 246, 175, + /* 980 */ 232, 20, 115, 273, 288, 195, 198, 225, 286, 260, + /* 990 */ 193, 246, 225, 285, 232, 69, 247, 247, 246, 232, + /* 1000 */ 246, 127, 269, 244, 242, 232, 303, 204, 246, 242, + /* 1010 */ 209, 209, 243, 246, 298, 204, 249, 69, 232, 221, + /* 1020 */ 214, 297, 228, 210, 262, 263, 264, 265, 225, 262, + /* 1030 */ 263, 264, 265, 214, 209, 232, 225, 206, 211, 219, + /* 1040 */ 219, 204, 253, 232, 202, 242, 0, 0, 60, 246, + /* 1050 */ 204, 38, 249, 242, 0, 151, 294, 246, 38, 38, + /* 1060 */ 38, 151, 225, 0, 38, 262, 263, 264, 265, 232, + /* 1070 */ 38, 225, 151, 262, 263, 264, 265, 204, 232, 242, + /* 1080 */ 0, 38, 0, 246, 0, 204, 38, 69, 242, 142, + /* 1090 */ 141, 104, 246, 138, 0, 0, 134, 0, 225, 262, + /* 1100 */ 263, 264, 265, 50, 0, 232, 225, 0, 262, 263, + /* 1110 */ 264, 265, 81, 232, 0, 242, 0, 0, 0, 246, + /* 1120 */ 0, 204, 0, 242, 0, 0, 204, 246, 0, 0, + /* 1130 */ 0, 0, 115, 0, 0, 262, 263, 264, 265, 0, + /* 1140 */ 0, 0, 225, 262, 263, 264, 265, 225, 0, 232, + /* 1150 */ 0, 0, 0, 0, 232, 0, 0, 22, 0, 242, + /* 1160 */ 0, 0, 204, 246, 242, 0, 43, 204, 246, 48, + /* 1170 */ 0, 0, 0, 204, 38, 43, 0, 0, 36, 262, + /* 1180 */ 263, 264, 265, 225, 262, 263, 264, 265, 225, 0, + /* 1190 */ 232, 78, 38, 67, 225, 232, 22, 0, 0, 0, + /* 1200 */ 242, 232, 0, 76, 246, 242, 38, 38, 22, 246, + /* 1210 */ 22, 242, 39, 38, 204, 246, 38, 38, 38, 0, + /* 1220 */ 262, 263, 264, 265, 0, 262, 263, 264, 265, 204, + /* 1230 */ 22, 262, 263, 264, 265, 225, 0, 22, 12, 13, + /* 1240 */ 204, 38, 232, 0, 22, 20, 0, 147, 22, 130, + /* 1250 */ 225, 38, 242, 0, 22, 204, 246, 232, 143, 57, + /* 1260 */ 22, 225, 0, 61, 38, 127, 0, 242, 232, 0, + /* 1270 */ 38, 246, 262, 263, 264, 265, 225, 130, 242, 130, + /* 1280 */ 4, 57, 246, 232, 82, 61, 69, 262, 263, 264, + /* 1290 */ 265, 43, 125, 242, 67, 19, 67, 246, 262, 263, + /* 1300 */ 264, 265, 67, 101, 102, 103, 82, 105, 69, 33, + /* 1310 */ 70, 70, 36, 262, 263, 264, 265, 41, 92, 69, + /* 1320 */ 44, 70, 70, 180, 92, 101, 102, 103, 69, 105, + /* 1330 */ 104, 67, 69, 174, 67, 81, 104, 180, 70, 81, + /* 1340 */ 70, 67, 81, 70, 68, 67, 180, 71, 4, 38, + /* 1350 */ 38, 38, 38, 38, 38, 2, 155, 70, 81, 69, + /* 1360 */ 69, 128, 70, 70, 138, 69, 69, 69, 0, 43, + /* 1370 */ 138, 69, 125, 79, 22, 69, 81, 70, 38, 38, + /* 1380 */ 81, 155, 156, 80, 38, 38, 69, 155, 156, 70, + /* 1390 */ 69, 22, 70, 69, 38, 70, 69, 38, 70, 69, + /* 1400 */ 69, 38, 94, 94, 94, 82, 69, 69, 104, 38, + /* 1410 */ 22, 47, 94, 48, 22, 38, 38, 38, 38, 38, + /* 1420 */ 38, 38, 22, 38, 38, 38, 0, 38, 38, 38, + /* 1430 */ 0, 38, 38, 38, 38, 36, 38, 0, 37, 0, + /* 1440 */ 43, 22, 21, 304, 22, 22, 21, 20, 304, 304, + /* 1450 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1460 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1470 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1480 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1490 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1500 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1510 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1520 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1530 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1540 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1550 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1560 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1570 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1580 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1590 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1600 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1610 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1620 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1630 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1640 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, }; -#define YY_SHIFT_COUNT (437) +#define YY_SHIFT_COUNT (510) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1285) +#define YY_SHIFT_MAX (1439) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 882, 168, 173, 266, 266, 266, 266, 341, 266, 266, - /* 10 */ 424, 463, 116, 392, 424, 424, 424, 424, 424, 424, - /* 20 */ 424, 424, 424, 424, 424, 424, 424, 424, 424, 424, - /* 30 */ 424, 424, 424, 317, 317, 317, 102, 1108, 1108, 73, - /* 40 */ 104, 104, 1108, 104, 104, 143, 339, 369, 369, 186, - /* 50 */ 436, 339, 104, 104, 339, 104, 339, 436, 339, 339, - /* 60 */ 104, 299, 0, 13, 13, 509, 833, 249, 677, 677, - /* 70 */ 677, 677, 677, 677, 677, 677, 677, 677, 677, 677, - /* 80 */ 677, 677, 677, 677, 677, 677, 677, 677, 590, 295, - /* 90 */ 137, 243, 243, 243, 239, 444, 436, 339, 339, 339, - /* 100 */ 285, 78, 78, 78, 78, 78, 660, 66, 118, 350, - /* 110 */ 458, 171, 232, 515, 144, 218, 144, 421, 497, 51, - /* 120 */ 607, 728, 649, 651, 651, 728, 765, 143, 444, 788, - /* 130 */ 143, 143, 728, 143, 813, 339, 339, 339, 339, 339, - /* 140 */ 339, 339, 339, 339, 339, 339, 728, 813, 765, 299, - /* 150 */ 444, 788, 299, 876, 741, 746, 777, 741, 746, 777, - /* 160 */ 777, 750, 754, 767, 787, 780, 444, 921, 830, 773, - /* 170 */ 781, 782, 879, 339, 746, 777, 777, 746, 777, 842, - /* 180 */ 444, 788, 299, 285, 299, 444, 911, 728, 299, 813, - /* 190 */ 1305, 1305, 1305, 1305, 1305, 48, 852, 801, 1183, 407, - /* 200 */ 480, 657, 563, 763, 758, 920, 776, 776, 776, 776, - /* 210 */ 776, 776, 776, 174, 19, 316, 134, 134, 134, 134, - /* 220 */ 327, 472, 485, 531, 642, 648, 698, 176, 545, 565, - /* 230 */ 613, 532, 413, 358, 332, 638, 504, 653, 645, 655, - /* 240 */ 663, 666, 672, 702, 521, 623, 713, 735, 738, 740, - /* 250 */ 742, 743, 778, 1000, 897, 877, 1004, 930, 1011, 1013, - /* 260 */ 899, 1015, 1018, 1020, 1021, 1022, 1023, 1003, 1026, 1027, - /* 270 */ 1033, 1035, 1036, 1037, 1040, 999, 1043, 996, 1045, 1047, - /* 280 */ 1010, 1019, 1006, 1054, 1057, 1058, 1059, 985, 989, 1028, - /* 290 */ 1029, 1048, 1065, 1031, 1038, 1039, 1041, 1042, 1046, 1071, - /* 300 */ 1063, 1081, 1064, 1049, 1089, 1069, 1055, 1092, 1076, 1099, - /* 310 */ 1079, 1082, 1103, 1105, 984, 1112, 1061, 1066, 991, 1032, - /* 320 */ 1034, 956, 1053, 1044, 1067, 1077, 1083, 1068, 1086, 1070, - /* 330 */ 1051, 1078, 1088, 1080, 969, 1075, 1090, 1091, 978, 1087, - /* 340 */ 1093, 1094, 1095, 973, 1130, 1097, 1109, 1111, 1119, 1124, - /* 350 */ 1131, 1148, 1050, 1100, 1110, 1104, 1113, 1114, 1115, 1117, - /* 360 */ 1122, 1073, 1123, 1194, 1152, 1084, 1134, 1120, 1125, 1126, - /* 370 */ 1177, 1135, 1128, 1144, 1179, 1182, 1147, 1153, 1185, 1156, - /* 380 */ 1157, 1190, 1161, 1166, 1200, 1171, 1172, 1202, 1174, 1127, - /* 390 */ 1149, 1150, 1151, 1224, 1165, 1180, 1211, 1154, 1184, 1186, - /* 400 */ 1213, 1217, 1234, 1209, 1212, 1238, 1223, 1225, 1226, 1227, - /* 410 */ 1228, 1229, 1230, 1240, 1231, 1232, 1233, 1235, 1236, 1237, - /* 420 */ 1239, 1241, 1242, 1272, 1243, 1246, 1244, 1276, 1245, 1247, - /* 430 */ 1278, 1285, 1264, 1267, 1268, 1269, 1271, 1273, + /* 0 */ 598, 0, 39, 78, 78, 78, 78, 234, 78, 78, + /* 10 */ 312, 468, 120, 273, 312, 312, 312, 312, 312, 312, + /* 20 */ 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + /* 30 */ 312, 312, 312, 206, 206, 206, 159, 1226, 1226, 34, + /* 40 */ 81, 81, 125, 1226, 81, 81, 81, 81, 81, 81, + /* 50 */ 360, 395, 465, 465, 125, 529, 395, 81, 81, 395, + /* 60 */ 81, 395, 529, 395, 395, 81, 512, 148, 431, 411, + /* 70 */ 411, 252, 425, 1232, 240, 1232, 1232, 1232, 1232, 1232, + /* 80 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, + /* 90 */ 1232, 1232, 1232, 1232, 38, 409, 23, 23, 23, 650, + /* 100 */ 568, 529, 395, 395, 395, 597, 271, 271, 271, 271, + /* 110 */ 271, 271, 809, 288, 402, 372, 119, 477, 63, 663, + /* 120 */ 432, 444, 267, 444, 595, 533, 537, 775, 771, 779, + /* 130 */ 686, 775, 775, 715, 711, 711, 775, 828, 529, 854, + /* 140 */ 360, 568, 858, 360, 360, 775, 360, 877, 395, 395, + /* 150 */ 395, 395, 395, 395, 395, 395, 395, 395, 395, 779, + /* 160 */ 779, 775, 877, 568, 828, 783, 529, 854, 512, 568, + /* 170 */ 858, 512, 911, 757, 761, 796, 757, 761, 796, 796, + /* 180 */ 768, 782, 795, 799, 804, 568, 961, 867, 788, 790, + /* 190 */ 797, 926, 395, 761, 796, 796, 761, 796, 874, 568, + /* 200 */ 858, 512, 597, 512, 568, 948, 779, 779, 775, 512, + /* 210 */ 877, 1448, 1448, 1448, 1448, 1448, 605, 578, 491, 1276, + /* 220 */ 1202, 1224, 16, 108, 333, 136, 136, 136, 136, 136, + /* 230 */ 136, 136, 149, 36, 482, 426, 359, 359, 359, 359, + /* 240 */ 383, 361, 608, 622, 624, 659, 667, 590, 734, 747, + /* 250 */ 681, 669, 701, 706, 646, 522, 621, 586, 720, 643, + /* 260 */ 721, 100, 722, 726, 744, 751, 764, 668, 737, 785, + /* 270 */ 787, 791, 792, 816, 817, 184, 1046, 1047, 988, 1054, + /* 280 */ 1013, 904, 1020, 1021, 1022, 910, 1063, 1026, 1032, 921, + /* 290 */ 1080, 1043, 1082, 1048, 1084, 1018, 947, 949, 987, 955, + /* 300 */ 1094, 1095, 1053, 962, 1097, 1104, 1031, 1107, 1114, 1116, + /* 310 */ 1117, 1118, 1120, 1122, 1124, 1125, 1128, 1129, 1130, 1131, + /* 320 */ 1017, 1133, 1134, 1139, 1140, 1141, 1148, 1135, 1150, 1151, + /* 330 */ 1152, 1153, 1155, 1156, 1158, 1160, 1161, 1123, 1165, 1121, + /* 340 */ 1170, 1171, 1136, 1142, 1132, 1172, 1176, 1177, 1189, 1113, + /* 350 */ 1127, 1154, 1126, 1174, 1197, 1168, 1169, 1175, 1178, 1126, + /* 360 */ 1179, 1180, 1198, 1186, 1199, 1188, 1173, 1219, 1208, 1203, + /* 370 */ 1236, 1215, 1243, 1222, 1225, 1246, 1119, 1100, 1213, 1253, + /* 380 */ 1115, 1238, 1147, 1138, 1262, 1266, 1149, 1269, 1217, 1248, + /* 390 */ 1167, 1227, 1229, 1143, 1240, 1235, 1241, 1239, 1250, 1251, + /* 400 */ 1259, 1252, 1264, 1254, 1263, 1267, 1157, 1268, 1270, 1258, + /* 410 */ 1159, 1274, 1261, 1273, 1278, 1166, 1344, 1311, 1312, 1313, + /* 420 */ 1314, 1315, 1316, 1353, 1201, 1277, 1287, 1290, 1291, 1292, + /* 430 */ 1293, 1296, 1297, 1233, 1298, 1368, 1326, 1247, 1302, 1294, + /* 440 */ 1295, 1299, 1352, 1306, 1303, 1307, 1340, 1341, 1317, 1319, + /* 450 */ 1346, 1321, 1322, 1347, 1324, 1325, 1356, 1327, 1328, 1359, + /* 460 */ 1330, 1308, 1309, 1310, 1318, 1369, 1323, 1331, 1363, 1304, + /* 470 */ 1337, 1338, 1371, 1126, 1388, 1365, 1364, 1392, 1377, 1378, + /* 480 */ 1379, 1380, 1381, 1382, 1383, 1400, 1385, 1126, 1386, 1387, + /* 490 */ 1389, 1390, 1391, 1393, 1394, 1395, 1426, 1396, 1399, 1397, + /* 500 */ 1430, 1398, 1401, 1437, 1439, 1419, 1421, 1422, 1423, 1425, + /* 510 */ 1427, }; -#define YY_REDUCE_COUNT (194) -#define YY_REDUCE_MIN (-235) -#define YY_REDUCE_MAX (998) +#define YY_REDUCE_COUNT (215) +#define YY_REDUCE_MIN (-226) +#define YY_REDUCE_MAX (1051) static const short yy_reduce_ofst[] = { - /* 0 */ 321, -7, 15, 108, -162, 140, 187, 273, 364, 395, - /* 10 */ 434, 439, -184, 477, 517, 522, 564, 594, 616, 691, - /* 20 */ 722, 752, 774, 796, 818, 840, 862, 884, 908, 932, - /* 30 */ 954, 976, 998, -153, -3, 212, 86, -24, -12, -219, - /* 40 */ -167, -166, -220, -147, 34, -120, 2, 74, 75, 64, - /* 50 */ -212, -72, 162, 172, 54, 225, 31, -159, 178, 209, - /* 60 */ 297, -149, -235, -235, -235, -90, -144, -134, -137, 151, - /* 70 */ 205, 222, 245, 270, 274, 307, 325, 338, 344, 351, - /* 80 */ 382, 387, 389, 431, 433, 438, 445, 483, -102, 85, - /* 90 */ 230, 220, 251, 284, 111, 282, -211, -81, 122, 256, - /* 100 */ 195, 349, 372, 408, 443, 478, 499, 380, 405, 432, - /* 110 */ 493, 449, 526, 486, 476, 476, 476, 530, 464, 492, - /* 120 */ 520, 576, 552, 556, 560, 589, 577, 600, 596, 601, - /* 130 */ 626, 643, 640, 644, 659, 639, 654, 656, 667, 668, - /* 140 */ 670, 673, 674, 675, 676, 686, 662, 661, 617, 703, - /* 150 */ 680, 627, 704, 678, 636, 683, 688, 650, 689, 693, - /* 160 */ 694, 671, 658, 681, 685, 476, 737, 714, 705, 679, - /* 170 */ 692, 695, 720, 530, 744, 747, 749, 745, 751, 756, - /* 180 */ 757, 753, 792, 769, 793, 772, 779, 797, 799, 810, - /* 190 */ 766, 803, 805, 806, 822, + /* 0 */ -180, 262, 495, -198, -58, 447, 538, 574, -129, 601, + /* 10 */ 656, -14, 617, 700, 705, 762, 176, 767, 803, 811, + /* 20 */ 837, 846, 873, 881, 917, 922, 958, 963, 969, 1010, + /* 30 */ 1025, 1036, 1051, -195, -170, -147, 197, -213, -204, 41, + /* 40 */ -209, -206, 247, -132, -208, -175, -1, 11, 111, 121, + /* 50 */ 318, -142, -176, -40, 118, -62, -214, 189, 335, -6, + /* 60 */ 354, 232, 110, 97, 314, 355, -55, -201, -156, -156, + /* 70 */ -156, 173, -185, -107, 126, 208, 259, 308, 310, 339, + /* 80 */ 362, 371, 388, 389, 390, 391, 406, 434, 435, 436, + /* 90 */ 437, 438, 440, 441, 122, 281, 329, 413, 414, 467, + /* 100 */ -10, 172, 65, -149, 338, 161, -226, -221, 387, 490, + /* 110 */ 497, 500, 454, 539, 530, 451, 456, 519, 475, 548, + /* 120 */ 503, 501, 501, 501, 552, 487, 511, 587, 555, 599, + /* 130 */ 571, 614, 619, 592, 602, 606, 636, 594, 628, 625, + /* 140 */ 664, 647, 642, 677, 678, 685, 679, 694, 676, 680, + /* 150 */ 682, 683, 688, 689, 690, 692, 697, 698, 699, 712, + /* 160 */ 713, 693, 723, 674, 655, 684, 691, 695, 725, 704, + /* 170 */ 707, 731, 687, 651, 714, 727, 666, 728, 730, 732, + /* 180 */ 671, 696, 702, 708, 501, 748, 729, 710, 703, 716, + /* 190 */ 724, 733, 552, 749, 745, 752, 750, 754, 759, 773, + /* 200 */ 769, 801, 798, 802, 786, 794, 806, 819, 813, 825, + /* 210 */ 831, 789, 820, 821, 827, 842, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 10 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 20 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 30 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 40 */ 1038, 1038, 1038, 1038, 1038, 1091, 1038, 1038, 1038, 1038, - /* 50 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 60 */ 1038, 1089, 1038, 1314, 1038, 1204, 1038, 1038, 1038, 1038, - /* 70 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 80 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 90 */ 1091, 1325, 1325, 1325, 1089, 1038, 1038, 1038, 1038, 1038, - /* 100 */ 1173, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1389, 1038, - /* 110 */ 1126, 1349, 1038, 1341, 1317, 1331, 1318, 1038, 1374, 1334, - /* 120 */ 1227, 1038, 1209, 1206, 1206, 1038, 1038, 1091, 1038, 1038, - /* 130 */ 1091, 1091, 1038, 1091, 1038, 1038, 1038, 1038, 1038, 1038, - /* 140 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1089, - /* 150 */ 1038, 1038, 1089, 1038, 1356, 1354, 1038, 1356, 1354, 1038, - /* 160 */ 1038, 1368, 1364, 1347, 1345, 1331, 1038, 1038, 1038, 1392, - /* 170 */ 1380, 1376, 1038, 1038, 1354, 1038, 1038, 1354, 1038, 1217, - /* 180 */ 1038, 1038, 1089, 1038, 1089, 1038, 1142, 1038, 1089, 1038, - /* 190 */ 1229, 1176, 1176, 1092, 1043, 1038, 1038, 1038, 1038, 1038, - /* 200 */ 1038, 1038, 1038, 1038, 1038, 1038, 1279, 1367, 1366, 1278, - /* 210 */ 1291, 1290, 1289, 1038, 1038, 1038, 1273, 1274, 1272, 1271, - /* 220 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 230 */ 1038, 1315, 1038, 1377, 1381, 1038, 1038, 1038, 1257, 1038, - /* 240 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 250 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 260 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 270 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 280 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 290 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 300 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 310 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1338, - /* 320 */ 1348, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 330 */ 1038, 1257, 1038, 1365, 1038, 1324, 1320, 1038, 1038, 1316, - /* 340 */ 1038, 1038, 1375, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 350 */ 1038, 1310, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 360 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1256, 1038, - /* 370 */ 1038, 1038, 1038, 1038, 1038, 1038, 1170, 1038, 1038, 1038, - /* 380 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1155, - /* 390 */ 1153, 1152, 1151, 1038, 1148, 1038, 1038, 1038, 1038, 1038, - /* 400 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 410 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 420 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, - /* 430 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 0 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 10 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 20 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 30 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 40 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 50 */ 1205, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 60 */ 1152, 1152, 1152, 1152, 1152, 1152, 1203, 1332, 1152, 1464, + /* 70 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 80 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 90 */ 1152, 1152, 1152, 1152, 1152, 1205, 1475, 1475, 1475, 1203, + /* 100 */ 1152, 1152, 1152, 1152, 1152, 1290, 1152, 1152, 1152, 1152, + /* 110 */ 1152, 1152, 1366, 1152, 1152, 1539, 1152, 1243, 1499, 1152, + /* 120 */ 1491, 1467, 1481, 1468, 1152, 1524, 1484, 1152, 1152, 1152, + /* 130 */ 1358, 1152, 1152, 1337, 1334, 1334, 1152, 1152, 1152, 1152, + /* 140 */ 1205, 1152, 1152, 1205, 1205, 1152, 1205, 1152, 1152, 1152, + /* 150 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 160 */ 1152, 1152, 1152, 1152, 1152, 1368, 1152, 1152, 1203, 1152, + /* 170 */ 1152, 1203, 1152, 1506, 1504, 1152, 1506, 1504, 1152, 1152, + /* 180 */ 1518, 1514, 1497, 1495, 1481, 1152, 1152, 1152, 1542, 1530, + /* 190 */ 1526, 1152, 1152, 1504, 1152, 1152, 1504, 1152, 1345, 1152, + /* 200 */ 1152, 1203, 1152, 1203, 1152, 1259, 1152, 1152, 1152, 1203, + /* 210 */ 1152, 1360, 1293, 1293, 1206, 1157, 1152, 1152, 1152, 1152, + /* 220 */ 1152, 1152, 1152, 1152, 1152, 1428, 1517, 1516, 1427, 1441, + /* 230 */ 1440, 1439, 1152, 1152, 1152, 1152, 1422, 1423, 1421, 1420, + /* 240 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 250 */ 1152, 1152, 1152, 1152, 1465, 1152, 1527, 1531, 1152, 1152, + /* 260 */ 1152, 1405, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 270 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 280 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 290 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 300 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 310 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 320 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 330 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 340 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 350 */ 1152, 1152, 1304, 1152, 1152, 1152, 1152, 1152, 1152, 1229, + /* 360 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 370 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 380 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 390 */ 1152, 1488, 1498, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 400 */ 1152, 1152, 1152, 1405, 1152, 1515, 1152, 1474, 1470, 1152, + /* 410 */ 1152, 1466, 1152, 1152, 1525, 1152, 1152, 1152, 1152, 1152, + /* 420 */ 1152, 1152, 1152, 1460, 1152, 1152, 1152, 1152, 1152, 1152, + /* 430 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 440 */ 1404, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1287, 1152, + /* 450 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 460 */ 1152, 1272, 1270, 1269, 1268, 1152, 1265, 1152, 1152, 1152, + /* 470 */ 1152, 1152, 1152, 1295, 1152, 1152, 1152, 1152, 1152, 1152, + /* 480 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1215, 1152, 1152, + /* 490 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 500 */ 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, + /* 510 */ 1152, }; /********** End of lemon-generated parsing tables *****************************/ @@ -784,21 +834,21 @@ static const char *const yyTokenName[] = { /* 64 */ "SINGLE_STABLE", /* 65 */ "STREAM_MODE", /* 66 */ "RETENTIONS", - /* 67 */ "TABLE", - /* 68 */ "NK_LP", - /* 69 */ "NK_RP", - /* 70 */ "STABLE", - /* 71 */ "ADD", - /* 72 */ "COLUMN", - /* 73 */ "MODIFY", - /* 74 */ "RENAME", - /* 75 */ "TAG", - /* 76 */ "SET", - /* 77 */ "NK_EQ", - /* 78 */ "USING", - /* 79 */ "TAGS", - /* 80 */ "NK_DOT", - /* 81 */ "NK_COMMA", + /* 67 */ "NK_COMMA", + /* 68 */ "TABLE", + /* 69 */ "NK_LP", + /* 70 */ "NK_RP", + /* 71 */ "STABLE", + /* 72 */ "ADD", + /* 73 */ "COLUMN", + /* 74 */ "MODIFY", + /* 75 */ "RENAME", + /* 76 */ "TAG", + /* 77 */ "SET", + /* 78 */ "NK_EQ", + /* 79 */ "USING", + /* 80 */ "TAGS", + /* 81 */ "NK_DOT", /* 82 */ "COMMENT", /* 83 */ "BOOL", /* 84 */ "TINYINT", @@ -833,164 +883,194 @@ static const char *const yyTokenName[] = { /* 113 */ "FUNCTIONS", /* 114 */ "INDEXES", /* 115 */ "FROM", - /* 116 */ "LIKE", - /* 117 */ "INDEX", - /* 118 */ "FULLTEXT", - /* 119 */ "FUNCTION", - /* 120 */ "INTERVAL", - /* 121 */ "TOPIC", - /* 122 */ "AS", - /* 123 */ "EXPLAIN", - /* 124 */ "ANALYZE", - /* 125 */ "VERBOSE", - /* 126 */ "NK_BOOL", - /* 127 */ "RATIO", - /* 128 */ "NULL", - /* 129 */ "NK_VARIABLE", - /* 130 */ "NK_UNDERLINE", - /* 131 */ "ROWTS", - /* 132 */ "TBNAME", - /* 133 */ "QSTARTTS", - /* 134 */ "QENDTS", - /* 135 */ "WSTARTTS", - /* 136 */ "WENDTS", - /* 137 */ "WDURATION", - /* 138 */ "BETWEEN", - /* 139 */ "IS", - /* 140 */ "NK_LT", - /* 141 */ "NK_GT", - /* 142 */ "NK_LE", - /* 143 */ "NK_GE", - /* 144 */ "NK_NE", - /* 145 */ "MATCH", - /* 146 */ "NMATCH", - /* 147 */ "IN", - /* 148 */ "JOIN", - /* 149 */ "INNER", - /* 150 */ "SELECT", - /* 151 */ "DISTINCT", - /* 152 */ "WHERE", - /* 153 */ "PARTITION", - /* 154 */ "BY", - /* 155 */ "SESSION", - /* 156 */ "STATE_WINDOW", - /* 157 */ "SLIDING", - /* 158 */ "FILL", - /* 159 */ "VALUE", - /* 160 */ "NONE", - /* 161 */ "PREV", - /* 162 */ "LINEAR", - /* 163 */ "NEXT", - /* 164 */ "GROUP", - /* 165 */ "HAVING", - /* 166 */ "ORDER", - /* 167 */ "SLIMIT", - /* 168 */ "SOFFSET", - /* 169 */ "LIMIT", - /* 170 */ "OFFSET", - /* 171 */ "ASC", - /* 172 */ "DESC", - /* 173 */ "NULLS", - /* 174 */ "FIRST", - /* 175 */ "LAST", - /* 176 */ "cmd", - /* 177 */ "account_options", - /* 178 */ "alter_account_options", - /* 179 */ "literal", - /* 180 */ "alter_account_option", - /* 181 */ "user_name", - /* 182 */ "dnode_endpoint", - /* 183 */ "dnode_host_name", - /* 184 */ "not_exists_opt", - /* 185 */ "db_name", - /* 186 */ "db_options", - /* 187 */ "exists_opt", - /* 188 */ "alter_db_options", - /* 189 */ "alter_db_option", - /* 190 */ "full_table_name", - /* 191 */ "column_def_list", - /* 192 */ "tags_def_opt", - /* 193 */ "table_options", - /* 194 */ "multi_create_clause", - /* 195 */ "tags_def", - /* 196 */ "multi_drop_clause", - /* 197 */ "alter_table_clause", - /* 198 */ "alter_table_options", - /* 199 */ "column_name", - /* 200 */ "type_name", - /* 201 */ "create_subtable_clause", - /* 202 */ "specific_tags_opt", - /* 203 */ "literal_list", - /* 204 */ "drop_table_clause", - /* 205 */ "col_name_list", - /* 206 */ "table_name", - /* 207 */ "column_def", - /* 208 */ "func_name_list", - /* 209 */ "alter_table_option", - /* 210 */ "col_name", - /* 211 */ "db_name_cond_opt", - /* 212 */ "like_pattern_opt", - /* 213 */ "table_name_cond", - /* 214 */ "from_db_opt", - /* 215 */ "func_name", - /* 216 */ "function_name", - /* 217 */ "index_name", - /* 218 */ "index_options", - /* 219 */ "func_list", - /* 220 */ "duration_literal", - /* 221 */ "sliding_opt", - /* 222 */ "func", - /* 223 */ "expression_list", - /* 224 */ "topic_name", - /* 225 */ "query_expression", - /* 226 */ "analyze_opt", - /* 227 */ "explain_options", - /* 228 */ "signed", - /* 229 */ "signed_literal", - /* 230 */ "table_alias", - /* 231 */ "column_alias", - /* 232 */ "expression", - /* 233 */ "pseudo_column", - /* 234 */ "column_reference", - /* 235 */ "subquery", - /* 236 */ "predicate", - /* 237 */ "compare_op", - /* 238 */ "in_op", - /* 239 */ "in_predicate_value", - /* 240 */ "boolean_value_expression", - /* 241 */ "boolean_primary", - /* 242 */ "common_expression", - /* 243 */ "from_clause", - /* 244 */ "table_reference_list", - /* 245 */ "table_reference", - /* 246 */ "table_primary", - /* 247 */ "joined_table", - /* 248 */ "alias_opt", - /* 249 */ "parenthesized_joined_table", - /* 250 */ "join_type", - /* 251 */ "search_condition", - /* 252 */ "query_specification", - /* 253 */ "set_quantifier_opt", - /* 254 */ "select_list", - /* 255 */ "where_clause_opt", - /* 256 */ "partition_by_clause_opt", - /* 257 */ "twindow_clause_opt", - /* 258 */ "group_by_clause_opt", - /* 259 */ "having_clause_opt", - /* 260 */ "select_sublist", - /* 261 */ "select_item", - /* 262 */ "fill_opt", - /* 263 */ "fill_mode", - /* 264 */ "group_by_list", - /* 265 */ "query_expression_body", - /* 266 */ "order_by_clause_opt", - /* 267 */ "slimit_clause_opt", - /* 268 */ "limit_clause_opt", - /* 269 */ "query_primary", - /* 270 */ "sort_specification_list", - /* 271 */ "sort_specification", - /* 272 */ "ordering_specification_opt", - /* 273 */ "null_ordering_opt", + /* 116 */ "ACCOUNTS", + /* 117 */ "APPS", + /* 118 */ "CONNECTIONS", + /* 119 */ "LICENCE", + /* 120 */ "QUERIES", + /* 121 */ "SCORES", + /* 122 */ "TOPICS", + /* 123 */ "VARIABLES", + /* 124 */ "LIKE", + /* 125 */ "INDEX", + /* 126 */ "FULLTEXT", + /* 127 */ "FUNCTION", + /* 128 */ "INTERVAL", + /* 129 */ "TOPIC", + /* 130 */ "AS", + /* 131 */ "DESC", + /* 132 */ "DESCRIBE", + /* 133 */ "RESET", + /* 134 */ "QUERY", + /* 135 */ "EXPLAIN", + /* 136 */ "ANALYZE", + /* 137 */ "VERBOSE", + /* 138 */ "NK_BOOL", + /* 139 */ "RATIO", + /* 140 */ "COMPACT", + /* 141 */ "VNODES", + /* 142 */ "IN", + /* 143 */ "OUTPUTTYPE", + /* 144 */ "AGGREGATE", + /* 145 */ "BUFSIZE", + /* 146 */ "STREAM", + /* 147 */ "INTO", + /* 148 */ "KILL", + /* 149 */ "CONNECTION", + /* 150 */ "MERGE", + /* 151 */ "VGROUP", + /* 152 */ "REDISTRIBUTE", + /* 153 */ "SPLIT", + /* 154 */ "SYNCDB", + /* 155 */ "NULL", + /* 156 */ "NK_VARIABLE", + /* 157 */ "NOW", + /* 158 */ "ROWTS", + /* 159 */ "TBNAME", + /* 160 */ "QSTARTTS", + /* 161 */ "QENDTS", + /* 162 */ "WSTARTTS", + /* 163 */ "WENDTS", + /* 164 */ "WDURATION", + /* 165 */ "BETWEEN", + /* 166 */ "IS", + /* 167 */ "NK_LT", + /* 168 */ "NK_GT", + /* 169 */ "NK_LE", + /* 170 */ "NK_GE", + /* 171 */ "NK_NE", + /* 172 */ "MATCH", + /* 173 */ "NMATCH", + /* 174 */ "JOIN", + /* 175 */ "INNER", + /* 176 */ "SELECT", + /* 177 */ "DISTINCT", + /* 178 */ "WHERE", + /* 179 */ "PARTITION", + /* 180 */ "BY", + /* 181 */ "SESSION", + /* 182 */ "STATE_WINDOW", + /* 183 */ "SLIDING", + /* 184 */ "FILL", + /* 185 */ "VALUE", + /* 186 */ "NONE", + /* 187 */ "PREV", + /* 188 */ "LINEAR", + /* 189 */ "NEXT", + /* 190 */ "GROUP", + /* 191 */ "HAVING", + /* 192 */ "ORDER", + /* 193 */ "SLIMIT", + /* 194 */ "SOFFSET", + /* 195 */ "LIMIT", + /* 196 */ "OFFSET", + /* 197 */ "ASC", + /* 198 */ "NULLS", + /* 199 */ "FIRST", + /* 200 */ "LAST", + /* 201 */ "cmd", + /* 202 */ "account_options", + /* 203 */ "alter_account_options", + /* 204 */ "literal", + /* 205 */ "alter_account_option", + /* 206 */ "user_name", + /* 207 */ "dnode_endpoint", + /* 208 */ "dnode_host_name", + /* 209 */ "not_exists_opt", + /* 210 */ "db_name", + /* 211 */ "db_options", + /* 212 */ "exists_opt", + /* 213 */ "alter_db_options", + /* 214 */ "integer_list", + /* 215 */ "alter_db_option", + /* 216 */ "full_table_name", + /* 217 */ "column_def_list", + /* 218 */ "tags_def_opt", + /* 219 */ "table_options", + /* 220 */ "multi_create_clause", + /* 221 */ "tags_def", + /* 222 */ "multi_drop_clause", + /* 223 */ "alter_table_clause", + /* 224 */ "alter_table_options", + /* 225 */ "column_name", + /* 226 */ "type_name", + /* 227 */ "create_subtable_clause", + /* 228 */ "specific_tags_opt", + /* 229 */ "literal_list", + /* 230 */ "drop_table_clause", + /* 231 */ "col_name_list", + /* 232 */ "table_name", + /* 233 */ "column_def", + /* 234 */ "func_name_list", + /* 235 */ "alter_table_option", + /* 236 */ "col_name", + /* 237 */ "db_name_cond_opt", + /* 238 */ "like_pattern_opt", + /* 239 */ "table_name_cond", + /* 240 */ "from_db_opt", + /* 241 */ "func_name", + /* 242 */ "function_name", + /* 243 */ "index_name", + /* 244 */ "index_options", + /* 245 */ "func_list", + /* 246 */ "duration_literal", + /* 247 */ "sliding_opt", + /* 248 */ "func", + /* 249 */ "expression_list", + /* 250 */ "topic_name", + /* 251 */ "query_expression", + /* 252 */ "analyze_opt", + /* 253 */ "explain_options", + /* 254 */ "agg_func_opt", + /* 255 */ "bufsize_opt", + /* 256 */ "stream_name", + /* 257 */ "dnode_list", + /* 258 */ "signed", + /* 259 */ "signed_literal", + /* 260 */ "table_alias", + /* 261 */ "column_alias", + /* 262 */ "expression", + /* 263 */ "pseudo_column", + /* 264 */ "column_reference", + /* 265 */ "subquery", + /* 266 */ "predicate", + /* 267 */ "compare_op", + /* 268 */ "in_op", + /* 269 */ "in_predicate_value", + /* 270 */ "boolean_value_expression", + /* 271 */ "boolean_primary", + /* 272 */ "common_expression", + /* 273 */ "from_clause", + /* 274 */ "table_reference_list", + /* 275 */ "table_reference", + /* 276 */ "table_primary", + /* 277 */ "joined_table", + /* 278 */ "alias_opt", + /* 279 */ "parenthesized_joined_table", + /* 280 */ "join_type", + /* 281 */ "search_condition", + /* 282 */ "query_specification", + /* 283 */ "set_quantifier_opt", + /* 284 */ "select_list", + /* 285 */ "where_clause_opt", + /* 286 */ "partition_by_clause_opt", + /* 287 */ "twindow_clause_opt", + /* 288 */ "group_by_clause_opt", + /* 289 */ "having_clause_opt", + /* 290 */ "select_sublist", + /* 291 */ "select_item", + /* 292 */ "fill_opt", + /* 293 */ "fill_mode", + /* 294 */ "group_by_list", + /* 295 */ "query_expression_body", + /* 296 */ "order_by_clause_opt", + /* 297 */ "slimit_clause_opt", + /* 298 */ "limit_clause_opt", + /* 299 */ "query_primary", + /* 300 */ "sort_specification_list", + /* 301 */ "sort_specification", + /* 302 */ "ordering_specification_opt", + /* 303 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1058,7 +1138,7 @@ static const char *const yyRuleName[] = { /* 57 */ "db_options ::= db_options FSYNC NK_INTEGER", /* 58 */ "db_options ::= db_options MAXROWS NK_INTEGER", /* 59 */ "db_options ::= db_options MINROWS NK_INTEGER", - /* 60 */ "db_options ::= db_options KEEP NK_INTEGER", + /* 60 */ "db_options ::= db_options KEEP integer_list", /* 61 */ "db_options ::= db_options PRECISION NK_STRING", /* 62 */ "db_options ::= db_options QUORUM NK_INTEGER", /* 63 */ "db_options ::= db_options REPLICA NK_INTEGER", @@ -1072,286 +1152,322 @@ static const char *const yyRuleName[] = { /* 71 */ "alter_db_options ::= alter_db_options alter_db_option", /* 72 */ "alter_db_option ::= BLOCKS NK_INTEGER", /* 73 */ "alter_db_option ::= FSYNC NK_INTEGER", - /* 74 */ "alter_db_option ::= KEEP NK_INTEGER", + /* 74 */ "alter_db_option ::= KEEP integer_list", /* 75 */ "alter_db_option ::= WAL NK_INTEGER", /* 76 */ "alter_db_option ::= QUORUM NK_INTEGER", /* 77 */ "alter_db_option ::= CACHELAST NK_INTEGER", - /* 78 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 79 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 80 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 81 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 82 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 83 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 84 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 85 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 86 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 87 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 88 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 89 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 90 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 91 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 92 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 93 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 94 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", - /* 95 */ "multi_create_clause ::= create_subtable_clause", - /* 96 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 97 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", - /* 98 */ "multi_drop_clause ::= drop_table_clause", - /* 99 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 100 */ "drop_table_clause ::= exists_opt full_table_name", - /* 101 */ "specific_tags_opt ::=", - /* 102 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", - /* 103 */ "full_table_name ::= table_name", - /* 104 */ "full_table_name ::= db_name NK_DOT table_name", - /* 105 */ "column_def_list ::= column_def", - /* 106 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 107 */ "column_def ::= column_name type_name", - /* 108 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 109 */ "type_name ::= BOOL", - /* 110 */ "type_name ::= TINYINT", - /* 111 */ "type_name ::= SMALLINT", - /* 112 */ "type_name ::= INT", - /* 113 */ "type_name ::= INTEGER", - /* 114 */ "type_name ::= BIGINT", - /* 115 */ "type_name ::= FLOAT", - /* 116 */ "type_name ::= DOUBLE", - /* 117 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 118 */ "type_name ::= TIMESTAMP", - /* 119 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 120 */ "type_name ::= TINYINT UNSIGNED", - /* 121 */ "type_name ::= SMALLINT UNSIGNED", - /* 122 */ "type_name ::= INT UNSIGNED", - /* 123 */ "type_name ::= BIGINT UNSIGNED", - /* 124 */ "type_name ::= JSON", - /* 125 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 126 */ "type_name ::= MEDIUMBLOB", - /* 127 */ "type_name ::= BLOB", - /* 128 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 129 */ "type_name ::= DECIMAL", - /* 130 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 131 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 132 */ "tags_def_opt ::=", - /* 133 */ "tags_def_opt ::= tags_def", - /* 134 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 135 */ "table_options ::=", - /* 136 */ "table_options ::= table_options COMMENT NK_STRING", - /* 137 */ "table_options ::= table_options KEEP NK_INTEGER", - /* 138 */ "table_options ::= table_options TTL NK_INTEGER", - /* 139 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 140 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", - /* 141 */ "table_options ::= table_options FILE_FACTOR NK_FLOAT", - /* 142 */ "table_options ::= table_options DELAY NK_INTEGER", - /* 143 */ "alter_table_options ::= alter_table_option", - /* 144 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 145 */ "alter_table_option ::= COMMENT NK_STRING", - /* 146 */ "alter_table_option ::= KEEP NK_INTEGER", - /* 147 */ "alter_table_option ::= TTL NK_INTEGER", - /* 148 */ "col_name_list ::= col_name", - /* 149 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 150 */ "col_name ::= column_name", - /* 151 */ "cmd ::= SHOW DNODES", - /* 152 */ "cmd ::= SHOW USERS", - /* 153 */ "cmd ::= SHOW DATABASES", - /* 154 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 155 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 156 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 157 */ "cmd ::= SHOW MNODES", - /* 158 */ "cmd ::= SHOW MODULES", - /* 159 */ "cmd ::= SHOW QNODES", - /* 160 */ "cmd ::= SHOW FUNCTIONS", - /* 161 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 162 */ "cmd ::= SHOW STREAMS", - /* 163 */ "db_name_cond_opt ::=", - /* 164 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 165 */ "like_pattern_opt ::=", - /* 166 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 167 */ "table_name_cond ::= table_name", - /* 168 */ "from_db_opt ::=", - /* 169 */ "from_db_opt ::= FROM db_name", - /* 170 */ "func_name_list ::= func_name", - /* 171 */ "func_name_list ::= func_name_list NK_COMMA col_name", - /* 172 */ "func_name ::= function_name", - /* 173 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 174 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 175 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 176 */ "index_options ::=", - /* 177 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 178 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 179 */ "func_list ::= func", - /* 180 */ "func_list ::= func_list NK_COMMA func", - /* 181 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 182 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 183 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", - /* 184 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 185 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 186 */ "analyze_opt ::=", - /* 187 */ "analyze_opt ::= ANALYZE", - /* 188 */ "explain_options ::=", - /* 189 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 190 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 191 */ "cmd ::= query_expression", - /* 192 */ "literal ::= NK_INTEGER", - /* 193 */ "literal ::= NK_FLOAT", - /* 194 */ "literal ::= NK_STRING", - /* 195 */ "literal ::= NK_BOOL", - /* 196 */ "literal ::= TIMESTAMP NK_STRING", - /* 197 */ "literal ::= duration_literal", - /* 198 */ "literal ::= NULL", - /* 199 */ "duration_literal ::= NK_VARIABLE", - /* 200 */ "signed ::= NK_INTEGER", - /* 201 */ "signed ::= NK_PLUS NK_INTEGER", - /* 202 */ "signed ::= NK_MINUS NK_INTEGER", - /* 203 */ "signed ::= NK_FLOAT", - /* 204 */ "signed ::= NK_PLUS NK_FLOAT", - /* 205 */ "signed ::= NK_MINUS NK_FLOAT", - /* 206 */ "signed_literal ::= signed", - /* 207 */ "signed_literal ::= NK_STRING", - /* 208 */ "signed_literal ::= NK_BOOL", - /* 209 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 210 */ "signed_literal ::= duration_literal", - /* 211 */ "signed_literal ::= NULL", - /* 212 */ "literal_list ::= signed_literal", - /* 213 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 214 */ "db_name ::= NK_ID", - /* 215 */ "table_name ::= NK_ID", - /* 216 */ "column_name ::= NK_ID", - /* 217 */ "function_name ::= NK_ID", - /* 218 */ "table_alias ::= NK_ID", - /* 219 */ "column_alias ::= NK_ID", - /* 220 */ "user_name ::= NK_ID", - /* 221 */ "index_name ::= NK_ID", - /* 222 */ "topic_name ::= NK_ID", - /* 223 */ "expression ::= literal", - /* 224 */ "expression ::= pseudo_column", - /* 225 */ "expression ::= column_reference", - /* 226 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 227 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 228 */ "expression ::= subquery", - /* 229 */ "expression ::= NK_LP expression NK_RP", - /* 230 */ "expression ::= NK_PLUS expression", - /* 231 */ "expression ::= NK_MINUS expression", - /* 232 */ "expression ::= expression NK_PLUS expression", - /* 233 */ "expression ::= expression NK_MINUS expression", - /* 234 */ "expression ::= expression NK_STAR expression", - /* 235 */ "expression ::= expression NK_SLASH expression", - /* 236 */ "expression ::= expression NK_REM expression", - /* 237 */ "expression_list ::= expression", - /* 238 */ "expression_list ::= expression_list NK_COMMA expression", - /* 239 */ "column_reference ::= column_name", - /* 240 */ "column_reference ::= table_name NK_DOT column_name", - /* 241 */ "pseudo_column ::= NK_UNDERLINE ROWTS", - /* 242 */ "pseudo_column ::= TBNAME", - /* 243 */ "pseudo_column ::= NK_UNDERLINE QSTARTTS", - /* 244 */ "pseudo_column ::= NK_UNDERLINE QENDTS", - /* 245 */ "pseudo_column ::= NK_UNDERLINE WSTARTTS", - /* 246 */ "pseudo_column ::= NK_UNDERLINE WENDTS", - /* 247 */ "pseudo_column ::= NK_UNDERLINE WDURATION", - /* 248 */ "predicate ::= expression compare_op expression", - /* 249 */ "predicate ::= expression BETWEEN expression AND expression", - /* 250 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 251 */ "predicate ::= expression IS NULL", - /* 252 */ "predicate ::= expression IS NOT NULL", - /* 253 */ "predicate ::= expression in_op in_predicate_value", - /* 254 */ "compare_op ::= NK_LT", - /* 255 */ "compare_op ::= NK_GT", - /* 256 */ "compare_op ::= NK_LE", - /* 257 */ "compare_op ::= NK_GE", - /* 258 */ "compare_op ::= NK_NE", - /* 259 */ "compare_op ::= NK_EQ", - /* 260 */ "compare_op ::= LIKE", - /* 261 */ "compare_op ::= NOT LIKE", - /* 262 */ "compare_op ::= MATCH", - /* 263 */ "compare_op ::= NMATCH", - /* 264 */ "in_op ::= IN", - /* 265 */ "in_op ::= NOT IN", - /* 266 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 267 */ "boolean_value_expression ::= boolean_primary", - /* 268 */ "boolean_value_expression ::= NOT boolean_primary", - /* 269 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 270 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 271 */ "boolean_primary ::= predicate", - /* 272 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 273 */ "common_expression ::= expression", - /* 274 */ "common_expression ::= boolean_value_expression", - /* 275 */ "from_clause ::= FROM table_reference_list", - /* 276 */ "table_reference_list ::= table_reference", - /* 277 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 278 */ "table_reference ::= table_primary", - /* 279 */ "table_reference ::= joined_table", - /* 280 */ "table_primary ::= table_name alias_opt", - /* 281 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 282 */ "table_primary ::= subquery alias_opt", - /* 283 */ "table_primary ::= parenthesized_joined_table", - /* 284 */ "alias_opt ::=", - /* 285 */ "alias_opt ::= table_alias", - /* 286 */ "alias_opt ::= AS table_alias", - /* 287 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 288 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 289 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 290 */ "join_type ::=", - /* 291 */ "join_type ::= INNER", - /* 292 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 293 */ "set_quantifier_opt ::=", - /* 294 */ "set_quantifier_opt ::= DISTINCT", - /* 295 */ "set_quantifier_opt ::= ALL", - /* 296 */ "select_list ::= NK_STAR", - /* 297 */ "select_list ::= select_sublist", - /* 298 */ "select_sublist ::= select_item", - /* 299 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 300 */ "select_item ::= common_expression", - /* 301 */ "select_item ::= common_expression column_alias", - /* 302 */ "select_item ::= common_expression AS column_alias", - /* 303 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 304 */ "where_clause_opt ::=", - /* 305 */ "where_clause_opt ::= WHERE search_condition", - /* 306 */ "partition_by_clause_opt ::=", - /* 307 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 308 */ "twindow_clause_opt ::=", - /* 309 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 310 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 311 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 312 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 313 */ "sliding_opt ::=", - /* 314 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 315 */ "fill_opt ::=", - /* 316 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 317 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 318 */ "fill_mode ::= NONE", - /* 319 */ "fill_mode ::= PREV", - /* 320 */ "fill_mode ::= NULL", - /* 321 */ "fill_mode ::= LINEAR", - /* 322 */ "fill_mode ::= NEXT", - /* 323 */ "group_by_clause_opt ::=", - /* 324 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 325 */ "group_by_list ::= expression", - /* 326 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 327 */ "having_clause_opt ::=", - /* 328 */ "having_clause_opt ::= HAVING search_condition", - /* 329 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 330 */ "query_expression_body ::= query_primary", - /* 331 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 332 */ "query_primary ::= query_specification", - /* 333 */ "order_by_clause_opt ::=", - /* 334 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 335 */ "slimit_clause_opt ::=", - /* 336 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 337 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 338 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 339 */ "limit_clause_opt ::=", - /* 340 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 341 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 342 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 343 */ "subquery ::= NK_LP query_expression NK_RP", - /* 344 */ "search_condition ::= common_expression", - /* 345 */ "sort_specification_list ::= sort_specification", - /* 346 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 347 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 348 */ "ordering_specification_opt ::=", - /* 349 */ "ordering_specification_opt ::= ASC", - /* 350 */ "ordering_specification_opt ::= DESC", - /* 351 */ "null_ordering_opt ::=", - /* 352 */ "null_ordering_opt ::= NULLS FIRST", - /* 353 */ "null_ordering_opt ::= NULLS LAST", + /* 78 */ "alter_db_option ::= REPLICA NK_INTEGER", + /* 79 */ "integer_list ::= NK_INTEGER", + /* 80 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", + /* 81 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 82 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 83 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 84 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 85 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 86 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 87 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 88 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 89 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 90 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 91 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 92 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 93 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 94 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 95 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 96 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 97 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", + /* 98 */ "multi_create_clause ::= create_subtable_clause", + /* 99 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 100 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", + /* 101 */ "multi_drop_clause ::= drop_table_clause", + /* 102 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 103 */ "drop_table_clause ::= exists_opt full_table_name", + /* 104 */ "specific_tags_opt ::=", + /* 105 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", + /* 106 */ "full_table_name ::= table_name", + /* 107 */ "full_table_name ::= db_name NK_DOT table_name", + /* 108 */ "column_def_list ::= column_def", + /* 109 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 110 */ "column_def ::= column_name type_name", + /* 111 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 112 */ "type_name ::= BOOL", + /* 113 */ "type_name ::= TINYINT", + /* 114 */ "type_name ::= SMALLINT", + /* 115 */ "type_name ::= INT", + /* 116 */ "type_name ::= INTEGER", + /* 117 */ "type_name ::= BIGINT", + /* 118 */ "type_name ::= FLOAT", + /* 119 */ "type_name ::= DOUBLE", + /* 120 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 121 */ "type_name ::= TIMESTAMP", + /* 122 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 123 */ "type_name ::= TINYINT UNSIGNED", + /* 124 */ "type_name ::= SMALLINT UNSIGNED", + /* 125 */ "type_name ::= INT UNSIGNED", + /* 126 */ "type_name ::= BIGINT UNSIGNED", + /* 127 */ "type_name ::= JSON", + /* 128 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 129 */ "type_name ::= MEDIUMBLOB", + /* 130 */ "type_name ::= BLOB", + /* 131 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 132 */ "type_name ::= DECIMAL", + /* 133 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 134 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 135 */ "tags_def_opt ::=", + /* 136 */ "tags_def_opt ::= tags_def", + /* 137 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 138 */ "table_options ::=", + /* 139 */ "table_options ::= table_options COMMENT NK_STRING", + /* 140 */ "table_options ::= table_options KEEP integer_list", + /* 141 */ "table_options ::= table_options TTL NK_INTEGER", + /* 142 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 143 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", + /* 144 */ "table_options ::= table_options FILE_FACTOR NK_FLOAT", + /* 145 */ "table_options ::= table_options DELAY NK_INTEGER", + /* 146 */ "alter_table_options ::= alter_table_option", + /* 147 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 148 */ "alter_table_option ::= COMMENT NK_STRING", + /* 149 */ "alter_table_option ::= KEEP integer_list", + /* 150 */ "alter_table_option ::= TTL NK_INTEGER", + /* 151 */ "col_name_list ::= col_name", + /* 152 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 153 */ "col_name ::= column_name", + /* 154 */ "cmd ::= SHOW DNODES", + /* 155 */ "cmd ::= SHOW USERS", + /* 156 */ "cmd ::= SHOW DATABASES", + /* 157 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 158 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 159 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 160 */ "cmd ::= SHOW MNODES", + /* 161 */ "cmd ::= SHOW MODULES", + /* 162 */ "cmd ::= SHOW QNODES", + /* 163 */ "cmd ::= SHOW FUNCTIONS", + /* 164 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 165 */ "cmd ::= SHOW STREAMS", + /* 166 */ "cmd ::= SHOW ACCOUNTS", + /* 167 */ "cmd ::= SHOW APPS", + /* 168 */ "cmd ::= SHOW CONNECTIONS", + /* 169 */ "cmd ::= SHOW LICENCE", + /* 170 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 171 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 172 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 173 */ "cmd ::= SHOW QUERIES", + /* 174 */ "cmd ::= SHOW SCORES", + /* 175 */ "cmd ::= SHOW TOPICS", + /* 176 */ "cmd ::= SHOW VARIABLES", + /* 177 */ "db_name_cond_opt ::=", + /* 178 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 179 */ "like_pattern_opt ::=", + /* 180 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 181 */ "table_name_cond ::= table_name", + /* 182 */ "from_db_opt ::=", + /* 183 */ "from_db_opt ::= FROM db_name", + /* 184 */ "func_name_list ::= func_name", + /* 185 */ "func_name_list ::= func_name_list NK_COMMA col_name", + /* 186 */ "func_name ::= function_name", + /* 187 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 188 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 189 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 190 */ "index_options ::=", + /* 191 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 192 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 193 */ "func_list ::= func", + /* 194 */ "func_list ::= func_list NK_COMMA func", + /* 195 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 196 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 197 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", + /* 198 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 199 */ "cmd ::= DESC full_table_name", + /* 200 */ "cmd ::= DESCRIBE full_table_name", + /* 201 */ "cmd ::= RESET QUERY CACHE", + /* 202 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 203 */ "analyze_opt ::=", + /* 204 */ "analyze_opt ::= ANALYZE", + /* 205 */ "explain_options ::=", + /* 206 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 207 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 208 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 209 */ "cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 210 */ "cmd ::= DROP FUNCTION function_name", + /* 211 */ "agg_func_opt ::=", + /* 212 */ "agg_func_opt ::= AGGREGATE", + /* 213 */ "bufsize_opt ::=", + /* 214 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 215 */ "cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression", + /* 216 */ "cmd ::= DROP STREAM stream_name", + /* 217 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 218 */ "cmd ::= KILL QUERY NK_INTEGER", + /* 219 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 220 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 221 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 222 */ "dnode_list ::= DNODE NK_INTEGER", + /* 223 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 224 */ "cmd ::= SYNCDB db_name REPLICA", + /* 225 */ "cmd ::= query_expression", + /* 226 */ "literal ::= NK_INTEGER", + /* 227 */ "literal ::= NK_FLOAT", + /* 228 */ "literal ::= NK_STRING", + /* 229 */ "literal ::= NK_BOOL", + /* 230 */ "literal ::= TIMESTAMP NK_STRING", + /* 231 */ "literal ::= duration_literal", + /* 232 */ "literal ::= NULL", + /* 233 */ "duration_literal ::= NK_VARIABLE", + /* 234 */ "signed ::= NK_INTEGER", + /* 235 */ "signed ::= NK_PLUS NK_INTEGER", + /* 236 */ "signed ::= NK_MINUS NK_INTEGER", + /* 237 */ "signed ::= NK_FLOAT", + /* 238 */ "signed ::= NK_PLUS NK_FLOAT", + /* 239 */ "signed ::= NK_MINUS NK_FLOAT", + /* 240 */ "signed_literal ::= signed", + /* 241 */ "signed_literal ::= NK_STRING", + /* 242 */ "signed_literal ::= NK_BOOL", + /* 243 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 244 */ "signed_literal ::= duration_literal", + /* 245 */ "signed_literal ::= NULL", + /* 246 */ "literal_list ::= signed_literal", + /* 247 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 248 */ "db_name ::= NK_ID", + /* 249 */ "table_name ::= NK_ID", + /* 250 */ "column_name ::= NK_ID", + /* 251 */ "function_name ::= NK_ID", + /* 252 */ "table_alias ::= NK_ID", + /* 253 */ "column_alias ::= NK_ID", + /* 254 */ "user_name ::= NK_ID", + /* 255 */ "index_name ::= NK_ID", + /* 256 */ "topic_name ::= NK_ID", + /* 257 */ "stream_name ::= NK_ID", + /* 258 */ "expression ::= literal", + /* 259 */ "expression ::= pseudo_column", + /* 260 */ "expression ::= column_reference", + /* 261 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 262 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 263 */ "expression ::= subquery", + /* 264 */ "expression ::= NK_LP expression NK_RP", + /* 265 */ "expression ::= NK_PLUS expression", + /* 266 */ "expression ::= NK_MINUS expression", + /* 267 */ "expression ::= expression NK_PLUS expression", + /* 268 */ "expression ::= expression NK_MINUS expression", + /* 269 */ "expression ::= expression NK_STAR expression", + /* 270 */ "expression ::= expression NK_SLASH expression", + /* 271 */ "expression ::= expression NK_REM expression", + /* 272 */ "expression_list ::= expression", + /* 273 */ "expression_list ::= expression_list NK_COMMA expression", + /* 274 */ "column_reference ::= column_name", + /* 275 */ "column_reference ::= table_name NK_DOT column_name", + /* 276 */ "pseudo_column ::= NOW", + /* 277 */ "pseudo_column ::= ROWTS", + /* 278 */ "pseudo_column ::= TBNAME", + /* 279 */ "pseudo_column ::= QSTARTTS", + /* 280 */ "pseudo_column ::= QENDTS", + /* 281 */ "pseudo_column ::= WSTARTTS", + /* 282 */ "pseudo_column ::= WENDTS", + /* 283 */ "pseudo_column ::= WDURATION", + /* 284 */ "predicate ::= expression compare_op expression", + /* 285 */ "predicate ::= expression BETWEEN expression AND expression", + /* 286 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 287 */ "predicate ::= expression IS NULL", + /* 288 */ "predicate ::= expression IS NOT NULL", + /* 289 */ "predicate ::= expression in_op in_predicate_value", + /* 290 */ "compare_op ::= NK_LT", + /* 291 */ "compare_op ::= NK_GT", + /* 292 */ "compare_op ::= NK_LE", + /* 293 */ "compare_op ::= NK_GE", + /* 294 */ "compare_op ::= NK_NE", + /* 295 */ "compare_op ::= NK_EQ", + /* 296 */ "compare_op ::= LIKE", + /* 297 */ "compare_op ::= NOT LIKE", + /* 298 */ "compare_op ::= MATCH", + /* 299 */ "compare_op ::= NMATCH", + /* 300 */ "in_op ::= IN", + /* 301 */ "in_op ::= NOT IN", + /* 302 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 303 */ "boolean_value_expression ::= boolean_primary", + /* 304 */ "boolean_value_expression ::= NOT boolean_primary", + /* 305 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 306 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 307 */ "boolean_primary ::= predicate", + /* 308 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 309 */ "common_expression ::= expression", + /* 310 */ "common_expression ::= boolean_value_expression", + /* 311 */ "from_clause ::= FROM table_reference_list", + /* 312 */ "table_reference_list ::= table_reference", + /* 313 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 314 */ "table_reference ::= table_primary", + /* 315 */ "table_reference ::= joined_table", + /* 316 */ "table_primary ::= table_name alias_opt", + /* 317 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 318 */ "table_primary ::= subquery alias_opt", + /* 319 */ "table_primary ::= parenthesized_joined_table", + /* 320 */ "alias_opt ::=", + /* 321 */ "alias_opt ::= table_alias", + /* 322 */ "alias_opt ::= AS table_alias", + /* 323 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 324 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 325 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 326 */ "join_type ::=", + /* 327 */ "join_type ::= INNER", + /* 328 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 329 */ "set_quantifier_opt ::=", + /* 330 */ "set_quantifier_opt ::= DISTINCT", + /* 331 */ "set_quantifier_opt ::= ALL", + /* 332 */ "select_list ::= NK_STAR", + /* 333 */ "select_list ::= select_sublist", + /* 334 */ "select_sublist ::= select_item", + /* 335 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 336 */ "select_item ::= common_expression", + /* 337 */ "select_item ::= common_expression column_alias", + /* 338 */ "select_item ::= common_expression AS column_alias", + /* 339 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 340 */ "where_clause_opt ::=", + /* 341 */ "where_clause_opt ::= WHERE search_condition", + /* 342 */ "partition_by_clause_opt ::=", + /* 343 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 344 */ "twindow_clause_opt ::=", + /* 345 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 346 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 347 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 348 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 349 */ "sliding_opt ::=", + /* 350 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 351 */ "fill_opt ::=", + /* 352 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 353 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 354 */ "fill_mode ::= NONE", + /* 355 */ "fill_mode ::= PREV", + /* 356 */ "fill_mode ::= NULL", + /* 357 */ "fill_mode ::= LINEAR", + /* 358 */ "fill_mode ::= NEXT", + /* 359 */ "group_by_clause_opt ::=", + /* 360 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 361 */ "group_by_list ::= expression", + /* 362 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 363 */ "having_clause_opt ::=", + /* 364 */ "having_clause_opt ::= HAVING search_condition", + /* 365 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 366 */ "query_expression_body ::= query_primary", + /* 367 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 368 */ "query_primary ::= query_specification", + /* 369 */ "order_by_clause_opt ::=", + /* 370 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 371 */ "slimit_clause_opt ::=", + /* 372 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 373 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 374 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 375 */ "limit_clause_opt ::=", + /* 376 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 377 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 378 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 379 */ "subquery ::= NK_LP query_expression NK_RP", + /* 380 */ "search_condition ::= common_expression", + /* 381 */ "sort_specification_list ::= sort_specification", + /* 382 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 383 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 384 */ "ordering_specification_opt ::=", + /* 385 */ "ordering_specification_opt ::= ASC", + /* 386 */ "ordering_specification_opt ::= DESC", + /* 387 */ "null_ordering_opt ::=", + /* 388 */ "null_ordering_opt ::= NULLS FIRST", + /* 389 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1478,148 +1594,153 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 176: /* cmd */ - case 179: /* literal */ - case 186: /* db_options */ - case 188: /* alter_db_options */ - case 190: /* full_table_name */ - case 193: /* table_options */ - case 197: /* alter_table_clause */ - case 198: /* alter_table_options */ - case 201: /* create_subtable_clause */ - case 204: /* drop_table_clause */ - case 207: /* column_def */ - case 210: /* col_name */ - case 211: /* db_name_cond_opt */ - case 212: /* like_pattern_opt */ - case 213: /* table_name_cond */ - case 214: /* from_db_opt */ - case 215: /* func_name */ - case 218: /* index_options */ - case 220: /* duration_literal */ - case 221: /* sliding_opt */ - case 222: /* func */ - case 225: /* query_expression */ - case 227: /* explain_options */ - case 228: /* signed */ - case 229: /* signed_literal */ - case 232: /* expression */ - case 233: /* pseudo_column */ - case 234: /* column_reference */ - case 235: /* subquery */ - case 236: /* predicate */ - case 239: /* in_predicate_value */ - case 240: /* boolean_value_expression */ - case 241: /* boolean_primary */ - case 242: /* common_expression */ - case 243: /* from_clause */ - case 244: /* table_reference_list */ - case 245: /* table_reference */ - case 246: /* table_primary */ - case 247: /* joined_table */ - case 249: /* parenthesized_joined_table */ - case 251: /* search_condition */ - case 252: /* query_specification */ - case 255: /* where_clause_opt */ - case 257: /* twindow_clause_opt */ - case 259: /* having_clause_opt */ - case 261: /* select_item */ - case 262: /* fill_opt */ - case 265: /* query_expression_body */ - case 267: /* slimit_clause_opt */ - case 268: /* limit_clause_opt */ - case 269: /* query_primary */ - case 271: /* sort_specification */ + case 201: /* cmd */ + case 204: /* literal */ + case 211: /* db_options */ + case 213: /* alter_db_options */ + case 216: /* full_table_name */ + case 219: /* table_options */ + case 223: /* alter_table_clause */ + case 224: /* alter_table_options */ + case 227: /* create_subtable_clause */ + case 230: /* drop_table_clause */ + case 233: /* column_def */ + case 236: /* col_name */ + case 237: /* db_name_cond_opt */ + case 238: /* like_pattern_opt */ + case 239: /* table_name_cond */ + case 240: /* from_db_opt */ + case 241: /* func_name */ + case 244: /* index_options */ + case 246: /* duration_literal */ + case 247: /* sliding_opt */ + case 248: /* func */ + case 251: /* query_expression */ + case 253: /* explain_options */ + case 258: /* signed */ + case 259: /* signed_literal */ + case 262: /* expression */ + case 263: /* pseudo_column */ + case 264: /* column_reference */ + case 265: /* subquery */ + case 266: /* predicate */ + case 269: /* in_predicate_value */ + case 270: /* boolean_value_expression */ + case 271: /* boolean_primary */ + case 272: /* common_expression */ + case 273: /* from_clause */ + case 274: /* table_reference_list */ + case 275: /* table_reference */ + case 276: /* table_primary */ + case 277: /* joined_table */ + case 279: /* parenthesized_joined_table */ + case 281: /* search_condition */ + case 282: /* query_specification */ + case 285: /* where_clause_opt */ + case 287: /* twindow_clause_opt */ + case 289: /* having_clause_opt */ + case 291: /* select_item */ + case 292: /* fill_opt */ + case 295: /* query_expression_body */ + case 297: /* slimit_clause_opt */ + case 298: /* limit_clause_opt */ + case 299: /* query_primary */ + case 301: /* sort_specification */ { - nodesDestroyNode((yypminor->yy364)); + nodesDestroyNode((yypminor->yy104)); } break; - case 177: /* account_options */ - case 178: /* alter_account_options */ - case 180: /* alter_account_option */ + case 202: /* account_options */ + case 203: /* alter_account_options */ + case 205: /* alter_account_option */ + case 255: /* bufsize_opt */ { } break; - case 181: /* user_name */ - case 182: /* dnode_endpoint */ - case 183: /* dnode_host_name */ - case 185: /* db_name */ - case 199: /* column_name */ - case 206: /* table_name */ - case 216: /* function_name */ - case 217: /* index_name */ - case 224: /* topic_name */ - case 230: /* table_alias */ - case 231: /* column_alias */ - case 248: /* alias_opt */ + case 206: /* user_name */ + case 207: /* dnode_endpoint */ + case 208: /* dnode_host_name */ + case 210: /* db_name */ + case 225: /* column_name */ + case 232: /* table_name */ + case 242: /* function_name */ + case 243: /* index_name */ + case 250: /* topic_name */ + case 256: /* stream_name */ + case 260: /* table_alias */ + case 261: /* column_alias */ + case 278: /* alias_opt */ { } break; - case 184: /* not_exists_opt */ - case 187: /* exists_opt */ - case 226: /* analyze_opt */ - case 253: /* set_quantifier_opt */ + case 209: /* not_exists_opt */ + case 212: /* exists_opt */ + case 252: /* analyze_opt */ + case 254: /* agg_func_opt */ + case 283: /* set_quantifier_opt */ { } break; - case 189: /* alter_db_option */ - case 209: /* alter_table_option */ + case 214: /* integer_list */ + case 217: /* column_def_list */ + case 218: /* tags_def_opt */ + case 220: /* multi_create_clause */ + case 221: /* tags_def */ + case 222: /* multi_drop_clause */ + case 228: /* specific_tags_opt */ + case 229: /* literal_list */ + case 231: /* col_name_list */ + case 234: /* func_name_list */ + case 245: /* func_list */ + case 249: /* expression_list */ + case 257: /* dnode_list */ + case 284: /* select_list */ + case 286: /* partition_by_clause_opt */ + case 288: /* group_by_clause_opt */ + case 290: /* select_sublist */ + case 294: /* group_by_list */ + case 296: /* order_by_clause_opt */ + case 300: /* sort_specification_list */ +{ + nodesDestroyList((yypminor->yy312)); +} + break; + case 215: /* alter_db_option */ + case 235: /* alter_table_option */ { } break; - case 191: /* column_def_list */ - case 192: /* tags_def_opt */ - case 194: /* multi_create_clause */ - case 195: /* tags_def */ - case 196: /* multi_drop_clause */ - case 202: /* specific_tags_opt */ - case 203: /* literal_list */ - case 205: /* col_name_list */ - case 208: /* func_name_list */ - case 219: /* func_list */ - case 223: /* expression_list */ - case 254: /* select_list */ - case 256: /* partition_by_clause_opt */ - case 258: /* group_by_clause_opt */ - case 260: /* select_sublist */ - case 264: /* group_by_list */ - case 266: /* order_by_clause_opt */ - case 270: /* sort_specification_list */ -{ - nodesDestroyList((yypminor->yy40)); -} - break; - case 200: /* type_name */ + case 226: /* type_name */ { } break; - case 237: /* compare_op */ - case 238: /* in_op */ + case 267: /* compare_op */ + case 268: /* in_op */ { } break; - case 250: /* join_type */ + case 280: /* join_type */ { } break; - case 263: /* fill_mode */ + case 293: /* fill_mode */ { } break; - case 272: /* ordering_specification_opt */ + case 302: /* ordering_specification_opt */ { } break; - case 273: /* null_ordering_opt */ + case 303: /* null_ordering_opt */ { } @@ -1918,360 +2039,396 @@ 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[] = { - { 176, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 176, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 177, 0 }, /* (2) account_options ::= */ - { 177, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 177, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 177, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 177, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 177, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 177, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 177, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 177, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 177, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 178, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 178, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 180, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 180, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 180, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 180, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 180, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 180, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 180, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 180, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 180, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 180, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 176, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 176, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 176, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 176, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 176, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ - { 176, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 176, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ - { 176, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ - { 176, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 176, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 176, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ - { 176, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 182, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ - { 183, -1 }, /* (37) dnode_host_name ::= NK_ID */ - { 183, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ - { 176, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ - { 176, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 176, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 176, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 176, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 176, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ - { 176, -2 }, /* (45) cmd ::= USE db_name */ - { 176, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 184, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ - { 184, 0 }, /* (48) not_exists_opt ::= */ - { 187, -2 }, /* (49) exists_opt ::= IF EXISTS */ - { 187, 0 }, /* (50) exists_opt ::= */ - { 186, 0 }, /* (51) db_options ::= */ - { 186, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ - { 186, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ - { 186, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ - { 186, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ - { 186, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ - { 186, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ - { 186, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ - { 186, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ - { 186, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ - { 186, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ - { 186, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ - { 186, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ - { 186, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ - { 186, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ - { 186, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ - { 186, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 186, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 186, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ - { 188, -1 }, /* (70) alter_db_options ::= alter_db_option */ - { 188, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ - { 189, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ - { 189, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ - { 189, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ - { 189, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ - { 189, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ - { 189, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ - { 176, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 176, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ - { 176, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 176, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ - { 176, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ - { 176, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ - { 176, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ - { 197, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ - { 197, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 197, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 197, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 197, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 197, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 197, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 197, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 197, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 197, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 194, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ - { 194, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 201, -9 }, /* (97) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 196, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ - { 196, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 204, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ - { 202, 0 }, /* (101) specific_tags_opt ::= */ - { 202, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 190, -1 }, /* (103) full_table_name ::= table_name */ - { 190, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ - { 191, -1 }, /* (105) column_def_list ::= column_def */ - { 191, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ - { 207, -2 }, /* (107) column_def ::= column_name type_name */ - { 207, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ - { 200, -1 }, /* (109) type_name ::= BOOL */ - { 200, -1 }, /* (110) type_name ::= TINYINT */ - { 200, -1 }, /* (111) type_name ::= SMALLINT */ - { 200, -1 }, /* (112) type_name ::= INT */ - { 200, -1 }, /* (113) type_name ::= INTEGER */ - { 200, -1 }, /* (114) type_name ::= BIGINT */ - { 200, -1 }, /* (115) type_name ::= FLOAT */ - { 200, -1 }, /* (116) type_name ::= DOUBLE */ - { 200, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 200, -1 }, /* (118) type_name ::= TIMESTAMP */ - { 200, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 200, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ - { 200, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ - { 200, -2 }, /* (122) type_name ::= INT UNSIGNED */ - { 200, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ - { 200, -1 }, /* (124) type_name ::= JSON */ - { 200, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 200, -1 }, /* (126) type_name ::= MEDIUMBLOB */ - { 200, -1 }, /* (127) type_name ::= BLOB */ - { 200, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 200, -1 }, /* (129) type_name ::= DECIMAL */ - { 200, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 200, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 192, 0 }, /* (132) tags_def_opt ::= */ - { 192, -1 }, /* (133) tags_def_opt ::= tags_def */ - { 195, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 193, 0 }, /* (135) table_options ::= */ - { 193, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ - { 193, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ - { 193, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ - { 193, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 193, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 193, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ - { 193, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ - { 198, -1 }, /* (143) alter_table_options ::= alter_table_option */ - { 198, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ - { 209, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ - { 209, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ - { 209, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ - { 205, -1 }, /* (148) col_name_list ::= col_name */ - { 205, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ - { 210, -1 }, /* (150) col_name ::= column_name */ - { 176, -2 }, /* (151) cmd ::= SHOW DNODES */ - { 176, -2 }, /* (152) cmd ::= SHOW USERS */ - { 176, -2 }, /* (153) cmd ::= SHOW DATABASES */ - { 176, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 176, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 176, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 176, -2 }, /* (157) cmd ::= SHOW MNODES */ - { 176, -2 }, /* (158) cmd ::= SHOW MODULES */ - { 176, -2 }, /* (159) cmd ::= SHOW QNODES */ - { 176, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ - { 176, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 176, -2 }, /* (162) cmd ::= SHOW STREAMS */ - { 211, 0 }, /* (163) db_name_cond_opt ::= */ - { 211, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ - { 212, 0 }, /* (165) like_pattern_opt ::= */ - { 212, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ - { 213, -1 }, /* (167) table_name_cond ::= table_name */ - { 214, 0 }, /* (168) from_db_opt ::= */ - { 214, -2 }, /* (169) from_db_opt ::= FROM db_name */ - { 208, -1 }, /* (170) func_name_list ::= func_name */ - { 208, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ - { 215, -1 }, /* (172) func_name ::= function_name */ - { 176, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 176, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 176, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 218, 0 }, /* (176) index_options ::= */ - { 218, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 218, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 219, -1 }, /* (179) func_list ::= func */ - { 219, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ - { 222, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ - { 176, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 176, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ - { 176, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ - { 176, -4 }, /* (185) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ - { 226, 0 }, /* (186) analyze_opt ::= */ - { 226, -1 }, /* (187) analyze_opt ::= ANALYZE */ - { 227, 0 }, /* (188) explain_options ::= */ - { 227, -3 }, /* (189) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 227, -3 }, /* (190) explain_options ::= explain_options RATIO NK_FLOAT */ - { 176, -1 }, /* (191) cmd ::= query_expression */ - { 179, -1 }, /* (192) literal ::= NK_INTEGER */ - { 179, -1 }, /* (193) literal ::= NK_FLOAT */ - { 179, -1 }, /* (194) literal ::= NK_STRING */ - { 179, -1 }, /* (195) literal ::= NK_BOOL */ - { 179, -2 }, /* (196) literal ::= TIMESTAMP NK_STRING */ - { 179, -1 }, /* (197) literal ::= duration_literal */ - { 179, -1 }, /* (198) literal ::= NULL */ - { 220, -1 }, /* (199) duration_literal ::= NK_VARIABLE */ - { 228, -1 }, /* (200) signed ::= NK_INTEGER */ - { 228, -2 }, /* (201) signed ::= NK_PLUS NK_INTEGER */ - { 228, -2 }, /* (202) signed ::= NK_MINUS NK_INTEGER */ - { 228, -1 }, /* (203) signed ::= NK_FLOAT */ - { 228, -2 }, /* (204) signed ::= NK_PLUS NK_FLOAT */ - { 228, -2 }, /* (205) signed ::= NK_MINUS NK_FLOAT */ - { 229, -1 }, /* (206) signed_literal ::= signed */ - { 229, -1 }, /* (207) signed_literal ::= NK_STRING */ - { 229, -1 }, /* (208) signed_literal ::= NK_BOOL */ - { 229, -2 }, /* (209) signed_literal ::= TIMESTAMP NK_STRING */ - { 229, -1 }, /* (210) signed_literal ::= duration_literal */ - { 229, -1 }, /* (211) signed_literal ::= NULL */ - { 203, -1 }, /* (212) literal_list ::= signed_literal */ - { 203, -3 }, /* (213) literal_list ::= literal_list NK_COMMA signed_literal */ - { 185, -1 }, /* (214) db_name ::= NK_ID */ - { 206, -1 }, /* (215) table_name ::= NK_ID */ - { 199, -1 }, /* (216) column_name ::= NK_ID */ - { 216, -1 }, /* (217) function_name ::= NK_ID */ - { 230, -1 }, /* (218) table_alias ::= NK_ID */ - { 231, -1 }, /* (219) column_alias ::= NK_ID */ - { 181, -1 }, /* (220) user_name ::= NK_ID */ - { 217, -1 }, /* (221) index_name ::= NK_ID */ - { 224, -1 }, /* (222) topic_name ::= NK_ID */ - { 232, -1 }, /* (223) expression ::= literal */ - { 232, -1 }, /* (224) expression ::= pseudo_column */ - { 232, -1 }, /* (225) expression ::= column_reference */ - { 232, -4 }, /* (226) expression ::= function_name NK_LP expression_list NK_RP */ - { 232, -4 }, /* (227) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 232, -1 }, /* (228) expression ::= subquery */ - { 232, -3 }, /* (229) expression ::= NK_LP expression NK_RP */ - { 232, -2 }, /* (230) expression ::= NK_PLUS expression */ - { 232, -2 }, /* (231) expression ::= NK_MINUS expression */ - { 232, -3 }, /* (232) expression ::= expression NK_PLUS expression */ - { 232, -3 }, /* (233) expression ::= expression NK_MINUS expression */ - { 232, -3 }, /* (234) expression ::= expression NK_STAR expression */ - { 232, -3 }, /* (235) expression ::= expression NK_SLASH expression */ - { 232, -3 }, /* (236) expression ::= expression NK_REM expression */ - { 223, -1 }, /* (237) expression_list ::= expression */ - { 223, -3 }, /* (238) expression_list ::= expression_list NK_COMMA expression */ - { 234, -1 }, /* (239) column_reference ::= column_name */ - { 234, -3 }, /* (240) column_reference ::= table_name NK_DOT column_name */ - { 233, -2 }, /* (241) pseudo_column ::= NK_UNDERLINE ROWTS */ - { 233, -1 }, /* (242) pseudo_column ::= TBNAME */ - { 233, -2 }, /* (243) pseudo_column ::= NK_UNDERLINE QSTARTTS */ - { 233, -2 }, /* (244) pseudo_column ::= NK_UNDERLINE QENDTS */ - { 233, -2 }, /* (245) pseudo_column ::= NK_UNDERLINE WSTARTTS */ - { 233, -2 }, /* (246) pseudo_column ::= NK_UNDERLINE WENDTS */ - { 233, -2 }, /* (247) pseudo_column ::= NK_UNDERLINE WDURATION */ - { 236, -3 }, /* (248) predicate ::= expression compare_op expression */ - { 236, -5 }, /* (249) predicate ::= expression BETWEEN expression AND expression */ - { 236, -6 }, /* (250) predicate ::= expression NOT BETWEEN expression AND expression */ - { 236, -3 }, /* (251) predicate ::= expression IS NULL */ - { 236, -4 }, /* (252) predicate ::= expression IS NOT NULL */ - { 236, -3 }, /* (253) predicate ::= expression in_op in_predicate_value */ - { 237, -1 }, /* (254) compare_op ::= NK_LT */ - { 237, -1 }, /* (255) compare_op ::= NK_GT */ - { 237, -1 }, /* (256) compare_op ::= NK_LE */ - { 237, -1 }, /* (257) compare_op ::= NK_GE */ - { 237, -1 }, /* (258) compare_op ::= NK_NE */ - { 237, -1 }, /* (259) compare_op ::= NK_EQ */ - { 237, -1 }, /* (260) compare_op ::= LIKE */ - { 237, -2 }, /* (261) compare_op ::= NOT LIKE */ - { 237, -1 }, /* (262) compare_op ::= MATCH */ - { 237, -1 }, /* (263) compare_op ::= NMATCH */ - { 238, -1 }, /* (264) in_op ::= IN */ - { 238, -2 }, /* (265) in_op ::= NOT IN */ - { 239, -3 }, /* (266) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 240, -1 }, /* (267) boolean_value_expression ::= boolean_primary */ - { 240, -2 }, /* (268) boolean_value_expression ::= NOT boolean_primary */ - { 240, -3 }, /* (269) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 240, -3 }, /* (270) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 241, -1 }, /* (271) boolean_primary ::= predicate */ - { 241, -3 }, /* (272) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 242, -1 }, /* (273) common_expression ::= expression */ - { 242, -1 }, /* (274) common_expression ::= boolean_value_expression */ - { 243, -2 }, /* (275) from_clause ::= FROM table_reference_list */ - { 244, -1 }, /* (276) table_reference_list ::= table_reference */ - { 244, -3 }, /* (277) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 245, -1 }, /* (278) table_reference ::= table_primary */ - { 245, -1 }, /* (279) table_reference ::= joined_table */ - { 246, -2 }, /* (280) table_primary ::= table_name alias_opt */ - { 246, -4 }, /* (281) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 246, -2 }, /* (282) table_primary ::= subquery alias_opt */ - { 246, -1 }, /* (283) table_primary ::= parenthesized_joined_table */ - { 248, 0 }, /* (284) alias_opt ::= */ - { 248, -1 }, /* (285) alias_opt ::= table_alias */ - { 248, -2 }, /* (286) alias_opt ::= AS table_alias */ - { 249, -3 }, /* (287) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 249, -3 }, /* (288) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 247, -6 }, /* (289) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 250, 0 }, /* (290) join_type ::= */ - { 250, -1 }, /* (291) join_type ::= INNER */ - { 252, -9 }, /* (292) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 253, 0 }, /* (293) set_quantifier_opt ::= */ - { 253, -1 }, /* (294) set_quantifier_opt ::= DISTINCT */ - { 253, -1 }, /* (295) set_quantifier_opt ::= ALL */ - { 254, -1 }, /* (296) select_list ::= NK_STAR */ - { 254, -1 }, /* (297) select_list ::= select_sublist */ - { 260, -1 }, /* (298) select_sublist ::= select_item */ - { 260, -3 }, /* (299) select_sublist ::= select_sublist NK_COMMA select_item */ - { 261, -1 }, /* (300) select_item ::= common_expression */ - { 261, -2 }, /* (301) select_item ::= common_expression column_alias */ - { 261, -3 }, /* (302) select_item ::= common_expression AS column_alias */ - { 261, -3 }, /* (303) select_item ::= table_name NK_DOT NK_STAR */ - { 255, 0 }, /* (304) where_clause_opt ::= */ - { 255, -2 }, /* (305) where_clause_opt ::= WHERE search_condition */ - { 256, 0 }, /* (306) partition_by_clause_opt ::= */ - { 256, -3 }, /* (307) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 257, 0 }, /* (308) twindow_clause_opt ::= */ - { 257, -6 }, /* (309) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 257, -4 }, /* (310) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 257, -6 }, /* (311) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 257, -8 }, /* (312) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 221, 0 }, /* (313) sliding_opt ::= */ - { 221, -4 }, /* (314) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 262, 0 }, /* (315) fill_opt ::= */ - { 262, -4 }, /* (316) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 262, -6 }, /* (317) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 263, -1 }, /* (318) fill_mode ::= NONE */ - { 263, -1 }, /* (319) fill_mode ::= PREV */ - { 263, -1 }, /* (320) fill_mode ::= NULL */ - { 263, -1 }, /* (321) fill_mode ::= LINEAR */ - { 263, -1 }, /* (322) fill_mode ::= NEXT */ - { 258, 0 }, /* (323) group_by_clause_opt ::= */ - { 258, -3 }, /* (324) group_by_clause_opt ::= GROUP BY group_by_list */ - { 264, -1 }, /* (325) group_by_list ::= expression */ - { 264, -3 }, /* (326) group_by_list ::= group_by_list NK_COMMA expression */ - { 259, 0 }, /* (327) having_clause_opt ::= */ - { 259, -2 }, /* (328) having_clause_opt ::= HAVING search_condition */ - { 225, -4 }, /* (329) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 265, -1 }, /* (330) query_expression_body ::= query_primary */ - { 265, -4 }, /* (331) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 269, -1 }, /* (332) query_primary ::= query_specification */ - { 266, 0 }, /* (333) order_by_clause_opt ::= */ - { 266, -3 }, /* (334) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 267, 0 }, /* (335) slimit_clause_opt ::= */ - { 267, -2 }, /* (336) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 267, -4 }, /* (337) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 267, -4 }, /* (338) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 268, 0 }, /* (339) limit_clause_opt ::= */ - { 268, -2 }, /* (340) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 268, -4 }, /* (341) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 268, -4 }, /* (342) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 235, -3 }, /* (343) subquery ::= NK_LP query_expression NK_RP */ - { 251, -1 }, /* (344) search_condition ::= common_expression */ - { 270, -1 }, /* (345) sort_specification_list ::= sort_specification */ - { 270, -3 }, /* (346) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 271, -3 }, /* (347) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 272, 0 }, /* (348) ordering_specification_opt ::= */ - { 272, -1 }, /* (349) ordering_specification_opt ::= ASC */ - { 272, -1 }, /* (350) ordering_specification_opt ::= DESC */ - { 273, 0 }, /* (351) null_ordering_opt ::= */ - { 273, -2 }, /* (352) null_ordering_opt ::= NULLS FIRST */ - { 273, -2 }, /* (353) null_ordering_opt ::= NULLS LAST */ + { 201, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 201, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 202, 0 }, /* (2) account_options ::= */ + { 202, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 202, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 202, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 202, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 202, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 202, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 202, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 202, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 202, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 203, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 203, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 205, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 205, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 205, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 205, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 205, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 205, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 205, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 205, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 205, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 205, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 201, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 201, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 201, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 201, -3 }, /* (27) cmd ::= DROP USER user_name */ + { 201, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ + { 201, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 201, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ + { 201, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ + { 201, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 201, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 201, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ + { 201, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 207, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ + { 208, -1 }, /* (37) dnode_host_name ::= NK_ID */ + { 208, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ + { 201, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ + { 201, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 201, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 201, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 201, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 201, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ + { 201, -2 }, /* (45) cmd ::= USE db_name */ + { 201, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 209, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ + { 209, 0 }, /* (48) not_exists_opt ::= */ + { 212, -2 }, /* (49) exists_opt ::= IF EXISTS */ + { 212, 0 }, /* (50) exists_opt ::= */ + { 211, 0 }, /* (51) db_options ::= */ + { 211, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ + { 211, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ + { 211, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ + { 211, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ + { 211, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ + { 211, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ + { 211, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ + { 211, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ + { 211, -3 }, /* (60) db_options ::= db_options KEEP integer_list */ + { 211, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ + { 211, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ + { 211, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ + { 211, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ + { 211, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ + { 211, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ + { 211, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 211, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 211, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ + { 213, -1 }, /* (70) alter_db_options ::= alter_db_option */ + { 213, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ + { 215, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ + { 215, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ + { 215, -2 }, /* (74) alter_db_option ::= KEEP integer_list */ + { 215, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ + { 215, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ + { 215, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ + { 215, -2 }, /* (78) alter_db_option ::= REPLICA NK_INTEGER */ + { 214, -1 }, /* (79) integer_list ::= NK_INTEGER */ + { 214, -3 }, /* (80) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 201, -9 }, /* (81) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 201, -3 }, /* (82) cmd ::= CREATE TABLE multi_create_clause */ + { 201, -9 }, /* (83) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 201, -3 }, /* (84) cmd ::= DROP TABLE multi_drop_clause */ + { 201, -4 }, /* (85) cmd ::= DROP STABLE exists_opt full_table_name */ + { 201, -3 }, /* (86) cmd ::= ALTER TABLE alter_table_clause */ + { 201, -3 }, /* (87) cmd ::= ALTER STABLE alter_table_clause */ + { 223, -2 }, /* (88) alter_table_clause ::= full_table_name alter_table_options */ + { 223, -5 }, /* (89) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 223, -4 }, /* (90) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 223, -5 }, /* (91) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 223, -5 }, /* (92) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 223, -5 }, /* (93) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 223, -4 }, /* (94) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 223, -5 }, /* (95) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 223, -5 }, /* (96) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 223, -6 }, /* (97) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + { 220, -1 }, /* (98) multi_create_clause ::= create_subtable_clause */ + { 220, -2 }, /* (99) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 227, -9 }, /* (100) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 222, -1 }, /* (101) multi_drop_clause ::= drop_table_clause */ + { 222, -2 }, /* (102) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 230, -2 }, /* (103) drop_table_clause ::= exists_opt full_table_name */ + { 228, 0 }, /* (104) specific_tags_opt ::= */ + { 228, -3 }, /* (105) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 216, -1 }, /* (106) full_table_name ::= table_name */ + { 216, -3 }, /* (107) full_table_name ::= db_name NK_DOT table_name */ + { 217, -1 }, /* (108) column_def_list ::= column_def */ + { 217, -3 }, /* (109) column_def_list ::= column_def_list NK_COMMA column_def */ + { 233, -2 }, /* (110) column_def ::= column_name type_name */ + { 233, -4 }, /* (111) column_def ::= column_name type_name COMMENT NK_STRING */ + { 226, -1 }, /* (112) type_name ::= BOOL */ + { 226, -1 }, /* (113) type_name ::= TINYINT */ + { 226, -1 }, /* (114) type_name ::= SMALLINT */ + { 226, -1 }, /* (115) type_name ::= INT */ + { 226, -1 }, /* (116) type_name ::= INTEGER */ + { 226, -1 }, /* (117) type_name ::= BIGINT */ + { 226, -1 }, /* (118) type_name ::= FLOAT */ + { 226, -1 }, /* (119) type_name ::= DOUBLE */ + { 226, -4 }, /* (120) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 226, -1 }, /* (121) type_name ::= TIMESTAMP */ + { 226, -4 }, /* (122) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 226, -2 }, /* (123) type_name ::= TINYINT UNSIGNED */ + { 226, -2 }, /* (124) type_name ::= SMALLINT UNSIGNED */ + { 226, -2 }, /* (125) type_name ::= INT UNSIGNED */ + { 226, -2 }, /* (126) type_name ::= BIGINT UNSIGNED */ + { 226, -1 }, /* (127) type_name ::= JSON */ + { 226, -4 }, /* (128) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 226, -1 }, /* (129) type_name ::= MEDIUMBLOB */ + { 226, -1 }, /* (130) type_name ::= BLOB */ + { 226, -4 }, /* (131) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 226, -1 }, /* (132) type_name ::= DECIMAL */ + { 226, -4 }, /* (133) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 226, -6 }, /* (134) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 218, 0 }, /* (135) tags_def_opt ::= */ + { 218, -1 }, /* (136) tags_def_opt ::= tags_def */ + { 221, -4 }, /* (137) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 219, 0 }, /* (138) table_options ::= */ + { 219, -3 }, /* (139) table_options ::= table_options COMMENT NK_STRING */ + { 219, -3 }, /* (140) table_options ::= table_options KEEP integer_list */ + { 219, -3 }, /* (141) table_options ::= table_options TTL NK_INTEGER */ + { 219, -5 }, /* (142) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 219, -5 }, /* (143) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ + { 219, -3 }, /* (144) table_options ::= table_options FILE_FACTOR NK_FLOAT */ + { 219, -3 }, /* (145) table_options ::= table_options DELAY NK_INTEGER */ + { 224, -1 }, /* (146) alter_table_options ::= alter_table_option */ + { 224, -2 }, /* (147) alter_table_options ::= alter_table_options alter_table_option */ + { 235, -2 }, /* (148) alter_table_option ::= COMMENT NK_STRING */ + { 235, -2 }, /* (149) alter_table_option ::= KEEP integer_list */ + { 235, -2 }, /* (150) alter_table_option ::= TTL NK_INTEGER */ + { 231, -1 }, /* (151) col_name_list ::= col_name */ + { 231, -3 }, /* (152) col_name_list ::= col_name_list NK_COMMA col_name */ + { 236, -1 }, /* (153) col_name ::= column_name */ + { 201, -2 }, /* (154) cmd ::= SHOW DNODES */ + { 201, -2 }, /* (155) cmd ::= SHOW USERS */ + { 201, -2 }, /* (156) cmd ::= SHOW DATABASES */ + { 201, -4 }, /* (157) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 201, -4 }, /* (158) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 201, -3 }, /* (159) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 201, -2 }, /* (160) cmd ::= SHOW MNODES */ + { 201, -2 }, /* (161) cmd ::= SHOW MODULES */ + { 201, -2 }, /* (162) cmd ::= SHOW QNODES */ + { 201, -2 }, /* (163) cmd ::= SHOW FUNCTIONS */ + { 201, -5 }, /* (164) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 201, -2 }, /* (165) cmd ::= SHOW STREAMS */ + { 201, -2 }, /* (166) cmd ::= SHOW ACCOUNTS */ + { 201, -2 }, /* (167) cmd ::= SHOW APPS */ + { 201, -2 }, /* (168) cmd ::= SHOW CONNECTIONS */ + { 201, -2 }, /* (169) cmd ::= SHOW LICENCE */ + { 201, -4 }, /* (170) cmd ::= SHOW CREATE DATABASE db_name */ + { 201, -4 }, /* (171) cmd ::= SHOW CREATE TABLE full_table_name */ + { 201, -4 }, /* (172) cmd ::= SHOW CREATE STABLE full_table_name */ + { 201, -2 }, /* (173) cmd ::= SHOW QUERIES */ + { 201, -2 }, /* (174) cmd ::= SHOW SCORES */ + { 201, -2 }, /* (175) cmd ::= SHOW TOPICS */ + { 201, -2 }, /* (176) cmd ::= SHOW VARIABLES */ + { 237, 0 }, /* (177) db_name_cond_opt ::= */ + { 237, -2 }, /* (178) db_name_cond_opt ::= db_name NK_DOT */ + { 238, 0 }, /* (179) like_pattern_opt ::= */ + { 238, -2 }, /* (180) like_pattern_opt ::= LIKE NK_STRING */ + { 239, -1 }, /* (181) table_name_cond ::= table_name */ + { 240, 0 }, /* (182) from_db_opt ::= */ + { 240, -2 }, /* (183) from_db_opt ::= FROM db_name */ + { 234, -1 }, /* (184) func_name_list ::= func_name */ + { 234, -3 }, /* (185) func_name_list ::= func_name_list NK_COMMA col_name */ + { 241, -1 }, /* (186) func_name ::= function_name */ + { 201, -8 }, /* (187) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 201, -10 }, /* (188) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 201, -6 }, /* (189) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 244, 0 }, /* (190) index_options ::= */ + { 244, -9 }, /* (191) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 244, -11 }, /* (192) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 245, -1 }, /* (193) func_list ::= func */ + { 245, -3 }, /* (194) func_list ::= func_list NK_COMMA func */ + { 248, -4 }, /* (195) func ::= function_name NK_LP expression_list NK_RP */ + { 201, -6 }, /* (196) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 201, -6 }, /* (197) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ + { 201, -4 }, /* (198) cmd ::= DROP TOPIC exists_opt topic_name */ + { 201, -2 }, /* (199) cmd ::= DESC full_table_name */ + { 201, -2 }, /* (200) cmd ::= DESCRIBE full_table_name */ + { 201, -3 }, /* (201) cmd ::= RESET QUERY CACHE */ + { 201, -4 }, /* (202) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 252, 0 }, /* (203) analyze_opt ::= */ + { 252, -1 }, /* (204) analyze_opt ::= ANALYZE */ + { 253, 0 }, /* (205) explain_options ::= */ + { 253, -3 }, /* (206) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 253, -3 }, /* (207) explain_options ::= explain_options RATIO NK_FLOAT */ + { 201, -6 }, /* (208) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + { 201, -9 }, /* (209) cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 201, -3 }, /* (210) cmd ::= DROP FUNCTION function_name */ + { 254, 0 }, /* (211) agg_func_opt ::= */ + { 254, -1 }, /* (212) agg_func_opt ::= AGGREGATE */ + { 255, 0 }, /* (213) bufsize_opt ::= */ + { 255, -2 }, /* (214) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 201, -7 }, /* (215) cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression */ + { 201, -3 }, /* (216) cmd ::= DROP STREAM stream_name */ + { 201, -3 }, /* (217) cmd ::= KILL CONNECTION NK_INTEGER */ + { 201, -3 }, /* (218) cmd ::= KILL QUERY NK_INTEGER */ + { 201, -4 }, /* (219) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 201, -4 }, /* (220) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 201, -3 }, /* (221) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 257, -2 }, /* (222) dnode_list ::= DNODE NK_INTEGER */ + { 257, -3 }, /* (223) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 201, -3 }, /* (224) cmd ::= SYNCDB db_name REPLICA */ + { 201, -1 }, /* (225) cmd ::= query_expression */ + { 204, -1 }, /* (226) literal ::= NK_INTEGER */ + { 204, -1 }, /* (227) literal ::= NK_FLOAT */ + { 204, -1 }, /* (228) literal ::= NK_STRING */ + { 204, -1 }, /* (229) literal ::= NK_BOOL */ + { 204, -2 }, /* (230) literal ::= TIMESTAMP NK_STRING */ + { 204, -1 }, /* (231) literal ::= duration_literal */ + { 204, -1 }, /* (232) literal ::= NULL */ + { 246, -1 }, /* (233) duration_literal ::= NK_VARIABLE */ + { 258, -1 }, /* (234) signed ::= NK_INTEGER */ + { 258, -2 }, /* (235) signed ::= NK_PLUS NK_INTEGER */ + { 258, -2 }, /* (236) signed ::= NK_MINUS NK_INTEGER */ + { 258, -1 }, /* (237) signed ::= NK_FLOAT */ + { 258, -2 }, /* (238) signed ::= NK_PLUS NK_FLOAT */ + { 258, -2 }, /* (239) signed ::= NK_MINUS NK_FLOAT */ + { 259, -1 }, /* (240) signed_literal ::= signed */ + { 259, -1 }, /* (241) signed_literal ::= NK_STRING */ + { 259, -1 }, /* (242) signed_literal ::= NK_BOOL */ + { 259, -2 }, /* (243) signed_literal ::= TIMESTAMP NK_STRING */ + { 259, -1 }, /* (244) signed_literal ::= duration_literal */ + { 259, -1 }, /* (245) signed_literal ::= NULL */ + { 229, -1 }, /* (246) literal_list ::= signed_literal */ + { 229, -3 }, /* (247) literal_list ::= literal_list NK_COMMA signed_literal */ + { 210, -1 }, /* (248) db_name ::= NK_ID */ + { 232, -1 }, /* (249) table_name ::= NK_ID */ + { 225, -1 }, /* (250) column_name ::= NK_ID */ + { 242, -1 }, /* (251) function_name ::= NK_ID */ + { 260, -1 }, /* (252) table_alias ::= NK_ID */ + { 261, -1 }, /* (253) column_alias ::= NK_ID */ + { 206, -1 }, /* (254) user_name ::= NK_ID */ + { 243, -1 }, /* (255) index_name ::= NK_ID */ + { 250, -1 }, /* (256) topic_name ::= NK_ID */ + { 256, -1 }, /* (257) stream_name ::= NK_ID */ + { 262, -1 }, /* (258) expression ::= literal */ + { 262, -1 }, /* (259) expression ::= pseudo_column */ + { 262, -1 }, /* (260) expression ::= column_reference */ + { 262, -4 }, /* (261) expression ::= function_name NK_LP expression_list NK_RP */ + { 262, -4 }, /* (262) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 262, -1 }, /* (263) expression ::= subquery */ + { 262, -3 }, /* (264) expression ::= NK_LP expression NK_RP */ + { 262, -2 }, /* (265) expression ::= NK_PLUS expression */ + { 262, -2 }, /* (266) expression ::= NK_MINUS expression */ + { 262, -3 }, /* (267) expression ::= expression NK_PLUS expression */ + { 262, -3 }, /* (268) expression ::= expression NK_MINUS expression */ + { 262, -3 }, /* (269) expression ::= expression NK_STAR expression */ + { 262, -3 }, /* (270) expression ::= expression NK_SLASH expression */ + { 262, -3 }, /* (271) expression ::= expression NK_REM expression */ + { 249, -1 }, /* (272) expression_list ::= expression */ + { 249, -3 }, /* (273) expression_list ::= expression_list NK_COMMA expression */ + { 264, -1 }, /* (274) column_reference ::= column_name */ + { 264, -3 }, /* (275) column_reference ::= table_name NK_DOT column_name */ + { 263, -1 }, /* (276) pseudo_column ::= NOW */ + { 263, -1 }, /* (277) pseudo_column ::= ROWTS */ + { 263, -1 }, /* (278) pseudo_column ::= TBNAME */ + { 263, -1 }, /* (279) pseudo_column ::= QSTARTTS */ + { 263, -1 }, /* (280) pseudo_column ::= QENDTS */ + { 263, -1 }, /* (281) pseudo_column ::= WSTARTTS */ + { 263, -1 }, /* (282) pseudo_column ::= WENDTS */ + { 263, -1 }, /* (283) pseudo_column ::= WDURATION */ + { 266, -3 }, /* (284) predicate ::= expression compare_op expression */ + { 266, -5 }, /* (285) predicate ::= expression BETWEEN expression AND expression */ + { 266, -6 }, /* (286) predicate ::= expression NOT BETWEEN expression AND expression */ + { 266, -3 }, /* (287) predicate ::= expression IS NULL */ + { 266, -4 }, /* (288) predicate ::= expression IS NOT NULL */ + { 266, -3 }, /* (289) predicate ::= expression in_op in_predicate_value */ + { 267, -1 }, /* (290) compare_op ::= NK_LT */ + { 267, -1 }, /* (291) compare_op ::= NK_GT */ + { 267, -1 }, /* (292) compare_op ::= NK_LE */ + { 267, -1 }, /* (293) compare_op ::= NK_GE */ + { 267, -1 }, /* (294) compare_op ::= NK_NE */ + { 267, -1 }, /* (295) compare_op ::= NK_EQ */ + { 267, -1 }, /* (296) compare_op ::= LIKE */ + { 267, -2 }, /* (297) compare_op ::= NOT LIKE */ + { 267, -1 }, /* (298) compare_op ::= MATCH */ + { 267, -1 }, /* (299) compare_op ::= NMATCH */ + { 268, -1 }, /* (300) in_op ::= IN */ + { 268, -2 }, /* (301) in_op ::= NOT IN */ + { 269, -3 }, /* (302) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 270, -1 }, /* (303) boolean_value_expression ::= boolean_primary */ + { 270, -2 }, /* (304) boolean_value_expression ::= NOT boolean_primary */ + { 270, -3 }, /* (305) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 270, -3 }, /* (306) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 271, -1 }, /* (307) boolean_primary ::= predicate */ + { 271, -3 }, /* (308) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 272, -1 }, /* (309) common_expression ::= expression */ + { 272, -1 }, /* (310) common_expression ::= boolean_value_expression */ + { 273, -2 }, /* (311) from_clause ::= FROM table_reference_list */ + { 274, -1 }, /* (312) table_reference_list ::= table_reference */ + { 274, -3 }, /* (313) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 275, -1 }, /* (314) table_reference ::= table_primary */ + { 275, -1 }, /* (315) table_reference ::= joined_table */ + { 276, -2 }, /* (316) table_primary ::= table_name alias_opt */ + { 276, -4 }, /* (317) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 276, -2 }, /* (318) table_primary ::= subquery alias_opt */ + { 276, -1 }, /* (319) table_primary ::= parenthesized_joined_table */ + { 278, 0 }, /* (320) alias_opt ::= */ + { 278, -1 }, /* (321) alias_opt ::= table_alias */ + { 278, -2 }, /* (322) alias_opt ::= AS table_alias */ + { 279, -3 }, /* (323) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 279, -3 }, /* (324) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 277, -6 }, /* (325) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 280, 0 }, /* (326) join_type ::= */ + { 280, -1 }, /* (327) join_type ::= INNER */ + { 282, -9 }, /* (328) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 283, 0 }, /* (329) set_quantifier_opt ::= */ + { 283, -1 }, /* (330) set_quantifier_opt ::= DISTINCT */ + { 283, -1 }, /* (331) set_quantifier_opt ::= ALL */ + { 284, -1 }, /* (332) select_list ::= NK_STAR */ + { 284, -1 }, /* (333) select_list ::= select_sublist */ + { 290, -1 }, /* (334) select_sublist ::= select_item */ + { 290, -3 }, /* (335) select_sublist ::= select_sublist NK_COMMA select_item */ + { 291, -1 }, /* (336) select_item ::= common_expression */ + { 291, -2 }, /* (337) select_item ::= common_expression column_alias */ + { 291, -3 }, /* (338) select_item ::= common_expression AS column_alias */ + { 291, -3 }, /* (339) select_item ::= table_name NK_DOT NK_STAR */ + { 285, 0 }, /* (340) where_clause_opt ::= */ + { 285, -2 }, /* (341) where_clause_opt ::= WHERE search_condition */ + { 286, 0 }, /* (342) partition_by_clause_opt ::= */ + { 286, -3 }, /* (343) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 287, 0 }, /* (344) twindow_clause_opt ::= */ + { 287, -6 }, /* (345) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 287, -4 }, /* (346) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 287, -6 }, /* (347) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 287, -8 }, /* (348) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 247, 0 }, /* (349) sliding_opt ::= */ + { 247, -4 }, /* (350) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 292, 0 }, /* (351) fill_opt ::= */ + { 292, -4 }, /* (352) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 292, -6 }, /* (353) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 293, -1 }, /* (354) fill_mode ::= NONE */ + { 293, -1 }, /* (355) fill_mode ::= PREV */ + { 293, -1 }, /* (356) fill_mode ::= NULL */ + { 293, -1 }, /* (357) fill_mode ::= LINEAR */ + { 293, -1 }, /* (358) fill_mode ::= NEXT */ + { 288, 0 }, /* (359) group_by_clause_opt ::= */ + { 288, -3 }, /* (360) group_by_clause_opt ::= GROUP BY group_by_list */ + { 294, -1 }, /* (361) group_by_list ::= expression */ + { 294, -3 }, /* (362) group_by_list ::= group_by_list NK_COMMA expression */ + { 289, 0 }, /* (363) having_clause_opt ::= */ + { 289, -2 }, /* (364) having_clause_opt ::= HAVING search_condition */ + { 251, -4 }, /* (365) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 295, -1 }, /* (366) query_expression_body ::= query_primary */ + { 295, -4 }, /* (367) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 299, -1 }, /* (368) query_primary ::= query_specification */ + { 296, 0 }, /* (369) order_by_clause_opt ::= */ + { 296, -3 }, /* (370) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 297, 0 }, /* (371) slimit_clause_opt ::= */ + { 297, -2 }, /* (372) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 297, -4 }, /* (373) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 297, -4 }, /* (374) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 298, 0 }, /* (375) limit_clause_opt ::= */ + { 298, -2 }, /* (376) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 298, -4 }, /* (377) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 298, -4 }, /* (378) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 265, -3 }, /* (379) subquery ::= NK_LP query_expression NK_RP */ + { 281, -1 }, /* (380) search_condition ::= common_expression */ + { 300, -1 }, /* (381) sort_specification_list ::= sort_specification */ + { 300, -3 }, /* (382) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 301, -3 }, /* (383) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 302, 0 }, /* (384) ordering_specification_opt ::= */ + { 302, -1 }, /* (385) ordering_specification_opt ::= ASC */ + { 302, -1 }, /* (386) ordering_specification_opt ::= DESC */ + { 303, 0 }, /* (387) null_ordering_opt ::= */ + { 303, -2 }, /* (388) null_ordering_opt ::= NULLS FIRST */ + { 303, -2 }, /* (389) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2360,11 +2517,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,177,&yymsp[0].minor); + yy_destructor(yypParser,202,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,178,&yymsp[0].minor); + yy_destructor(yypParser,203,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2378,20 +2535,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,177,&yymsp[-2].minor); +{ yy_destructor(yypParser,202,&yymsp[-2].minor); { } - yy_destructor(yypParser,179,&yymsp[0].minor); + yy_destructor(yypParser,204,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,180,&yymsp[0].minor); +{ yy_destructor(yypParser,205,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,178,&yymsp[-1].minor); +{ yy_destructor(yypParser,203,&yymsp[-1].minor); { } - yy_destructor(yypParser,180,&yymsp[0].minor); + yy_destructor(yypParser,205,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2405,31 +2562,31 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,179,&yymsp[0].minor); + yy_destructor(yypParser,204,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy437, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy129, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy437, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy129, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy437); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy129); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy437, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy129, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy0); } break; case 30: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy437); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy129); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -2446,17 +2603,18 @@ static YYACTIONTYPE yy_reduce( case 36: /* dnode_endpoint ::= NK_STRING */ case 37: /* dnode_host_name ::= NK_ID */ yytestcase(yyruleno==37); case 38: /* dnode_host_name ::= NK_IPTOKEN */ yytestcase(yyruleno==38); - case 214: /* db_name ::= NK_ID */ yytestcase(yyruleno==214); - case 215: /* table_name ::= NK_ID */ yytestcase(yyruleno==215); - case 216: /* column_name ::= NK_ID */ yytestcase(yyruleno==216); - case 217: /* function_name ::= NK_ID */ yytestcase(yyruleno==217); - case 218: /* table_alias ::= NK_ID */ yytestcase(yyruleno==218); - case 219: /* column_alias ::= NK_ID */ yytestcase(yyruleno==219); - case 220: /* user_name ::= NK_ID */ yytestcase(yyruleno==220); - case 221: /* index_name ::= NK_ID */ yytestcase(yyruleno==221); - case 222: /* topic_name ::= NK_ID */ yytestcase(yyruleno==222); -{ yylhsminor.yy437 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy437 = yylhsminor.yy437; + case 248: /* db_name ::= NK_ID */ yytestcase(yyruleno==248); + case 249: /* table_name ::= NK_ID */ yytestcase(yyruleno==249); + case 250: /* column_name ::= NK_ID */ yytestcase(yyruleno==250); + case 251: /* function_name ::= NK_ID */ yytestcase(yyruleno==251); + case 252: /* table_alias ::= NK_ID */ yytestcase(yyruleno==252); + case 253: /* column_alias ::= NK_ID */ yytestcase(yyruleno==253); + case 254: /* user_name ::= NK_ID */ yytestcase(yyruleno==254); + case 255: /* index_name ::= NK_ID */ yytestcase(yyruleno==255); + case 256: /* topic_name ::= NK_ID */ yytestcase(yyruleno==256); + case 257: /* stream_name ::= NK_ID */ yytestcase(yyruleno==257); +{ yylhsminor.yy129 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy129 = yylhsminor.yy129; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2471,967 +2629,1057 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropQnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 43: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy493, &yymsp[-1].minor.yy437, yymsp[0].minor.yy364); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy129, yymsp[0].minor.yy104); } break; case 44: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy493, &yymsp[0].minor.yy437); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy185, &yymsp[0].minor.yy129); } break; case 45: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy437); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy129); } break; case 46: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy437, yymsp[0].minor.yy364); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy129, yymsp[0].minor.yy104); } break; case 47: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy493 = true; } +{ yymsp[-2].minor.yy185 = true; } break; case 48: /* not_exists_opt ::= */ case 50: /* exists_opt ::= */ yytestcase(yyruleno==50); - case 186: /* analyze_opt ::= */ yytestcase(yyruleno==186); - case 293: /* set_quantifier_opt ::= */ yytestcase(yyruleno==293); -{ yymsp[1].minor.yy493 = false; } + case 203: /* analyze_opt ::= */ yytestcase(yyruleno==203); + case 211: /* agg_func_opt ::= */ yytestcase(yyruleno==211); + case 329: /* set_quantifier_opt ::= */ yytestcase(yyruleno==329); +{ yymsp[1].minor.yy185 = false; } break; case 49: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy493 = true; } +{ yymsp[-1].minor.yy185 = true; } break; case 51: /* db_options ::= */ -{ yymsp[1].minor.yy364 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy104 = createDefaultDatabaseOptions(pCxt); } break; case 52: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 53: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 54: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 55: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 56: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 57: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 58: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 59: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 60: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 60: /* db_options ::= db_options KEEP integer_list */ +{ yylhsminor.yy104 = setDatabaseKeepOption(pCxt, yymsp[-2].minor.yy104, yymsp[0].minor.yy312); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 61: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 62: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 63: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 64: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 65: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 66: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 67: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 68: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 69: /* db_options ::= db_options RETENTIONS NK_STRING */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseOption(pCxt, yymsp[-2].minor.yy104, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; case 70: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy364 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy364 = setDatabaseOption(pCxt, yylhsminor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } - yymsp[0].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy104 = setDatabaseAlterOption(pCxt, yylhsminor.yy104, &yymsp[0].minor.yy253); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; case 71: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-1].minor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; +{ yylhsminor.yy104 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy104, &yymsp[0].minor.yy253); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; case 72: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy253.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } break; case 73: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy253.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } break; - case 74: /* alter_db_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = DB_OPTION_KEEP; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } + case 74: /* alter_db_option ::= KEEP integer_list */ +{ yymsp[-1].minor.yy253.type = DB_OPTION_KEEP; yymsp[-1].minor.yy253.pKeep = yymsp[0].minor.yy312; } break; case 75: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = DB_OPTION_WAL; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy253.type = DB_OPTION_WAL; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } break; case 76: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy253.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } break; case 77: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } - break; - case 78: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 80: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==80); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy493, yymsp[-5].minor.yy364, yymsp[-3].minor.yy40, yymsp[-1].minor.yy40, yymsp[0].minor.yy364); } - break; - case 79: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy40); } - break; - case 81: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy40); } - break; - case 82: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy493, yymsp[0].minor.yy364); } - break; - case 83: /* cmd ::= ALTER TABLE alter_table_clause */ - case 84: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==84); - case 191: /* cmd ::= query_expression */ yytestcase(yyruleno==191); -{ pCxt->pRootNode = yymsp[0].minor.yy364; } - break; - case 85: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy364 = createAlterTableOption(pCxt, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; - break; - case 86: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; - break; - case 87: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy364 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy364, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy437); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; - break; - case 88: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; - break; - case 89: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy364 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; - break; - case 90: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; - break; - case 91: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy364 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy364, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy437); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; - break; - case 92: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; - break; - case 93: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy364 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; - break; - case 94: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy364 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy364, &yymsp[-2].minor.yy437, yymsp[0].minor.yy364); } - yymsp[-5].minor.yy364 = yylhsminor.yy364; - break; - case 95: /* multi_create_clause ::= create_subtable_clause */ - case 98: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==98); - case 105: /* column_def_list ::= column_def */ yytestcase(yyruleno==105); - case 148: /* col_name_list ::= col_name */ yytestcase(yyruleno==148); - case 170: /* func_name_list ::= func_name */ yytestcase(yyruleno==170); - case 179: /* func_list ::= func */ yytestcase(yyruleno==179); - case 212: /* literal_list ::= signed_literal */ yytestcase(yyruleno==212); - case 298: /* select_sublist ::= select_item */ yytestcase(yyruleno==298); - case 345: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==345); -{ yylhsminor.yy40 = createNodeList(pCxt, yymsp[0].minor.yy364); } - yymsp[0].minor.yy40 = yylhsminor.yy40; +{ yymsp[-1].minor.yy253.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } + break; + case 78: /* alter_db_option ::= REPLICA NK_INTEGER */ +{ yymsp[-1].minor.yy253.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } + break; + case 79: /* integer_list ::= NK_INTEGER */ +{ yylhsminor.yy312 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy312 = yylhsminor.yy312; + break; + case 80: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ + case 223: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==223); +{ yylhsminor.yy312 = addNodeToList(pCxt, yymsp[-2].minor.yy312, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy312 = yylhsminor.yy312; + break; + case 81: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 83: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==83); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy185, yymsp[-5].minor.yy104, yymsp[-3].minor.yy312, yymsp[-1].minor.yy312, yymsp[0].minor.yy104); } + break; + case 82: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy312); } + break; + case 84: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy312); } + break; + case 85: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy185, yymsp[0].minor.yy104); } + break; + case 86: /* cmd ::= ALTER TABLE alter_table_clause */ + case 87: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==87); + case 225: /* cmd ::= query_expression */ yytestcase(yyruleno==225); +{ pCxt->pRootNode = yymsp[0].minor.yy104; } + break; + case 88: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy104 = createAlterTableOption(pCxt, yymsp[-1].minor.yy104, yymsp[0].minor.yy104); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; + break; + case 89: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ +{ yylhsminor.yy104 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy104, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy129, yymsp[0].minor.yy336); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; + break; + case 90: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ +{ yylhsminor.yy104 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy104, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy129); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; + break; + case 91: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ +{ yylhsminor.yy104 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy104, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy129, yymsp[0].minor.yy336); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; + break; + case 92: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ +{ yylhsminor.yy104 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy104, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; + break; + case 93: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ +{ yylhsminor.yy104 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy104, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy129, yymsp[0].minor.yy336); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; + break; + case 94: /* alter_table_clause ::= full_table_name DROP TAG column_name */ +{ yylhsminor.yy104 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy104, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy129); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; + break; + case 95: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ +{ yylhsminor.yy104 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy104, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy129, yymsp[0].minor.yy336); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; + break; + case 96: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ +{ yylhsminor.yy104 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy104, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; + break; + case 97: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ +{ yylhsminor.yy104 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy104, &yymsp[-2].minor.yy129, yymsp[0].minor.yy104); } + yymsp[-5].minor.yy104 = yylhsminor.yy104; + break; + case 98: /* multi_create_clause ::= create_subtable_clause */ + case 101: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==101); + case 108: /* column_def_list ::= column_def */ yytestcase(yyruleno==108); + case 151: /* col_name_list ::= col_name */ yytestcase(yyruleno==151); + case 184: /* func_name_list ::= func_name */ yytestcase(yyruleno==184); + case 193: /* func_list ::= func */ yytestcase(yyruleno==193); + case 246: /* literal_list ::= signed_literal */ yytestcase(yyruleno==246); + case 334: /* select_sublist ::= select_item */ yytestcase(yyruleno==334); + case 381: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==381); +{ yylhsminor.yy312 = createNodeList(pCxt, yymsp[0].minor.yy104); } + yymsp[0].minor.yy312 = yylhsminor.yy312; break; - case 96: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 99: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==99); -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-1].minor.yy40, yymsp[0].minor.yy364); } - yymsp[-1].minor.yy40 = yylhsminor.yy40; + case 99: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 102: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==102); +{ yylhsminor.yy312 = addNodeToList(pCxt, yymsp[-1].minor.yy312, yymsp[0].minor.yy104); } + yymsp[-1].minor.yy312 = yylhsminor.yy312; break; - case 97: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy364 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy493, yymsp[-7].minor.yy364, yymsp[-5].minor.yy364, yymsp[-4].minor.yy40, yymsp[-1].minor.yy40); } - yymsp[-8].minor.yy364 = yylhsminor.yy364; + case 100: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ +{ yylhsminor.yy104 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy185, yymsp[-7].minor.yy104, yymsp[-5].minor.yy104, yymsp[-4].minor.yy312, yymsp[-1].minor.yy312); } + yymsp[-8].minor.yy104 = yylhsminor.yy104; break; - case 100: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy364 = createDropTableClause(pCxt, yymsp[-1].minor.yy493, yymsp[0].minor.yy364); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 103: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy104 = createDropTableClause(pCxt, yymsp[-1].minor.yy185, yymsp[0].minor.yy104); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 101: /* specific_tags_opt ::= */ - case 132: /* tags_def_opt ::= */ yytestcase(yyruleno==132); - case 306: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==306); - case 323: /* group_by_clause_opt ::= */ yytestcase(yyruleno==323); - case 333: /* order_by_clause_opt ::= */ yytestcase(yyruleno==333); -{ yymsp[1].minor.yy40 = NULL; } + case 104: /* specific_tags_opt ::= */ + case 135: /* tags_def_opt ::= */ yytestcase(yyruleno==135); + case 342: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==342); + case 359: /* group_by_clause_opt ::= */ yytestcase(yyruleno==359); + case 369: /* order_by_clause_opt ::= */ yytestcase(yyruleno==369); +{ yymsp[1].minor.yy312 = NULL; } break; - case 102: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy40 = yymsp[-1].minor.yy40; } + case 105: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy312 = yymsp[-1].minor.yy312; } break; - case 103: /* full_table_name ::= table_name */ -{ yylhsminor.yy364 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy437, NULL); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 106: /* full_table_name ::= table_name */ +{ yylhsminor.yy104 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy129, NULL); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 104: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy364 = createRealTableNode(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437, NULL); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 107: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy104 = createRealTableNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129, NULL); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 106: /* column_def_list ::= column_def_list NK_COMMA column_def */ - case 149: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==149); - case 171: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==171); - case 180: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==180); - case 213: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==213); - case 299: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==299); - case 346: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==346); -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, yymsp[0].minor.yy364); } - yymsp[-2].minor.yy40 = yylhsminor.yy40; + case 109: /* column_def_list ::= column_def_list NK_COMMA column_def */ + case 152: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==152); + case 185: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==185); + case 194: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==194); + case 247: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==247); + case 335: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==335); + case 382: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==382); +{ yylhsminor.yy312 = addNodeToList(pCxt, yymsp[-2].minor.yy312, yymsp[0].minor.yy104); } + yymsp[-2].minor.yy312 = yylhsminor.yy312; break; - case 107: /* column_def ::= column_name type_name */ -{ yylhsminor.yy364 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420, NULL); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 110: /* column_def ::= column_name type_name */ +{ yylhsminor.yy104 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy129, yymsp[0].minor.yy336, NULL); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 108: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy364 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy437, yymsp[-2].minor.yy420, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + case 111: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy104 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-2].minor.yy336, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 109: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 112: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 110: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 113: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 111: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 114: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 112: /* type_name ::= INT */ - case 113: /* type_name ::= INTEGER */ yytestcase(yyruleno==113); -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_INT); } + case 115: /* type_name ::= INT */ + case 116: /* type_name ::= INTEGER */ yytestcase(yyruleno==116); +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 114: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 117: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 115: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 118: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 116: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 119: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 117: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 120: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy336 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 118: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 121: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 119: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 122: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy336 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 120: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 123: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy336 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 121: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 124: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy336 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 122: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_UINT); } + case 125: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy336 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 123: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 126: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy336 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 124: /* type_name ::= JSON */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_JSON); } + case 127: /* type_name ::= JSON */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 125: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 128: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy336 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 126: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 129: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 127: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 130: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 128: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 131: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy336 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 129: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 132: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy336 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 130: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy420 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 133: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy336 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 131: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy420 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 134: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy336 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 133: /* tags_def_opt ::= tags_def */ - case 297: /* select_list ::= select_sublist */ yytestcase(yyruleno==297); -{ yylhsminor.yy40 = yymsp[0].minor.yy40; } - yymsp[0].minor.yy40 = yylhsminor.yy40; + case 136: /* tags_def_opt ::= tags_def */ + case 333: /* select_list ::= select_sublist */ yytestcase(yyruleno==333); +{ yylhsminor.yy312 = yymsp[0].minor.yy312; } + yymsp[0].minor.yy312 = yylhsminor.yy312; break; - case 134: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy40 = yymsp[-1].minor.yy40; } + case 137: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy312 = yymsp[-1].minor.yy312; } break; - case 135: /* table_options ::= */ -{ yymsp[1].minor.yy364 = createDefaultTableOptions(pCxt); } + case 138: /* table_options ::= */ +{ yymsp[1].minor.yy104 = createDefaultTableOptions(pCxt); } break; - case 136: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 139: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy104 = setTableOption(pCxt, yymsp[-2].minor.yy104, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 137: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 140: /* table_options ::= table_options KEEP integer_list */ +{ yylhsminor.yy104 = setTableKeepOption(pCxt, yymsp[-2].minor.yy104, yymsp[0].minor.yy312); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 138: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 141: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy104 = setTableOption(pCxt, yymsp[-2].minor.yy104, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 139: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy364 = setTableSmaOption(pCxt, yymsp[-4].minor.yy364, yymsp[-1].minor.yy40); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; + case 142: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy104 = setTableSmaOption(pCxt, yymsp[-4].minor.yy104, yymsp[-1].minor.yy312); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; break; - case 140: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ yylhsminor.yy364 = setTableRollupOption(pCxt, yymsp[-4].minor.yy364, yymsp[-1].minor.yy40); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; + case 143: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ +{ yylhsminor.yy104 = setTableRollupOption(pCxt, yymsp[-4].minor.yy104, yymsp[-1].minor.yy312); } + yymsp[-4].minor.yy104 = yylhsminor.yy104; break; - case 141: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 144: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ +{ yylhsminor.yy104 = setTableOption(pCxt, yymsp[-2].minor.yy104, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 142: /* table_options ::= table_options DELAY NK_INTEGER */ -{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 145: /* table_options ::= table_options DELAY NK_INTEGER */ +{ yylhsminor.yy104 = setTableOption(pCxt, yymsp[-2].minor.yy104, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 143: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy364 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy364 = setTableOption(pCxt, yylhsminor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 146: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy104 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy104 = setTableAlterOption(pCxt, yylhsminor.yy104, &yymsp[0].minor.yy253); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 144: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-1].minor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 147: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy104 = setTableAlterOption(pCxt, yymsp[-1].minor.yy104, &yymsp[0].minor.yy253); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 145: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy29.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } + case 148: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy253.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } break; - case 146: /* alter_table_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } + case 149: /* alter_table_option ::= KEEP integer_list */ +{ yymsp[-1].minor.yy253.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy253.pKeep = yymsp[0].minor.yy312; } break; - case 147: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy29.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } + case 150: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy253.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy253.val = yymsp[0].minor.yy0; } break; - case 150: /* col_name ::= column_name */ -{ yylhsminor.yy364 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy437); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 153: /* col_name ::= column_name */ +{ yylhsminor.yy104 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy129); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 151: /* cmd ::= SHOW DNODES */ + case 154: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } break; - case 152: /* cmd ::= SHOW USERS */ + case 155: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL, NULL); } break; - case 153: /* cmd ::= SHOW DATABASES */ + case 156: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; - case 154: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy364, yymsp[0].minor.yy364); } + case 157: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy104, yymsp[0].minor.yy104); } break; - case 155: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy364, yymsp[0].minor.yy364); } + case 158: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy104, yymsp[0].minor.yy104); } break; - case 156: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy364, NULL); } + case 159: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy104, NULL); } break; - case 157: /* cmd ::= SHOW MNODES */ + case 160: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } break; - case 158: /* cmd ::= SHOW MODULES */ + case 161: /* cmd ::= SHOW MODULES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT, NULL, NULL); } break; - case 159: /* cmd ::= SHOW QNODES */ + case 162: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL, NULL); } break; - case 160: /* cmd ::= SHOW FUNCTIONS */ + case 163: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; - case 161: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } + case 164: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy104, yymsp[0].minor.yy104); } break; - case 162: /* cmd ::= SHOW STREAMS */ + case 165: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } break; - case 163: /* db_name_cond_opt ::= */ - case 168: /* from_db_opt ::= */ yytestcase(yyruleno==168); -{ yymsp[1].minor.yy364 = createDefaultDatabaseCondValue(pCxt); } + case 166: /* cmd ::= SHOW ACCOUNTS */ +{ pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; - case 164: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy437); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 167: /* cmd ::= SHOW APPS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } break; - case 165: /* like_pattern_opt ::= */ - case 176: /* index_options ::= */ yytestcase(yyruleno==176); - case 304: /* where_clause_opt ::= */ yytestcase(yyruleno==304); - case 308: /* twindow_clause_opt ::= */ yytestcase(yyruleno==308); - case 313: /* sliding_opt ::= */ yytestcase(yyruleno==313); - case 315: /* fill_opt ::= */ yytestcase(yyruleno==315); - case 327: /* having_clause_opt ::= */ yytestcase(yyruleno==327); - case 335: /* slimit_clause_opt ::= */ yytestcase(yyruleno==335); - case 339: /* limit_clause_opt ::= */ yytestcase(yyruleno==339); -{ yymsp[1].minor.yy364 = NULL; } + case 168: /* cmd ::= SHOW CONNECTIONS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } break; - case 166: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 169: /* cmd ::= SHOW LICENCE */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } break; - case 167: /* table_name_cond ::= table_name */ -{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy437); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 170: /* cmd ::= SHOW CREATE DATABASE db_name */ +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy129); } break; - case 169: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy437); } + case 171: /* cmd ::= SHOW CREATE TABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy104); } break; - case 172: /* func_name ::= function_name */ -{ yylhsminor.yy364 = createFunctionNode(pCxt, &yymsp[0].minor.yy437, NULL); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 172: /* cmd ::= SHOW CREATE STABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy104); } break; - case 173: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy493, &yymsp[-3].minor.yy437, &yymsp[-1].minor.yy437, NULL, yymsp[0].minor.yy364); } + case 173: /* cmd ::= SHOW QUERIES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } break; - case 174: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy493, &yymsp[-5].minor.yy437, &yymsp[-3].minor.yy437, yymsp[-1].minor.yy40, NULL); } + case 174: /* cmd ::= SHOW SCORES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } break; - case 175: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy493, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437); } + case 175: /* cmd ::= SHOW TOPICS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } break; - case 177: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy364 = createIndexOption(pCxt, yymsp[-6].minor.yy40, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), NULL, yymsp[0].minor.yy364); } + case 176: /* cmd ::= SHOW VARIABLES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } break; - case 178: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy364 = createIndexOption(pCxt, yymsp[-8].minor.yy40, releaseRawExprNode(pCxt, yymsp[-4].minor.yy364), releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), yymsp[0].minor.yy364); } + case 177: /* db_name_cond_opt ::= */ + case 182: /* from_db_opt ::= */ yytestcase(yyruleno==182); +{ yymsp[1].minor.yy104 = createDefaultDatabaseCondValue(pCxt); } break; - case 181: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy364 = createFunctionNode(pCxt, &yymsp[-3].minor.yy437, yymsp[-1].minor.yy40); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + case 178: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy129); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy493, &yymsp[-2].minor.yy437, yymsp[0].minor.yy364, NULL); } + case 179: /* like_pattern_opt ::= */ + case 190: /* index_options ::= */ yytestcase(yyruleno==190); + case 340: /* where_clause_opt ::= */ yytestcase(yyruleno==340); + case 344: /* twindow_clause_opt ::= */ yytestcase(yyruleno==344); + case 349: /* sliding_opt ::= */ yytestcase(yyruleno==349); + case 351: /* fill_opt ::= */ yytestcase(yyruleno==351); + case 363: /* having_clause_opt ::= */ yytestcase(yyruleno==363); + case 371: /* slimit_clause_opt ::= */ yytestcase(yyruleno==371); + case 375: /* limit_clause_opt ::= */ yytestcase(yyruleno==375); +{ yymsp[1].minor.yy104 = NULL; } break; - case 183: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy493, &yymsp[-2].minor.yy437, NULL, &yymsp[0].minor.yy437); } + case 180: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 184: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy493, &yymsp[0].minor.yy437); } + case 181: /* table_name_cond ::= table_name */ +{ yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy129); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 185: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy493, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } + case 183: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy129); } break; - case 187: /* analyze_opt ::= ANALYZE */ - case 294: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==294); -{ yymsp[0].minor.yy493 = true; } + case 186: /* func_name ::= function_name */ +{ yylhsminor.yy104 = createFunctionNode(pCxt, &yymsp[0].minor.yy129, NULL); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 188: /* explain_options ::= */ -{ yymsp[1].minor.yy364 = createDefaultExplainOptions(pCxt); } + case 187: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy129, &yymsp[-1].minor.yy129, NULL, yymsp[0].minor.yy104); } break; - case 189: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy364 = setExplainVerbose(pCxt, yymsp[-2].minor.yy364, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 188: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy185, &yymsp[-5].minor.yy129, &yymsp[-3].minor.yy129, yymsp[-1].minor.yy312, NULL); } break; - case 190: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy364 = setExplainRatio(pCxt, yymsp[-2].minor.yy364, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 189: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy185, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129); } break; - case 192: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 191: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy104 = createIndexOption(pCxt, yymsp[-6].minor.yy312, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), NULL, yymsp[0].minor.yy104); } break; - case 193: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 192: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ +{ yymsp[-10].minor.yy104 = createIndexOption(pCxt, yymsp[-8].minor.yy312, releaseRawExprNode(pCxt, yymsp[-4].minor.yy104), releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), yymsp[0].minor.yy104); } break; - case 194: /* literal ::= NK_STRING */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 195: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy104 = createFunctionNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-1].minor.yy312); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 195: /* literal ::= NK_BOOL */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 196: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy185, &yymsp[-2].minor.yy129, yymsp[0].minor.yy104, NULL); } break; - case 196: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 197: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy185, &yymsp[-2].minor.yy129, NULL, &yymsp[0].minor.yy129); } break; - case 197: /* literal ::= duration_literal */ - case 206: /* signed_literal ::= signed */ yytestcase(yyruleno==206); - case 223: /* expression ::= literal */ yytestcase(yyruleno==223); - case 224: /* expression ::= pseudo_column */ yytestcase(yyruleno==224); - case 225: /* expression ::= column_reference */ yytestcase(yyruleno==225); - case 228: /* expression ::= subquery */ yytestcase(yyruleno==228); - case 267: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==267); - case 271: /* boolean_primary ::= predicate */ yytestcase(yyruleno==271); - case 273: /* common_expression ::= expression */ yytestcase(yyruleno==273); - case 274: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==274); - case 276: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==276); - case 278: /* table_reference ::= table_primary */ yytestcase(yyruleno==278); - case 279: /* table_reference ::= joined_table */ yytestcase(yyruleno==279); - case 283: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==283); - case 330: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==330); - case 332: /* query_primary ::= query_specification */ yytestcase(yyruleno==332); -{ yylhsminor.yy364 = yymsp[0].minor.yy364; } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 198: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy185, &yymsp[0].minor.yy129); } break; - case 198: /* literal ::= NULL */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 199: /* cmd ::= DESC full_table_name */ + case 200: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==200); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy104); } break; - case 199: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 201: /* cmd ::= RESET QUERY CACHE */ +{ pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 200: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 202: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy185, yymsp[-1].minor.yy104, yymsp[0].minor.yy104); } break; - case 201: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 204: /* analyze_opt ::= ANALYZE */ + case 212: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==212); + case 330: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==330); +{ yymsp[0].minor.yy185 = true; } break; - case 202: /* signed ::= NK_MINUS NK_INTEGER */ + case 205: /* explain_options ::= */ +{ yymsp[1].minor.yy104 = createDefaultExplainOptions(pCxt); } + break; + case 206: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy104 = setExplainVerbose(pCxt, yymsp[-2].minor.yy104, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; + break; + case 207: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy104 = setExplainRatio(pCxt, yymsp[-2].minor.yy104, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; + break; + case 208: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy312); } + break; + case 209: /* cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy185, &yymsp[-5].minor.yy129, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy336, yymsp[0].minor.yy196); } + break; + case 210: /* cmd ::= DROP FUNCTION function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy129); } + break; + case 213: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy196 = 0; } + break; + case 214: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy196 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + break; + case 215: /* cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy129, &yymsp[-2].minor.yy129, yymsp[0].minor.yy104); } + break; + case 216: /* cmd ::= DROP STREAM stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy129); } + break; + case 217: /* cmd ::= KILL CONNECTION NK_INTEGER */ +{ pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } + break; + case 218: /* cmd ::= KILL QUERY NK_INTEGER */ +{ pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_QUERY_STMT, &yymsp[0].minor.yy0); } + break; + case 219: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ +{ pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } + break; + case 220: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy312); } + break; + case 221: /* cmd ::= SPLIT VGROUP NK_INTEGER */ +{ pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } + break; + case 222: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy312 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + break; + case 224: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy129); } + break; + case 226: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 227: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 228: /* literal ::= NK_STRING */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 229: /* literal ::= NK_BOOL */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 230: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; + break; + case 231: /* literal ::= duration_literal */ + case 240: /* signed_literal ::= signed */ yytestcase(yyruleno==240); + case 258: /* expression ::= literal */ yytestcase(yyruleno==258); + case 259: /* expression ::= pseudo_column */ yytestcase(yyruleno==259); + case 260: /* expression ::= column_reference */ yytestcase(yyruleno==260); + case 263: /* expression ::= subquery */ yytestcase(yyruleno==263); + case 303: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==303); + case 307: /* boolean_primary ::= predicate */ yytestcase(yyruleno==307); + case 309: /* common_expression ::= expression */ yytestcase(yyruleno==309); + case 310: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==310); + case 312: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==312); + case 314: /* table_reference ::= table_primary */ yytestcase(yyruleno==314); + case 315: /* table_reference ::= joined_table */ yytestcase(yyruleno==315); + case 319: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==319); + case 366: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==366); + case 368: /* query_primary ::= query_specification */ yytestcase(yyruleno==368); +{ yylhsminor.yy104 = yymsp[0].minor.yy104; } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 232: /* literal ::= NULL */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 233: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 234: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 235: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + break; + case 236: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 203: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 237: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 204: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 238: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 205: /* signed ::= NK_MINUS NK_FLOAT */ + case 239: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 207: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 241: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 208: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 242: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 209: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 243: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 210: /* signed_literal ::= duration_literal */ - case 344: /* search_condition ::= common_expression */ yytestcase(yyruleno==344); -{ yylhsminor.yy364 = releaseRawExprNode(pCxt, yymsp[0].minor.yy364); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 244: /* signed_literal ::= duration_literal */ + case 380: /* search_condition ::= common_expression */ yytestcase(yyruleno==380); +{ yylhsminor.yy104 = releaseRawExprNode(pCxt, yymsp[0].minor.yy104); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 211: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } + case 245: /* signed_literal ::= NULL */ +{ yymsp[0].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; - case 226: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy437, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy437, yymsp[-1].minor.yy40)); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + case 261: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy129, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-1].minor.yy312)); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 227: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy437, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy437, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + case 262: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy129, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy129, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 229: /* expression ::= NK_LP expression NK_RP */ - case 272: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==272); -{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364)); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 264: /* expression ::= NK_LP expression NK_RP */ + case 308: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==308); +{ yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy104)); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 230: /* expression ::= NK_PLUS expression */ + case 265: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy364)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy104)); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 231: /* expression ::= NK_MINUS expression */ + case 266: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy364), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy104), NULL)); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 232: /* expression ::= expression NK_PLUS expression */ + case 267: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 233: /* expression ::= expression NK_MINUS expression */ + case 268: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 234: /* expression ::= expression NK_STAR expression */ + case 269: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 235: /* expression ::= expression NK_SLASH expression */ + case 270: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 236: /* expression ::= expression NK_REM expression */ + case 271: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 237: /* expression_list ::= expression */ -{ yylhsminor.yy40 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364)); } - yymsp[0].minor.yy40 = yylhsminor.yy40; + case 272: /* expression_list ::= expression */ +{ yylhsminor.yy312 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy104)); } + yymsp[0].minor.yy312 = yylhsminor.yy312; break; - case 238: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, releaseRawExprNode(pCxt, yymsp[0].minor.yy364)); } - yymsp[-2].minor.yy40 = yylhsminor.yy40; + case 273: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy312 = addNodeToList(pCxt, yymsp[-2].minor.yy312, releaseRawExprNode(pCxt, yymsp[0].minor.yy104)); } + yymsp[-2].minor.yy312 = yylhsminor.yy312; break; - case 239: /* column_reference ::= column_name */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy437, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy437)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + case 274: /* column_reference ::= column_name */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy129, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy129)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 240: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437, createColumnNode(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437)); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 275: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129, createColumnNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129)); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 241: /* pseudo_column ::= NK_UNDERLINE ROWTS */ - case 243: /* pseudo_column ::= NK_UNDERLINE QSTARTTS */ yytestcase(yyruleno==243); - case 244: /* pseudo_column ::= NK_UNDERLINE QENDTS */ yytestcase(yyruleno==244); - case 245: /* pseudo_column ::= NK_UNDERLINE WSTARTTS */ yytestcase(yyruleno==245); - case 246: /* pseudo_column ::= NK_UNDERLINE WENDTS */ yytestcase(yyruleno==246); - case 247: /* pseudo_column ::= NK_UNDERLINE WDURATION */ yytestcase(yyruleno==247); + case 276: /* pseudo_column ::= NOW */ + case 277: /* pseudo_column ::= ROWTS */ yytestcase(yyruleno==277); + case 278: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==278); + case 279: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==279); + case 280: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==280); + case 281: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==281); + case 282: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==282); + case 283: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==283); +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + case 284: /* predicate ::= expression compare_op expression */ + case 289: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==289); { - SToken t = yymsp[-1].minor.yy0; - t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy364 = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy60, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 242: /* pseudo_column ::= TBNAME */ -{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy364 = yylhsminor.yy364; - break; - case 248: /* predicate ::= expression compare_op expression */ - case 253: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==253); + case 285: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy328, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy104), releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-4].minor.yy104 = yylhsminor.yy104; break; - case 249: /* predicate ::= expression BETWEEN expression AND expression */ + case 286: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy364), releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[-5].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-4].minor.yy364 = yylhsminor.yy364; + yymsp[-5].minor.yy104 = yylhsminor.yy104; break; - case 250: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 287: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[-5].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), NULL)); } - yymsp[-5].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 251: /* predicate ::= expression IS NULL */ + case 288: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy104), NULL)); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 252: /* predicate ::= expression IS NOT NULL */ + case 290: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy60 = OP_TYPE_LOWER_THAN; } + break; + case 291: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy60 = OP_TYPE_GREATER_THAN; } + break; + case 292: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy60 = OP_TYPE_LOWER_EQUAL; } + break; + case 293: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy60 = OP_TYPE_GREATER_EQUAL; } + break; + case 294: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy60 = OP_TYPE_NOT_EQUAL; } + break; + case 295: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy60 = OP_TYPE_EQUAL; } + break; + case 296: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy60 = OP_TYPE_LIKE; } + break; + case 297: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy60 = OP_TYPE_NOT_LIKE; } + break; + case 298: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy60 = OP_TYPE_MATCH; } + break; + case 299: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy60 = OP_TYPE_NMATCH; } + break; + case 300: /* in_op ::= IN */ +{ yymsp[0].minor.yy60 = OP_TYPE_IN; } + break; + case 301: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy60 = OP_TYPE_NOT_IN; } + break; + case 302: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy312)); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; + break; + case 304: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy104), NULL)); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 254: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy328 = OP_TYPE_LOWER_THAN; } - break; - case 255: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy328 = OP_TYPE_GREATER_THAN; } - break; - case 256: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy328 = OP_TYPE_LOWER_EQUAL; } - break; - case 257: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy328 = OP_TYPE_GREATER_EQUAL; } - break; - case 258: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy328 = OP_TYPE_NOT_EQUAL; } - break; - case 259: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy328 = OP_TYPE_EQUAL; } - break; - case 260: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy328 = OP_TYPE_LIKE; } - break; - case 261: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy328 = OP_TYPE_NOT_LIKE; } - break; - case 262: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy328 = OP_TYPE_MATCH; } - break; - case 263: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy328 = OP_TYPE_NMATCH; } - break; - case 264: /* in_op ::= IN */ -{ yymsp[0].minor.yy328 = OP_TYPE_IN; } - break; - case 265: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy328 = OP_TYPE_NOT_IN; } - break; - case 266: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy40)); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; - break; - case 268: /* boolean_value_expression ::= NOT boolean_primary */ + case 305: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy364), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 269: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 306: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy104); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 270: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); - } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 311: /* from_clause ::= FROM table_reference_list */ + case 341: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==341); + case 364: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==364); +{ yymsp[-1].minor.yy104 = yymsp[0].minor.yy104; } break; - case 275: /* from_clause ::= FROM table_reference_list */ - case 305: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==305); - case 328: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==328); -{ yymsp[-1].minor.yy364 = yymsp[0].minor.yy364; } + case 313: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy104 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy104, yymsp[0].minor.yy104, NULL); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 277: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy364 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy364, yymsp[0].minor.yy364, NULL); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 316: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy104 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 280: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy364 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 317: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy104 = createRealTableNode(pCxt, &yymsp[-3].minor.yy129, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 281: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy364 = createRealTableNode(pCxt, &yymsp[-3].minor.yy437, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + case 318: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy104 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy104), &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 282: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy364 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364), &yymsp[0].minor.yy437); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 320: /* alias_opt ::= */ +{ yymsp[1].minor.yy129 = nil_token; } break; - case 284: /* alias_opt ::= */ -{ yymsp[1].minor.yy437 = nil_token; } + case 321: /* alias_opt ::= table_alias */ +{ yylhsminor.yy129 = yymsp[0].minor.yy129; } + yymsp[0].minor.yy129 = yylhsminor.yy129; break; - case 285: /* alias_opt ::= table_alias */ -{ yylhsminor.yy437 = yymsp[0].minor.yy437; } - yymsp[0].minor.yy437 = yylhsminor.yy437; + case 322: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy129 = yymsp[0].minor.yy129; } break; - case 286: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy437 = yymsp[0].minor.yy437; } + case 323: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 324: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==324); +{ yymsp[-2].minor.yy104 = yymsp[-1].minor.yy104; } break; - case 287: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 288: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==288); -{ yymsp[-2].minor.yy364 = yymsp[-1].minor.yy364; } + case 325: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy104 = createJoinTableNode(pCxt, yymsp[-4].minor.yy532, yymsp[-5].minor.yy104, yymsp[-2].minor.yy104, yymsp[0].minor.yy104); } + yymsp[-5].minor.yy104 = yylhsminor.yy104; break; - case 289: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy364 = createJoinTableNode(pCxt, yymsp[-4].minor.yy392, yymsp[-5].minor.yy364, yymsp[-2].minor.yy364, yymsp[0].minor.yy364); } - yymsp[-5].minor.yy364 = yylhsminor.yy364; + case 326: /* join_type ::= */ +{ yymsp[1].minor.yy532 = JOIN_TYPE_INNER; } break; - case 290: /* join_type ::= */ -{ yymsp[1].minor.yy392 = JOIN_TYPE_INNER; } + case 327: /* join_type ::= INNER */ +{ yymsp[0].minor.yy532 = JOIN_TYPE_INNER; } break; - case 291: /* join_type ::= INNER */ -{ yymsp[0].minor.yy392 = JOIN_TYPE_INNER; } - break; - case 292: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 328: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy364 = createSelectStmt(pCxt, yymsp[-7].minor.yy493, yymsp[-6].minor.yy40, yymsp[-5].minor.yy364); - yymsp[-8].minor.yy364 = addWhereClause(pCxt, yymsp[-8].minor.yy364, yymsp[-4].minor.yy364); - yymsp[-8].minor.yy364 = addPartitionByClause(pCxt, yymsp[-8].minor.yy364, yymsp[-3].minor.yy40); - yymsp[-8].minor.yy364 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy364, yymsp[-2].minor.yy364); - yymsp[-8].minor.yy364 = addGroupByClause(pCxt, yymsp[-8].minor.yy364, yymsp[-1].minor.yy40); - yymsp[-8].minor.yy364 = addHavingClause(pCxt, yymsp[-8].minor.yy364, yymsp[0].minor.yy364); + yymsp[-8].minor.yy104 = createSelectStmt(pCxt, yymsp[-7].minor.yy185, yymsp[-6].minor.yy312, yymsp[-5].minor.yy104); + yymsp[-8].minor.yy104 = addWhereClause(pCxt, yymsp[-8].minor.yy104, yymsp[-4].minor.yy104); + yymsp[-8].minor.yy104 = addPartitionByClause(pCxt, yymsp[-8].minor.yy104, yymsp[-3].minor.yy312); + yymsp[-8].minor.yy104 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy104, yymsp[-2].minor.yy104); + yymsp[-8].minor.yy104 = addGroupByClause(pCxt, yymsp[-8].minor.yy104, yymsp[-1].minor.yy312); + yymsp[-8].minor.yy104 = addHavingClause(pCxt, yymsp[-8].minor.yy104, yymsp[0].minor.yy104); } break; - case 295: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy493 = false; } + case 331: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy185 = false; } break; - case 296: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy40 = NULL; } + case 332: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy312 = NULL; } break; - case 300: /* select_item ::= common_expression */ + case 336: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); - yylhsminor.yy364 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy104), &t); } - yymsp[0].minor.yy364 = yylhsminor.yy364; + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 301: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy364 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364), &yymsp[0].minor.yy437); } - yymsp[-1].minor.yy364 = yylhsminor.yy364; + case 337: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy104 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy104), &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 302: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy364 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), &yymsp[0].minor.yy437); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 338: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy104 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), &yymsp[0].minor.yy129); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 303: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy364 = createColumnNode(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 339: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy104 = createColumnNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 307: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 324: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==324); - case 334: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==334); -{ yymsp[-2].minor.yy40 = yymsp[0].minor.yy40; } + case 343: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 360: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==360); + case 370: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==370); +{ yymsp[-2].minor.yy312 = yymsp[0].minor.yy312; } break; - case 309: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy364 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), releaseRawExprNode(pCxt, yymsp[-1].minor.yy364)); } + case 345: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy104 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy104), releaseRawExprNode(pCxt, yymsp[-1].minor.yy104)); } break; - case 310: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy364 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364)); } + case 346: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy104 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy104)); } break; - case 311: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy364 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), NULL, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } + case 347: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy104 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy104), NULL, yymsp[-1].minor.yy104, yymsp[0].minor.yy104); } break; - case 312: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy364 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy364), releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } + case 348: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy104 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy104), releaseRawExprNode(pCxt, yymsp[-3].minor.yy104), yymsp[-1].minor.yy104, yymsp[0].minor.yy104); } break; - case 314: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy364 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy364); } + case 350: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy104 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy104); } break; - case 316: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy364 = createFillNode(pCxt, yymsp[-1].minor.yy478, NULL); } + case 352: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy104 = createFillNode(pCxt, yymsp[-1].minor.yy550, NULL); } break; - case 317: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy364 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy40)); } + case 353: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy104 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy312)); } break; - case 318: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy478 = FILL_MODE_NONE; } + case 354: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy550 = FILL_MODE_NONE; } break; - case 319: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy478 = FILL_MODE_PREV; } + case 355: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy550 = FILL_MODE_PREV; } break; - case 320: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy478 = FILL_MODE_NULL; } + case 356: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy550 = FILL_MODE_NULL; } break; - case 321: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy478 = FILL_MODE_LINEAR; } + case 357: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy550 = FILL_MODE_LINEAR; } break; - case 322: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy478 = FILL_MODE_NEXT; } + case 358: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy550 = FILL_MODE_NEXT; } break; - case 325: /* group_by_list ::= expression */ -{ yylhsminor.yy40 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[0].minor.yy40 = yylhsminor.yy40; + case 361: /* group_by_list ::= expression */ +{ yylhsminor.yy312 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } + yymsp[0].minor.yy312 = yylhsminor.yy312; break; - case 326: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy40 = yylhsminor.yy40; + case 362: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy312 = addNodeToList(pCxt, yymsp[-2].minor.yy312, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } + yymsp[-2].minor.yy312 = yylhsminor.yy312; break; - case 329: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 365: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy364 = addOrderByClause(pCxt, yymsp[-3].minor.yy364, yymsp[-2].minor.yy40); - yylhsminor.yy364 = addSlimitClause(pCxt, yylhsminor.yy364, yymsp[-1].minor.yy364); - yylhsminor.yy364 = addLimitClause(pCxt, yylhsminor.yy364, yymsp[0].minor.yy364); + yylhsminor.yy104 = addOrderByClause(pCxt, yymsp[-3].minor.yy104, yymsp[-2].minor.yy312); + yylhsminor.yy104 = addSlimitClause(pCxt, yylhsminor.yy104, yymsp[-1].minor.yy104); + yylhsminor.yy104 = addLimitClause(pCxt, yylhsminor.yy104, yymsp[0].minor.yy104); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 331: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy364 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy364, yymsp[0].minor.yy364); } - yymsp[-3].minor.yy364 = yylhsminor.yy364; + case 367: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy104 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy104, yymsp[0].minor.yy104); } + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 336: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 340: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==340); -{ yymsp[-1].minor.yy364 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 372: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 376: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==376); +{ yymsp[-1].minor.yy104 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 337: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 341: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==341); -{ yymsp[-3].minor.yy364 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 373: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 377: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==377); +{ yymsp[-3].minor.yy104 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 338: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 342: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==342); -{ yymsp[-3].minor.yy364 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 374: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 378: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==378); +{ yymsp[-3].minor.yy104 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 343: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy364); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 379: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy104); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 347: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy364 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), yymsp[-1].minor.yy210, yymsp[0].minor.yy177); } - yymsp[-2].minor.yy364 = yylhsminor.yy364; + case 383: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy104 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy104), yymsp[-1].minor.yy354, yymsp[0].minor.yy489); } + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 348: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy210 = ORDER_ASC; } + case 384: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy354 = ORDER_ASC; } break; - case 349: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy210 = ORDER_ASC; } + case 385: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy354 = ORDER_ASC; } break; - case 350: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy210 = ORDER_DESC; } + case 386: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy354 = ORDER_DESC; } break; - case 351: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy177 = NULL_ORDER_DEFAULT; } + case 387: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy489 = NULL_ORDER_DEFAULT; } break; - case 352: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy177 = NULL_ORDER_FIRST; } + case 388: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy489 = NULL_ORDER_FIRST; } break; - case 353: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy177 = NULL_ORDER_LAST; } + case 389: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy489 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parserInsertTest.cpp b/source/libs/parser/test/parserInsertTest.cpp index 90e2ba3db2..d292fcf8b0 100644 --- a/source/libs/parser/test/parserInsertTest.cpp +++ b/source/libs/parser/test/parserInsertTest.cpp @@ -62,7 +62,7 @@ protected: void dumpReslut() { SVnodeModifOpStmt* pStmt = getVnodeModifStmt(res_); size_t num = taosArrayGetSize(pStmt->pDataBlocks); - cout << "schemaAttache:" << (int32_t)pStmt->schemaAttache << ", payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType << ", numOfVgs:" << num << endl; + cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType << ", numOfVgs:" << num << endl; for (size_t i = 0; i < num; ++i) { SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(pStmt->pDataBlocks, i); cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl; @@ -81,7 +81,6 @@ protected: void checkReslut(int32_t numOfTables, int16_t numOfRows1, int16_t numOfRows2 = -1) { SVnodeModifOpStmt* pStmt = getVnodeModifStmt(res_); - ASSERT_EQ(pStmt->schemaAttache, 0); ASSERT_EQ(pStmt->payloadType, PAYLOAD_TYPE_KV); ASSERT_EQ(pStmt->insertType, TSDB_QUERY_TYPE_INSERT); size_t num = taosArrayGetSize(pStmt->pDataBlocks); @@ -168,6 +167,18 @@ TEST_F(InsertTest, multiTableMultiRowTest) { checkReslut(2, 3, 2); } +// INSERT INTO +// tb1_name USING st1_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...) +// tb2_name USING st2_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...) +TEST_F(InsertTest, autoCreateTableTest) { + setDatabase("root", "test"); + + bind("insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")"); + ASSERT_EQ(run(), TSDB_CODE_SUCCESS); + dumpReslut(); + checkReslut(1, 3); +} + TEST_F(InsertTest, toleranceTest) { setDatabase("root", "test"); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 7f6d8826e6..f57f476d51 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -288,7 +288,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect // set the output if (TSDB_CODE_SUCCESS == code) { pJoin->node.pTargets = nodesCloneList(pLeft->pTargets); - if (NULL == pJoin->pOnConditions) { + if (NULL == pJoin->node.pTargets) { code = TSDB_CODE_OUT_OF_MEMORY; } if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 9ef1c01cd1..11baeff04a 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -719,6 +719,14 @@ static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExc if (NULL == pScan->pScanCols) { code = TSDB_CODE_OUT_OF_MEMORY; } + + if (TSDB_CODE_SUCCESS == code) { + code = sortScanCols(pScan->pScanCols); + } + + if (TSDB_CODE_SUCCESS == code) { + code = sortScanCols(pScan->pScanCols); + } if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pScan->pScanCols, pScan->node.pOutputDataBlockDesc); } diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index d19d88f455..ad76c8f879 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -195,6 +195,12 @@ TEST_F(PlannerTest, interval) { bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); ASSERT_TRUE(run()); + + bind("SELECT count(*) FROM t1 interval(10s) fill(linear)"); + ASSERT_TRUE(run()); + + bind("SELECT count(*), sum(c1) FROM t1 interval(10s) fill(value, 10, 20)"); + ASSERT_TRUE(run()); } TEST_F(PlannerTest, sessionWindow) { diff --git a/source/libs/qcom/CMakeLists.txt b/source/libs/qcom/CMakeLists.txt index a9bf0f5594..d50047e592 100644 --- a/source/libs/qcom/CMakeLists.txt +++ b/source/libs/qcom/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories( target_link_libraries( qcom - PRIVATE os util transport + PRIVATE os util transport nodes ) if(${BUILD_TEST}) diff --git a/source/libs/qcom/inc/queryInt.h b/source/libs/qcom/inc/queryInt.h index 75c1e134cd..f120bf26ce 100644 --- a/source/libs/qcom/inc/queryInt.h +++ b/source/libs/qcom/inc/queryInt.h @@ -21,7 +21,6 @@ extern "C" { #endif - #ifdef __cplusplus } #endif diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h index 834a722bd8..977fab2e85 100644 --- a/source/libs/scalar/inc/filterInt.h +++ b/source/libs/scalar/inc/filterInt.h @@ -36,8 +36,6 @@ extern "C" { #define FILTER_DUMMY_EMPTY_OPTR 127 -#define MAX_NUM_STR_SIZE 40 - #define FILTER_RM_UNIT_MIN_ROWS 100 enum { @@ -231,7 +229,7 @@ typedef struct SFltBuildGroupCtx { int32_t code; } SFltBuildGroupCtx; -typedef struct SFilterInfo { +struct SFilterInfo { bool scalarMode; SFltScalarCtx sclCtx; uint32_t options; @@ -256,7 +254,7 @@ typedef struct SFilterInfo { SArray *blkList; SFilterPCtx pctx; -} SFilterInfo; +}; #define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR || (t) == TSDB_DATA_TYPE_JSON) #define FILTER_NO_MERGE_OPTR(o) ((o) == OP_TYPE_IS_NULL || (o) == OP_TYPE_IS_NOT_NULL || (o) == FILTER_DUMMY_EMPTY_OPTR) diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index cf34fc24a9..58b62bb05e 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -47,7 +47,7 @@ int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out); SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows); #define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) -#define GET_PARAM_BYTES(_c) ((_c)->pColumnInfoData->info.bytes) +#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) void sclFreeParam(SScalarParam *param); diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index b0632bbc34..05f9a36551 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3638,16 +3638,16 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) info = *pInfo; info->options = options; - SFltTreeStat stat = {0}; - FLT_ERR_JRET(fltReviseNodes(info, &pNode, &stat)); + SFltTreeStat stat1 = {0}; + FLT_ERR_JRET(fltReviseNodes(info, &pNode, &stat1)); - info->scalarMode = stat.scalarMode; + info->scalarMode = stat1.scalarMode; if (!info->scalarMode) { FLT_ERR_JRET(fltInitFromNode(pNode, info, options)); } else { info->sclCtx.node = pNode; - FLT_ERR_JRET(fltOptimizeNodes(info, &info->sclCtx.node, &stat)); + FLT_ERR_JRET(fltOptimizeNodes(info, &info->sclCtx.node, &stat1)); } return code; @@ -3664,25 +3664,16 @@ _return: bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols) { if (info->scalarMode) { SScalarParam output = {0}; + + SDataType type = {.type = TSDB_DATA_TYPE_BOOL, .bytes = sizeof(bool)}; + output.columnData = createColumnInfoData(&type, pSrc->info.rows); + + *p = (int8_t *)output.columnData->pData; SArray *pList = taosArrayInit(1, POINTER_BYTES); taosArrayPush(pList, &pSrc); - - FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); + FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); taosArrayDestroy(pList); - // TODO Fix it -// *p = output.orig.data; -// output.orig.data = NULL; -// -// sclFreeParam(&output); -// -// int8_t *r = output.data; -// for (int32_t i = 0; i < output.num; ++i) { -// if (0 == *(r+i)) { -// return false; -// } -// } - return true; } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index dd3edcf1a3..3a6f28141a 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -29,7 +29,7 @@ SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows) { pColumnData->info.scale = pType->scale; pColumnData->info.precision = pType->precision; - int32_t code = blockDataEnsureColumnCapacity(pColumnData, numOfRows); + int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows); if (code != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pColumnData); @@ -44,7 +44,7 @@ int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) { in.columnData = createColumnInfoData(&pValueNode->node.resType, 1); colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); - blockDataEnsureColumnCapacity(out->columnData, 1); + colInfoDataEnsureCapacity(out->columnData, 1); int32_t code = vectorConvertImpl(&in, out); sclFreeParam(&in); @@ -162,7 +162,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t param->numOfRows = 1; param->columnData = createColumnInfoData(&valueNode->node.resType, 1); if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type) { - colDataAppend(param->columnData, 0, NULL, true); + colDataAppendNULL(param->columnData, 0); } else { colDataAppend(param->columnData, 0, nodesGetValueFromNode(valueNode), false); } @@ -310,12 +310,10 @@ int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outp SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } -// for (int32_t i = 0; i < rowNum; ++i) { - code = (*ffpSet.process)(params, node->pParameterList->length, output); - if (code) { - sclError("scalar function exec failed, funcId:%d, code:%s", node->funcId, tstrerror(code)); - SCL_ERR_JRET(code); -// } + code = (*ffpSet.process)(params, node->pParameterList->length, output); + if (code) { + sclError("scalar function exec failed, funcId:%d, code:%s", node->funcId, tstrerror(code)); + SCL_ERR_JRET(code); } _return: @@ -446,7 +444,6 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { *pNode = (SNode*)res; sclFreeParam(&output); - return DEAL_RES_CONTINUE; } @@ -688,8 +685,9 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { int32_t code = 0; SScalarCtx ctx = {.code = 0, .pBlockList = pBlockList}; + // TODO: OPT performance - ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (NULL == ctx.pRes) { sclError("taosHashInit failed, num:%d", SCL_DEFAULT_OP_NUM); SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 0486049296..6971377f2e 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -4,7 +4,18 @@ #include "sclInt.h" #include "sclvector.h" +typedef float (*_float_fn)(float); +typedef double (*_double_fn)(double); +typedef double (*_double_fn_2)(double, double); +typedef int (*_conv_fn)(int); +typedef void (*_trim_fn)(char *, char*, int32_t, int32_t); +typedef int16_t (*_len_fn)(char *, int32_t); + /** Math functions **/ +double tlog(double v, double base) { + return log(v) / log(base); +} + int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; @@ -23,7 +34,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu colDataSetNull_f(pOutputData->nullbitmap, i); continue; } - out[i] = (in[i] > 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0)? in[i] : -in[i]; } break; } @@ -36,7 +47,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu colDataSetNull_f(pOutputData->nullbitmap, i); continue; } - out[i] = (in[i] > 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0)? in[i] : -in[i]; } break; } @@ -49,7 +60,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu colDataSetNull_f(pOutputData->nullbitmap, i); continue; } - out[i] = (in[i] > 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0)? in[i] : -in[i]; } break; } @@ -62,7 +73,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu colDataSetNull_f(pOutputData->nullbitmap, i); continue; } - out[i] = (in[i] > 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0)? in[i] : -in[i]; } break; } @@ -75,7 +86,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu colDataSetNull_f(pOutputData->nullbitmap, i); continue; } - out[i] = (in[i] > 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0)? in[i] : -in[i]; } break; } @@ -88,7 +99,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu colDataSetNull_f(pOutputData->nullbitmap, i); continue; } - out[i] = (in[i] > 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0)? in[i] : -in[i]; } break; } @@ -102,14 +113,6 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu return TSDB_CODE_SUCCESS; } -typedef float (*_float_fn)(float); -typedef double (*_double_fn)(double); -typedef double (*_double_fn_2)(double, double); - -double tlog(double v, double base) { - return log(v) / log(base); -} - int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn valFn) { int32_t type = GET_PARAM_TYPE(pInput); if (inputNum != 1 || !IS_NUMERIC_TYPE(type)) { @@ -211,6 +214,407 @@ int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam* p return TSDB_CODE_SUCCESS; } +/** String functions **/ +int16_t tlength(char *input, int32_t type) { + return varDataLen(input); +} + +int16_t tcharlength(char *input, int32_t type) { + if (type == TSDB_DATA_TYPE_VARCHAR) { + return varDataLen(input); + } else { //NCHAR + return varDataLen(input) / TSDB_NCHAR_SIZE; + } +} + +void tltrim(char *input, char *output, int32_t type, int32_t charLen) { + int32_t numOfSpaces = 0; + if (type == TSDB_DATA_TYPE_VARCHAR) { + for (int32_t i = 0; i < charLen; ++i) { + if (!isspace(*(varDataVal(input) + i))) { + break; + } + numOfSpaces++; + } + } else { //NCHAR + for (int32_t i = 0; i < charLen; ++i) { + if (!iswspace(*((uint32_t *)varDataVal(input) + i))) { + break; + } + numOfSpaces++; + } + } + + int32_t resLen; + if (type == TSDB_DATA_TYPE_VARCHAR) { + resLen = charLen - numOfSpaces; + memcpy(varDataVal(output), varDataVal(input) + numOfSpaces, resLen); + } else { + resLen = (charLen - numOfSpaces) * TSDB_NCHAR_SIZE; + memcpy(varDataVal(output), varDataVal(input) + numOfSpaces * TSDB_NCHAR_SIZE, resLen); + } + + varDataSetLen(output, resLen); +} + +void trtrim(char *input, char *output, int32_t type, int32_t charLen) { + int32_t numOfSpaces = 0; + if (type == TSDB_DATA_TYPE_VARCHAR) { + for (int32_t i = charLen - 1; i >= 0; --i) { + if (!isspace(*(varDataVal(input) + i))) { + break; + } + numOfSpaces++; + } + } else { //NCHAR + for (int32_t i = charLen - 1; i < charLen; ++i) { + if (!iswspace(*((uint32_t *)varDataVal(input) + i))) { + break; + } + numOfSpaces++; + } + } + + int32_t resLen; + if (type == TSDB_DATA_TYPE_VARCHAR) { + resLen = charLen - numOfSpaces; + } else { + resLen = (charLen - numOfSpaces) * TSDB_NCHAR_SIZE; + } + memcpy(varDataVal(output), varDataVal(input), resLen); + + varDataSetLen(output, resLen); +} + +int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _len_fn lenFn) { + int32_t type = GET_PARAM_TYPE(pInput); + if (inputNum != 1 || !IS_VAR_DATA_TYPE(type)) { + return TSDB_CODE_FAILED; + } + + SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pOutputData = pOutput->columnData; + + char *in = pInputData->pData; + int16_t *out = (int16_t *)pOutputData->pData; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + + out[i] = lenFn(in, type); + in += varDataTLen(in); + } + + pOutput->numOfRows = pInput->numOfRows; + return TSDB_CODE_SUCCESS; +} + +static void setVarTypeOutputBuf(SColumnInfoData *pOutputData, int32_t len, int32_t type) { + pOutputData->pData = taosMemoryCalloc(len, sizeof(char)); + pOutputData->info.type = type; + pOutputData->info.bytes = len; + pOutputData->varmeta.length = len; + pOutputData->varmeta.allocLen = len; +} + +int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + if (inputNum < 2 || inputNum > 8) { // concat accpet 2-8 input strings + return TSDB_CODE_FAILED; + } + + SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *)); + SColumnInfoData *pOutputData = pOutput->columnData; + char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); + char *outputBuf = NULL; + + int32_t inputLen = 0; + int32_t numOfRows = 0; + for (int32_t i = 0; i < inputNum; ++i) { + if (!IS_VAR_DATA_TYPE(GET_PARAM_TYPE(&pInput[i])) || + GET_PARAM_TYPE(&pInput[i]) != GET_PARAM_TYPE(&pInput[0])) { + return TSDB_CODE_FAILED; + } + if (pInput[i].numOfRows > numOfRows) { + numOfRows = pInput[i].numOfRows; + } + } + for (int32_t i = 0; i < inputNum; ++i) { + pInputData[i] = pInput[i].columnData; + input[i] = pInputData[i]->pData; + if (pInput[i].numOfRows == 1) { + inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * numOfRows; + } else { + inputLen += pInputData[i]->varmeta.length - numOfRows * VARSTR_HEADER_SIZE; + } + } + + int32_t outputLen = inputLen + numOfRows * VARSTR_HEADER_SIZE; + outputBuf = taosMemoryCalloc(outputLen, 1); + char *output = outputBuf; + + bool hasNull = false; + for (int32_t k = 0; k < numOfRows; ++k) { + for (int32_t i = 0; i < inputNum; ++i) { + if (colDataIsNull_s(pInputData[i], k)) { + colDataAppendNULL(pOutputData, k); + hasNull = true; + break; + } + } + + if (hasNull) { + continue; + } + + int16_t dataLen = 0; + for (int32_t i = 0; i < inputNum; ++i) { + memcpy(varDataVal(output) + dataLen, varDataVal(input[i]), varDataLen(input[i])); + dataLen += varDataLen(input[i]); + if (pInput[i].numOfRows != 1) { + input[i] += varDataTLen(input[i]); + } + } + varDataSetLen(output, dataLen); + colDataAppend(pOutputData, k, output, false); + output += varDataTLen(output); + } + + pOutput->numOfRows = numOfRows; + taosMemoryFree(input); + taosMemoryFree(outputBuf); + taosMemoryFree(pInputData); + + return TSDB_CODE_SUCCESS; +} + +int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + if (inputNum < 3 || inputNum > 9) { // concat accpet 3-9 input strings including the separator + return TSDB_CODE_FAILED; + } + + SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *)); + SColumnInfoData *pOutputData = pOutput->columnData; + char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); + char *outputBuf = NULL; + + int32_t inputLen = 0; + int32_t numOfRows = 0; + for (int32_t i = 1; i < inputNum; ++i) { + if (!IS_VAR_DATA_TYPE(GET_PARAM_TYPE(&pInput[i])) || + GET_PARAM_TYPE(&pInput[i]) != GET_PARAM_TYPE(&pInput[1])) { + return TSDB_CODE_FAILED; + } + if (pInput[i].numOfRows > numOfRows) { + numOfRows = pInput[i].numOfRows; + } + } + for (int32_t i = 0; i < inputNum; ++i) { + pInputData[i] = pInput[i].columnData; + if (i == 0) { + // calculate required separator space + int32_t factor = (GET_PARAM_TYPE(&pInput[1]) == TSDB_DATA_TYPE_NCHAR) ? TSDB_NCHAR_SIZE : 1; + inputLen += (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * numOfRows * (inputNum - 2) * factor; + } else if (pInput[i].numOfRows == 1) { + inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * numOfRows; + } else { + inputLen += pInputData[i]->varmeta.length - numOfRows * VARSTR_HEADER_SIZE; + } + input[i] = pInputData[i]->pData; + } + + int32_t outputLen = inputLen + numOfRows * VARSTR_HEADER_SIZE; + outputBuf = taosMemoryCalloc(outputLen, 1); + char *output = outputBuf; + + for (int32_t k = 0; k < numOfRows; ++k) { + if (colDataIsNull_s(pInputData[0], k)) { + colDataAppendNULL(pOutputData, k); + continue; + } + + int16_t dataLen = 0; + for (int32_t i = 1; i < inputNum; ++i) { + if (colDataIsNull_s(pInputData[i], k)) { + continue; + } + + memcpy(varDataVal(output) + dataLen, varDataVal(input[i]), varDataLen(input[i])); + dataLen += varDataLen(input[i]); + if (pInput[i].numOfRows != 1) { + input[i] += varDataTLen(input[i]); + } + + if (i < inputNum - 1) { + //insert the separator + char *sep = pInputData[0]->pData; + memcpy(varDataVal(output) + dataLen, varDataVal(sep), varDataLen(sep)); + dataLen += varDataLen(sep); + } + } + varDataSetLen(output, dataLen); + colDataAppend(pOutputData, k, output, false); + output += varDataTLen(output); + } + + pOutput->numOfRows = numOfRows; + taosMemoryFree(input); + taosMemoryFree(outputBuf); + taosMemoryFree(pInputData); + + return TSDB_CODE_SUCCESS; +} + +int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _conv_fn convFn) { + int32_t type = GET_PARAM_TYPE(pInput); + if (inputNum != 1 || !IS_VAR_DATA_TYPE(type)) { + return TSDB_CODE_FAILED; + } + + SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pOutputData = pOutput->columnData; + + char *input = pInputData->pData; + char *output = NULL; + + int32_t outputLen = pInputData->varmeta.length; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + output = outputBuf; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_s(pInputData, i)) { + colDataAppendNULL(pOutputData, i); + continue; + } + + int32_t len = varDataLen(input); + if (type == TSDB_DATA_TYPE_VARCHAR) { + for (int32_t j = 0; j < len; ++j) { + *(varDataVal(output) + j) = convFn(*(varDataVal(input) + j)); + } + } else { //NCHAR + for (int32_t j = 0; j < len / TSDB_NCHAR_SIZE; ++j) { + *((uint32_t *)varDataVal(output) + j) = convFn(*((uint32_t *)varDataVal(input) + j)); + } + } + varDataSetLen(output, len); + colDataAppend(pOutputData, i, output, false); + input += varDataTLen(input); + output += varDataTLen(output); + } + + pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); + + return TSDB_CODE_SUCCESS; +} + + +int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _trim_fn trimFn) { + int32_t type = GET_PARAM_TYPE(pInput); + if (inputNum != 1 || !IS_VAR_DATA_TYPE(type)) { + return TSDB_CODE_FAILED; + } + + SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pOutputData = pOutput->columnData; + + char *input = pInputData->pData; + char *output = NULL; + + int32_t outputLen = pInputData->varmeta.length; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + output = outputBuf; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_s(pInputData, i)) { + colDataAppendNULL(pOutputData, i); + continue; + } + + int32_t len = varDataLen(input); + int32_t charLen = (type == TSDB_DATA_TYPE_VARCHAR) ? len : len / TSDB_NCHAR_SIZE; + trimFn(input, output, type, charLen); + + varDataSetLen(output, len); + colDataAppend(pOutputData, i, output, false); + input += varDataTLen(input); + output += varDataTLen(output); + } + + pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); + + return TSDB_CODE_SUCCESS; +} + +int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + if (inputNum != 2 && inputNum!= 3) { + return TSDB_CODE_FAILED; + } + + int32_t subPos = 0; + GET_TYPED_DATA(subPos, int32_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData); + if (subPos == 0) { //subPos needs to be positive or negative values; + return TSDB_CODE_FAILED; + } + + int32_t subLen = INT16_MAX; + if (inputNum == 3) { + GET_TYPED_DATA(subLen, int32_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); + if (subLen < 0) { //subLen cannot be negative + return TSDB_CODE_FAILED; + } + subLen = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subLen : subLen * TSDB_NCHAR_SIZE; + } + + SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pOutputData = pOutput->columnData; + + char *input = pInputData->pData; + char *output = NULL; + + int32_t outputLen = pInputData->varmeta.length; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + output = outputBuf; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_s(pInputData, i)) { + colDataAppendNULL(pOutputData, i); + continue; + } + + int32_t len = varDataLen(input); + int32_t startPosBytes; + + if (subPos > 0) { + startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subPos - 1 : (subPos - 1) * TSDB_NCHAR_SIZE; + startPosBytes = MIN(startPosBytes, len); + } else { + startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? len + subPos : len + subPos * TSDB_NCHAR_SIZE; + startPosBytes = MAX(startPosBytes, 0); + } + + subLen = MIN(subLen, len - startPosBytes); + if (subLen > 0) { + memcpy(varDataVal(output), varDataVal(input) + startPosBytes, subLen); + } + + varDataSetLen(output, subLen); + colDataAppend(pOutputData, i , output, false); + input += varDataTLen(input); + output += varDataTLen(output); + } + + pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); + + return TSDB_CODE_SUCCESS; +} + + int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { return doScalarFunctionUnique(pInput, inputNum, pOutput, atan); } @@ -259,57 +663,28 @@ int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut return doScalarFunction(pInput, inputNum, pOutput, roundf, round); } -static void tlength(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { - assert(numOfInput == 1); -#if 0 - int64_t* out = (int64_t*) pOutput->data; - char* s = pLeft->data; - - for(int32_t i = 0; i < pLeft->num; ++i) { - out[i] = varDataLen(POINTER_SHIFT(s, i * pLeft->bytes)); - } -#endif +int32_t lowerFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doCaseConvFunction(pInput, inputNum, pOutput, tolower); } -static void tconcat(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { - assert(numOfInput > 0); -#if 0 - int32_t rowLen = 0; - int32_t num = 1; - for(int32_t i = 0; i < numOfInput; ++i) { - rowLen += pLeft[i].bytes; - - if (pLeft[i].num > 1) { - num = pLeft[i].num; - } - } - - pOutput->data = taosMemoryRealloc(pOutput->data, rowLen * num); - assert(pOutput->data); - - char* rstart = pOutput->data; - for(int32_t i = 0; i < num; ++i) { - - char* s = rstart; - varDataSetLen(s, 0); - for (int32_t j = 0; j < numOfInput; ++j) { - char* p1 = POINTER_SHIFT(pLeft[j].data, i * pLeft[j].bytes); - - memcpy(varDataVal(s) + varDataLen(s), varDataVal(p1), varDataLen(p1)); - varDataLen(s) += varDataLen(p1); - } - - rstart += rowLen; - } -#endif +int32_t upperFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doCaseConvFunction(pInput, inputNum, pOutput, toupper); } -static void tltrim(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { - +int32_t ltrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doTrimFunction(pInput, inputNum, pOutput, tltrim); } -static void trtrim(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { +int32_t rtrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doTrimFunction(pInput, inputNum, pOutput, trtrim); +} +int32_t lengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doLengthFunction(pInput, inputNum, pOutput, tlength); +} + +int32_t charLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doLengthFunction(pInput, inputNum, pOutput, tcharlength); } static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows) { @@ -410,4 +785,4 @@ int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p ASSERT(inputNum == 1); colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t*) colDataGetData(pInput->columnData, 4)); return TSDB_CODE_SUCCESS; -} \ No newline at end of file +} diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index d08352602d..eb242b3e17 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -158,23 +158,23 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { int64_t value = strtoll(buf, NULL, 10); - colDataAppend(pOut->columnData, rowIndex, (char*) &value, false); + colDataAppendInt64(pOut->columnData, rowIndex, &value); } static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { uint64_t value = strtoull(buf, NULL, 10); - colDataAppend(pOut->columnData, rowIndex, (char*) &value, false); + colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*) &value); } static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex) { double value = strtod(buf, NULL); - colDataAppend(pOut->columnData, rowIndex, (char*) &value, false); + colDataAppendDouble(pOut->columnData, rowIndex, &value); } static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex) { int64_t value = strtoll(buf, NULL, 10); bool v = (value != 0)? true:false; - colDataAppend(pOut->columnData, rowIndex, (char*) &v, false); + colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v); } int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { @@ -198,7 +198,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in pOut->numOfRows = pIn->numOfRows; for (int32_t i = 0; i < pIn->numOfRows; ++i) { if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) { - colDataAppend(pOut->columnData, i, NULL, true); + colDataAppendNULL(pOut->columnData, i); continue; } @@ -242,13 +242,13 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { case TSDB_DATA_TYPE_BOOL: { for (int32_t i = 0; i < pIn->numOfRows; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { - colDataAppend(pOutputCol, i, NULL, true); + colDataAppendNULL(pOutputCol, i); continue; } bool value = 0; GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); - colDataAppend(pOutputCol, i, (char*) &value, false); + colDataAppendInt8(pOutputCol, i, (int8_t*) &value); } break; } @@ -259,13 +259,13 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { case TSDB_DATA_TYPE_TIMESTAMP: { for (int32_t i = 0; i < pIn->numOfRows; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { - colDataAppend(pOutputCol, i, NULL, true); + colDataAppendNULL(pOutputCol, i); continue; } int64_t value = 0; GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); - colDataAppend(pOutputCol, i, (char *)&value, false); + colDataAppendInt64(pOutputCol, i, &value); } break; } @@ -275,26 +275,26 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { case TSDB_DATA_TYPE_UBIGINT: for (int32_t i = 0; i < pIn->numOfRows; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { - colDataAppend(pOutputCol, i, NULL, true); + colDataAppendNULL(pOutputCol, i); continue; } uint64_t value = 0; GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i)); - colDataAppend(pOutputCol, i, (char*) &value, false); + colDataAppendInt64(pOutputCol, i, (int64_t*)&value); } break; case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: for (int32_t i = 0; i < pIn->numOfRows; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { - colDataAppend(pOutputCol, i, NULL, true); + colDataAppendNULL(pOutputCol, i); continue; } double value = 0; GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i)); - colDataAppend(pOutputCol, i, (char*) &value, false); + colDataAppendDouble(pOutputCol, i, &value); } break; default: @@ -445,7 +445,7 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig double *output = (double *)pOutputCol->pData; if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, 0); @@ -526,7 +526,7 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig double *output = (double *)pOutputCol->pData; if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { *output = (getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, 0)) * factor; @@ -585,7 +585,7 @@ static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* double *output = (double *)pOutputCol->pData; if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, 0); @@ -665,7 +665,7 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p } else if (pLeft->numOfRows == 1) { if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows); } else { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { *output = getVectorDoubleValueFnLeft(pLeftCol->pData, 0) / getVectorDoubleValueFnRight(pRightCol->pData, i); @@ -677,7 +677,7 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p } } else if (pRight->numOfRows == 1) { if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows); } else { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, 0); @@ -713,14 +713,14 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { if (colDataIsNull_f(pLeftCol->nullbitmap, i) || colDataIsNull_f(pRightCol->nullbitmap, i)) { - colDataAppend(pOutputCol, i, NULL, true); + colDataAppendNULL(pOutputCol, i); continue; } double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); - if (compareDoubleVal(&zero, &rx)) { - colDataAppend(pOutputCol, i, NULL, true); + if (isnan(lx) || isinf(lx) || isnan(rx) || isinf(rx)) { + colDataAppendNULL(pOutputCol, i); continue; } @@ -728,18 +728,18 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam } } else if (pLeft->numOfRows == 1) { double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, 0); - if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + if (colDataIsNull_f(pLeftCol->nullbitmap, 0) || isnan(lx) || isinf(lx)) { // Set pLeft->numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows); } else { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { if (colDataIsNull_f(pRightCol->nullbitmap, i)) { - colDataAppend(pOutputCol, i, NULL, true); + colDataAppendNULL(pOutputCol, i); continue; } double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); - if (compareDoubleVal(&zero, &rx)) { - colDataAppend(pOutputCol, i, NULL, true); + if (isnan(rx) || isinf(rx) || FLT_EQUAL(rx, 0)) { + colDataAppendNULL(pOutputCol, i); continue; } @@ -748,18 +748,18 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam } } else if (pRight->numOfRows == 1) { double rx = getVectorDoubleValueFnRight(pRightCol->pData, 0); - if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + if (colDataIsNull_f(pRightCol->nullbitmap, 0) || FLT_EQUAL(rx, 0)) { // Set pLeft->numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows); } else { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { - if (colDataIsNull_f(pRightCol->nullbitmap, i)) { - colDataAppend(pOutputCol, i, NULL, true); + if (colDataIsNull_f(pLeftCol->nullbitmap, i)) { + colDataAppendNULL(pOutputCol, i); continue; } - double lx = getVectorDoubleValueFnLeft(pRightCol->pData, i); - if (compareDoubleVal(&zero, &lx)) { - colDataAppend(pOutputCol, i, NULL, true); + double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); + if (isnan(lx) || isinf(lx)) { + colDataAppendNULL(pOutputCol, i); continue; } @@ -830,7 +830,7 @@ static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRigh double *output = (double *)pOutputCol->pData; if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, 0); @@ -887,7 +887,7 @@ static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRight int64_t *output = (int64_t *)pOutputCol->pData; if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value - // TODO set numOfRows NULL value + colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { int64_t rx = getVectorBigintValueFnRight(pRightCol->pData, 0); for (; i >= 0 && i < numOfRows; i += step, output += 1) { @@ -946,56 +946,51 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * if (pRight->pHashFilter != NULL) { for (; i >= 0 && i < pLeft->numOfRows; i += step) { - if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) /*|| - colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) { + if (colDataIsNull_s(pLeft->columnData, i)) { continue; } char *pLeftData = colDataGetData(pLeft->columnData, i); bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter); - colDataAppend(pOut->columnData, i, (char *)&res, false); + colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); } return; } if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step) { - if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) || - colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)) { + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { continue; // TODO set null or ignore } char *pLeftData = colDataGetData(pLeft->columnData, i); char *pRightData = colDataGetData(pRight->columnData, i); bool res = filterDoCompare(fp, optr, pLeftData, pRightData); - colDataAppend(pOut->columnData, i, (char *)&res, false); + colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); } } else if (pRight->numOfRows == 1) { char *pRightData = colDataGetData(pRight->columnData, 0); ASSERT(pLeft->pHashFilter == NULL); for (; i >= 0 && i < pLeft->numOfRows; i += step) { - if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) /*|| - colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) { + if (colDataIsNull_s(pLeft->columnData, i)) { continue; } char *pLeftData = colDataGetData(pLeft->columnData, i); bool res = filterDoCompare(fp, optr, pLeftData, pRightData); - colDataAppend(pOut->columnData, i, (char *)&res, false); + colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); } } else if (pLeft->numOfRows == 1) { char *pLeftData = colDataGetData(pLeft->columnData, 0); - for (; i >= 0 && i < pRight->numOfRows; i += step) { - if (colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL) /*|| - colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) { + if (colDataIsNull_s(pRight->columnData, i)) { continue; } char *pRightData = colDataGetData(pLeft->columnData, i); bool res = filterDoCompare(fp, optr, pLeftData, pRightData); - colDataAppend(pOut->columnData, i, (char *)&res, false); + colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); } } } @@ -1076,23 +1071,16 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { for(int32_t i = 0; i < pLeft->numOfRows; ++i) { - int8_t v = 0; - if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL)) { - v = 1; - } - colDataAppend(pOut->columnData, i, (char*) &v, false); + int8_t v = colDataIsNull_s(pLeft->columnData, i)? 1:0; + colDataAppendInt8(pOut->columnData, i, &v); } - pOut->numOfRows = pLeft->numOfRows; } void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { for(int32_t i = 0; i < pLeft->numOfRows; ++i) { - int8_t v = 1; - if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL)) { - v = 0; - } - colDataAppend(pOut->columnData, i, (char*) &v, false); + int8_t v = colDataIsNull_s(pLeft->columnData, i)? 0:1; + colDataAppendInt8(pOut->columnData, i, &v); } pOut->numOfRows = pLeft->numOfRows; } diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 54f82eae2d..1a82c8f955 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -155,7 +155,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in res->info.numOfCols++; SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - blockDataEnsureColumnCapacity(pColumn, rowNum); + colInfoDataEnsureCapacity(pColumn, rowNum); for (int32_t i = 0; i < rowNum; ++i) { colDataAppend(pColumn, i, (const char *)value, false); @@ -275,7 +275,6 @@ TEST(timerangeTest, greater_and_lower) { nodesDestroyNode(logicNode); } - TEST(columnTest, smallint_column_greater_double_value) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; int16_t leftv[5]= {1, 2, 3, 4, 5}; @@ -386,7 +385,6 @@ TEST(columnTest, int_column_greater_smallint_value) { blockDataDestroy(src); } - TEST(columnTest, int_column_in_double_list) { SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; int32_t leftv[5] = {1, 2, 3, 4, 5}; @@ -432,8 +430,6 @@ TEST(columnTest, int_column_in_double_list) { blockDataDestroy(src); } - - TEST(columnTest, binary_column_in_binary_list) { SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; bool eRes[5] = {true, true, false, false, false}; @@ -497,7 +493,6 @@ TEST(columnTest, binary_column_in_binary_list) { blockDataDestroy(src); } - TEST(columnTest, binary_column_like_binary) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; char rightv[64] = {0}; @@ -546,7 +541,6 @@ TEST(columnTest, binary_column_like_binary) { blockDataDestroy(src); } - TEST(columnTest, binary_column_is_null) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; @@ -641,8 +635,6 @@ TEST(columnTest, binary_column_is_not_null) { blockDataDestroy(src); } - - TEST(opTest, smallint_column_greater_int_column) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; int16_t leftv[5] = {1, -6, -2, 11, 101}; @@ -680,7 +672,6 @@ TEST(opTest, smallint_column_greater_int_column) { blockDataDestroy(src); } - TEST(opTest, smallint_value_add_int_column) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; int32_t leftv = 1; @@ -719,8 +710,6 @@ TEST(opTest, smallint_value_add_int_column) { blockDataDestroy(src); } - - TEST(opTest, bigint_column_multi_binary_column) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; int64_t leftv[5]= {1, 2, 3, 4, 5}; @@ -845,8 +834,6 @@ TEST(opTest, smallint_column_or_float_column) { blockDataDestroy(src); } - - TEST(opTest, smallint_column_or_double_value) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; int16_t leftv[5]= {0, 2, 3, 0, -1}; @@ -885,7 +872,6 @@ TEST(opTest, smallint_column_or_double_value) { blockDataDestroy(src); } - TEST(opTest, binary_column_is_true) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; @@ -930,7 +916,6 @@ TEST(opTest, binary_column_is_true) { blockDataDestroy(src); } - TEST(filterModelogicTest, diff_columns_and_or_and) { flttInitLogFile(); @@ -1071,7 +1056,6 @@ TEST(filterModelogicTest, same_column_and_or_and) { blockDataDestroy(src); } - TEST(filterModelogicTest, diff_columns_or_and_or) { SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; SNode *logicNode1 = NULL, *logicNode2 = NULL; @@ -1210,8 +1194,6 @@ TEST(filterModelogicTest, same_column_or_and_or) { blockDataDestroy(src); } - - TEST(scalarModelogicTest, diff_columns_or_and_or) { flttInitLogFile(); @@ -1283,8 +1265,6 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { blockDataDestroy(src); } - - int main(int argc, char** argv) { taosSeedRand(taosGetTimestampSec()); testing::InitGoogleTest(&argc, argv); diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 153222516c..61ef2fdce2 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -99,7 +99,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s SColumnInfoData idata = {0}; idata.info = *colInfo; - blockDataEnsureColumnCapacity(&idata, rows); + colInfoDataEnsureCapacity(&idata, rows); taosArrayPush(res->pDataBlock, &idata); @@ -186,7 +186,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in res->info.numOfCols++; SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - blockDataEnsureColumnCapacity(pColumn, rowNum); + colInfoDataEnsureCapacity(pColumn, rowNum); for (int32_t i = 0; i < rowNum; ++i) { colDataAppend(pColumn, i, (const char *)value, false); @@ -1467,7 +1467,7 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t input->numOfRows = num; input->columnData->info = createColumnInfo(0, type, bytes); - blockDataEnsureColumnCapacity(input->columnData, num); + colInfoDataEnsureCapacity(input->columnData, num); if (setVal) { for (int32_t i = 0; i < num; ++i) { diff --git a/source/libs/scheduler/CMakeLists.txt b/source/libs/scheduler/CMakeLists.txt index a4a299317c..1a62c7d89d 100644 --- a/source/libs/scheduler/CMakeLists.txt +++ b/source/libs/scheduler/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories( target_link_libraries( scheduler - PUBLIC os util nodes planner qcom common catalog transport + PUBLIC os util nodes planner qcom common catalog transport command ) if(${BUILD_TEST}) diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index 518da6e2b8..22bd039219 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -142,10 +142,10 @@ typedef struct SSchTask { } SSchTask; typedef struct SSchJobAttr { - bool needFetch; - bool syncSchedule; - bool queryJob; - bool needFlowCtrl; + EExplainMode explainMode; + bool syncSchedule; + bool queryJob; + bool needFlowCtrl; } SSchJobAttr; typedef struct SSchJob { diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 86eaa09594..c4186bc511 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -19,6 +19,7 @@ #include "tmsg.h" #include "tref.h" #include "trpc.h" +#include "command.h" SSchedulerMgmt schMgmt = {0}; @@ -75,10 +76,10 @@ void schFreeRpcCtx(SRpcCtx *pCtx) { SRpcCtxVal *ctxVal = (SRpcCtxVal *)pIter; (*ctxVal->freeFunc)(ctxVal->val); - + pIter = taosHashIterate(pCtx->args, pIter); } - + taosHashCleanup(pCtx->args); if (pCtx->brokenVal.freeFunc) { @@ -86,7 +87,7 @@ void schFreeRpcCtx(SRpcCtx *pCtx) { } } -void schFreeTask(SSchTask* pTask) { +void schFreeTask(SSchTask *pTask) { if (pTask->candidateAddrs) { taosArrayDestroy(pTask->candidateAddrs); } @@ -125,41 +126,47 @@ int32_t schValidateTaskReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t m case TDMT_SCH_LINK_BROKEN: return TSDB_CODE_SUCCESS; case TDMT_VND_QUERY_RSP: // query_rsp may be processed later than ready_rsp - if (lastMsgType != reqMsgType && -1 != lastMsgType && TDMT_VND_FETCH != lastMsgType) { - SCH_TASK_DLOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), TMSG_INFO(msgType)); + if (lastMsgType != reqMsgType && -1 != lastMsgType && TDMT_VND_FETCH != lastMsgType) { + SCH_TASK_DLOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), + TMSG_INFO(msgType)); } - + if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { - SCH_TASK_DLOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); + SCH_TASK_DLOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), + TMSG_INFO(msgType)); } - + SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); return TSDB_CODE_SUCCESS; case TDMT_VND_RES_READY_RSP: reqMsgType = TDMT_VND_QUERY; if (lastMsgType != reqMsgType && -1 != lastMsgType) { - SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", (lastMsgType > 0 ? TMSG_INFO(lastMsgType) : "null"), TMSG_INFO(msgType)); + SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", + (lastMsgType > 0 ? TMSG_INFO(lastMsgType) : "null"), TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - + if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { - SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); + SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), + TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); return TSDB_CODE_SUCCESS; case TDMT_VND_FETCH_RSP: - if (lastMsgType != reqMsgType && -1 != lastMsgType) { - SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), TMSG_INFO(msgType)); + if (lastMsgType != reqMsgType && -1 != lastMsgType) { + SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), + TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - + if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { - SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); + SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), + TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - + SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); return TSDB_CODE_SUCCESS; case TDMT_VND_CREATE_TABLE_RSP: @@ -171,12 +178,14 @@ int32_t schValidateTaskReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t m } if (lastMsgType != reqMsgType) { - SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), TMSG_INFO(msgType)); + SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), + TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - + if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { - SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); + SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), + TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } @@ -358,7 +367,7 @@ int32_t schRecordTaskSucceedNode(SSchJob *pJob, SSchTask *pTask) { int32_t schRecordTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, void *handle) { SSchNodeInfo nodeInfo = {.addr = *addr, .handle = handle}; - + if (NULL == taosArrayPush(pTask->execNodes, &nodeInfo)) { SCH_TASK_ELOG("taosArrayPush nodeInfo to execNodes list failed, errno:%d", errno); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -588,7 +597,7 @@ int32_t schMoveTaskToFailList(SSchJob *pJob, SSchTask *pTask, bool *moved) { if (0 != code) { if (HASH_NODE_EXIST(code)) { *moved = true; - + SCH_TASK_WLOG("task already in failTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } @@ -613,7 +622,7 @@ int32_t schMoveTaskToExecList(SSchJob *pJob, SSchTask *pTask, bool *moved) { if (0 != code) { if (HASH_NODE_EXIST(code)) { *moved = true; - + SCH_TASK_ELOG("task already in execTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } @@ -632,7 +641,7 @@ int32_t schMoveTaskToExecList(SSchJob *pJob, SSchTask *pTask, bool *moved) { int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry) { int8_t status = 0; ++pTask->tryTimes; - + if (schJobNeedToStop(pJob, &status)) { *needRetry = false; SCH_TASK_DLOG("task no more retry cause of job status, job status:%s", jobTaskStatusStr(status)); @@ -644,7 +653,7 @@ int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bo SCH_TASK_DLOG("task no more retry since reach max try times, tryTimes:%d", pTask->tryTimes); return TSDB_CODE_SUCCESS; } - + if (!NEED_SCHEDULER_RETRY_ERROR(errCode)) { *needRetry = false; SCH_TASK_DLOG("task no more retry cause of errCode, errCode:%x - %s", errCode, tstrerror(errCode)); @@ -655,7 +664,8 @@ int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bo if (SCH_IS_DATA_SRC_TASK(pTask)) { if (pTask->tryTimes >= SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)) { *needRetry = false; - SCH_TASK_DLOG("task no more retry since all ep tried, tryTimes:%d, epNum:%d", pTask->tryTimes, SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)); + SCH_TASK_DLOG("task no more retry since all ep tried, tryTimes:%d, epNum:%d", pTask->tryTimes, + SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)); return TSDB_CODE_SUCCESS; } } else { @@ -663,14 +673,15 @@ int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bo if ((pTask->candidateIdx + 1) >= candidateNum) { *needRetry = false; - SCH_TASK_DLOG("task no more retry since all candiates tried, candidateIdx:%d, candidateNum:%d", pTask->candidateIdx, candidateNum); + SCH_TASK_DLOG("task no more retry since all candiates tried, candidateIdx:%d, candidateNum:%d", + pTask->candidateIdx, candidateNum); return TSDB_CODE_SUCCESS; } } *needRetry = true; SCH_TASK_DLOG("task need the %dth retry, errCode:%x - %s", pTask->tryTimes, errCode, tstrerror(errCode)); - + return TSDB_CODE_SUCCESS; } @@ -707,9 +718,8 @@ int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans) { memcpy(&hb->trans, trans, sizeof(*trans)); SCH_UNLOCK(SCH_WRITE, &hb->lock); - qDebug("hb connection updated, sId:%" PRIx64 ", nodeId:%d, fqdn:%s, port:%d, instance:%p, handle:%p", - schMgmt.sId, epId->nodeId, epId->ep.fqdn, epId->ep.port, trans->transInst, - trans->transHandle); + qDebug("hb connection updated, sId:%" PRIx64 ", nodeId:%d, fqdn:%s, port:%d, instance:%p, handle:%p", schMgmt.sId, + epId->nodeId, epId->ep.fqdn, epId->ep.port, trans->transInst, trans->transHandle); return TSDB_CODE_SUCCESS; } @@ -731,15 +741,15 @@ void schUpdateJobErrCode(SSchJob *pJob, int32_t errCode) { if (NEED_CLIENT_HANDLE_ERROR(origCode)) { return; } - + if (NEED_CLIENT_HANDLE_ERROR(errCode)) { atomic_store_32(&pJob->errCode, errCode); goto _return; } return; - -_return: + +_return: SCH_JOB_DLOG("job errCode updated to %x - %s", errCode, tstrerror(errCode)); } @@ -826,7 +836,7 @@ int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode) } SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_FAILED); - + if (SCH_IS_WAIT_ALL_JOB(pJob)) { SCH_LOCK(SCH_WRITE, &pTask->level->lock); pTask->level->taskFailed++; @@ -834,9 +844,9 @@ int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode) SCH_UNLOCK(SCH_WRITE, &pTask->level->lock); schUpdateJobErrCode(pJob, errCode); - + if (taskDone < pTask->level->taskNum) { - SCH_TASK_DLOG("need to wait other tasks, doneNum:%d, allNum:%d", taskDone, pTask->level->taskNum); + SCH_TASK_DLOG("need to wait other tasks, doneNum:%d, allNum:%d", taskDone, pTask->level->taskNum); SCH_RET(errCode); } } @@ -868,7 +878,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { int32_t parentNum = pTask->parents ? (int32_t)taosArrayGetSize(pTask->parents) : 0; if (parentNum == 0) { - int32_t taskDone = 0; + int32_t taskDone = 0; if (SCH_IS_WAIT_ALL_JOB(pJob)) { SCH_LOCK(SCH_WRITE, &pTask->level->lock); pTask->level->taskSucceed++; @@ -966,7 +976,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch int8_t status = 0; if (schJobNeedToStop(pJob, &status)) { - SCH_TASK_ELOG("rsp not processed cause of job status, job status:%s, rspCode:0x%x", jobTaskStatusStr(status), rspCode); + SCH_TASK_ELOG("rsp not processed cause of job status, job status:%s, rspCode:0x%x", jobTaskStatusStr(status), + rspCode); SCH_RET(atomic_load_32(&pJob->errCode)); } @@ -986,11 +997,11 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_ERR_JRET(rsp->code); } } - + taosArrayDestroy(batchRsp.rspList); } - } - + } + SCH_ERR_JRET(rspCode); SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; @@ -1012,21 +1023,21 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch break; } case TDMT_VND_QUERY_RSP: { - SQueryTableRsp rsp = {0}; - if (msg) { - tDeserializeSQueryTableRsp(msg, msgSize, &rsp); - SCH_ERR_JRET(rsp.code); - } - - SCH_ERR_JRET(rspCode); - - if (NULL == msg) { - SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); - } - - //SCH_ERR_JRET(schBuildAndSendMsg(pJob, pTask, NULL, TDMT_VND_RES_READY)); - - break; + SQueryTableRsp rsp = {0}; + if (msg) { + tDeserializeSQueryTableRsp(msg, msgSize, &rsp); + SCH_ERR_JRET(rsp.code); + } + + SCH_ERR_JRET(rspCode); + + if (NULL == msg) { + SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } + + // SCH_ERR_JRET(schBuildAndSendMsg(pJob, pTask, NULL, TDMT_VND_RES_READY)); + + break; } case TDMT_VND_RES_READY_RSP: { SResReadyRsp *rsp = (SResReadyRsp *)msg; @@ -1089,14 +1100,14 @@ _return: } int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, int32_t rspCode) { - int32_t code = 0; + int32_t code = 0; SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; - SSchTask *pTask = NULL; + SSchTask *pTask = NULL; SSchJob *pJob = schAcquireJob(pParam->refId); if (NULL == pJob) { qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "taosAcquireRef job failed, may be dropped, refId:%" PRIx64, - pParam->queryId, pParam->taskId, pParam->refId); + pParam->queryId, pParam->taskId, pParam->refId); SCH_ERR_JRET(TSDB_CODE_QRY_JOB_FREED); } @@ -1115,7 +1126,7 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in pTask = *task; SCH_TASK_DLOG("rsp msg received, type:%s, handle:%p, code:%s", TMSG_INFO(msgType), pMsg->handle, tstrerror(rspCode)); - SCH_SET_TASK_HANDLE(pTask, pMsg->handle); + SCH_SET_TASK_HANDLE(pTask, pMsg->handle); SCH_ERR_JRET(schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode)); _return: @@ -1175,7 +1186,8 @@ int32_t schHandleHbCallback(void *param, const SDataBuf *pMsg, int32_t code) { SCH_ERR_RET(schUpdateHbConnection(&rsp.epId, &trans)); int32_t taskNum = (int32_t)taosArrayGetSize(rsp.taskStatus); - qDebug("%d task status in hb rsp, nodeId:%d, fqdn:%s, port:%d", taskNum, rsp.epId.nodeId, rsp.epId.ep.fqdn, rsp.epId.ep.port); + qDebug("%d task status in hb rsp, nodeId:%d, fqdn:%s, port:%d", taskNum, rsp.epId.nodeId, rsp.epId.ep.fqdn, + rsp.epId.ep.port); for (int32_t i = 0; i < taskNum; ++i) { STaskStatus *taskStatus = taosArrayGet(rsp.taskStatus, i); @@ -1189,8 +1201,9 @@ int32_t schHandleHbCallback(void *param, const SDataBuf *pMsg, int32_t code) { } // TODO - - SCH_JOB_DLOG("TID:0x%" PRIx64 " task status in server: %s", taskStatus->taskId, jobTaskStatusStr(taskStatus->status)); + + SCH_JOB_DLOG("TID:0x%" PRIx64 " task status in server: %s", taskStatus->taskId, + jobTaskStatusStr(taskStatus->status)); schReleaseJob(taskStatus->refId); } @@ -1210,7 +1223,7 @@ int32_t schHandleLinkBrokenCallback(void *param, const SDataBuf *pMsg, int32_t c if (head->isHbParam) { SSchHbCallbackParam *hbParam = (SSchHbCallbackParam *)param; - SSchTrans trans = {.transInst = hbParam->transport, .transHandle = NULL}; + SSchTrans trans = {.transInst = hbParam->transport, .transHandle = NULL}; SCH_ERR_RET(schUpdateHbConnection(&hbParam->nodeEpId, &trans)); SCH_ERR_RET(schBuildAndSendHbMsg(&hbParam->nodeEpId)); @@ -1221,7 +1234,6 @@ int32_t schHandleLinkBrokenCallback(void *param, const SDataBuf *pMsg, int32_t c return TSDB_CODE_SUCCESS; } - int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { switch (msgType) { case TDMT_VND_CREATE_TABLE: @@ -1260,8 +1272,8 @@ void schFreeRpcCtxVal(const void *arg) { if (NULL == arg) { return; } - - SMsgSendInfo* pMsgSendInfo = (SMsgSendInfo *)arg; + + SMsgSendInfo *pMsgSendInfo = (SMsgSendInfo *)arg; taosMemoryFreeClear(pMsgSendInfo->param); taosMemoryFreeClear(pMsgSendInfo); } @@ -1303,11 +1315,10 @@ int32_t schMakeHbCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) { return TSDB_CODE_SUCCESS; } - int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb) { - int32_t code = 0; - SMsgSendInfo* pMsgSendInfo = NULL; - + int32_t code = 0; + SMsgSendInfo *pMsgSendInfo = NULL; + pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == pMsgSendInfo) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); @@ -1320,17 +1331,17 @@ int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal * SCH_ERR_JRET(schMakeTaskCallbackParam(pJob, pTask, &pMsgSendInfo->param)); } - int32_t msgType = TDMT_SCH_LINK_BROKEN; + int32_t msgType = TDMT_SCH_LINK_BROKEN; __async_send_cb_fn_t fp = NULL; SCH_ERR_JRET(schGetCallbackFp(msgType, &fp)); - + pMsgSendInfo->fp = fp; brokenVal->msgType = msgType; brokenVal->val = pMsgSendInfo; brokenVal->clone = schCloneSMsgSendInfo; brokenVal->freeFunc = schFreeRpcCtxVal; - + return TSDB_CODE_SUCCESS; _return: @@ -1342,16 +1353,16 @@ _return: } int32_t schMakeQueryRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { - int32_t code = 0; + int32_t code = 0; SSchTaskCallbackParam *param = NULL; - SMsgSendInfo* pMsgSendInfo = NULL; + SMsgSendInfo *pMsgSendInfo = NULL; pCtx->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pCtx->args) { SCH_TASK_ELOG("taosHashInit %d RpcCtx failed", 1); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - + pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == pMsgSendInfo) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); @@ -1364,7 +1375,7 @@ int32_t schMakeQueryRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - int32_t msgType = TDMT_VND_RES_READY_RSP; + int32_t msgType = TDMT_VND_RES_READY_RSP; __async_send_cb_fn_t fp = NULL; SCH_ERR_JRET(schGetCallbackFp(TDMT_VND_RES_READY, &fp)); @@ -1372,7 +1383,7 @@ int32_t schMakeQueryRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { param->refId = pJob->refId; param->taskId = SCH_TASK_ID(pTask); param->transport = pJob->transport; - + pMsgSendInfo->param = param; pMsgSendInfo->fp = fp; @@ -1396,11 +1407,11 @@ _return: } int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { - int32_t code = 0; + int32_t code = 0; SSchHbCallbackParam *param = NULL; - SMsgSendInfo* pMsgSendInfo = NULL; - SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); - SQueryNodeEpId epId = {0}; + SMsgSendInfo *pMsgSendInfo = NULL; + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); + SQueryNodeEpId epId = {0}; epId.nodeId = addr->nodeId; memcpy(&epId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp)); @@ -1410,7 +1421,7 @@ int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { SCH_TASK_ELOG("taosHashInit %d RpcCtx failed", 1); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - + pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == pMsgSendInfo) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); @@ -1423,13 +1434,13 @@ int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - int32_t msgType = TDMT_VND_QUERY_HEARTBEAT_RSP; + int32_t msgType = TDMT_VND_QUERY_HEARTBEAT_RSP; __async_send_cb_fn_t fp = NULL; SCH_ERR_JRET(schGetCallbackFp(TDMT_VND_QUERY_HEARTBEAT, &fp)); param->nodeEpId = epId; param->transport = pJob->transport; - + pMsgSendInfo->param = param; pMsgSendInfo->fp = fp; @@ -1452,19 +1463,18 @@ _return: SCH_RET(code); } - int32_t schRegisterHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *epId, bool *exist) { - int32_t code = 0; + int32_t code = 0; SSchHbTrans hb = {0}; hb.trans.transInst = pJob->transport; - + SCH_ERR_RET(schMakeHbRpcCtx(pJob, pTask, &hb.rpcCtx)); code = taosHashPut(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId), &hb, sizeof(SSchHbTrans)); if (code) { schFreeRpcCtx(&hb.rpcCtx); - + if (HASH_NODE_EXIST(code)) { *exist = true; return TSDB_CODE_SUCCESS; @@ -1477,8 +1487,6 @@ int32_t schRegisterHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId * return TSDB_CODE_SUCCESS; } - - int32_t schCloneCallbackParam(SSchCallbackParamHeader *pSrc, SSchCallbackParamHeader **pDst) { if (pSrc->isHbParam) { SSchHbCallbackParam *dst = taosMemoryMalloc(sizeof(SSchHbCallbackParam)); @@ -1498,16 +1506,16 @@ int32_t schCloneCallbackParam(SSchCallbackParamHeader *pSrc, SSchCallbackParamHe qError("malloc SSchTaskCallbackParam failed"); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - + memcpy(dst, pSrc, sizeof(*dst)); *pDst = (SSchCallbackParamHeader *)dst; - + return TSDB_CODE_SUCCESS; } int32_t schCloneSMsgSendInfo(void *src, void **dst) { SMsgSendInfo *pSrc = src; - int32_t code = 0; + int32_t code = 0; SMsgSendInfo *pDst = taosMemoryMalloc(sizeof(*pSrc)); if (NULL == pDst) { qError("malloc SMsgSendInfo for rpcCtx failed, len:%d", (int32_t)sizeof(*pSrc)); @@ -1522,7 +1530,7 @@ int32_t schCloneSMsgSendInfo(void *src, void **dst) { *dst = pDst; return TSDB_CODE_SUCCESS; - + _return: taosMemoryFreeClear(pDst); @@ -1533,7 +1541,7 @@ int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) { int32_t code = 0; memcpy(&pDst->brokenVal, &pSrc->brokenVal, sizeof(pSrc->brokenVal)); pDst->brokenVal.val = NULL; - + SCH_ERR_RET(schCloneSMsgSendInfo(pSrc->brokenVal.val, &pDst->brokenVal.val)); pDst->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); @@ -1543,16 +1551,16 @@ int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) { } SRpcCtxVal dst = {0}; - void *pIter = taosHashIterate(pSrc->args, NULL); + void *pIter = taosHashIterate(pSrc->args, NULL); while (pIter) { SRpcCtxVal *pVal = (SRpcCtxVal *)pIter; - int32_t *msgType = taosHashGetKey(pIter, NULL); + int32_t *msgType = taosHashGetKey(pIter, NULL); dst = *pVal; dst.val = NULL; - + SCH_ERR_JRET(schCloneSMsgSendInfo(pVal->val, &dst.val)); - + if (taosHashPut(pDst->args, msgType, sizeof(*msgType), &dst, sizeof(dst))) { qError("taosHashPut msg %d to rpcCtx failed", *msgType); (*dst.freeFunc)(dst.val); @@ -1570,8 +1578,8 @@ _return: SCH_RET(code); } - -int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet* epSet, int32_t msgType, void *msg, uint32_t msgSize, bool persistHandle, SRpcCtx *ctx) { +int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet *epSet, int32_t msgType, void *msg, + uint32_t msgSize, bool persistHandle, SRpcCtx *ctx) { int32_t code = 0; SSchTrans *trans = (SSchTrans *)transport; @@ -1603,11 +1611,11 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet* pMsgSendInfo->msgType = msgType; pMsgSendInfo->fp = fp; - qDebug("start to send %s msg to node[%d,%s,%d], refId:%" PRIx64 "instance:%p, handle:%p", - TMSG_INFO(msgType), ntohl(((SMsgHead *)msg)->vgId), epSet->eps[epSet->inUse].fqdn, epSet->eps[epSet->inUse].port, - pJob->refId, trans->transInst, trans->transHandle); - - int64_t transporterId = 0; + qDebug("start to send %s msg to node[%d,%s,%d], refId:%" PRIx64 "instance:%p, handle:%p", TMSG_INFO(msgType), + ntohl(((SMsgHead *)msg)->vgId), epSet->eps[epSet->inUse].fqdn, epSet->eps[epSet->inUse].port, pJob->refId, + trans->transInst, trans->transHandle); + + int64_t transporterId = 0; code = asyncSendMsgToServerExt(trans->transInst, epSet, &transporterId, pMsgSendInfo, persistHandle, ctx); if (code) { SCH_ERR_JRET(code); @@ -1625,18 +1633,19 @@ _return: int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId) { SSchedulerHbReq req = {0}; - int32_t code = 0; - SRpcCtx rpcCtx = {0}; - SSchTrans trans = {0}; - int32_t msgType = TDMT_VND_QUERY_HEARTBEAT; + int32_t code = 0; + SRpcCtx rpcCtx = {0}; + SSchTrans trans = {0}; + int32_t msgType = TDMT_VND_QUERY_HEARTBEAT; - req.header.vgId = htonl(nodeEpId->nodeId); + req.header.vgId = nodeEpId->nodeId; req.sId = schMgmt.sId; memcpy(&req.epId, nodeEpId, sizeof(SQueryNodeEpId)); SSchHbTrans *hb = taosHashGet(schMgmt.hbConnections, nodeEpId, sizeof(SQueryNodeEpId)); if (NULL == hb) { - qError("taosHashGet hb connection failed, nodeId:%d, fqdn:%s, port:%d", nodeEpId->nodeId, nodeEpId->ep.fqdn, nodeEpId->ep.port); + qError("taosHashGet hb connection failed, nodeId:%d, fqdn:%s, port:%d", nodeEpId->nodeId, nodeEpId->ep.fqdn, + nodeEpId->ep.port); SCH_ERR_RET(code); } @@ -1644,9 +1653,9 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId) { code = schCloneHbRpcCtx(&hb->rpcCtx, &rpcCtx); memcpy(&trans, &hb->trans, sizeof(trans)); SCH_UNLOCK(SCH_WRITE, &hb->lock); - + SCH_ERR_RET(code); - + int32_t msgSize = tSerializeSSchedulerHbReq(NULL, 0, &req); if (msgSize < 0) { qError("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize); @@ -1657,7 +1666,7 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId) { qError("calloc hb req %d failed", msgSize); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - + if (tSerializeSSchedulerHbReq(msg, msgSize, &req) < 0) { qError("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -1686,17 +1695,18 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId) { pMsgSendInfo->msgInfo.handle = trans.transHandle; pMsgSendInfo->msgType = msgType; pMsgSendInfo->fp = fp; - - int64_t transporterId = 0; - SEpSet epSet = {.inUse = 0, .numOfEps = 1}; + + int64_t transporterId = 0; + SEpSet epSet = {.inUse = 0, .numOfEps = 1}; memcpy(&epSet.eps[0], &nodeEpId->ep, sizeof(nodeEpId->ep)); - qDebug("start to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d", trans.transInst, trans.transHandle, nodeEpId->ep.fqdn, nodeEpId->ep.port); - + qDebug("start to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d", trans.transInst, trans.transHandle, + nodeEpId->ep.fqdn, nodeEpId->ep.port); + code = asyncSendMsgToServerExt(trans.transInst, &epSet, &transporterId, pMsgSendInfo, true, &rpcCtx); if (code) { - qError("fail to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d, error:%x - %s", - trans.transInst, trans.transHandle, nodeEpId->ep.fqdn, nodeEpId->ep.port, code, tstrerror(code)); + qError("fail to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d, error:%x - %s", trans.transInst, + trans.transHandle, nodeEpId->ep.fqdn, nodeEpId->ep.port, code, tstrerror(code)); SCH_ERR_JRET(code); } @@ -1714,12 +1724,12 @@ _return: int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t msgType) { uint32_t msgSize = 0; - void *msg = NULL; - int32_t code = 0; - bool isCandidateAddr = false; - bool persistHandle = false; - SRpcCtx rpcCtx = {0}; - + void *msg = NULL; + int32_t code = 0; + bool isCandidateAddr = false; + bool persistHandle = false; + SRpcCtx rpcCtx = {0}; + if (NULL == addr) { addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); isCandidateAddr = true; @@ -1743,7 +1753,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, case TDMT_VND_QUERY: { SCH_ERR_RET(schMakeQueryRpcCtx(pJob, pTask, &rpcCtx)); - + uint32_t len = strlen(pJob->sql); msgSize = sizeof(SSubQueryMsg) + pTask->msgLen + len; msg = taosMemoryCalloc(1, msgSize); @@ -1824,7 +1834,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, } case TDMT_VND_QUERY_HEARTBEAT: { SCH_ERR_RET(schMakeHbRpcCtx(pJob, pTask, &rpcCtx)); - + SSchedulerHbReq req = {0}; req.sId = schMgmt.sId; req.header.vgId = addr->nodeId; @@ -1858,7 +1868,8 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, SCH_SET_TASK_LASTMSG_TYPE(pTask, msgType); SSchTrans trans = {.transInst = pJob->transport, .transHandle = SCH_GET_TASK_HANDLE(pTask)}; - SCH_ERR_JRET(schAsyncSendMsg(pJob, pTask, &trans, &epSet, msgType, msg, msgSize, persistHandle, (rpcCtx.args ? &rpcCtx : NULL))); + SCH_ERR_JRET(schAsyncSendMsg(pJob, pTask, &trans, &epSet, msgType, msg, msgSize, persistHandle, + (rpcCtx.args ? &rpcCtx : NULL))); if (msgType == TDMT_VND_QUERY) { SCH_ERR_RET(schRecordTaskExecNode(pJob, pTask, addr, trans.transHandle)); @@ -1904,7 +1915,7 @@ int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask) { if (schJobNeedToStop(pJob, &status)) { SCH_TASK_DLOG("no need to launch task cause of job status, job status:%s", jobTaskStatusStr(status)); - + SCH_RET(atomic_load_32(&pJob->errCode)); } @@ -1913,7 +1924,7 @@ int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(schPushTaskToExecList(pJob, pTask)); SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_EXECUTING); } - + SSubplan *plan = pTask->plan; if (NULL == pTask->msg) { // TODO add more detailed reason for failure @@ -2073,7 +2084,7 @@ void schFreeJobImpl(void *job) { taosArrayDestroy(pJob->levels); taosArrayDestroy(pJob->nodeList); - + taosMemoryFreeClear(pJob->resData); taosMemoryFreeClear(pJob); @@ -2095,6 +2106,7 @@ static int32_t schExecJobImpl(void *transport, SArray *pNodeList, SQueryPlan *pD SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + pJob->attr.explainMode = pDag->explainInfo.mode; pJob->attr.syncSchedule = syncSchedule; pJob->transport = transport; pJob->sql = sql; @@ -2128,19 +2140,24 @@ static int32_t schExecJobImpl(void *transport, SArray *pNodeList, SQueryPlan *pD tsem_init(&pJob->rspSem, 0, 0); - pJob->refId = taosAddRef(schMgmt.jobRef, pJob); - if (pJob->refId < 0) { - SCH_JOB_ELOG("taosHashPut job failed, error:%s", tstrerror(terrno)); + int64_t refId = taosAddRef(schMgmt.jobRef, pJob); + if (refId < 0) { + SCH_JOB_ELOG("taosAddRef job failed, error:%s", tstrerror(terrno)); SCH_ERR_JRET(terrno); } + if (NULL == schAcquireJob(refId)) { + SCH_JOB_ELOG("schAcquireJob job failed, refId:%" PRIx64, refId); + SCH_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + + pJob->refId = refId; + SCH_JOB_DLOG("job refId:%" PRIx64, pJob->refId); pJob->status = JOB_TASK_STATUS_NOT_START; SCH_ERR_JRET(schLaunchJob(pJob)); - schAcquireJob(pJob->refId); - *job = pJob->refId; if (syncSchedule) { @@ -2160,6 +2177,54 @@ _return: SCH_RET(code); } +int32_t schExecStaticExplain(void *transport, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql, + bool syncSchedule) { + qDebug("QID:0x%" PRIx64 " job started", pDag->queryId); + + int32_t code = 0; + SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob)); + if (NULL == pJob) { + qError("QID:%" PRIx64 " calloc %d failed", pDag->queryId, (int32_t)sizeof(SSchJob)); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + pJob->sql = sql; + pJob->attr.queryJob = true; + pJob->attr.explainMode = pDag->explainInfo.mode; + pJob->queryId = pDag->queryId; + pJob->subPlans = pDag->pSubplans; + + SCH_ERR_JRET(qExecStaticExplain(pDag, (SRetrieveTableRsp **)&pJob->resData)); + + int64_t refId = taosAddRef(schMgmt.jobRef, pJob); + if (refId < 0) { + SCH_JOB_ELOG("taosAddRef job failed, error:%s", tstrerror(terrno)); + SCH_ERR_JRET(terrno); + } + + if (NULL == schAcquireJob(refId)) { + SCH_JOB_ELOG("schAcquireJob job failed, refId:%" PRIx64, refId); + SCH_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + + pJob->refId = refId; + + SCH_JOB_DLOG("job refId:%" PRIx64, pJob->refId); + + pJob->status = JOB_TASK_STATUS_PARTIAL_SUCCEED; + *job = pJob->refId; + SCH_JOB_DLOG("job exec done, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); + + schReleaseJob(pJob->refId); + + return TSDB_CODE_SUCCESS; + +_return: + + schFreeJobImpl(pJob); + SCH_RET(code); +} + int32_t schedulerInit(SSchedulerCfg *cfg) { if (schMgmt.jobRef) { qError("scheduler already initialized"); @@ -2208,13 +2273,17 @@ int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryPlan *pDag, in SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - SCH_ERR_RET(schExecJobImpl(transport, nodeList, pDag, pJob, sql, true)); + if (EXPLAIN_MODE_STATIC == pDag->explainInfo.mode) { + SCH_ERR_RET(schExecStaticExplain(transport, nodeList, pDag, pJob, sql, true)); + } else { + SCH_ERR_RET(schExecJobImpl(transport, nodeList, pDag, pJob, sql, true)); + } SSchJob *job = schAcquireJob(*pJob); pRes->code = atomic_load_32(&job->errCode); pRes->numOfRows = job->resNumOfRows; - + schReleaseJob(*pJob); return TSDB_CODE_SUCCESS; @@ -2391,18 +2460,22 @@ int32_t schedulerFetchRows(int64_t job, void **pData) { SCH_JOB_DLOG("job already succeed, status:%s", jobTaskStatusStr(status)); goto _return; } else if (status == JOB_TASK_STATUS_PARTIAL_SUCCEED) { - SCH_ERR_JRET(schFetchFromRemote(pJob)); + if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) { + SCH_ERR_JRET(schFetchFromRemote(pJob)); + tsem_wait(&pJob->rspSem); + } + } else { + SCH_JOB_ELOG("job status error for fetch, status:%s", jobTaskStatusStr(status)); + SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); } - tsem_wait(&pJob->rspSem); - status = SCH_GET_JOB_STATUS(pJob); if (JOB_TASK_STATUS_FAILED == status || JOB_TASK_STATUS_DROPPING == status) { SCH_JOB_ELOG("job failed or dropping, status:%s", jobTaskStatusStr(status)); SCH_ERR_JRET(atomic_load_32(&pJob->errCode)); } - + if (pJob->resData && ((SRetrieveTableRsp *)pJob->resData)->completed) { SCH_ERR_JRET(schCheckAndUpdateJobStatus(pJob, JOB_TASK_STATUS_SUCCEED)); } diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index fb6c0f6c12..8aaaa414ca 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -38,7 +38,7 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* req.taskId = pTask->fixedEpDispatcher.taskId; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - // TODO fix tbname issue + // TODO use general name rule of schemaless char ctbName[TSDB_TABLE_FNAME_LEN + 22]; // all groupId must be the same in an array SSDataBlock* pBlock = taosArrayGet(data, 0); @@ -152,6 +152,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in // sink if (pTask->sinkType == TASK_SINK__TABLE) { // + blockDebugShowData(pRes); } else if (pTask->sinkType == TASK_SINK__SMA) { pTask->smaSink.smaHandle(pTask->ahandle, pTask->smaSink.smaId, pRes); // diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index fc27e88cf1..f4e1621742 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -29,15 +29,15 @@ struct SBTree { int minLocal; int maxLeaf; int minLeaf; - u8 *pTmp; + void *pBuf; }; #define TDB_BTREE_PAGE_COMMON_HDR u8 flags; -#define TDB_BTREE_PAGE_GET_FLAGS(PAGE) (PAGE)->pData[0] +#define TDB_BTREE_PAGE_GET_FLAGS(PAGE) (PAGE)->pData[0] #define TDB_BTREE_PAGE_SET_FLAGS(PAGE, flags) ((PAGE)->pData[0] = (flags)) -#define TDB_BTREE_PAGE_IS_ROOT(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_ROOT) -#define TDB_BTREE_PAGE_IS_LEAF(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_LEAF) +#define TDB_BTREE_PAGE_IS_ROOT(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_ROOT) +#define TDB_BTREE_PAGE_IS_LEAF(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_LEAF) #define TDB_BTREE_ASSERT_FLAG(flags) \ ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \ TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0)) @@ -101,7 +101,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S // pBt->kcmpr pBt->kcmpr = kcmpr ? kcmpr : tdbDefaultKeyCmprFn; // pBt->pageSize - pBt->pageSize = tdbPagerGetPageSize(pPager); + pBt->pageSize = pPager->pageSize; // pBt->maxLocal pBt->maxLocal = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr)) / 4; // pBt->minLocal: Should not be allowed smaller than 15, which is [nPayload][nKey][nData] @@ -127,132 +127,144 @@ int tdbBtreeClose(SBTree *pBt) { return 0; } -int tdbBtCursorInsert(SBTC *pBtc, const void *pKey, int kLen, const void *pVal, int vLen) { - int ret; - int idx; - SPager *pPager; - SCell *pCell; - int szCell; - int cret; - SBTree *pBt; +int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen) { + SBTC btc; + SCell *pCell; + void *pBuf; + int szCell; + int szBuf; + int ret; + int idx; + int c; - ret = tdbBtcMoveTo(pBtc, pKey, kLen, &cret); + tdbBtcOpen(&btc, pBt); + + // move to the position to insert + ret = tdbBtcMoveTo(&btc, pKey, kLen, &c); if (ret < 0) { - // TODO: handle error + tdbBtcClose(&btc); + ASSERT(0); return -1; } - if (pBtc->idx == -1) { - ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0); + if (btc.idx == -1) { idx = 0; } else { - if (cret > 0) { - idx = pBtc->idx + 1; - } else if (cret < 0) { - idx = pBtc->idx; + if (c > 0) { + idx = btc.idx + 1; + } else if (c < 0) { + idx = btc.idx; } else { - /* TODO */ + // TDB does NOT allow same key + tdbBtcClose(&btc); ASSERT(0); - } - } - - // TODO: refact code here - pBt = pBtc->pBt; - if (!pBt->pTmp) { - pBt->pTmp = (u8 *)tdbOsMalloc(pBt->pageSize); - if (pBt->pTmp == NULL) { return -1; } } - pCell = pBt->pTmp; + // make sure enough space to hold the cell + szBuf = kLen + vLen + 14; + pBuf = TDB_REALLOC(pBt->pBuf, pBt->pageSize > szBuf ? szBuf : pBt->pageSize); + if (pBuf == NULL) { + tdbBtcClose(&btc); + ASSERT(0); + return -1; + } + pBt->pBuf = pBuf; + pCell = (SCell *)pBt->pBuf; - // Encode the cell - ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pVal, vLen, pCell, &szCell); + // encode cell + ret = tdbBtreeEncodeCell(btc.pPage, pKey, kLen, pVal, vLen, pCell, &szCell); if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); return -1; } - // Insert the cell to the index - ret = tdbPageInsertCell(pBtc->pPage, idx, pCell, szCell, 0); + // mark the page dirty + ret = tdbPagerWrite(pBt->pPager, btc.pPage); if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); return -1; } - // If page is overflow, balance the tree - if (pBtc->pPage->nOverflow > 0) { - ret = tdbBtreeBalance(pBtc); + // insert the cell + ret = tdbPageInsertCell(btc.pPage, idx, pCell, szCell, 0); + if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); + return -1; + } + + // check if need balance + if (btc.pPage->nOverflow > 0) { + ret = tdbBtreeBalance(&btc); if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); return -1; } } + tdbBtcClose(&btc); + return 0; } int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) { - SBTC btc; - SCell *pCell; - int cret; - void *pVal; - SCellDecoder cd; - - tdbBtcOpen(&btc, pBt); - - tdbBtcMoveTo(&btc, pKey, kLen, &cret); - - if (cret) { - return cret; - } - - pCell = tdbPageGetCell(btc.pPage, btc.idx); - tdbBtreeDecodeCell(btc.pPage, pCell, &cd); - - *vLen = cd.vLen; - pVal = TDB_REALLOC(*ppVal, *vLen); - if (pVal == NULL) { - return -1; - } - - *ppVal = pVal; - memcpy(*ppVal, cd.pVal, cd.vLen); - return 0; + return tdbBtreePGet(pBt, pKey, kLen, NULL, NULL, ppVal, vLen); } int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen) { SBTC btc; SCell *pCell; int cret; - void *pTKey; - void *pTVal; + int ret; + void *pTKey = NULL; + void *pTVal = NULL; SCellDecoder cd; tdbBtcOpen(&btc, pBt); - tdbBtcMoveTo(&btc, pKey, kLen, &cret); + ret = tdbBtcMoveTo(&btc, pKey, kLen, &cret); + if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); + } + if (cret) { - return cret; + tdbBtcClose(&btc); + return -1; } pCell = tdbPageGetCell(btc.pPage, btc.idx); tdbBtreeDecodeCell(btc.pPage, pCell, &cd); - pTKey = TDB_REALLOC(*ppKey, cd.kLen); - pTVal = TDB_REALLOC(*ppVal, cd.vLen); - - if (pTKey == NULL || pTVal == NULL) { - TDB_FREE(pTKey); - TDB_FREE(pTVal); + if (ppKey) { + pTKey = TDB_REALLOC(*ppKey, cd.kLen); + if (pTKey == NULL) { + tdbBtcClose(&btc); + ASSERT(0); + return -1; + } + *ppKey = pTKey; + *pkLen = cd.kLen; + memcpy(*ppKey, cd.pKey, cd.kLen); } - *ppKey = pTKey; + pTVal = TDB_REALLOC(*ppVal, cd.vLen); + if (pTVal == NULL) { + tdbBtcClose(&btc); + ASSERT(0); + return -1; + } *ppVal = pTVal; - *pkLen = cd.kLen; *vLen = cd.vLen; - - memcpy(*ppKey, cd.pKey, cd.kLen); memcpy(*ppVal, cd.pVal, cd.vLen); + tdbBtcClose(&btc); + return 0; } @@ -300,7 +312,8 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { return -1; } - // TODO: Unref the page + // TODO: here still has problem + tdbPagerReturnPage(pBt->pPager, pPage); ASSERT(pgno != 0); pBt->root = pgno; @@ -371,17 +384,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { return 0; } -#ifndef TDB_BTREE_BALANCE -typedef struct { - SBTree *pBt; - SPage *pParent; - int idx; - i8 nOld; - SPage *pOldPages[3]; - i8 nNewPages; - SPage *pNewPages[5]; -} SBtreeBalanceHelper; - +// TDB_BTREE_BALANCE ===================== static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { SPager *pPager; SPage *pChild; @@ -408,6 +411,13 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { ((SIntHdr *)pChild->pData)->pgno = ((SIntHdr *)(pRoot->pData))->pgno; } + ret = tdbPagerWrite(pPager, pChild); + if (ret < 0) { + // TODO + ASSERT(0); + return 0; + } + // Copy the root page content to the child page tdbPageCopy(pRoot, pChild); @@ -472,6 +482,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ASSERT(0); return -1; } + + ret = tdbPagerWrite(pBt->pPager, pOlds[i]); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } } // copy the parent key out if child pages are not leaf page childNotLeaf = !TDB_BTREE_PAGE_IS_LEAF(pOlds[0]); @@ -492,6 +509,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } rPgno = ((SIntHdr *)pOlds[nOlds - 1]->pData)->pgno; } + + ret = tdbPagerWrite(pBt->pPager, pParent); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } + // drop the cells on parent page for (int i = 0; i < nOlds; i++) { nCells = TDB_PAGE_TOTAL_CELLS(pParent); @@ -619,6 +644,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (ret < 0) { ASSERT(0); } + + ret = tdbPagerWrite(pBt->pPager, pNews[iNew]); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } } } @@ -732,14 +764,24 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } + // TODO: here is not corrent for drop case + for (int i = 0; i < nNews; i++) { + if (i < nOlds) { + tdbPagerReturnPage(pBt->pPager, pOlds[i]); + } else { + tdbPagerReturnPage(pBt->pPager, pNews[i]); + } + } + return 0; } static int tdbBtreeBalance(SBTC *pBtc) { int iPage; + int ret; + int nFree; SPage *pParent; SPage *pPage; - int ret; u8 flags; u8 leaf; u8 root; @@ -750,10 +792,11 @@ static int tdbBtreeBalance(SBTC *pBtc) { pPage = pBtc->pPage; leaf = TDB_BTREE_PAGE_IS_LEAF(pPage); root = TDB_BTREE_PAGE_IS_ROOT(pPage); + nFree = TDB_PAGE_FREE_SIZE(pPage); // when the page is not overflow and not too empty, the balance work // is finished. Just break out the balance loop. - if (pPage->nOverflow == 0 /* TODO: && pPage->nFree <= */) { + if (pPage->nOverflow == 0 && nFree < TDB_PAGE_USABLE_SIZE(pPage) * 2 / 3) { break; } @@ -781,6 +824,8 @@ static int tdbBtreeBalance(SBTC *pBtc) { return -1; } + tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); + pBtc->iPage--; pBtc->pPage = pBtc->pgStack[pBtc->iPage]; } @@ -788,7 +833,7 @@ static int tdbBtreeBalance(SBTC *pBtc) { return 0; } -#endif +// TDB_BTREE_BALANCE // TDB_BTREE_CELL ===================== static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const void *pKey, int kLen, const void *pVal, @@ -1028,12 +1073,11 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { // move upward for (;;) { - if (pBtc->iPage == 0) { + if (pBtc->iPage == iPage) { pBtc->idx = 0; break; } - if (pBtc->iPage < iPage) break; tdbBtcMoveUpward(pBtc); } } @@ -1056,6 +1100,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { int tdbBtcMoveToLast(SBTC *pBtc) { int ret; + int nCells; SBTree *pBt; SPager *pPager; SPgno pgno; @@ -1071,27 +1116,56 @@ int tdbBtcMoveToLast(SBTC *pBtc) { return -1; } + nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); pBtc->iPage = 0; + if (nCells > 0) { + pBtc->idx = TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage) ? nCells - 1 : nCells; + } else { + // no data at all, point to an invalid position + ASSERT(TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)); + pBtc->idx = -1; + return 0; + } } else { - // move from a position - ASSERT(0); + int iPage = 0; + + // downward search + for (; iPage < pBtc->iPage; iPage++) { + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pBtc->pgStack[iPage])); + nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pgStack[iPage]); + if (pBtc->idxStack[iPage] != nCells) break; + } + + // move upward + for (;;) { + if (pBtc->iPage == iPage) { + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) { + pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1; + } else { + pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + } + break; + } + + tdbBtcMoveUpward(pBtc); + } } // move downward for (;;) { - if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) { - // TODO: handle empty case - ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) > 0); - pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1; - break; - } else { - pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break; - ret = tdbBtcMoveDownward(pBtc); - if (ret < 0) { - ASSERT(0); - return -1; - } + ret = tdbBtcMoveDownward(pBtc); + if (ret < 0) { + ASSERT(0); + return -1; + } + + nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) { + pBtc->idx = nCells - 1; + } else { + pBtc->idx = nCells; } } @@ -1104,6 +1178,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { void *pKey, *pVal; int ret; + // current cursor points to an invalid position if (pBtc->idx < 0) { return -1; } @@ -1134,12 +1209,17 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { memcpy(pVal, cd.pVal, cd.vLen); ret = tdbBtcMoveToNext(pBtc); + if (ret < 0) { + ASSERT(0); + return -1; + } return 0; } static int tdbBtcMoveToNext(SBTC *pBtc) { int nCells; + int ret; SCell *pCell; ASSERT(TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)); @@ -1151,39 +1231,35 @@ static int tdbBtcMoveToNext(SBTC *pBtc) { return 0; } - if (pBtc->iPage == 0) { - pBtc->idx = -1; - return 0; - } - - // Move upward + // move upward for (;;) { - tdbBtcMoveUpward(pBtc); - pBtc->idx++; - - nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); - if (pBtc->idx <= nCells) { - break; - } - if (pBtc->iPage == 0) { pBtc->idx = -1; return 0; } - } - // Move downward - for (;;) { - nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + tdbBtcMoveUpward(pBtc); + pBtc->idx++; - tdbBtcMoveDownward(pBtc); - pBtc->idx = 0; - - if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) { + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)); + if (pBtc->idx <= TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) { break; } } + // move downward + for (;;) { + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break; + + ret = tdbBtcMoveDownward(pBtc); + if (ret < 0) { + ASSERT(0); + return -1; + } + + pBtc->idx = 0; + } + return 0; } @@ -1230,91 +1306,145 @@ static int tdbBtcMoveUpward(SBTC *pBtc) { } static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { - int ret; - SBTree *pBt; - SPager *pPager; + int ret; + int nCells; + int c; + SBTree *pBt; + SCell *pCell; + SPager *pPager; + SCellDecoder cd = {0}; pBt = pBtc->pBt; pPager = pBt->pPager; if (pBtc->iPage < 0) { - ASSERT(pBtc->iPage == -1); - ASSERT(pBtc->idx == -1); - - // Move from the root + // move from a clear cursor ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt); if (ret < 0) { + // TODO ASSERT(0); - return -1; - } - - pBtc->iPage = 0; - - if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) { - // Current page is empty - // ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pBtc->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF)); return 0; } - for (;;) { - int lidx, ridx, midx, c, nCells; - SCell *pCell; - SPage *pPage; - SCellDecoder cd = {0}; + pBtc->iPage = 0; + pBtc->idx = -1; + // for empty tree, just return with an invalid position + if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) return 0; + } else { + SPage *pPage; + int idx; + int iPage = 0; - pPage = pBtc->pPage; + // downward search + for (; iPage < pBtc->iPage; iPage++) { + pPage = pBtc->pgStack[iPage]; + idx = pBtc->idxStack[iPage]; nCells = TDB_PAGE_TOTAL_CELLS(pPage); - lidx = 0; - ridx = nCells - 1; - ASSERT(nCells > 0); + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pPage)); - for (;;) { - if (lidx > ridx) break; - - midx = (lidx + ridx) >> 1; - - pCell = tdbPageGetCell(pPage, midx); - ret = tdbBtreeDecodeCell(pPage, pCell, &cd); - if (ret < 0) { - // TODO: handle error - ASSERT(0); - return -1; - } - - // Compare the key values + // check if key <= current position + if (idx < nCells) { + pCell = tdbPageGetCell(pPage, idx); + tdbBtreeDecodeCell(pPage, pCell, &cd); c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); - if (c < 0) { - /* input-key < cell-key */ - ridx = midx - 1; - } else if (c > 0) { - /* input-key > cell-key */ - lidx = midx + 1; - } else { - /* input-key == cell-key */ - break; - } + if (c > 0) break; } - // Move downward or break - u8 leaf = TDB_BTREE_PAGE_IS_LEAF(pPage); - if (leaf) { - pBtc->idx = midx; - *pCRst = c; - break; - } else { - if (c <= 0) { - pBtc->idx = midx; - } else { - pBtc->idx = midx + 1; - } - tdbBtcMoveDownward(pBtc); + // check if key > current - 1 position + if (idx > 0) { + pCell = tdbPageGetCell(pPage, idx - 1); + tdbBtreeDecodeCell(pPage, pCell, &cd); + c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + if (c <= 0) break; } } - } else { - // TODO: Move the cursor from a some position instead of a clear state - ASSERT(0); + // move upward + for (;;) { + if (pBtc->iPage == iPage) break; + tdbBtcMoveUpward(pBtc); + } + } + + // search downward to the leaf + for (;;) { + int lidx, ridx, midx; + SPage *pPage; + + pPage = pBtc->pPage; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); + lidx = 0; + ridx = nCells - 1; + + ASSERT(nCells > 0); + ASSERT(pBtc->idx == -1); + + // compare first cell + midx = lidx; + pCell = tdbPageGetCell(pPage, midx); + tdbBtreeDecodeCell(pPage, pCell, &cd); + c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + if (c <= 0) { + ridx = lidx - 1; + } else { + lidx = lidx + 1; + } + + // compare last cell + if (lidx <= ridx) { + midx = ridx; + pCell = tdbPageGetCell(pPage, midx); + tdbBtreeDecodeCell(pPage, pCell, &cd); + c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + if (c >= 0) { + lidx = ridx + 1; + } else { + ridx = ridx - 1; + } + } + + // binary search + for (;;) { + if (lidx > ridx) break; + + midx = (lidx + ridx) >> 1; + + pCell = tdbPageGetCell(pPage, midx); + ret = tdbBtreeDecodeCell(pPage, pCell, &cd); + if (ret < 0) { + // TODO: handle error + ASSERT(0); + return -1; + } + + // Compare the key values + c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + if (c < 0) { + // pKey < cd.pKey + ridx = midx - 1; + } else if (c > 0) { + // pKey > cd.pKey + lidx = midx + 1; + } else { + // pKey == cd.pKey + break; + } + } + + // keep search downward or break + if (TDB_BTREE_PAGE_IS_LEAF(pPage)) { + pBtc->idx = midx; + *pCRst = c; + break; + } else { + if (c <= 0) { + pBtc->idx = midx; + } else { + pBtc->idx = midx + 1; + } + tdbBtcMoveDownward(pBtc); + } } return 0; diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index e41e41f72a..fe7b8c6d48 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -49,6 +49,8 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF if (ret < 0) { return -1; } + + tdbEnvAddPager(pEnv, pPager); } ASSERT(pPager != NULL); @@ -74,22 +76,7 @@ int tdbDbDrop(TDB *pDb) { } int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { - SBTC btc; - SBTC *pCur; - int ret; - - pCur = &btc; - ret = tdbBtcOpen(pCur, pDb->pBt); - if (ret < 0) { - return -1; - } - - ret = tdbBtCursorInsert(pCur, pKey, keyLen, pVal, valLen); - if (ret < 0) { - return -1; - } - - return 0; + return tdbBtreeInsert(pDb->pBt, pKey, keyLen, pVal, valLen); } int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 4439147e09..06d37df653 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -19,6 +19,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) { TENV *pEnv; int dsize; int zsize; + int tsize; u8 *pPtr; int ret; @@ -53,6 +54,14 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) { return -1; } + pEnv->nPgrHash = 8; + tsize = sizeof(SPager *) * pEnv->nPgrHash; + pEnv->pgrHash = TDB_REALLOC(pEnv->pgrHash, tsize); + if (pEnv->pgrHash == NULL) { + return -1; + } + memset(pEnv->pgrHash, 0, tsize); + mkdir(rootDir, 0755); *ppEnv = pEnv; @@ -64,7 +73,99 @@ int tdbEnvClose(TENV *pEnv) { return 0; } +int tdbBegin(TENV *pEnv) { + SPager *pPager; + int ret; + + for (pPager = pEnv->pgrList; pPager; pPager = pPager->pNext) { + ret = tdbPagerBegin(pPager); + if (ret < 0) { + ASSERT(0); + return -1; + } + } + + return 0; +} + +int tdbCommit(TENV *pEnv) { + SPager *pPager; + int ret; + + for (pPager = pEnv->pgrList; pPager; pPager = pPager->pNext) { + ret = tdbPagerCommit(pPager); + if (ret < 0) { + ASSERT(0); + return -1; + } + } + + return 0; +} + +int tdbRollback(TENV *pEnv) { + ASSERT(0); + return 0; +} + SPager *tdbEnvGetPager(TENV *pEnv, const char *fname) { - // TODO - return NULL; + u32 hash; + SPager **ppPager; + + hash = tdbCstringHash(fname); + ppPager = &pEnv->pgrHash[hash % pEnv->nPgrHash]; + for (; *ppPager && (strcmp(fname, (*ppPager)->dbFileName) != 0); ppPager = &((*ppPager)->pHashNext)) { + } + + return *ppPager; +} + +void tdbEnvAddPager(TENV *pEnv, SPager *pPager) { + u32 hash; + SPager **ppPager; + + // rehash if neccessary + if (pEnv->nPager + 1 > pEnv->nPgrHash) { + // TODO + } + + // add to list + pPager->pNext = pEnv->pgrList; + pEnv->pgrList = pPager; + + // add to hash + hash = tdbCstringHash(pPager->dbFileName); + ppPager = &pEnv->pgrHash[hash % pEnv->nPgrHash]; + pPager->pHashNext = *ppPager; + *ppPager = pPager; + + // increase the counter + pEnv->nPager++; +} + +void tdbEnvRemovePager(TENV *pEnv, SPager *pPager) { + u32 hash; + SPager **ppPager; + + // remove from the list + for (ppPager = &pEnv->pgrList; *ppPager && (*ppPager != pPager); ppPager = &((*ppPager)->pNext)) { + } + ASSERT(*ppPager == pPager); + *ppPager = pPager->pNext; + + // remove from hash + hash = tdbCstringHash(pPager->dbFileName); + ppPager = &pEnv->pgrHash[hash % pEnv->nPgrHash]; + for (; *ppPager && *ppPager != pPager; ppPager = &((*ppPager)->pHashNext)) { + } + ASSERT(*ppPager == pPager); + *ppPager = pPager->pNext; + + // decrease the counter + pEnv->nPager--; + + // rehash if necessary + if (pEnv->nPgrHash > 8 && pEnv->nPager < pEnv->nPgrHash / 2) { + // TODO + } } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 07c267a15c..d886cfd889 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -34,18 +34,6 @@ struct SPCache { }) #define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL) -// For page ref -#define TDB_INIT_PAGE_REF(pPage) ((pPage)->nRef = 0) -#if 0 -#define TDB_REF_PAGE(pPage) (++(pPage)->nRef) -#define TDB_UNREF_PAGE(pPage) (--(pPage)->nRef) -#define TDB_GET_PAGE_REF(pPage) ((pPage)->nRef) -#else -#define TDB_REF_PAGE(pPage) atomic_add_fetch_32(&((pPage)->nRef), 1) -#define TDB_UNREF_PAGE(pPage) atomic_sub_fetch_32(&((pPage)->nRef), 1) -#define TDB_GET_PAGE_REF(pPage) atomic_load_32(&((pPage)->nRef)) -#endif - static int tdbPCacheOpenImpl(SPCache *pCache); static void tdbPCacheInitLock(SPCache *pCache); static void tdbPCacheClearLock(SPCache *pCache); @@ -107,12 +95,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) { ASSERT(nRef >= 0); if (nRef == 0) { - if (1 /*TODO: page still clean*/) { - tdbPCacheUnpinPage(pCache, pPage); - } else { - // TODO - ASSERT(0); - } + tdbPCacheUnpinPage(pCache, pPage); } } @@ -192,6 +175,8 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) { tdbPCacheLock(pCache); + ASSERT(!pPage->isDirty); + nRef = TDB_GET_PAGE_REF(pPage); ASSERT(nRef >= 0); if (nRef == 0) { diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 748633da34..2bc40a6aad 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -15,20 +15,6 @@ #include "tdbInt.h" -struct SPager { - char *dbFileName; - char *jFileName; - int pageSize; - uint8_t fid[TDB_FILE_ID_LEN]; - tdb_fd_t fd; - tdb_fd_t jfd; - SPCache *pCache; - SPgno dbFileSize; - SPgno dbOrigSize; - SPage *pDirty; - u8 inTran; -}; - typedef struct __attribute__((__packed__)) { u8 hdrString[16]; u16 pageSize; @@ -41,9 +27,8 @@ TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct") #define TDB_PAGE_INITIALIZED(pPage) ((pPage)->pPager != NULL) -static int tdbPagerReadPage(SPager *pPager, SPage *pPage); static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno); -static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg); +static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg, u8 loadPage); static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage); static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage); @@ -131,26 +116,36 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) { } int tdbPagerWrite(SPager *pPager, SPage *pPage) { - int ret; + int ret; + SPage **ppPage; + ASSERT(pPager->inTran); +#if 0 if (pPager->inTran == 0) { ret = tdbPagerBegin(pPager); if (ret < 0) { return -1; } } +#endif if (pPage->isDirty) return 0; + // ref page one more time so the page will not be release + TDB_REF_PAGE(pPage); + // Set page as dirty pPage->isDirty = 1; - // Add page to dirty list - // TODO: sort the list according to the page number - pPage->pDirtyNext = pPager->pDirty; - pPager->pDirty = pPage; + // Add page to dirty list(TODO: NOT use O(n^2) algorithm) + for (ppPage = &pPager->pDirty; (*ppPage) && TDB_PAGE_PGNO(*ppPage) < TDB_PAGE_PGNO(pPage); + ppPage = &((*ppPage)->pDirtyNext)) { + } + ASSERT(*ppPage == NULL || TDB_PAGE_PGNO(*ppPage) > TDB_PAGE_PGNO(pPage)); + pPage->pDirtyNext = *ppPage; + *ppPage = pPage; - // Write page to journal + // Write page to journal if neccessary if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize) { ret = tdbPagerWritePageToJournal(pPager, pPage); if (ret < 0) { @@ -184,54 +179,46 @@ int tdbPagerCommit(SPager *pPager) { SPage *pPage; int ret; - // Begin commit - { - // TODO: Sync the journal file (Here or when write ?) + // sync the journal file + ret = tdbOsFSync(pPager->jfd); + if (ret < 0) { + // TODO + ASSERT(0); + return 0; } - for (;;) { - pPage = pPager->pDirty; - - if (pPage == NULL) break; - + // loop to write the dirty pages to file + for (pPage = pPager->pDirty; pPage; pPage = pPage->pDirtyNext) { + // TODO: update the page footer ret = tdbPagerWritePageToDB(pPager, pPage); if (ret < 0) { ASSERT(0); return -1; } + } + // release the page + for (pPage = pPager->pDirty; pPage; pPage = pPager->pDirty) { pPager->pDirty = pPage->pDirtyNext; pPage->pDirtyNext = NULL; - // TODO: release the page + pPage->isDirty = 0; + + tdbPCacheRelease(pPager->pCache, pPage); } + // sync the db file tdbOsFSync(pPager->fd); + // remote the journal file tdbOsClose(pPager->jfd); tdbOsRemove(pPager->jFileName); - // pPager->jfd = -1; + pPager->dbOrigSize = pPager->dbFileSize; + pPager->inTran = 0; return 0; } -static int tdbPagerReadPage(SPager *pPager, SPage *pPage) { - i64 offset; - int ret; - - ASSERT(memcmp(pPager->fid, pPage->pgid.fileid, TDB_FILE_ID_LEN) == 0); - - offset = (pPage->pgid.pgno - 1) * (i64)(pPager->pageSize); - ret = tdbOsPRead(pPager->fd, pPage->pData, pPager->pageSize, offset); - if (ret < 0) { - // TODO: handle error - return -1; - } - return 0; -} - -int tdbPagerGetPageSize(SPager *pPager) { return pPager->pageSize; } - int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg) { SPage *pPage; SPgid pgid; @@ -247,7 +234,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage // Initialize the page if need if (!TDB_PAGE_INITIALIZED(pPage)) { - ret = tdbPagerInitPage(pPager, pPage, initPage, arg); + ret = tdbPagerInitPage(pPager, pPage, initPage, arg, 1); if (ret < 0) { return -1; } @@ -284,7 +271,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage ASSERT(!TDB_PAGE_INITIALIZED(pPage)); // Initialize the page if need - ret = tdbPagerInitPage(pPager, pPage, initPage, arg); + ret = tdbPagerInitPage(pPager, pPage, initPage, arg, 0); if (ret < 0) { return -1; } @@ -332,10 +319,11 @@ static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno) { return 0; } -static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg) { +static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg, u8 loadPage) { int ret; int lcode; int nLoops; + i64 nRead; lcode = TDB_TRY_LOCK_PAGE(pPage); if (lcode == P_LOCK_SUCC) { @@ -344,6 +332,19 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage return 0; } + if (loadPage) { + nRead = tdbOsPRead(pPager->fd, pPage->pData, pPage->pageSize, ((i64)pPage->pageSize) * TDB_PAGE_PGNO(pPage)); + if (nRead < 0) { + // TODO + ASSERT(0); + return -1; + } else if (nRead < pPage->pageSize) { + // TODO + ASSERT(0); + return -1; + } + } + ret = (*initPage)(pPage, arg); if (ret < 0) { TDB_UNLOCK_PAGE(pPage); diff --git a/source/libs/tdb/src/db/tdbTxn.c b/source/libs/tdb/src/db/tdbTxn.c index fd4d5de60e..03bcbb44a7 100644 --- a/source/libs/tdb/src/db/tdbTxn.c +++ b/source/libs/tdb/src/db/tdbTxn.c @@ -15,17 +15,29 @@ #include "tdbInt.h" -int tdbTxnBegin(TENV *pEnv) { - // TODO - return 0; -} +// int tdbTxnBegin(TENV *pEnv) { +// // TODO +// return 0; +// } -int tdbTxnCommit(TENV *pEnv) { - // TODO - return 0; -} +// int tdbTxnCommit(TENV *pEnv) { +// SPager *pPager = NULL; +// int ret; -int tdbTxnRollback(TENV *pEnv) { - // TODO - return 0; -} \ No newline at end of file +// for (;;) { +// break; +// ret = tdbPagerCommit(pPager); +// if (ret < 0) { +// ASSERT(0); +// return -1; +// } +// } + +// // TODO +// return 0; +// } + +// int tdbTxnRollback(TENV *pEnv) { +// // TODO +// return 0; +// } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h index 2797b5ea5e..2eba5f4f1a 100644 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ b/source/libs/tdb/src/inc/tdbBtree.h @@ -40,7 +40,7 @@ struct SBTC { // SBTree int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt); int tdbBtreeClose(SBTree *pBt); -int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen); +int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen); int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen); diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index a651c3a12e..e10c5d54e0 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/source/libs/tdb/src/inc/tdbEnv.h @@ -25,11 +25,20 @@ typedef struct STEnv { char *jfname; int jfd; SPCache *pCache; + SPager *pgrList; + int nPager; + int nPgrHash; + SPager **pgrHash; } TENV; int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv); int tdbEnvClose(TENV *pEnv); +int tdbBegin(TENV *pEnv); +int tdbCommit(TENV *pEnv); +int tdbRollback(TENV *pEnv); +void tdbEnvAddPager(TENV *pEnv, SPager *pPager); +void tdbEnvRemovePager(TENV *pEnv, SPager *pPager); SPager *tdbEnvGetPager(TENV *pEnv, const char *fname); #ifdef __cplusplus diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 361a460cef..57e01f904c 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -16,8 +16,6 @@ #ifndef _TD_TDB_INTERNAL_H_ #define _TD_TDB_INTERNAL_H_ -#include "os.h" - #include "tdb.h" #ifdef __cplusplus @@ -91,23 +89,6 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { // dbname #define TDB_MAX_DBNAME_LEN 24 -// tdb_log -#define tdbError(var) - -#define TERR_A(val, op, flag) \ - do { \ - if (((val) = (op)) != 0) { \ - goto flag; \ - } \ - } while (0) - -#define TERR_B(val, op, flag) \ - do { \ - if (((val) = (op)) == NULL) { \ - goto flag; \ - } \ - } while (0) - #define TDB_VARIANT_LEN ((int)-1) typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2); diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 196bbdafc7..ae389708f4 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -24,6 +24,8 @@ extern "C" { #define TDB_FOR_TDENGINE #ifdef TDB_FOR_TDENGINE +#include "os.h" +#include "thash.h" // For memory ----------------- #define tdbOsMalloc taosMemoryMalloc @@ -95,7 +97,11 @@ typedef int tdb_fd_t; #define tdbOsOpen(PATH, OPTION, MODE) open((PATH), (OPTION), (MODE)) -#define tdbOsClose close +#define tdbOsClose(FD) \ + do { \ + close(FD); \ + (FD) = -1; \ + } while (0) i64 tdbOsRead(tdb_fd_t fd, void *pData, i64 nBytes); i64 tdbOsPRead(tdb_fd_t fd, void *pData, i64 nBytes, i64 offset); diff --git a/source/libs/tdb/src/inc/tdbPCache.h b/source/libs/tdb/src/inc/tdbPCache.h index c7fa155615..f71d34ab53 100644 --- a/source/libs/tdb/src/inc/tdbPCache.h +++ b/source/libs/tdb/src/inc/tdbPCache.h @@ -33,6 +33,18 @@ extern "C" { SPager *pPager; \ SPgid pgid; +// For page ref +#define TDB_INIT_PAGE_REF(pPage) ((pPage)->nRef = 0) +#if 0 +#define TDB_REF_PAGE(pPage) (++(pPage)->nRef) +#define TDB_UNREF_PAGE(pPage) (--(pPage)->nRef) +#define TDB_GET_PAGE_REF(pPage) ((pPage)->nRef) +#else +#define TDB_REF_PAGE(pPage) atomic_add_fetch_32(&((pPage)->nRef), 1) +#define TDB_UNREF_PAGE(pPage) atomic_sub_fetch_32(&((pPage)->nRef), 1) +#define TDB_GET_PAGE_REF(pPage) atomic_load_32(&((pPage)->nRef)) +#endif + int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache); int tdbPCacheClose(SPCache *pCache); SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage); diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 563fb53e98..77a1ee5f6e 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -100,6 +100,7 @@ struct SPage { // APIs #define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) #define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) +#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage) #define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno) #define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) #define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) diff --git a/source/libs/tdb/src/inc/tdbPager.h b/source/libs/tdb/src/inc/tdbPager.h index f4cc822f27..81b6074431 100644 --- a/source/libs/tdb/src/inc/tdbPager.h +++ b/source/libs/tdb/src/inc/tdbPager.h @@ -20,13 +20,28 @@ extern "C" { #endif +struct SPager { + char *dbFileName; + char *jFileName; + int pageSize; + uint8_t fid[TDB_FILE_ID_LEN]; + tdb_fd_t fd; + tdb_fd_t jfd; + SPCache *pCache; + SPgno dbFileSize; + SPgno dbOrigSize; + SPage *pDirty; + u8 inTran; + SPager *pNext; // used by TENV + SPager *pHashNext; // used by TENV +}; + int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager); int tdbPagerClose(SPager *pPager); int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate); int tdbPagerWrite(SPager *pPager, SPage *pPage); int tdbPagerBegin(SPager *pPager); int tdbPagerCommit(SPager *pPager); -int tdbPagerGetPageSize(SPager *pPager); int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); void tdbPagerReturnPage(SPager *pPager, SPage *pPage); diff --git a/source/libs/tdb/src/inc/tdbTxn.h b/source/libs/tdb/src/inc/tdbTxn.h index cc11369785..0be2dad3c2 100644 --- a/source/libs/tdb/src/inc/tdbTxn.h +++ b/source/libs/tdb/src/inc/tdbTxn.h @@ -28,10 +28,6 @@ struct STxn { void *xArg; }; -int tdbTxnBegin(TENV *pEnv); -int tdbTxnCommit(TENV *pEnv); -int tdbTxnRollback(TENV *pEnv); - #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index c06d9d18c9..6abddb5b22 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -101,6 +101,8 @@ static inline int tdbGetVarInt(const u8 *p, int *v) { return n; } +static inline u32 tdbCstringHash(const char *s) { return MurmurHash3_32(s, strlen(s)); } + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index f41e2bcbee..9e1277a53d 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -118,10 +118,10 @@ TEST(tdb_test, simple_test) { TENV *pEnv; TDB *pDb; FKeyComparator compFunc; - int nData = 1000000; + int nData = 50000000; // Open Env - ret = tdbEnvOpen("tdb", 4096, 256000, &pEnv); + ret = tdbEnvOpen("tdb", 4096, 64, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database @@ -134,36 +134,23 @@ TEST(tdb_test, simple_test) { char val[64]; { // Insert some data - int i = 1; - SPoolMem *pPool; - int memPoolCapacity = 16 * 1024; + for (int i = 1; i <= nData;) { + tdbBegin(pEnv); - pPool = openPool(); - - tdbTxnBegin(pEnv); - - for (;;) { - if (i > nData) break; - - sprintf(key, "key%d", i); - sprintf(val, "value%d", i); - ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val)); - GTEST_ASSERT_EQ(ret, 0); - - if (pPool->size >= memPoolCapacity) { - tdbTxnCommit(pEnv); - - clearPool(pPool); - - tdbTxnBegin(pEnv); + for (int k = 0; k < 2000; k++) { + sprintf(key, "key%d", i); + sprintf(val, "value%d", i); + ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val)); + GTEST_ASSERT_EQ(ret, 0); + i++; } - i++; + tdbCommit(pEnv); } - - closePool(pPool); } + tdbCommit(pEnv); + { // Query the data void *pVal = NULL; int vLen; @@ -173,6 +160,7 @@ TEST(tdb_test, simple_test) { sprintf(val, "value%d", i); ret = tdbDbGet(pDb, key, strlen(key), &pVal, &vLen); + ASSERT(ret == 0); GTEST_ASSERT_EQ(ret, 0); GTEST_ASSERT_EQ(vLen, strlen(val)); diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 5296a16703..2545eeab4b 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -30,6 +30,9 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) { pRead->curFileFirstVer = -1; pRead->capacity = 0; pRead->status = 0; + + taosThreadMutexInit(&pRead->mutex, NULL); + pRead->pHead = taosMemoryMalloc(sizeof(SWalHead)); if (pRead->pHead == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; @@ -135,6 +138,22 @@ static int32_t walReadSeekVer(SWalReadHandle *pRead, int64_t ver) { return 0; } +int32_t walReadWithHandle_s(SWalReadHandle *pRead, int64_t ver, SWalReadHead **ppHead) { + taosThreadMutexLock(&pRead->mutex); + if (walReadWithHandle(pRead, ver) < 0) { + taosThreadMutexUnlock(&pRead->mutex); + return -1; + } + *ppHead = taosMemoryMalloc(sizeof(SWalReadHead) + pRead->pHead->head.len); + if (*ppHead == NULL) { + taosThreadMutexUnlock(&pRead->mutex); + return -1; + } + memcpy(*ppHead, &pRead->pHead->head, sizeof(SWalReadHead) + pRead->pHead->head.len); + taosThreadMutexUnlock(&pRead->mutex); + return 0; +} + int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) { int code; // TODO: check wal life @@ -145,7 +164,9 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) { } } - if (!taosValidFile(pRead->pReadLogTFile)) return -1; + if (!taosValidFile(pRead->pReadLogTFile)) { + return -1; + } code = taosReadFile(pRead->pReadLogTFile, pRead->pHead, sizeof(SWalHead)); if (code != sizeof(SWalHead)) { diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index ed93708c07..a7855539a4 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -294,7 +294,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) { #if FILE_WITH_LOCK taosThreadRwlockWrlock(&((*ppFile)->rwlock)); #endif - if (ppFile == NULL || *ppFile == NULL || (*ppFile)->fd == -1) { + if (ppFile == NULL || *ppFile == NULL) { return 0; } if ((*ppFile)->fp != NULL) { @@ -325,7 +325,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { #if FILE_WITH_LOCK taosThreadRwlockRdlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. int64_t leftbytes = count; int64_t readbytes; char *tbuf = (char *)buf; @@ -365,7 +365,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) #if FILE_WITH_LOCK taosThreadRwlockRdlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. int64_t ret = pread(pFile->fd, buf, count, offset); #if FILE_WITH_LOCK taosThreadRwlockUnlock(&(pFile->rwlock)); @@ -380,7 +380,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { #if FILE_WITH_LOCK taosThreadRwlockWrlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. int64_t nleft = count; int64_t nwritten = 0; @@ -414,7 +414,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { #if FILE_WITH_LOCK taosThreadRwlockRdlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. int64_t ret = lseek(pFile->fd, (long)offset, whence); #if FILE_WITH_LOCK taosThreadRwlockUnlock(&(pFile->rwlock)); @@ -429,7 +429,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. struct stat fileStat; int32_t code = fstat(pFile->fd, &fileStat); @@ -456,7 +456,7 @@ int32_t taosLockFile(TdFilePtr pFile) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. return (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB); #endif @@ -469,7 +469,7 @@ int32_t taosUnLockFile(TdFilePtr pFile) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. return (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB); #endif @@ -529,7 +529,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. return ftruncate(pFile->fd, l_size); #endif @@ -750,7 +750,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) { if (pFile == NULL) { return NULL; } - assert(pFile->fd >= 0); + assert(pFile->fd >= 0); // Please check if you have closed the file. void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0); return ptr; diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index f4d4c74d1d..3545aabdca 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -23,15 +23,22 @@ #define TD_MEMORY_STACK_TRACE_DEPTH 10 +typedef struct TdMemoryInfo *TdMemoryInfoPtr; + typedef struct TdMemoryInfo { int32_t symbol; int32_t memorySize; void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX -} *TdMemoryInfoPtr , TdMemoryInfo; + // TdMemoryInfoPtr pNext; + // TdMemoryInfoPtr pPrev; +} TdMemoryInfo; + +// static TdMemoryInfoPtr GlobalMemoryPtr = NULL; #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) - + #define tstrdup(str) _strdup(str) #else + #define tstrdup(str) strdup(str) #include @@ -129,6 +136,26 @@ void *taosMemoryRealloc(void *ptr, int32_t size) { #endif } +void *taosMemoryStrDup(void *ptr) { +#ifdef USE_TD_MEMORY + if (ptr == NULL) return NULL; + + TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); + assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); + + void *tmp = tstrdup((const char *)pTdMemoryInfo); + if (tmp == NULL) return NULL; + + memcpy(tmp, pTdMemoryInfo, sizeof(TdMemoryInfo)); + taosBackTrace(((TdMemoryInfoPtr)tmp)->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH); + + return (char*)tmp + sizeof(TdMemoryInfo); +#else + return tstrdup((const char *)ptr); +#endif +} + + void taosMemoryFree(const void *ptr) { if (ptr == NULL) return; diff --git a/source/os/src/osProc.c b/source/os/src/osProc.c index 6c58e71003..1cdd41ad78 100644 --- a/source/os/src/osProc.c +++ b/source/os/src/osProc.c @@ -17,11 +17,46 @@ #define _DEFAULT_SOURCE #include "os.h" -int32_t taosNewProc(const char *args) { - return 0; +static char *tsProcPath = NULL; + +int32_t taosNewProc(char **args) { + int32_t pid = fork(); + if (pid == 0) { + args[0] = tsProcPath; + // close(STDIN_FILENO); + close(STDOUT_FILENO); + // close(STDERR_FILENO); + return execvp(tsProcPath, args); + } else { + return pid; + } } -void taosSetProcName(char **argv, const char *name) { +void taosWaitProc(int32_t pid) { + int32_t status = -1; + waitpid(pid, &status, 0); +} + +void taosKillProc(int32_t pid) { kill(pid, SIGINT); } + +bool taosProcExist(int32_t pid) { + int32_t p = getpgid(pid); + return p >= 0; +} + +// the length of the new name must be less than the original name to take effect +void taosSetProcName(int32_t argc, char **argv, const char *name) { prctl(PR_SET_NAME, name); - strcpy(argv[0], name); -} \ No newline at end of file + + for (int32_t i = 0; i < argc; ++i) { + int32_t len = strlen(argv[i]); + for (int32_t j = 0; j < len; ++j) { + argv[i][j] = 0; + } + if (i == 0) { + tstrncpy(argv[0], name, len + 1); + } + } +} + +void taosSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; } diff --git a/source/os/src/osShm.c b/source/os/src/osShm.c index ba184c1f5d..bf784f14ac 100644 --- a/source/os/src/osShm.c +++ b/source/os/src/osShm.c @@ -17,10 +17,10 @@ #define _DEFAULT_SOURCE #include "os.h" -int32_t taosCreateShm(SShm* pShm, int32_t shmsize) { +int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) { pShm->id = -1; - int32_t shmid = shmget(0X95279527, shmsize, IPC_CREAT | 0600); + int32_t shmid = shmget(0X95270000 + key, shmsize, IPC_CREAT | 0600); if (shmid < 0) { return -1; } diff --git a/source/os/src/osSignal.c b/source/os/src/osSignal.c index ce029cdfe5..1d7fa517e5 100644 --- a/source/os/src/osSignal.c +++ b/source/os/src/osSignal.c @@ -59,7 +59,7 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp) { struct sigaction act; memset(&act, 0, sizeof(act)); #if 1 - act.sa_flags = SA_SIGINFO; + act.sa_flags = SA_SIGINFO | SA_RESTART; act.sa_sigaction = (FLinuxSignalHandler)sigfp; #else act.sa_handler = sigfp; @@ -71,6 +71,6 @@ void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); } void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); } -void taosKillChildOnSelfStopped() { prctl(PR_SET_PDEATHSIG, SIGKILL); } +void taosKillChildOnParentStopped() { prctl(PR_SET_PDEATHSIG, SIGKILL); } #endif diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index d4abcb962a..93022de021 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -173,6 +173,7 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight) { if (isnan(p2)) { return 1; } + if (FLT_EQUAL(p1, p2)) { return 0; } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 96bb638b95..ce9ef5b1c0 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -590,12 +590,12 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { } int32_t cfgLoadFromEnvVar(SConfig *pConfig) { - uInfo("load from global env variables"); + uInfo("load from env variables not implemented yet"); return 0; } int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) { - uInfo("load from env file %s", filepath); + uInfo("load from env file not implemented yet"); return 0; } @@ -654,6 +654,6 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { } int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { - uInfo("load from apoll url %s", url); + uInfo("load from apoll url not implemented yet"); return 0; } diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 0efcf517a9..93a843fee8 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -121,7 +121,8 @@ int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj) { return tjsonAddItemToArray(pJson, pJobj); } -int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void* pArray, int32_t itemSize, int32_t num) { +int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void* pArray, int32_t itemSize, + int32_t num) { if (num > 0) { SJson* pJsonArray = tjsonAddArrayToObject(pJson, pName); if (NULL == pJsonArray) { @@ -168,7 +169,7 @@ int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal } *pVal = strtol(p, NULL, 10); - return (errno == EINVAL || errno == ERANGE) ? TSDB_CODE_FAILED:TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } int32_t tjsonGetIntValue(const SJson* pJson, const char* pName, int32_t* pVal) { @@ -199,19 +200,19 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV } *pVal = strtoul(p, NULL, 10); - return (errno == ERANGE||errno == EINVAL) ? TSDB_CODE_FAILED:TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } int32_t tjsonGetUIntValue(const SJson* pJson, const char* pName, uint32_t* pVal) { uint64_t val = 0; - int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); + int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); *pVal = val; return code; } int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal) { uint64_t val = 0; - int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); + int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); *pVal = val; return code; } @@ -264,7 +265,7 @@ int32_t tjsonMakeObject(const SJson* pJson, const char* pName, FToObject func, v int32_t tjsonToArray(const SJson* pJson, const char* pName, FToObject func, void* pArray, int32_t itemSize) { const cJSON* jArray = tjsonGetObjectItem(pJson, pName); - int32_t size = (NULL == jArray ? 0 : tjsonGetArraySize(jArray)); + int32_t size = (NULL == jArray ? 0 : tjsonGetArraySize(jArray)); for (int32_t i = 0; i < size; ++i) { int32_t code = func(tjsonGetArrayItem(jArray, i), (char*)pArray + itemSize * i); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index ef15f44f8f..563acfec78 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -214,6 +214,7 @@ static void *taosThreadToOpenNewFile(void *param) { tsLogObj.logHandle->pFile = pFile; tsLogObj.lines = 0; tsLogObj.openInProgress = 0; + taosSsleep(3); taosCloseLogByFd(pOldFile); uInfo(" new log file:%d is opened", tsLogObj.flag); diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index d7e199039a..600413068c 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -140,14 +140,16 @@ static void taosProcDestroySem(SProcQueue *pQueue) { pQueue->sem = NULL; } } +#endif static void taosProcCleanupQueue(SProcQueue *pQueue) { +#if 0 if (pQueue != NULL) { taosProcDestroyMutex(pQueue); taosProcDestroySem(pQueue); } -} #endif +} static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, const char *pBody, int32_t rawBodyLen, ProcFuncType ftype) { @@ -222,7 +224,6 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea taosThreadMutexLock(&pQueue->mutex); if (pQueue->total - pQueue->avail <= 0) { taosThreadMutexUnlock(&pQueue->mutex); - tsem_post(&pQueue->sem); terrno = TSDB_CODE_OUT_OF_SHM_MEM; return 0; } @@ -317,7 +318,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { pProc->pChildQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + cstart, csize); pProc->pParentQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + pstart, psize); if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) { - // taosProcCleanupQueue(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pChildQueue); taosMemoryFree(pProc); return NULL; } @@ -336,7 +337,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { pProc->parentConsumeFp = pCfg->parentConsumeFp; pProc->isChild = pCfg->isChild; - uDebug("proc:%s, is initialized, child:%d child queue:%p parent queue:%p", pProc->name, pProc->isChild, + uDebug("proc:%s, is initialized, isChild:%d child queue:%p parent queue:%p", pProc->name, pProc->isChild, pProc->pChildQueue, pProc->pParentQueue); return pProc; @@ -376,7 +377,7 @@ static void taosProcThreadLoop(SProcObj *pProc) { int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype, mallocHeadFp, freeHeadFp, mallocBodyFp, freeBodyFp); if (numOfMsgs == 0) { - uInfo("proc:%s, get no msg from queue:%p and exit the proc thread", pProc->name, pQueue); + uDebug("proc:%s, get no msg from queue:%p and exit the proc thread", pProc->name, pQueue); break; } else if (numOfMsgs < 0) { uTrace("proc:%s, get no msg from queue:%p since %s", pProc->name, pQueue, terrstr()); @@ -399,19 +400,19 @@ int32_t taosProcRun(SProcObj *pProc) { return -1; } - uDebug("proc:%s, start to consume queue:%p", pProc->name, pProc->pChildQueue); + uDebug("proc:%s, start to consume queue:%p, thread:%" PRId64, pProc->name, pProc->pChildQueue, pProc->thread); return 0; } static void taosProcStop(SProcObj *pProc) { if (!taosCheckPthreadValid(pProc->thread)) return; - uDebug("proc:%s, start to join thread", pProc->name); + uDebug("proc:%s, start to join thread:%" PRId64, pProc->name, pProc->thread); SProcQueue *pQueue; if (pProc->isChild) { - pQueue = pProc->pParentQueue; - } else { pQueue = pProc->pChildQueue; + } else { + pQueue = pProc->pParentQueue; } tsem_post(&pQueue->sem); taosThreadJoin(pProc->thread, NULL); @@ -419,10 +420,11 @@ static void taosProcStop(SProcObj *pProc) { void taosProcCleanup(SProcObj *pProc) { if (pProc != NULL) { - uDebug("proc:%s, clean up", pProc->name); + uDebug("proc:%s, start to clean up", pProc->name); taosProcStop(pProc); - // taosProcCleanupQueue(pProc->pChildQueue); - // taosProcCleanupQueue(pProc->pParentQueue); + taosProcCleanupQueue(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pParentQueue); + uDebug("proc:%s, is cleaned up", pProc->name); taosMemoryFree(pProc); } } @@ -432,7 +434,9 @@ int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, return taosProcQueuePush(pProc->pChildQueue, pHead, headLen, pBody, bodyLen, ftype); } -int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - ProcFuncType ftype) { - return taosProcQueuePush(pProc->pParentQueue, pHead, headLen, pBody, bodyLen, ftype); +void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, + ProcFuncType ftype) { + while (taosProcQueuePush(pProc->pParentQueue, pHead, headLen, pBody, bodyLen, ftype) != 0) { + taosMsleep(1); + } } diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 46b6a40166..b756976394 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -5,6 +5,8 @@ ./test.sh -f tsim/user/basic1.sim # ---- db +./test.sh -f tsim/db/create_all_options.sim +./test.sh -f tsim/db/alter_option.sim ./test.sh -f tsim/db/basic1.sim ./test.sh -f tsim/db/basic2.sim ./test.sh -f tsim/db/basic3.sim @@ -22,12 +24,13 @@ ./test.sh -f tsim/insert/null.sim # ---- parser -#./test.sh -f tsim/parser/groupby-basic.sim -#./test.sh -f tsim/parser/fourArithmetic-basic.sim +./test.sh -f tsim/parser/groupby-basic.sim +./test.sh -f tsim/parser/fourArithmetic-basic.sim # ---- query ./test.sh -f tsim/query/interval.sim ./test.sh -f tsim/query/interval-offset.sim +./test.sh -f tsim/query/scalarFunction.sim # ---- show ./test.sh -f tsim/show/basic.sim @@ -38,6 +41,8 @@ # ---- tmq ./test.sh -f tsim/tmq/basic.sim ./test.sh -f tsim/tmq/basic1.sim +#./test.sh -f tsim/tmq/oneTopic.sim +#./test.sh -f tsim/tmq/multiTopic.sim # --- stable ./test.sh -f tsim/stable/disk.sim @@ -48,4 +53,10 @@ ./test.sh -f tsim/stable/values.sim ./test.sh -f tsim/stable/vnode3.sim + +# --- for multi process mode +./test.sh -f tsim/user/basic1.sim -m +./test.sh -f tsim/stable/vnode3.sim -m +./test.sh -f tsim/tmq/basic.sim -m + #======================b1-end=============== diff --git a/tests/script/runAllSimCases.sh b/tests/script/runAllSimCases.sh new file mode 100755 index 0000000000..e1eea1cc38 --- /dev/null +++ b/tests/script/runAllSimCases.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +################################################## +# +# Do simulation test +# +################################################## + +set -e +#set -x + +while read line +do + firstChar=`echo ${line:0:1}` + if [[ -n "$line" ]] && [[ $firstChar != "#" ]]; then + echo "======== $line ========" + $line + fi +done < ./jenkins/basic.txt + + diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 1bbfccf989..38b6d9aadb 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -5,18 +5,12 @@ set +e echo "Executing deploy.sh" -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 +MULTIPROCESS=0 +while getopts "n:i:m" arg do case $arg in n) @@ -25,6 +19,9 @@ do i) NODE=$OPTARG ;; + m) + MULTIPROCESS=1 + ;; ?) echo "unkonw argument" ;; @@ -145,5 +142,5 @@ echo "statusInterval 1" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG echo "telemetryReporting 0" >> $TAOS_CFG -echo "multiProcess 0" >> $TAOS_CFG +echo "multiProcess ${MULTIPROCESS}" >> $TAOS_CFG echo " " >> $TAOS_CFG diff --git a/tests/script/test.sh b/tests/script/test.sh index f89b9fb1a2..8b77575e18 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -7,7 +7,6 @@ ################################################## set +e -#set -x FILE_NAME= RELEASE=0 @@ -16,7 +15,8 @@ VALGRIND=0 UNIQUE=0 UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` -while getopts "f:avu" arg +MULTIPROCESS=0 +while getopts "f:avum" arg do case $arg in f) @@ -28,6 +28,9 @@ do u) UNIQUE=1 ;; + m) + MULTIPROCESS=1 + ;; ?) echo "unknow argument" ;; @@ -125,8 +128,13 @@ if [ -n "$FILE_NAME" ]; then echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME else - echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME - $PROGRAM -c $CFG_DIR -f $FILE_NAME + if [[ $MULTIPROCESS -eq 1 ]];then + echo "ExcuteCmd(multiprocess):" $PROGRAM -m -c $CFG_DIR -f $FILE_NAME + $PROGRAM -m -c $CFG_DIR -f $FILE_NAME + else + echo "ExcuteCmd(singleprocess):" $PROGRAM -c $CFG_DIR -f $FILE_NAME + $PROGRAM -c $CFG_DIR -f $FILE_NAME + fi fi else echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim diff --git a/tests/script/tsim/db/alter_option.sim b/tests/script/tsim/db/alter_option.sim index 5c2848883b..f79bf88ad2 100644 --- a/tests/script/tsim/db/alter_option.sim +++ b/tests/script/tsim/db/alter_option.sim @@ -59,24 +59,14 @@ endi print ============= create database #database_option: { # BLOCKS value [3~1000, default: 6] -# | CACHE value [default: 16M] # | CACHELAST value [0, 1, 2, 3] -# | COMP [0 | 1 | 2] -# | DAYS value [unit is minutes] # | FSYNC value [0 ~ 180000 ms] -# | MAXROWS value [default: 4096] -# | MINROWS value [default: 100] # | KEEP value [days, 365000] -# | PRECISION ['ms' | 'us' | 'ns'] # | QUORUM value [1 | 2] # | REPLICA value [1 | 3] -# | TTL value [unit is day, min=1] # | WAL value [1 | 2] -# | VGROUPS value [default: 2] -# | SINGLE_STABLE [0 | 1] -# | STREAM_MODE [0 | 1] -sql create database db BLOCKS 7 CACHE 3 CACHELAST 3 COMP 0 DAYS 240 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1000 PRECISION 'ns' QUORUM 1 REPLICA 3 TTL 7 WAL 2 VGROUPS 6 SINGLE_STABLE 1 STREAM_MODE 1 +sql create database db BLOCKS 7 CACHE 3 CACHELAST 3 COMP 0 DAYS 345600 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1440000 PRECISION 'ns' QUORUM 1 REPLICA 3 TTL 7 WAL 2 VGROUPS 6 SINGLE_STABLE 1 STREAM_MODE 1 sql show databases print rows: $rows print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 @@ -102,10 +92,10 @@ endi if $data5_db != 1 then # quorum return -1 endi -if $data6_db != 240 then # days +if $data6_db != 345600 then # days return -1 endi -if $data7_db != 1000,1000,1000 then # keep +if $data7_db != 1440000,1440000,1440000 then # keep return -1 endi if $data8_db != 3 then # cache @@ -148,7 +138,7 @@ sql_error alter database db ntables 0 sql_error alter database db ntables 1 sql_error alter database db ntables 10 -#print ============== modify replica +#print ============== modify replica # TD-14409 sql_error alter database db replica 2 sql_error alter database db replica 5 sql_error alter database db replica -1 @@ -187,28 +177,16 @@ sql_error alter database db quorum 4 sql_error alter database db quorum 5 #print ============== modify days -#sql alter database db days 480 -#sql show databases -#print days $data6_db -#if $data6_db != 480 then # days -# return -1 -#endi -#sql alter database db days 360 -#sql show databases -#print days $data6_db -#if $data6_db != 360 then # days -# return -1 -#endi - +sql_error alter database db days 480 +sql_error alter database db days 360 sql_error alter database db days 0 -#sql_error alter database db days 14400 # set over than keep - +sql_error alter database db days 14400 # set over than keep print ============== modify keep sql alter database db keep 2000 sql show databases print keep $data7_db -if $data7_db != 1000,1000,2000 then +if $data7_db != 2000,2000,2000 then return -1 endi @@ -230,25 +208,14 @@ sql_error alter database db keep -1 #sql_error alter database db keep 365001 print ============== modify cache -#sql alter database db cache 12 -#sql show databases -#print cache $data8_db -#if $data8_db != 12 then -# return -1 -#endi -#sql alter database db cache 1 -#sql show databases -#print cache $data8_db -#if $data8_db != 6 then -# return -1 -#endi -# -#sql_error alter database db cache 60 -#sql_error alter database db cache 50 -#sql_error alter database db cache 20 -#sql_error alter database db cache 3 -#sql_error alter database db cache 129 -#sql_error alter database db cache 300 +sql_error alter database db cache 12 +sql_error alter database db cache 1 +sql_error alter database db cache 60 +sql_error alter database db cache 50 +sql_error alter database db cache 20 +sql_error alter database db cache 3 +sql_error alter database db cache 129 +sql_error alter database db cache 300 sql_error alter database db cache 0 sql_error alter database db cache -1 @@ -276,45 +243,18 @@ sql_error alter database db blocks 0 sql_error alter database db blocks -1 sql_error alter database db blocks 10001 -#print ============== modify minrows -#sql alter database db minrows 8 -#sql show databases -#print minrows $data10_db -#if $data10_db != 8 then -# return -1 -#endi -#sql alter database db minrows 200 -#sql show databases -#print minrows $data10_db -#if $data10_db != 200 then -# return -1 -#endi -# -#sql alter database db minrows 11 -#sql show databases -#print minrows $data10_db -#if $data10_db != 11 then -# return -1 -#endi -#sql_error alter database db minrows 8000 -#sql_error alter database db minrows 8001 +print ============== modify minrows +sql_error alter database db minrows 8 +sql_error alter database db minrows 200 +sql_error alter database db minrows 11 +sql_error alter database db minrows 8000 +sql_error alter database db minrows 8001 -#print ============== modify maxrows -#sql alter database db maxrows 1000 -#sql show databases -#print maxrows $data11_db -#if $data11_db != 1000 then -# return -1 -#endi -#sql alter database db maxrows 2000 -#sql show databases -#print maxrows $data11_db -#if $data11_db != 2000 then -# return -1 -#endi -# -#sql_error alter database db maxrows 11 # equal minrows -#sql_error alter database db maxrows 10 # little than minrows +print ============== modify maxrows +sql_error alter database db maxrows 1000 +sql_error alter database db maxrows 2000 +sql_error alter database db maxrows 11 # equal minrows +sql_error alter database db maxrows 10 # little than minrows print ============== step wal sql alter database db wal 1 @@ -330,7 +270,7 @@ if $data12_db != 2 then return -1 endi -sql_error alter database db wal 0 +sql_error alter database db wal 0 # TD-14436 sql_error alter database db wal 3 sql_error alter database db wal 100 sql_error alter database db wal -1 @@ -348,35 +288,20 @@ print fsync $data13_db if $data13_db != 500 then return -1 endi -sql_error alter database db fsync 0 +sql alter database db fsync 0 +sql show databases +print fsync $data13_db +if $data13_db != 0 then + return -1 +endi +sql_error alter database db fsync 180001 sql_error alter database db fsync -1 print ============== modify comp -sql alter database db comp 1 -sql show databases -print comp $data14_db -if $data14_db != 1 then - return -1 -endi -sql alter database db comp 2 -sql show databases -print comp $data14_db -if $data14_db != 2 then - return -1 -endi -sql alter database db comp 1 -sql show databases -print comp $data14_db -if $data14_db != 1 then - return -1 -endi -sql alter database db comp 0 -sql show databases -print comp $data14_db -if $data14_db != 0 then - return -1 -endi - +sql_error alter database db comp 1 +sql_error alter database db comp 2 +sql_error alter database db comp 1 +sql_error alter database db comp 0 sql_error alter database db comp 3 sql_error alter database db comp 4 sql_error alter database db comp 5 @@ -414,30 +339,15 @@ if $data15_db != 3 then return -1 endi -sql_error alter database db comp 4 -sql_error alter database db comp 10 -sql_error alter database db comp -1 +sql_error alter database db cachelast 4 +sql_error alter database db cachelast 10 +sql_error alter database db cachelast -1 print ============== modify precision -sql alter database db precision 'ms' -sql show databases -print precision $data16_db -if $data16_db != ms then - return -1 -endi -sql alter database db precision 'us' -sql show databases -print precision $data16_db -if $data16_db != us then - return -1 -endi -sql alter database db precision 'ns' -sql show databases -print precision $data16_db -if $data16_db != ns then - return -1 -endi - +sql_error alter database db precision 'ms' +sql_error alter database db precision 'us' +sql_error alter database db precision 'ns' +sql_error alter database db precision 'ys' sql_error alter database db prec 'xs' #system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/db/basic6.sim b/tests/script/tsim/db/basic6.sim index 7e57fe8f1b..a768a0da38 100644 --- a/tests/script/tsim/db/basic6.sim +++ b/tests/script/tsim/db/basic6.sim @@ -15,7 +15,7 @@ $tb = $tbPrefix . $i print =============== step1 # quorum presicion -sql create database $db vgroups 8 replica 1 days 20 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us' +sql create database $db vgroups 8 replica 1 days 2880 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us' sql show databases print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 @@ -35,7 +35,7 @@ endi if $data04 != 1 then return -1 endi -if $data06 != 20 then +if $data06 != 2880 then return -1 endi if $data07 != 3650,3650,3650 then @@ -67,7 +67,7 @@ print =============== step4 sql_error drop database $db print =============== step5 -sql create database $db replica 1 days 15 keep 1500 +sql create database $db replica 1 days 21600 keep 2160000 sql show databases print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 if $data00 != $db then @@ -79,7 +79,7 @@ endi if $data04 != 1 then return -1 endi -if $data06 != 15 then +if $data06 != 21600 then return -1 endi diff --git a/tests/script/tsim/db/create_all_options.sim b/tests/script/tsim/db/create_all_options.sim new file mode 100644 index 0000000000..7f39474f4d --- /dev/null +++ b/tests/script/tsim/db/create_all_options.sim @@ -0,0 +1,486 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 + +$loop_cnt = 0 +check_dnode_ready_1: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> rows: $rows +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 +if $data00 != 1 then + return -1 +endi +if $data01 != localhost:7100 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_1 +endi +if $data14 != ready then + goto check_dnode_ready_1 +endi +if $data24 != ready then + goto check_dnode_ready_1 +endi + +print ============= create database with all options +#database_option: { +# | BLOCKS value [3~1000, default: 6] +# | CACHE value [default: 16] +# | CACHELAST value [0, 1, 2, 3, default: 0] +# | COMP [0 | 1 | 2, default: 2] +# | DAYS value [60m ~ min(3650d,keep), default: 10d, unit may be minut/hour/day] +# | FSYNC value [0 ~ 180000 ms, default: 3000] +# | MAXROWS value [200~10000, default: 4096] +# | MINROWS value [10~1000, default: 100] +# | KEEP value [max(1d ~ 365000d), default: 1d, unit may be minut/hour/day] +# | PRECISION ['ms' | 'us' | 'ns', default: ms] +# | QUORUM value [1 | 2, default: 1] +# | REPLICA value [1 | 3, default: 1] +# | TTL value [1d ~ , default: 1] +# | WAL value [1 | 2, default: 1] +# | VGROUPS value [default: 2] +# | SINGLE_STABLE [0 | 1, default: ] +# | STREAM_MODE [0 | 1, default: ] +# +#$data0_db : name +#$data1_db : create_time +#$data2_db : vgroups +#$data3_db : ntables +#$data4_db : replica +#$data5_db : quorum +#$data6_db : days +#$data7_db : keep +#$data8_db : cache +#$data9_db : blocks +#$data10_db : minrows +#$data11_db : maxrows +#$data12_db : wal +#$data13_db : fsync +#$data14_db : comp +#$data15_db : cachelast +#$data16_db : precision + +print ====> create database db, with default +sql create database db +sql show databases +print rows: $rows +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $rows != 2 then + return -1 +endi +if $data0_db != db then # name + return -1 +endi +if $data2_db != 2 then # vgroups + return -1 +endi +if $data3_db != 0 then # ntables + return -1 +endi +if $data4_db != 1 then # replica + return -1 +endi +if $data5_db != 1 then # quorum + return -1 +endi +if $data6_db != 14400 then # days + return -1 +endi +if $data7_db != 5256000,5256000,5256000 then # keep + return -1 +endi +if $data8_db != 16 then # cache + return -1 +endi +if $data9_db != 6 then # blocks + return -1 +endi +if $data10_db != 100 then # minrows + return -1 +endi +if $data11_db != 4096 then # maxrows + return -1 +endi +if $data12_db != 1 then # wal + return -1 +endi +if $data13_db != 3000 then # fsync + return -1 +endi +if $data14_db != 2 then # comp + return -1 +endi +if $data15_db != 0 then # cachelast + return -1 +endi +if $data16_db != ms then # precision + return -1 +endi +sql drop database db + +print ====> BLOCKS value [3~1000, default: 6] +sql create database db BLOCKS 3 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data9_db != 3 then + return -1 +endi +sql drop database db + +sql create database db BLOCKS 1000 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data9_db != 1000 then + return -1 +endi +sql drop database db +sql_error create database db BLOCKS 2 +sql_error create database db BLOCKS 0 +sql_error create database db BLOCKS -1 + +print ====> CACHE value [default: 16] +sql create database db CACHE 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data8_db != 1 then + return -1 +endi +sql drop database db + +sql create database db CACHE 128 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data8_db != 128 then + return -1 +endi +sql drop database db + +print ====> CACHELAST value [0, 1, 2, 3, default: 0] +sql create database db CACHELAST 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data15_db != 1 then + return -1 +endi +sql drop database db + +sql create database db CACHELAST 2 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data15_db != 2 then + return -1 +endi +sql drop database db + +sql create database db CACHELAST 3 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data15_db != 3 then + return -1 +endi +sql drop database db +sql_error create database db CACHELAST 4 +sql_error create database db CACHELAST -1 + +print ====> COMP [0 | 1 | 2, default: 2] +sql create database db COMP 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data14_db != 1 then + return -1 +endi +sql drop database db + +sql create database db COMP 0 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data14_db != 0 then + return -1 +endi +sql drop database db +sql_error create database db COMP 3 +sql_error create database db COMP -1 + +#print ====> DAYS value [60m ~ min(3650d,keep), default: 10d, unit may be minut/hour/day] +#print ====> KEEP value [max(1d ~ 365000d), default: 1d, unit may be minut/hour/day] +#sql create database db DAYS 60m KEEP 60m +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data6_db != 60 then +# return -1 +#endi +#if $data7_db != 60,60,60 then +# return -1 +#endi +#sql drop database db +#sql create database db DAYS 60m KEEP 1d +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data6_db != 60 then +# return -1 +#endi +#if $data7_db != 1440,1440,1440 then +# return -1 +#endi +#sql create database db DAYS 3650d KEEP 365000d +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data6_db != 5256000 then +# return -1 +#endi +#if $data7_db != 525600000,525600000,525600000 then +# return -1 +#endi +#sql drop database db +#sql_error create database db DAYS -59m +#sql_error create database db DAYS 59m +#sql_error create database db DAYS 5256001m +#sql_error create database db DAYS 3651d +#sql_error create database db KEEP -59m +#sql_error create database db KEEP 14399m +#sql_error create database db KEEP 525600001m +#sql_error create database db KEEP 365001d + +print ====> FSYNC value [0 ~ 180000 ms, default: 3000] +sql create database db FSYNC 0 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data13_db != 0 then + return -1 +endi +sql drop database db + +sql create database db FSYNC 180000 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data13_db != 180000 then + return -1 +endi +sql drop database db +sql_error create database db FSYNC 180001 +sql_error create database db FSYNC -1 + +print ====> MAXROWS value [200~10000, default: 4096], MINROWS value [10~1000, default: 100] +sql create database db MAXROWS 10000 MINROWS 1000 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data10_db != 1000 then + return -1 +endi +if $data11_db != 10000 then + return -1 +endi +sql drop database db + +sql create database db MAXROWS 200 MINROWS 10 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data10_db != 10 then + return -1 +endi +if $data11_db != 200 then + return -1 +endi +sql drop database db +sql_error create database db MAXROWS -1 +sql_error create database db MAXROWS 0 +sql_error create database db MAXROWS 199 +sql_error create database db MAXROWS 10001 +sql_error create database db MINROWS -1 +sql_error create database db MINROWS 0 +sql_error create database db MINROWS 9 +sql_error create database db MINROWS 1001 +sql_error create database db MAXROWS 500 MINROWS 1000 + +print ====> PRECISION ['ms' | 'us' | 'ns', default: ms] +sql create database db PRECISION 'us' +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data16_db != us then + return -1 +endi +sql drop database db + +sql create database db PRECISION 'ns' +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data16_db != ns then + return -1 +endi +sql drop database db +sql_error create database db PRECISION 'as' +sql_error create database db PRECISION -1 + +print ====> QUORUM value [1 | 2, default: 1] +#sql create database db QUORUM 2 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data5_db != 2 then +# return -1 +#endi +#sql drop database db + +sql create database db QUORUM 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data5_db != 1 then + return -1 +endi +sql drop database db +sql_error create database db QUORUM 3 +sql_error create database db QUORUM 0 +sql_error create database db QUORUM -1 + +print ====> REPLICA value [1 | 3, default: 1] +sql create database db REPLICA 3 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data4_db != 3 then + return -1 +endi +sql drop database db + +sql create database db REPLICA 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data4_db != 1 then + return -1 +endi +sql drop database db +sql_error create database db REPLICA 2 +sql_error create database db REPLICA 0 +sql_error create database db REPLICA -1 +sql_error create database db REPLICA 4 + +print ====> TTL value [1d ~ , default: 1] +sql create database db TTL 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $dataXX_db != 1 then +# return -1 +#endi +sql drop database db + +sql create database db TTL 10 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $dataXX_db != 10 then +# return -1 +#endi +sql drop database db +sql_error create database db TTL 0 +sql_error create database db TTL -1 + +print ====> WAL value [1 | 2, default: 1] +sql create database db WAL 2 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data12_db != 2 then + return -1 +endi +sql drop database db + +sql create database db WAL 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data12_db != 1 then + return -1 +endi +sql drop database db +sql_error create database db WAL 3 +sql_error create database db WAL -1 +sql_error create database db WAL 0 + +print ====> VGROUPS value [1~4096, default: 2] +sql create database db VGROUPS 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data2_db != 1 then + return -1 +endi +sql drop database db + +sql create database db VGROUPS 16 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +if $data2_db != 16 then + return -1 +endi +sql drop database db +sql_error create database db VGROUPS 4097 +sql_error create database db VGROUPS -1 +sql_error create database db VGROUPS 0 + +print ====> SINGLE_STABLE [0 | 1, default: ] +sql create database db SINGLE_STABLE 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $dataXXXX_db != 1 then +# return -1 +#endi +sql drop database db + +sql create database db SINGLE_STABLE 0 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $dataXXXX_db != 0 then +# return -1 +#endi +sql drop database db +sql_error create database db SINGLE_STABLE 2 +sql_error create database db SINGLE_STABLE -1 + +print ====> STREAM_MODE [0 | 1, default: ] +sql create database db STREAM_MODE 1 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $dataXXX_db != 1 then +# return -1 +#endi +sql drop database db + +sql create database db STREAM_MODE 0 +sql show databases +print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $dataXXX_db != 0 then +# return -1 +#endi +sql drop database db +sql_error create database db STREAM_MODE 2 +sql_error create database db STREAM_MODE -1 + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/parser/fourArithmetic-basic.sim b/tests/script/tsim/parser/fourArithmetic-basic.sim index 2ade01522e..bb35df5a90 100644 --- a/tests/script/tsim/parser/fourArithmetic-basic.sim +++ b/tests/script/tsim/parser/fourArithmetic-basic.sim @@ -78,6 +78,10 @@ while $i < $tbNum $tstart = 1640966400000 endw + +$loop_test = 0 +loop_test_pos: + sql select ts, c2-c1, c3/c1, c4+c1, c1*9, c1%3 from ct0 print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 @@ -107,4 +111,31 @@ endi if $data93 != 8.000000000 then return -1 endi + +if $loop_test == 0 then + print =============== stop and restart taosd + system sh/exec.sh -n dnode1 -s stop -x SIGINT + system sh/exec.sh -n dnode1 -s start + + $loop_cnt = 0 + check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + sql show dnodes + print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 + if $data00 != 1 then + return -1 + endi + if $data04 != ready then + goto check_dnode_ready_0 + endi + + $loop_test = 1 + goto loop_test_pos +endi + #system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/parser/groupby-basic.sim b/tests/script/tsim/parser/groupby-basic.sim index c0cbfa8aeb..f073200a05 100644 --- a/tests/script/tsim/parser/groupby-basic.sim +++ b/tests/script/tsim/parser/groupby-basic.sim @@ -45,7 +45,7 @@ $tstart = 1640966400000 # 2022-01-01 00:00:00.000 print ==== create db, stable, ctables, insert data sql drop database if exists $db -x step1 step1: -sql create database if not exists $db keep 3650 +sql create database if not exists $db sql use $db sql create table $mt (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(12)) @@ -112,25 +112,26 @@ print $data90 $data91 $data92 $data93 if $rows != 10 then return -1 endi -#if $data00 != 10 then -# return -1 -#endi +if $data00 != 10 then + return -1 +endi if $data01 != 0 then return -1 endi -#if $data10 != 10 then -# return -1 -#endi +if $data10 != 10 then + return -1 +endi if $data11 != 1 then return -1 endi -#if $data90 != 10 then -# return -1 -#endi +if $data90 != 10 then + return -1 +endi if $data91 != 9 then return -1 endi +print ==== select first(ts),c1 from group_tb0 group by c1; sql select first(ts),c1 from group_tb0 group by c1; print rows: $rows print $data00 $data01 $data02 $data03 @@ -142,19 +143,29 @@ if $row != 10 then return -1 endi -if $data00 != @2022-01-01 00:00:00.000@ then +if $data00 != @22-01-01 00:00:00.000@ then return -1 endi if $data01 != 0 then return -1 endi -if $data90 != @2022-01-01 00:00:00.009@ then +if $data90 != @22-01-01 00:00:00.009@ then return -1 endi if $data91 != 9 then return -1 endi +print ==== select first(ts),c1 from interval(5m) group_tb0 group by c1; +sql select first(ts),c1 from group_tb0 group by c1; +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +print $data20 $data21 $data22 $data23 +print $data80 $data81 $data82 $data83 +print $data90 $data91 $data92 $data93 + +return sql select sum(c1), c1, avg(c1), min(c1), max(c2) from group_tb0 where c1 < 20 group by c1; if $row != 20 then diff --git a/tests/script/tsim/query/interval-offset.sim b/tests/script/tsim/query/interval-offset.sim index 4c4ebc6670..616ece99e0 100644 --- a/tests/script/tsim/query/interval-offset.sim +++ b/tests/script/tsim/query/interval-offset.sim @@ -7,7 +7,7 @@ sql connect print =============== create database sql create database d0 sql show databases -if $rows != 2 then +if $rows != 2 then return -1 endi @@ -17,7 +17,7 @@ print =============== create super table and child table sql create table stb (ts timestamp, tbcol int) tags (t1 int) sql show stables print $rows $data00 $data01 $data02 -if $rows != 1 then +if $rows != 1 then return -1 endi @@ -29,7 +29,7 @@ sql show tables print $rows $data00 $data10 $data20 if $rows != 4 then return -1 -endi +endi print =============== insert data into child table ct1 (s) sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1 ) @@ -73,41 +73,47 @@ sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8 ) sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9 ) print ================ start query ====================== -sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s) -print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s) +sql select _wstartts, _wendts, _wduration, _qstartts, _qendts, count(*) from ct1 interval(10s, 2s) +print ===> select _wstartts, _wendts, _wduration, _qstartts, _qendts, count(*) from ct1 interval(10s, 2s) print ===> rows: $rows -print ===> rows0: $data00 $data01 $data02 $data03 $data04 -print ===> rows1: $data10 $data11 $data12 $data13 $data14 -print ===> rows2: $data20 $data21 $data22 $data23 $data24 -print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 +print ===> rows0: $data00 $data01 $data02 $data05 +print ===> rows1: $data10 $data11 $data12 $data15 +print ===> rows2: $data20 $data21 $data22 $data25 +print ===> rows3: $data30 $data31 $data32 $data35 +print ===> rows4: $data40 $data41 $data42 $data45 if $rows != 5 then return -1 -endi -if $data00 != 1 then +endi +if $data00 != @22-01-01 01:00:52.000@ then return -1 -endi -if $data40 != 1 then +endi +if $data02 != 10000 then return -1 -endi +endi +if $data45 != 1 then + return -1 +endi -sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s) sliding(10s) -print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s) sliding(10s) +sql select _wstartts, _wendts, _wduration, _qstartts, _qendts, count(*) from ct1 interval(10s, 2s) sliding(10s) +print ===> select _wstartts, _wendts, _wduration, _qstartts, _qendts, count(*) from ct1 interval(10s, 2s) sliding(10s) print ===> rows: $rows -print ===> rows0: $data00 $data01 $data02 $data03 $data04 -print ===> rows1: $data10 $data11 $data12 $data13 $data14 -print ===> rows2: $data20 $data21 $data22 $data23 $data24 -print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 +print ===> rows0: $data00 $data01 $data02 $data05 +print ===> rows1: $data10 $data11 $data12 $data15 +print ===> rows2: $data20 $data21 $data22 $data25 +print ===> rows3: $data30 $data31 $data32 $data35 +print ===> rows4: $data40 $data41 $data42 $data45 if $rows != 5 then return -1 -endi -if $data00 != 1 then +endi +if $data00 != @22-01-01 01:00:52.000@ then return -1 -endi -if $data40 != 1 then +endi +if $data02 != 10000 then return -1 -endi +endi +if $data45 != 1 then + return -1 +endi sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s) sliding(5s) print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s) sliding(5s) @@ -123,16 +129,16 @@ print ===> rows7: $data70 $data71 $data72 $data73 $data74 print ===> rows8: $data80 $data81 $data82 $data83 $data84 if $rows != 9 then return -1 -endi +endi if $data00 != 1 then return -1 -endi +endi if $data70 != 2 then return -1 -endi +endi if $data80 != 1 then return -1 -endi +endi sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct2 interval(1d, 2h) print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct2 interval(1d, 2h) @@ -144,10 +150,10 @@ print ===> rows3: $data30 $data31 $data32 $data33 $data34 print ===> rows4: $data40 $data41 $data42 $data43 $data44 if $rows != 4 then return -1 -endi +endi if $data00 != 1 then return -1 -endi +endi if $data10 != 2 then return -1 endi @@ -155,101 +161,102 @@ endi sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct2 interval(1d, 2h) sliding(12h) print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct2 interval(1d, 2h) sliding(12h) print ===> rows: $rows -print ===> rows0: $data00 $data01 $data02 $data03 $data04 $data05 -print ===> rows1: $data10 $data11 $data12 $data13 $data14 $data15 -print ===> rows2: $data20 $data21 $data22 $data23 $data24 $data25 -print ===> rows3: $data30 $data31 $data32 $data33 $data34 $data35 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 $data45 -print ===> rows5: $data50 $data51 $data52 $data53 $data54 $data55 -print ===> rows6: $data60 $data61 $data62 $data63 $data64 $data65 -print ===> rows7: $data70 $data71 $data72 $data73 $data74 $data75 +print ===> rows0: $data00 $data01 $data02 $data03 $data04 $data05 +print ===> rows1: $data10 $data11 $data12 $data13 $data14 $data15 +print ===> rows2: $data20 $data21 $data22 $data23 $data24 $data25 +print ===> rows3: $data30 $data31 $data32 $data33 $data34 $data35 +print ===> rows4: $data40 $data41 $data42 $data43 $data44 $data45 +print ===> rows5: $data50 $data51 $data52 $data53 $data54 $data55 +print ===> rows6: $data60 $data61 $data62 $data63 $data64 $data65 +print ===> rows7: $data70 $data71 $data72 $data73 $data74 $data75 if $rows != 8 then return -1 -endi +endi if $data00 != 1 then return -1 -endi +endi if $data10 != 2 then return -1 -endi +endi if $data70 != 1 then return -1 endi - -sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct3 interval(1n, 1w) + +sql select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct3 interval(1n, 1w) print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct3 interval(1n, 1w) print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 -#if $rows != 5 then -# return -1 -#endi -#if $data00 != 1 then -# return -1 -#endi -#if $data40 != 1 then -# return -1 -#endi +if $rows != 4 then + return -1 +endi +if $data00 != @21-12-08 00:00:00.000@ then + return -1 +endi +if $data31 != 1 then + return -1 +endi +if $data34 != $data31 then + return -1 +endi +if $data02 != 2678400000 then + return -1 +endi -sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct3 interval(1n, 1w) sliding(2w) +sql select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct3 interval(1n, 1w) sliding(2w) print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct3 interval(1n, 1w) sliding(2w) print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 -#if $rows != 5 then -# return -1 -#endi -#if $data00 != 1 then -# return -1 -#endi -#if $data40 != 1 then -# return -1 -#endi +if $rows != 4 then + return -1 +endi +if $data00 != @21-11-30 08:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data31 != $data34 then + return -1 +endi -sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct3 interval(1n, 1w) sliding(4w) -print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct3 interval(1n, 1w) sliding(4w) +sql select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct3 interval(1n, 1w) sliding(4w) +print ===> select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct3 interval(1n, 1w) sliding(4w) print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 -print ===> rows5: $data50 $data51 $data52 $data53 $data54 -print ===> rows6: $data60 $data61 $data62 $data63 $data64 -print ===> rows7: $data70 $data71 $data72 $data73 $data74 -#if $rows != 8 then -# return -1 -#endi -#if $data00 != 2 then -# return -1 -#endi -#if $data70 != 1 then -# return -1 -#endi +if $rows != 4 then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data04 != 1 then + return -1 +endi -sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct4 interval(1y, 6n) -print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct4 interval(1y, 6n) +sql select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct4 interval(1y, 6n) +print ===> select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct4 interval(1y, 6n) print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 -print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 -#if $rows != 5 then -# return -1 -#endi -#if $data00 != 1 then -# return -1 -#endi -#if $data40 != 1 then -# return -1 -#endi +if $rows != 3 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data04 != 2 then + return -1 +endi sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct4 interval(1y, 6n) sliding(6n) print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct4 interval(1y, 6n) sliding(6n) @@ -257,38 +264,31 @@ print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 -print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 -#if $rows != 5 then -# return -1 -#endi -#if $data00 != 1 then -# return -1 -#endi -#if $data40 != 1 then -# return -1 -#endi +if $rows != 3 then + return -1 +endi +if $data00 != 2 then + return -1 +endi +if $data04 != 2 then + return -1 +endi -sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct4 interval(1y, 6n) sliding(12n) -print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct4 interval(1y, 6n) sliding(12n) +sql select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct4 interval(1y, 6n) sliding(12n) +print ===> select _wstartts, count(tbcol), _wduration, _wstartts, count(*) from ct4 interval(1y, 6n) sliding(12n) print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 -print ===> rows3: $data30 $data31 $data32 $data33 $data34 -print ===> rows4: $data40 $data41 $data42 $data43 $data44 -print ===> rows5: $data50 $data51 $data52 $data53 $data54 -print ===> rows6: $data60 $data61 $data62 $data63 $data64 -print ===> rows7: $data70 $data71 $data72 $data73 $data74 -#if $rows != 8 then -# return -1 -#endi -#if $data00 != 2 then -# return -1 -#endi -#if $data70 != 1 then -# return -1 -#endi +if $rows != 3 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data04 != 2 then + return -1 +endi #================================================= print =============== stop and restart taosd @@ -322,9 +322,4 @@ endi #sql select count(*) from car where ts > '2019-05-14 00:00:00' interval(1y, 5d) - - - - - #system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/interval.sim b/tests/script/tsim/query/interval.sim index 6dd0a9537e..384008c887 100644 --- a/tests/script/tsim/query/interval.sim +++ b/tests/script/tsim/query/interval.sim @@ -29,18 +29,18 @@ $i = 0 while $i < $tbNum $tb = $tbPrefix . $i sql create table $tb using $mt tags( $i ) - + $x = 0 while $x < $rowNum $cc = $x * 60000 $ms = 1601481600000 + $cc - sql insert into $tb values ($ms , $x ) + sql insert into $tb values ($ms , $x ) $x = $x + 1 - endw - + endw + $i = $i + 1 -endw +endw print =============== step2 $i = 1 @@ -49,51 +49,51 @@ $tb = $tbPrefix . $i sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m) print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m) print ===> $rows $data01 $data05 -if $rows != $rowNum then +if $rows != $rowNum then return -1 endi -if $data00 != 1 then +if $data00 != 1 then return -1 endi -if $data04 != 1 then +if $data04 != 1 then return -1 endi -#print =============== step3 +print =============== step3 #$cc = 4 * 60000 #$ms = 1601481600000 + $cc #sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms interval(1m) #print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms interval(1m) #print ===> $rows $data01 $data05 -#if $rows != 5 then +#if $rows != 5 then # return -1 #endi -#if $data00 != 1 then +#if $data00 != 1 then # return -1 #endi -#if $data04 != 1 then +#if $data04 != 1 then # return -1 #endi -#print =============== step4 +print =============== step4 #$cc = 40 * 60000 #$ms = 1601481600000 + $cc #$cc = 1 * 60000 #$ms2 = 1601481600000 - $cc -#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) -#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) -#print ===> $rows $data01 $data05 -#if $rows != 20 then -# return -1 -#endi -#if $data00 != 1 then -# return -1 -#endi -#if $data04 != 1 then -# return -1 -#endi +sql select _wstartts, _wendts, _wduration, _qstartts, _qendts, count(tbcol) from $tb interval(1m) +print ===> select _wstartts, _wendts, _wduration, _qstartts, _qendts, count(tbcol) from $tb interval(1m) +print ===> $rows $data01 $data05 +if $rows != $rowNum then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data02 != 60000 then + return -1 +endi #print =============== step5 #$cc = 40 * 60000 @@ -105,13 +105,13 @@ endi #sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) fill(value,0) #print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) fill(value,0) #print ===> $rows $data21 $data25 -#if $rows != 42 then +#if $rows != 42 then # return -1 #endi -#if $data20 != 1 then +#if $data20 != 1 then # return -1 #endi -#if $data24 != 1 then +#if $data24 != 1 then # return -1 #endi @@ -119,10 +119,10 @@ endi #sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m) #print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m) #print ===> $rows $data11 -#if $rows != 20 then +#if $rows != 20 then # return -1 #endi -#if $data11 != 10 then +#if $data11 != 10 then # return -1 #endi @@ -132,10 +132,10 @@ endi #sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms interval(1m) #print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms interval(1m) #print ===> $rows $data11 -#if $rows != 5 then +#if $rows != 5 then # return -1 #endi -#if $data11 != 10 then +#if $data11 != 10 then # return -1 #endi @@ -149,10 +149,10 @@ endi #sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) #print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) #print ===> $rows $data11 -#if $rows != 20 then +#if $rows != 20 then # return -1 #endi -#if $data11 != 10 then +#if $data11 != 10 then # return -1 #endi # @@ -166,18 +166,18 @@ endi #sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0) #print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0) #print ===> $rows $data11 -#if $rows != 42 then +#if $rows != 42 then # return -1 #endi -#if $data11 != 10 then +#if $data11 != 10 then # return -1 #endi print =============== clear #sql drop database $db #sql show databases -#if $rows != 0 then +#if $rows != 0 then # return -1 #endi -#system sh/exec.sh -n dnode1 -s stop -x SIGINT +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/scalarFunction.sim b/tests/script/tsim/query/scalarFunction.sim index 912e3ffcd8..9e6d378bd0 100644 --- a/tests/script/tsim/query/scalarFunction.sim +++ b/tests/script/tsim/query/scalarFunction.sim @@ -37,11 +37,11 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d sql use $dbNamme print =============== create super table -sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int) +sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int) print =============== create child table $tbPrefix = ct -$tbNum = 2 +$tbNum = 100 $i = 0 while $i < $tbNum @@ -54,7 +54,7 @@ print =============== create normal table sql create table ntb (ts timestamp, c1 int, c2 float, c3 double) sql show tables -if $rows != 3 then +if $rows != 101 then return -1 endi @@ -83,6 +83,12 @@ while $i < $tbNum $tstart = 1640966400000 endw +$totalRows = $rowNum * $tbNum +print ====> totalRows of stb: $totalRows + +$loop_test = 0 +loop_test_pos: + print ====> abs sql select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ct1 print ====> select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ct1 @@ -97,11 +103,106 @@ print ====> $data60 $data61 $data62 $data63 $data64 $data65 print ====> $data70 $data71 $data72 $data73 $data74 $data75 print ====> $data80 $data81 $data82 $data83 $data84 $data85 print ====> $data90 $data91 $data92 $data93 $data94 $data95 -if $rows != 10 then +if $rows != $rowNum then + return -1 +endi +print ====> select c1, abs(c1), c2, abs(c2), c3, abs(c3) from stb +sql select c1, abs(c1), c2, abs(c2), c3, abs(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ntb +sql select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> log +sql select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ct1 +print ====> select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from stb +sql select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ntb +sql select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> pow +sql select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ct1 +print ====> select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from stb +sql select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ntb +sql select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> sqrt +sql select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ct1 +print ====> select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from stb +sql select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ntb +sql select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ntb +if $rows != $rowNum then return -1 endi print ====> sin +sql select c1, sin(c1), sin(c1) * 3.14159265 / 180 from ct1 sql select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ct1 print ====> select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ct1 print ====> rows: $rows @@ -115,7 +216,17 @@ print ====> $data60 $data61 $data62 $data63 $data64 $data65 print ====> $data70 $data71 $data72 $data73 $data74 $data75 print ====> $data80 $data81 $data82 $data83 $data84 $data85 print ====> $data90 $data91 $data92 $data93 $data94 $data95 -if $rows != 10 then +if $rows != $rowNum then + return -1 +endi +print ====> select c1, sin(c1), c2, sin(c2), c3, sin(c3) from stb +sql select c1, sin(c1), c2, sin(c2), c3, sin(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ntb +sql select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ntb +if $rows != $rowNum then return -1 endi @@ -133,8 +244,241 @@ print ====> $data60 $data61 $data62 $data63 $data64 $data65 print ====> $data70 $data71 $data72 $data73 $data74 $data75 print ====> $data80 $data81 $data82 $data83 $data84 $data85 print ====> $data90 $data91 $data92 $data93 $data94 $data95 -if $rows != 10 then +if $rows != $rowNum then + return -1 +endi +print ====> select c1, cos(c1), c2, cos(c2), c3, cos(c3) from stb +sql select c1, cos(c1), c2, cos(c2), c3, cos(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ntb +sql select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ntb +if $rows != $rowNum then return -1 endi +print ====> tan +sql select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ct1 +print ====> select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, tan(c1), c2, tan(c2), c3, tan(c3) from stb +sql select c1, tan(c1), c2, tan(c2), c3, tan(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ntb +sql select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> asin +sql select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ct1 +print ====> select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, asin(c1), c2, asin(c2), c3, asin(c3) from stb +sql select c1, asin(c1), c2, asin(c2), c3, asin(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ntb +sql select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> acos +sql select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ct1 +print ====> select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, acos(c1), c2, acos(c2), c3, acos(c3) from stb +sql select c1, acos(c1), c2, acos(c2), c3, acos(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ntb +sql select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> atan +sql select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ct1 +print ====> select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, atan(c1), c2, atan(c2), c3, atan(c3) from stb +sql select c1, atan(c1), c2, atan(c2), c3, atan(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ntb +sql select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> ceil +sql select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ct1 +print ====> select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from stb +sql select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ntb +sql select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ntb +if $rows != $rowNum then + return -1 +endi + +print ====> floor +sql select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ct1 +print ====> select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, floor(c1), c2, floor(c2), c3, floor(c3) from stb +sql select c1, floor(c1), c2, floor(c2), c3, floor(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ntb +sql select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ntb +if $rows != $rowNum then + return -1 +endi + + +print ====> round +sql select c1, round(c1), c2, round(c2), c3, round(c3) from ct1 +print ====> select c1, round(c1), c2, round(c2), c3, round(c3) from ct1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != $rowNum then + return -1 +endi +print ====> select c1, round(c1), c2, round(c2), c3, round(c3) from stb +sql select c1, round(c1), c2, round(c2), c3, round(c3) from stb +if $rows != $totalRows then + return -1 +endi +print ====> select c1, round(c1), c2, round(c2), c3, round(c3) from ntb +sql select c1, round(c1), c2, round(c2), c3, round(c3) from ntb +if $rows != $rowNum then + return -1 +endi + +if $loop_test == 0 then + print =============== stop and restart taosd + system sh/exec.sh -n dnode1 -s stop -x SIGINT + system sh/exec.sh -n dnode1 -s start + + $loop_cnt = 0 + check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + sql show dnodes + print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 + if $data00 != 1 then + return -1 + endi + if $data04 != ready then + goto check_dnode_ready_0 + endi + + $loop_test = 1 + goto loop_test_pos +endi + #system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim new file mode 100644 index 0000000000..98f63f42e3 --- /dev/null +++ b/tests/script/tsim/query/session.sim @@ -0,0 +1,338 @@ +#### session windows + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$vgroups = 4 +$dbNamme = d0 + +print ====> create database d1 precision 'us' +sql create database d1 precision 'us' +sql use d1 +sql create table dev_001 (ts timestamp ,i timestamp ,j int) +sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4) +sql create table secondts(ts timestamp,t2 timestamp,i int) +sql insert into secondts values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4) + +print ====> create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 +#print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 + +sql use $dbNamme + +print =============== create super table, child table and insert data +sql create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50), tag2 binary(16)) +sql create table if not exists dev_001 using st tags("dev_01", "tag_01") +sql create table if not exists dev_002 using st tags("dev_02", "tag_02") + +sql INSERT INTO dev_001 VALUES('2020-05-13 10:00:00.000', 1) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:00:00.005', 2) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:00:00.011', 3) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:00:01.011', 4) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:00:01.611', 5) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:00:02.612', 6) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:01:02.612', 7) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:02:02.612', 8) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:03:02.613', 9) +sql INSERT INTO dev_001 VALUES('2020-05-13 11:00:00.000', 10) +sql INSERT INTO dev_001 VALUES('2020-05-13 12:00:00.000', 11) +sql INSERT INTO dev_001 VALUES('2020-05-13 13:00:00.001', 12) +sql INSERT INTO dev_001 VALUES('2020-05-14 13:00:00.001', 13) +sql INSERT INTO dev_001 VALUES('2020-05-15 14:00:00.000', 14) +sql INSERT INTO dev_001 VALUES('2020-05-20 10:00:00.000', 15) +sql INSERT INTO dev_001 VALUES('2020-05-27 10:00:00.001', 16) + +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.000', 1) +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.005', 2) +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.009', 3) +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.0021', 4) +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.031', 5) +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.036', 6) +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.51', 7) + +$loop_test = 0 +loop_test_pos: + +# session(ts,5a) +print ====> select count(*) from dev_001 session(ts,5a) +sql select count(*) from dev_001 session(ts,5a) +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +print ====> $data40 $data41 $data42 $data43 $data44 $data45 +print ====> $data50 $data51 $data52 $data53 $data54 $data55 +print ====> $data60 $data61 $data62 $data63 $data64 $data65 +print ====> $data70 $data71 $data72 $data73 $data74 $data75 +print ====> $data80 $data81 $data82 $data83 $data84 $data85 +print ====> $data90 $data91 $data92 $data93 $data94 $data95 +if $rows != 15 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + + +print ====> select count(*) from (select * from dev_001) session(ts,5a) +sql select count(*) from (select * from dev_001) session(ts,5a) +if $rows != 15 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +print ====> select count(*) from dev_001 session(ts,1s) +sql select count(*) from dev_001 session(ts,1s) +if $rows != 12 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +print ====> select count(*) from (select * from dev_001) session(ts,1s) +sql select count(*) from (select * from dev_001) session(ts,1s) +if $rows != 12 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +print ====> select count(*) from dev_001 session(ts,1000a) +sql select count(*) from dev_001 session(ts,1000a) +if $rows != 12 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +print ====> select count(*) from (select * from dev_001) session(ts,1000a) +sql select count(*) from (select * from dev_001) session(ts,1000a) +if $rows != 12 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +print ====> select count(*) from dev_001 session(ts,1m) +sql select count(*) from dev_001 session(ts,1m) +if $rows != 9 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +print ====> select count(*) from (select * from dev_001) session(ts,1m) +sql select count(*) from (select * from dev_001) session(ts,1m) +if $rows != 9 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +print ====> select count(*) from dev_001 session(ts,1h) +sql select count(*) from dev_001 session(ts,1h) +if $rows != 6 then + return -1 +endi +if $data01 != 11 then + return -1 +endi + +print ====> select count(*) from (select * from dev_001) session(ts,1h) +sql select count(*) from (select * from dev_001) session(ts,1h) +if $rows != 6 then + return -1 +endi +if $data01 != 11 then + return -1 +endi + +print ====> select count(*) from dev_001 session(ts,1d) +sql select count(*) from dev_001 session(ts,1d) +if $rows != 4 then + return -1 +endi +if $data01 != 13 then + return -1 +endi + +print ====> select count(*) from (select * from dev_001) session(ts,1d) +sql select count(*) from (select * from dev_001) session(ts,1d) +if $rows != 4 then + return -1 +endi +if $data01 != 13 then + return -1 +endi + +print ====> select count(*) from dev_001 session(ts,1w) +sql select count(*) from dev_001 session(ts,1w) +if $rows != 2 then + return -1 +endi +if $data01 != 15 then + return -1 +endi + +print ====> select count(*) from (select * from dev_001) session(ts,1w) +sql select count(*) from (select * from dev_001) session(ts,1w) +if $rows != 2 then + return -1 +endi +if $data01 != 15 then + return -1 +endi + +print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) +sql select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) +if $rows != 2 then + return -1 +endi +if $data01 != 13 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 13 then + return -1 +endi +if $data04 != 7 then + return -1 +endi +if $data05 != 91 then + return -1 +endi +if $data06 != 1 then + return -1 +endi +if $data07 != 13 then + return -1 +endi +if $data08 != @{slop:1.000000, intercept:0.000000}@ then + return -1 +endi +if $data09 != 12 then + return -1 +endi +# $data0-10 != 3.741657387 +# $data0-11 != 1 +# $data1-11 != 14 + +print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1) from (select * from dev_001 where ts <'2020-05-20 0:0:0') session(ts,1d) +sql select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1) from (select * from dev_001 where ts <'2020-05-20 0:0:0') session(ts,1d) +if $rows != 2 then + return -1 +endi +if $data01 != 13 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 13 then + return -1 +endi +if $data04 != 7 then + return -1 +endi +if $data05 != 91 then + return -1 +endi +if $data06 != 1 then + return -1 +endi +if $data07 != 13 then + return -1 +endi +if $data08 != @{slop:1.000000, intercept:0.000000}@ then + return -1 +endi + +sql_error select * from dev_001 session(ts,1w) +sql_error select count(*) from st session(ts,1w) +sql_error select count(*) from dev_001 group by tagtype session(ts,1w) +sql_error select count(*) from dev_001 session(ts,1n) +sql_error select count(*) from dev_001 session(ts,1y) +sql_error select count(*) from dev_001 session(ts,0s) +sql_error select count(*) from dev_001 session(i,1y) +sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' + +print ====> create database d1 precision 'us' +sql create database d1 precision 'us' +sql use d1 +sql create table dev_001 (ts timestamp ,i timestamp ,j int) +sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4) +print ====> select count(*) from dev_001 session(ts,1u) +sql select count(*) from dev_001 session(ts,1u) +if $rows != 2 then + return -1 +endi +if $data01 != 3 then + return -1 +endi +sql_error select count(*) from dev_001 session(i,1s) +sql create table secondts(ts timestamp,t2 timestamp,i int) +sql_error select count(*) from secondts session(t2,2s) + + +if $loop_test == 0 then + print =============== stop and restart taosd + system sh/exec.sh -n dnode1 -s stop -x SIGINT + system sh/exec.sh -n dnode1 -s start + + $loop_cnt = 0 + check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + sql show dnodes + print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 + if $data00 != 1 then + return -1 + endi + if $data04 != ready then + goto check_dnode_ready_0 + endi + + $loop_test = 1 + goto loop_test_pos +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/testCaseSuite.sim b/tests/script/tsim/testCaseSuite.sim index bf184f8794..4245529343 100644 --- a/tests/script/tsim/testCaseSuite.sim +++ b/tests/script/tsim/testCaseSuite.sim @@ -1,6 +1,7 @@ run tsim/user/basic1.sim +run tsim/db/alter_option.sim run tsim/db/basic1.sim run tsim/db/basic2.sim run tsim/db/basic3.sim @@ -20,6 +21,7 @@ run tsim/insert/null.sim run tsim/query/interval.sim run tsim/query/interval-offset.sim +run tsim/query/scalarFunction.sim run tsim/show/basic.sim diff --git a/tests/script/tsim/tmq/multiTopic.sim b/tests/script/tsim/tmq/multiTopic.sim new file mode 100644 index 0000000000..cd977e5909 --- /dev/null +++ b/tests/script/tsim/tmq/multiTopic.sim @@ -0,0 +1,224 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=1, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=1, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene2 and scene4 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 1 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 +print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 + +if $loop_cnt == 0 then + if $rows != 2 then + return -1 + endi + if $data02 != 1 then # vgroups + print vgroups: $data02 + return -1 + endi +else + if $rows != 3 then + return -1 + endi + if $data00 == d1 then + if $data02 != 4 then # vgroups + print vgroups: $data02 + return -1 + endi + else + if $data12 != 4 then # vgroups + print vgroups: $data12 + return -1 + endi + endi +endi + +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +#sql create topic topic_stb_all as select * from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== insert data +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $c = $x / 10 + $c = $c * 10 + $c = $x - $c + + $binary = ' . binary + $binary = $binary . $c + $binary = $binary . ' + + sql insert into $tb values ($tstart , $c , $x , $binary ) + sql insert into ntb values ($tstart , $c , $x , $binary ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + $i = $i + 1 + $tstart = 1640966400000 +endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$totalMsgCnt = $rowNum * $tbNum +print inserted totalMsgCnt: $totalMsgCnt + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$numOfTopics = 2 +$totalMsgCntOfmultiTopics = $totalMsgCnt * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $totalMsgCntOfmultiTopics +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function, topic_stb_all" -k "group.id:tg2" +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function, topic_stb_all" -k "group.id:tg2" +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 20000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +$numOfTopics = 3 +$totalMsgCntOfmultiTopics = $rowNum * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $totalMsgCntOfmultiTopics +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 300, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +$numOfTopics = 3 +$totalMsgCntOfmultiTopics = $totalMsgCnt * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $totalMsgCntOfmultiTopics +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_all, topic_ntb_function" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_all, topic_ntb_function" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 30000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/oneTopic.sim b/tests/script/tsim/tmq/oneTopic.sim new file mode 100644 index 0000000000..8e8d00977c --- /dev/null +++ b/tests/script/tsim/tmq/oneTopic.sim @@ -0,0 +1,264 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=1, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=1, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene1 and scene3 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 1 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 +print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 + +if $loop_cnt == 0 then + if $rows != 2 then + return -1 + endi + if $data02 != 1 then # vgroups + print vgroups: $data02 + return -1 + endi +else + if $rows != 3 then + return -1 + endi + if $data00 == d1 then + if $data02 != 4 then # vgroups + print vgroups: $data02 + return -1 + endi + else + if $data12 != 4 then # vgroups + print vgroups: $data12 + return -1 + endi + endi +endi + +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +#sql create topic topic_stb_all as select * from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== insert data +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $c = $x / 10 + $c = $c * 10 + $c = $x - $c + + $binary = ' . binary + $binary = $binary . $c + $binary = $binary . ' + + sql insert into $tb values ($tstart , $c , $x , $binary ) + sql insert into ntb values ($tstart , $c , $x , $binary ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + $i = $i + 1 + $tstart = 1640966400000 +endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$totalMsgCnt = $rowNum * $tbNum +print inserted totalMsgCnt: $totalMsgCnt + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $totalMsgCnt +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_all" -k "group.id:tg2" +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_all" -k "group.id:tg2" +#print cmd result----> $system_content +##if $system_content != @{consume success: 10000, 0}@ then +#if $system_content != $expect_result then +# return -1 +#endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_function" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_function" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $rowNum +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 100, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_all" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_all" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 100, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 100, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $totalMsgCnt +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_all" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_all" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2" +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2" +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/test-all.sh b/tests/test-all.sh index aa7c4240bc..ff9905e209 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -91,20 +91,23 @@ function runSimCaseOneByOnefq { for ((i=$start;i<=$end;i++)) ; do line=`sed -n "$i"p jenkins/basic.txt` if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then - case=`echo $line | grep sim$ |awk '{print $NF}'` + #case=`echo $line | grep sim$ |awk '{print $NF}'` + case=`echo $line | grep -o ".*\.sim" |awk '{print $NF}'` start_time=`date +%s` date +%F\ %T | tee -a out.log if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then - echo -n $case - ./test.sh -f $case > case.log 2>&1 \ + #echo -n $case + echo -n $line + $line > case.log 2>&1 \ && \ ([ -f ../../../sim/tsim/log/taoslog0.0 ] && grep -q 'script.*'$case'.*failed.*, err.*lineNum' ../../../sim/tsim/log/taoslog0.0 && echo -e "${RED} failed${NC}" | tee -a out.log || echo -e "${GREEN} success${NC}" | tee -a out.log )|| \ ([ -f ../../../sim/tsim/log/taoslog0.0 ] && grep -q 'script.*success.*m$' ../../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log ) || \ ( echo -e "${RED} failed${NC}" | tee -a out.log && echo '=====================log=====================' && cat case.log ) else - echo -n $case - ./test.sh -f $case > ../../sim/case.log 2>&1 && \ + #echo -n $case + echo -n $line + $line > ../../sim/case.log 2>&1 && \ ([ -f ../../sim/tsim/log/taoslog0.0 ] && grep -q 'script.*'$case'.*failed.*, err.*lineNum' ../../sim/tsim/log/taoslog0.0 && echo -e "${RED} failed${NC}" | tee -a out.log || echo -e "${GREEN} success${NC}" | tee -a out.log )|| \ ([ -f ../../sim/tsim/log/taoslog0.0 ] && grep -q 'script.*success.*m$' ../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log ) || \ ( echo -e "${RED} failed${NC}" | tee -a out.log && echo '=====================log=====================' && pwd && cat ../../sim/case.log ) diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 78f1c7e015..38264331c1 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -226,7 +226,7 @@ void loop_consume(tmq_t* tmq) { int32_t totalRows = 0; int32_t skipLogNum = 0; while (running) { - tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 6000); + tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 3000); if (tmqMsg) { totalMsgs++; diff --git a/tests/tsim/inc/simInt.h b/tests/tsim/inc/simInt.h index 1e2190e308..a667139de1 100644 --- a/tests/tsim/inc/simInt.h +++ b/tests/tsim/inc/simInt.h @@ -155,6 +155,7 @@ extern int32_t simScriptSucced; extern int32_t simDebugFlag; extern char simScriptDir[]; extern bool abortExecution; +extern bool useMultiProcess; SScript *simParseScript(char *fileName); SScript *simProcessCallOver(SScript *script); diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 855705e904..9a0b48197a 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -305,25 +305,24 @@ bool simExecuteRunBackCmd(SScript *script, char *option) { return true; } -void simReplaceShToBat(char *dst) { - char *sh = strstr(dst, ".sh"); - if (sh != NULL) { +void simReplaceStr(char *buf, char *src, char *dst) { + char *begin = strstr(buf, src); + if (begin != NULL) { + int32_t srcLen = (int32_t)strlen(src); int32_t dstLen = (int32_t)strlen(dst); - char *end = dst + dstLen; - *(end + 1) = 0; + int32_t interval = (dstLen - srcLen); + int32_t remainLen = (int32_t)strlen(buf); + char *end = buf + remainLen; + *(end + interval) = 0; - for (char *p = end; p >= sh; p--) { - *(p + 1) = *p; + for (char *p = end; p >= begin; p--) { + *(p + interval) = *p; } - sh[0] = '.'; - sh[1] = 'b'; - sh[2] = 'a'; - sh[3] = 't'; - sh[4] = ' '; + memcpy(begin, dst, dstLen); } - simDebug("system cmd is %s", dst); + simInfo("system cmd is %s", buf); } bool simExecuteSystemCmd(SScript *script, char *option) { @@ -334,9 +333,13 @@ bool simExecuteSystemCmd(SScript *script, char *option) { simVisuallizeOption(script, option, buf + strlen(buf)); #else sprintf(buf, "%s%s", simScriptDir, option); - simReplaceShToBat(buf); + simReplaceStr(buf, ".sh", ".bat"); #endif + if (useMultiProcess) { + simReplaceStr(buf, "deploy.sh", "deploy.sh -m"); + } + simLogSql(buf, true); int32_t code = system(buf); int32_t repeatTimes = 0; diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c index b57299e752..8898f1b201 100644 --- a/tests/tsim/src/simMain.c +++ b/tests/tsim/src/simMain.c @@ -18,6 +18,7 @@ bool simExecSuccess = false; bool abortExecution = false; +bool useMultiProcess = false; void simHandleSignal(int32_t signo, void *sigInfo, void *context) { simSystemCleanUp(); @@ -32,6 +33,8 @@ int32_t main(int32_t argc, char *argv[]) { tstrncpy(configDir, argv[++i], 128); } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) { strcpy(scriptFile, argv[++i]); + } else if (strcmp(argv[i], "-m") == 0) { + useMultiProcess = true; } else { printf("usage: %s [options] \n", argv[0]); printf(" [-c config]: config directory, default is: %s\n", configDir);