diff --git a/.clang-format b/.clang-format index 3ddd8b43f6238f30000b96d8e676892ab2dcec68..e58d518b3b8cacdd1e13dd965805fa364a996eb2 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 8757104ad9ed24374aac00a6906f766dc28b8290..efb4d1830eb81e36f5066dacdff5d954ea2793b7 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 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 create topic test_stb_topic_1, reason:%s\n", taos_errstr(pRes)); + 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 40d8ff9b0b5325a4ac2e89aa5198938889378015..8ffa932bd29d6f89441c7f045611f42e058dd872 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 0260316618b3d488294b96a9b8bf341ed72eacf8..0fd2fd8df9c49f0352dbe89f50e678b9f7fbcf20 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, @@ -124,8 +125,25 @@ typedef struct TAOS_MULTI_BIND { int num; } TAOS_MULTI_BIND; +typedef enum { + SET_CONF_RET_SUCC = 0, + SET_CONF_RET_ERR_PART = -1, + SET_CONF_RET_ERR_INNER = -2, + SET_CONF_RET_ERR_JSON_INVALID = -3, + SET_CONF_RET_ERR_JSON_PARSE = -4, + SET_CONF_RET_ERR_ONLY_ONCE = -5, + SET_CONF_RET_ERR_TOO_LONG = -6 +} SET_CONF_RET_CODE; + +#define RET_MSG_LENGTH 1024 +typedef struct setConfRet { + SET_CONF_RET_CODE retCode; + char retMsg[RET_MSG_LENGTH]; +} setConfRet; + DLL_EXPORT void taos_cleanup(void); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); +DLL_EXPORT setConfRet taos_set_config(const char *config); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port); @@ -168,10 +186,13 @@ DLL_EXPORT int taos_select_db(TAOS *taos, const char *db); DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields); DLL_EXPORT void taos_stop_query(TAOS_RES *res); 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 int *taos_fetch_lengths(TAOS_RES *res); +DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res); DLL_EXPORT const char *taos_get_server_info(TAOS *taos); DLL_EXPORT const char *taos_get_client_info(); diff --git a/include/common/taosdef.h b/include/common/taosdef.h index 797ebf29c59c38bc4fd5af1143976037360843b1..5001a99c2a2cca535ccea1231599044e12733efb 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 51eabb7d617ed42ab6ad520bb6da69d178ae92bb..8332e9d09a777c16d841d84e4890ad2665037e2a 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, @@ -198,8 +209,8 @@ typedef struct SGroupbyExpr { } SGroupbyExpr; enum { - FUNC_PARAM_TYPE_VALUE = 0, - FUNC_PARAM_TYPE_COLUMN, + FUNC_PARAM_TYPE_VALUE = 0x1, + FUNC_PARAM_TYPE_COLUMN= 0x2, }; typedef struct SFunctParam { @@ -239,7 +250,7 @@ typedef struct SSessionWindow { 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 4a47acfa50169c4970364d5ab978c00362a17e00..248d7d0db668ec481748ac20a896b4fd51a2d7e1 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -133,7 +133,8 @@ static FORCE_INLINE int32_t colDataAppendInt32(SColumnInfoData* pColumnInfoData, } static FORCE_INLINE int32_t colDataAppendInt64(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int64_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_BIGINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UBIGINT); + int32_t type = pColumnInfoData->info.type; + ASSERT(type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT || type == TSDB_DATA_TYPE_TIMESTAMP); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(int64_t*)p = *(int64_t*)v; } @@ -175,17 +176,18 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock); double blockDataGetSerialRowSize(const SSDataBlock* pBlock); size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock); -SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols); - 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 blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); -void blockDataCleanup(SSDataBlock* pDataBlock); +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); -size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize); -void* blockDataDestroy(SSDataBlock* pBlock); void blockDebugShowData(const SArray* dataBlocks); diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 4a3ce2db86b01a3c7134bed68b389bd7d3b97b7c..da724206d9d01c7cf61ac57ca7c27a298ddff85b 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/tglobal.h b/include/common/tglobal.h index 90aac6edcdec34c4efee9abacb995c7d3827f9f3..089cb5bb94935a4a5b40cb19db4c86ec47c5c29b 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -51,7 +51,7 @@ extern int32_t tsCompatibleModel; extern bool tsEnableSlaveQuery; extern bool tsPrintAuth; extern int64_t tsTickPerDay[3]; -extern int32_t tsMultiProcess; +extern bool tsMultiProcess; // monitor extern bool tsEnableMonitor; diff --git a/include/common/tmsg.h b/include/common/tmsg.h index de2163817968389f025df96583f61ed1bd2ec710..12909875d514717465fd504d0c259f46b0f3bab8 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; @@ -469,8 +483,7 @@ typedef struct { int32_t tz; // query client timezone char intervalUnit; char slidingUnit; - char - offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. + char offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. int8_t precision; int64_t interval; int64_t sliding; @@ -525,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); @@ -1403,13 +1417,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 { @@ -1417,10 +1430,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; }; @@ -1899,7 +1911,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) { @@ -2017,7 +2032,6 @@ typedef struct { int8_t slidingUnit; // MACRO: TIME_UNIT_XXX int8_t timezoneInt; // sma data expired if timezone changes. char indexName[TSDB_INDEX_NAME_LEN]; - char timezone[TD_TIMEZONE_LEN]; int32_t exprLen; int32_t tagsFilterLen; int64_t indexUid; @@ -2055,32 +2069,6 @@ void* tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq); int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq); void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq); -typedef struct { - col_id_t colId; - uint16_t blockSize; // sma data block size - char data[]; -} STSmaColData; - -typedef struct { - tb_uid_t tableUid; // super/child/normal table uid - int32_t dataLen; // not including head - char data[]; -} STSmaTbData; - -typedef struct { - int64_t indexUid; - TSKEY skey; // startKey of one interval/sliding window - int64_t interval; - int32_t dataLen; // not including head - int8_t intervalUnit; - char data[]; -} STSmaDataWrapper; // sma data for a interval/sliding window - -// interval/sliding => window - -// => window->table->colId -// => 当一个window下所有的表均计算完成时,流计算告知tsdb清除window的过期标记 - // RSma: Rollup SMA typedef struct { int64_t interval; diff --git a/include/common/trow.h b/include/common/trow.h index df28bc9962da9198ecca010eb518ec5674e09d0e..01f40763829d7a3edd01a7bd01e59883ff566ac4 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); @@ -937,9 +937,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col STColumn *pCol = NULL; STSchema *pSchema = pIter->pSchema; while (pIter->colIdx <= pSchema->numOfCols) { - pCol = &pSchema->columns[pIter->colIdx]; + pCol = &pSchema->columns[pIter->colIdx]; // 1st column of schema is primary TS key if (colId == pCol->colId) { - ++pIter->colIdx; break; } else if (colId < pCol->colId) { ++pIter->colIdx; @@ -948,7 +947,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col return false; } } - return tdGetTpRowDataOfCol(pIter, pCol->type, pCol->offset - sizeof(TSKEY), pVal); + tdGetTpRowDataOfCol(pIter, pCol->type, pCol->offset - sizeof(TSKEY), pVal); + ++pIter->colIdx; } else if (TD_IS_KV_ROW(pIter->pRow)) { return tdGetKvRowValOfColEx(pIter, colId, colType, &pIter->kvIdx, pVal); } else { @@ -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 57af24e6353ad221d9a33bd83fe91f0a89af7d2b..306f54bedb2f5609dc2f1e48d47f483e2d9f0d0f 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 83de5b6918079bf1365d9e2651b9672fae0a3c71..8d996be21e768339ce5998684749b31a2a5392bf 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,62 +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_NK_BOOL 123 -#define TK_NULL 124 -#define TK_NK_VARIABLE 125 -#define TK_NK_UNDERLINE 126 -#define TK_ROWTS 127 -#define TK_TBNAME 128 -#define TK_QSTARTTS 129 -#define TK_QENDTS 130 -#define TK_WSTARTTS 131 -#define TK_WENDTS 132 -#define TK_WDURATION 133 -#define TK_BETWEEN 134 -#define TK_IS 135 -#define TK_NK_LT 136 -#define TK_NK_GT 137 -#define TK_NK_LE 138 -#define TK_NK_GE 139 -#define TK_NK_NE 140 -#define TK_MATCH 141 -#define TK_NMATCH 142 -#define TK_IN 143 -#define TK_JOIN 144 -#define TK_INNER 145 -#define TK_SELECT 146 -#define TK_DISTINCT 147 -#define TK_WHERE 148 -#define TK_PARTITION 149 -#define TK_BY 150 -#define TK_SESSION 151 -#define TK_STATE_WINDOW 152 -#define TK_SLIDING 153 -#define TK_FILL 154 -#define TK_VALUE 155 -#define TK_NONE 156 -#define TK_PREV 157 -#define TK_LINEAR 158 -#define TK_NEXT 159 -#define TK_GROUP 160 -#define TK_HAVING 161 -#define TK_ORDER 162 -#define TK_SLIMIT 163 -#define TK_SOFFSET 164 -#define TK_LIMIT 165 -#define TK_OFFSET 166 -#define TK_ASC 167 -#define TK_DESC 168 -#define TK_NULLS 169 -#define TK_FIRST 170 -#define TK_LAST 171 +#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_NK_UNDERLINE 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 @@ -200,10 +229,9 @@ #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/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index 8d19ce23dfdfce22a3e0e9b0961f58aa9319bc74..e4f4bdf8f994c31df6f31ce6df1347e384df5de6 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -46,11 +46,12 @@ typedef struct { char localFqdn[TSDB_FQDN_LEN]; char firstEp[TSDB_EP_LEN]; char secondEp[TSDB_EP_LEN]; - SDiskCfg *pDisks; + SDiskCfg *disks; int32_t numOfDisks; + int8_t ntype; } SDnodeOpt; -typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_RELOAD } EDndEvent; +typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; /** * @brief Initialize and start the dnode. diff --git a/include/libs/command/command.h b/include/libs/command/command.h new file mode 100644 index 0000000000000000000000000000000000000000..7e58d39692dbe17ba88ec6fb9c34796c0894e02f --- /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/executor/executor.h b/include/libs/executor/executor.h index fbdb1d66b4f48ccf9f6f8d80083eb5ae398fde25..d3cd828cf50d7351de1c7e2dc35b1062e1e66486 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -37,6 +37,11 @@ typedef struct SReadHandle { #define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1 #define STREAM_DATA_TYPE_SSDATA_BLOCK 0x2 +typedef enum { + OPTR_EXEC_MODEL_BATCH = 0x1, + OPTR_EXEC_MODEL_STREAM = 0x2, +} EOPTR_EXEC_MODEL; + /** * Create the exec task for streaming mode * @param pMsg @@ -84,7 +89,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isA * @return */ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan, - qTaskInfo_t* pTaskInfo, DataSinkHandle* handle); + qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, EOPTR_EXEC_MODEL model); /** * The main task execution function, including query on both table and multiple tables, diff --git a/include/libs/function/function.h b/include/libs/function/function.h index e7895bd972f9ecf89ca9b842150db08b444a7660..278d9d8b7c503889f147984bc151e0e80a02e259 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -41,6 +41,7 @@ typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx); typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); typedef struct SScalarFuncExecFuncs { + FExecGetEnv getEnv; FScalarExecProcess process; } SScalarFuncExecFuncs; @@ -241,7 +242,6 @@ typedef struct tExprNode { }; } tExprNode; -void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree); void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)); typedef struct SAggFunctionInfo { @@ -267,28 +267,6 @@ struct SScalarParam { int32_t numOfRows; }; -typedef struct SMultiFunctionsDesc { - bool stableQuery; - bool groupbyColumn; - bool agg; - bool arithmeticOnAgg; - bool projectionQuery; - bool hasFilter; - bool onlyTagQuery; - bool orderProjectQuery; - bool globalMerge; - bool multigroupResult; - bool blockDistribution; - bool stateWindow; - bool timewindow; - bool sessionWindow; - bool topbotQuery; - bool interpQuery; - bool distinct; - bool join; - bool continueQuery; -} SMultiFunctionsDesc; - int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, SResultDataInfo* pInfo, int16_t extLength, bool isSuperTable); @@ -296,8 +274,6 @@ bool qIsValidUdf(SArray* pUdfInfo, const char* name, int32_t len, int32_t* funct tExprNode* exprTreeFromBinary(const void* data, size_t size); -void extractFunctionDesc(SArray* pFunctionIdList, SMultiFunctionsDesc* pDesc); - tExprNode* exprdup(tExprNode* pTree); void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num); diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index a03c496b4f71079992954a7919e30d737df7bdce..069aec14b571cfd96ba28d32c4ae5dd67438602c 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 411d34063c63e822e478d32ac9c001a167190745..9668082696a74986b991e64059f52d5889895477 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -70,6 +70,7 @@ typedef enum ENodeType { QUERY_NODE_DATABASE_OPTIONS, QUERY_NODE_TABLE_OPTIONS, QUERY_NODE_INDEX_OPTIONS, + QUERY_NODE_EXPLAIN_OPTIONS, // Statement nodes are used in parser and planner module. QUERY_NODE_SET_OPERATOR, @@ -99,6 +100,18 @@ typedef enum ENodeType { QUERY_NODE_CREATE_TOPIC_STMT, 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, @@ -111,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, @@ -211,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 68e081cd1539f32d78aeec7cc676f5dcbfab59d0..37163f60ddea165075ebf6615bba46993d3d7342 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -49,6 +49,7 @@ typedef struct SScanLogicNode { STimeWindow scanRange; SName tableName; bool showRewrite; + double ratio; } SScanLogicNode; typedef struct SJoinLogicNode { @@ -197,7 +198,7 @@ typedef struct STableScanPhysiNode { SScanPhysiNode scan; uint8_t scanFlag; // denotes reversed scan of data or not STimeWindow scanRange; - SNode* pScanConditions; + double ratio; } STableScanPhysiNode; typedef STableScanPhysiNode STableSeqScanPhysiNode; @@ -252,6 +253,7 @@ typedef struct SIntervalPhysiNode { int64_t sliding; int8_t intervalUnit; int8_t slidingUnit; + uint8_t precision; SFillNode* pFill; } SIntervalPhysiNode; @@ -297,18 +299,23 @@ typedef struct SSubplan { SDataSinkNode* pDataSink; // data of the subplan flow into the datasink } SSubplan; -typedef enum EQueryMode { - QUERY_MODE_NORMAL = 1, - QUERY_MODE_EXPLAIN, - QUERY_MODE_EXPLAIN_AN -} EQueryMode; +typedef enum EExplainMode { + EXPLAIN_MODE_DISABLE = 1, + EXPLAIN_MODE_STATIC, + EXPLAIN_MODE_ANALYZE +} EExplainMode; + +typedef struct SExplainInfo { + EExplainMode mode; + bool verbose; +} SExplainInfo; typedef struct SQueryPlan { ENodeType type; uint64_t queryId; int32_t numOfSubplans; - SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0. + SExplainInfo explainInfo; } SQueryPlan; #ifdef __cplusplus diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 5dc2cd35b75f7627d8b10474649185d63f695e20..ddcbaa0beea8f584b133ee62f054e32ccd9b40ea 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -131,6 +131,7 @@ typedef struct SRealTableNode { struct STableMeta* pMeta; SVgroupsInfo* pVgroupList; char useDbName[TSDB_DB_NAME_LEN]; + double ratio; } SRealTableNode; typedef struct STempTableNode { @@ -282,6 +283,19 @@ typedef struct SVnodeModifOpStmt { const char* sql; // current sql statement position } SVnodeModifOpStmt; +typedef struct SExplainOptions { + ENodeType type; + bool verbose; + double ratio; +} SExplainOptions; + +typedef struct SExplainStmt { + ENodeType type; + bool analyze; + SExplainOptions* pOptions; + SNode* pQuery; +} SExplainStmt; + void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext); void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext); @@ -300,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 074753472172485802c465261e9708a7efeda285..f10185c44fe44338143c64c0feffa80cbb6c4f37 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 f487e5ae22b84586a8c2ac660dbdc7ff9bb94124..bb550e75e8c5e0f8afbd619c29c1eb165ceadcc4 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 10ef0c1b23ffd773e6a5758beda6dcfee90737c6..b5acc64f0b7040070cc6e85481c7f41adea5e298 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -70,6 +70,13 @@ int32_t ltrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut 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); +int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t qStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t qEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); #ifdef __cplusplus } diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 8b1ac3ed8d3513f03bffcf71ed4af17bfe650adc..e635227eaa68f9f077deff60ea32eeae607146c3 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/os.h b/include/os/os.h index e7ce7d09eafffcb51c5582829788af7417e7fbcb..3ea94d009437e9cd32cfa1b95ce44d4f28fe2d3b 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -42,6 +42,9 @@ extern "C" { #include #include #include +#include +#include +#include #if defined(DARWIN) #else @@ -70,7 +73,6 @@ extern "C" { #include #include - #include "osAtomic.h" #include "osDef.h" #include "osDir.h" @@ -80,10 +82,12 @@ extern "C" { #include "osLz4.h" #include "osMath.h" #include "osMemory.h" +#include "osProc.h" #include "osRand.h" #include "osThread.h" #include "osSemaphore.h" #include "osSignal.h" +#include "osShm.h" #include "osSleep.h" #include "osSocket.h" #include "osString.h" diff --git a/include/os/osMemory.h b/include/os/osMemory.h index 62ac82782c5d6c77d27bea9df825fc8e5be69e60..e516000c66cb24f3f12c41007d7996fe35f2e3a4 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 new file mode 100644 index 0000000000000000000000000000000000000000..f09b695ef4e55f0ab9bb9b0113cc1befff58daa0 --- /dev/null +++ b/include/os/osProc.h @@ -0,0 +1,34 @@ +/* + * 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_OS_PROC_H_ +#define _TD_OS_PROC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +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 +} +#endif + +#endif /*_TD_OS_PROC_H_*/ diff --git a/include/os/osShm.h b/include/os/osShm.h new file mode 100644 index 0000000000000000000000000000000000000000..d26a99e2778e56ccc1d58b185cfa0ee7b19ebd89 --- /dev/null +++ b/include/os/osShm.h @@ -0,0 +1,37 @@ +/* + * 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_OS_SHM_H_ +#define _TD_OS_SHM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + int32_t id; + int32_t size; + void* ptr; +} SShm; + +int32_t taosCreateShm(SShm *pShm, int32_t shmsize) ; +void taosDropShm(SShm *pShm); +int32_t taosAttachShm(SShm *pShm); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_OS_SHM_H_*/ diff --git a/include/os/osSignal.h b/include/os/osSignal.h index ab4b6fa242cce2a7250ec6e7f3c669d62dd0ac21..e22c43684cda403d82eabd670b6828f2fb99bc85 100644 --- a/include/os/osSignal.h +++ b/include/os/osSignal.h @@ -49,6 +49,8 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp); void taosIgnSignal(int32_t signum); void taosDflSignal(int32_t signum); +void taosKillChildOnParentStopped(); + #ifdef __cplusplus } #endif diff --git a/include/os/osThread.h b/include/os/osThread.h index 6d8ff1de3eb39d7bb1c3c7e8be84415db638dd73..a145b0da073e7aa9222561d6cded80ff9d730f54 100644 --- a/include/os/osThread.h +++ b/include/os/osThread.h @@ -32,6 +32,9 @@ typedef pthread_once_t TdThreadOnce; typedef pthread_rwlockattr_t TdThreadRwlockAttr; typedef pthread_cond_t TdThreadCond; typedef pthread_condattr_t TdThreadCondAttr; +typedef pthread_key_t TdThreadKey; +typedef pthread_barrier_t TdThreadBarrier; +typedef pthread_barrierattr_t TdThreadBarrierAttr; #define taosThreadCleanupPush pthread_cleanup_push #define taosThreadCleanupPop pthread_cleanup_pop @@ -49,68 +52,180 @@ typedef pthread_condattr_t TdThreadCondAttr; #define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID #define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID #define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID - #define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID - #define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID - #define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID - #define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID - #define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID - #define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID - #define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID - #define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID - #define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID - #define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID - #define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID - #define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID - #define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID + #define pthread_key_t PTHREAD_KEY_T_TYPE_TAOS_FORBID + #define pthread_barrier_t PTHREAD_BARRIER_T_TYPE_TAOS_FORBID + #define pthread_barrierattr_t PTHREAD_BARRIERATTR_T_TYPE_TAOS_FORBID #define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID - #define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID - #define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID #define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID - #define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID - #define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID - #define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID - #define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID + #define pthread_attr_getdetachstate PTHREAD_ATTR_GETDETACHSTATE_FUNC_TAOS_FORBID + #define pthread_attr_getinheritsched PTHREAD_ATTR_GETINHERITSCHED_FUNC_TAOS_FORBID + #define pthread_attr_getschedparam PTHREAD_ATTR_GETSCHEDPARAM_FUNC_TAOS_FORBID + #define pthread_attr_getschedpolicy PTHREAD_ATTR_GETSCHEDPOLICY_FUNC_TAOS_FORBID + #define pthread_attr_getscope PTHREAD_ATTR_GETSCOPE_FUNC_TAOS_FORBID + #define pthread_attr_getstacksize PTHREAD_ATTR_GETSTACKSIZE_FUNC_TAOS_FORBID + #define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID + #define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID + #define pthread_attr_setinheritsched PTHREAD_ATTR_SETINHERITSCHED_FUNC_TAOS_FORBID + #define pthread_attr_setschedparam PTHREAD_ATTR_SETSCHEDPARAM_FUNC_TAOS_FORBID + #define pthread_attr_setschedpolicy PTHREAD_ATTR_SETSCHEDPOLICY_FUNC_TAOS_FORBID + #define pthread_attr_setscope PTHREAD_ATTR_SETSCOPE_FUNC_TAOS_FORBID + #define pthread_attr_setstacksize PTHREAD_ATTR_SETSTACKSIZE_FUNC_TAOS_FORBID + #define pthread_barrier_destroy PTHREAD_BARRIER_DESTROY_FUNC_TAOS_FORBID + #define pthread_barrier_init PTHREAD_BARRIER_INIT_FUNC_TAOS_FORBID + #define pthread_barrier_wait PTHREAD_BARRIER_WAIT_FUNC_TAOS_FORBID + #define pthread_barrierattr_destroy PTHREAD_BARRIERATTR_DESTROY_FUNC_TAOS_FORBID + #define pthread_barrierattr_getpshared PTHREAD_BARRIERATTR_GETPSHARED_FUNC_TAOS_FORBID + #define pthread_barrierattr_init PTHREAD_BARRIERATTR_INIT_FUNC_TAOS_FORBID + #define pthread_barrierattr_setpshared PTHREAD_BARRIERATTR_SETPSHARED_FUNC_TAOS_FORBID + #define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID + #define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID #define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID + #define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID #define pthread_cond_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID - #define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID #define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID - #define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID + #define pthread_cond_timedwait PTHREAD_COND_TIMEDWAIT_FUNC_TAOS_FORBID + #define pthread_condattr_destroy PTHREAD_CONDATTR_DESTROY_FUNC_TAOS_FORBID + #define pthread_condattr_getpshared PTHREAD_CONDATTR_GETPSHARED_FUNC_TAOS_FORBID + #define pthread_condattr_init PTHREAD_CONDATTR_INIT_FUNC_TAOS_FORBID + #define pthread_condattr_setpshared PTHREAD_CONDATTR_SETPSHARED_FUNC_TAOS_FORBID + #define pthread_detach PTHREAD_DETACH_FUNC_TAOS_FORBID #define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID - #define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID - #define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID + #define pthread_exit PTHREAD_EXIT_FUNC_TAOS_FORBID + #define pthread_getschedparam PTHREAD_GETSCHEDPARAM_FUNC_TAOS_FORBID + #define pthread_getspecific PTHREAD_GETSPECIFIC_FUNC_TAOS_FORBID + #define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID + #define pthread_key_create PTHREAD_KEY_CREATE_FUNC_TAOS_FORBID + #define pthread_key_delete PTHREAD_KEY_DELETE_FUNC_TAOS_FORBID #define pthread_kill PTHREAD_KILL_FUNC_TAOS_FORBID + #define pthread_mutex_consistent PTHREAD_MUTEX_CONSISTENT_FUNC_TAOS_FORBID + #define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID + #define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID + #define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID + #define pthread_mutex_timedlock PTHREAD_MUTEX_TIMEDLOCK_FUNC_TAOS_FORBID + #define pthread_mutex_trylock PTHREAD_MUTEX_TRYLOCK_FUNC_TAOS_FORBID + #define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID + #define pthread_mutexattr_destroy PTHREAD_MUTEXATTR_DESTROY_FUNC_TAOS_FORBID + #define pthread_mutexattr_getpshared PTHREAD_MUTEXATTR_GETPSHARED_FUNC_TAOS_FORBID + #define pthread_mutexattr_getrobust PTHREAD_MUTEXATTR_GETROBUST_FUNC_TAOS_FORBID + #define pthread_mutexattr_gettype PTHREAD_MUTEXATTR_GETTYPE_FUNC_TAOS_FORBID + #define pthread_mutexattr_init PTHREAD_MUTEXATTR_INIT_FUNC_TAOS_FORBID + #define pthread_mutexattr_setpshared PTHREAD_MUTEXATTR_SETPSHARED_FUNC_TAOS_FORBID + #define pthread_mutexattr_setrobust PTHREAD_MUTEXATTR_SETROBUST_FUNC_TAOS_FORBID + #define pthread_mutexattr_settype PTHREAD_MUTEXATTR_SETTYPE_FUNC_TAOS_FORBID + #define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID + #define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID + #define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID + #define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID + #define pthread_rwlock_timedrdlock PTHREAD_RWLOCK_TIMEDRDLOCK_FUNC_TAOS_FORBID + #define pthread_rwlock_timedwrlock PTHREAD_RWLOCK_TIMEDWRLOCK_FUNC_TAOS_FORBID + #define pthread_rwlock_tryrdlock PTHREAD_RWLOCK_TRYRDLOCK_FUNC_TAOS_FORBID + #define pthread_rwlock_trywrlock PTHREAD_RWLOCK_TRYWRLOCK_FUNC_TAOS_FORBID + #define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID + #define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID + #define pthread_rwlockattr_destroy PTHREAD_RWLOCKATTR_DESTROY_FUNC_TAOS_FORBID + #define pthread_rwlockattr_getpshared PTHREAD_RWLOCKATTR_GETPSHARED_FUNC_TAOS_FORBID + #define pthread_rwlockattr_init PTHREAD_RWLOCKATTR_INIT_FUNC_TAOS_FORBID + #define pthread_rwlockattr_setpshared PTHREAD_RWLOCKATTR_SETPSHARED_FUNC_TAOS_FORBID + #define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID + #define pthread_setcancelstate PTHREAD_SETCANCELSTATE_FUNC_TAOS_FORBID + #define pthread_setcanceltype PTHREAD_SETCANCELTYPE_FUNC_TAOS_FORBID + #define pthread_setschedparam PTHREAD_SETSCHEDPARAM_FUNC_TAOS_FORBID + #define pthread_setspecific PTHREAD_SETSPECIFIC_FUNC_TAOS_FORBID + #define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID + #define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID + #define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID + #define pthread_spin_trylock PTHREAD_SPIN_TRYLOCK_FUNC_TAOS_FORBID + #define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID + #define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID + #define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID + #define sigwait SIGWAIT_FUNC_TAOS_FORBID #endif -int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared); -int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr); -int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock); +int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg); +int32_t taosThreadAttrDestroy(TdThreadAttr * attr); +int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate); +int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched); +int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param); +int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy); +int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope); +int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize); +int32_t taosThreadAttrInit(TdThreadAttr * attr); +int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate); +int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched); +int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param); +int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy); +int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope); +int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize); +int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier); +int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count); +int32_t taosThreadBarrierWait(TdThreadBarrier * barrier); +int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr); +int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared); +int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr); +int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared); +int32_t taosThreadCancel(TdThread thread); +int32_t taosThreadCondDestroy(TdThreadCond * cond); +int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr); +int32_t taosThreadCondSignal(TdThreadCond * cond); +int32_t taosThreadCondBroadcast(TdThreadCond * cond); +int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex); +int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime); +int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr); +int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared); +int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr); +int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared); +int32_t taosThreadDetach(TdThread thread); +int32_t taosThreadEqual(TdThread t1, TdThread t2); +void taosThreadExit(void *valuePtr); +int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param); +void *taosThreadGetSpecific(TdThreadKey key); +int32_t taosThreadJoin(TdThread thread, void **valuePtr); +int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *)); +int32_t taosThreadKeyDelete(TdThreadKey key); +int32_t taosThreadKill(TdThread thread, int32_t sig); +int32_t taosThreadMutexConsistent(TdThreadMutex* mutex); int32_t taosThreadMutexDestroy(TdThreadMutex * mutex); -int32_t taosThreadSpinLock(TdThreadSpinlock *lock); -int32_t taosThreadMutexLock(TdThreadMutex *mutex); -int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock); -int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock); -int32_t taosThreadMutexUnlock(TdThreadMutex *mutex); -int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock); -int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock); -void taosThreadTestCancel(void); -int32_t taosThreadAttrInit(TdThreadAttr *attr); -int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg); -int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void)); -int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState); -int32_t taosThreadAttrDestroy(TdThreadAttr *attr); -int32_t taosThreadJoin(TdThread thread, void **pValue); -int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr); -int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock); -int32_t taosThreadCondSignal(TdThreadCond *cond); -int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr); -int32_t taosThreadCondBroadcast(TdThreadCond *cond); -int32_t taosThreadCondDestroy(TdThreadCond *cond); -int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex); +int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr); +int32_t taosThreadMutexLock(TdThreadMutex * mutex); +int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime); +int32_t taosThreadMutexTryLock(TdThreadMutex * mutex); +int32_t taosThreadMutexUnlock(TdThreadMutex * mutex); +int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr); +int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared); +int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust); +int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind); +int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr); +int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared); +int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust); +int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind); +int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)); +int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock); +int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr); +int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock); +int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime); +int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime); +int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock); +int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock); +int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock); +int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock); +int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr); +int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared); +int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr); +int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared); TdThread taosThreadSelf(void); -int32_t taosThreadEqual(TdThread t1, TdThread t2); -int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset); -int32_t taosThreadCancel(TdThread thread); -int32_t taosThreadKill(TdThread thread, int sig); +int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate); +int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype); +int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param); +int32_t taosThreadSetSpecific(TdThreadKey key, const void *value); +int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock); +int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared); +int32_t taosThreadSpinLock(TdThreadSpinlock * lock); +int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock); +int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock); +void taosThreadTestCancel(void); +int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset); +int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig); + #ifdef __cplusplus } #endif diff --git a/include/os/osTime.h b/include/os/osTime.h index 031b9d28f96405cc0fe71dd8f4cdab024df75539..766fec0fbd9c1a74be89e87fb74bf4d17a0e3453 100644 --- a/include/os/osTime.h +++ b/include/os/osTime.h @@ -20,6 +20,8 @@ extern "C" { #endif +#include + // If the error is in a third-party library, place this header file under the third-party library header file. // When you want to use this feature, you should find or add the same function in the following section. #ifndef ALLOW_FORBID_FUNC @@ -44,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 994ad7afc683397f1dc82ccdf0a4e8e1be29e623..4e2cb7944a7a155aa1d3aa07c8dfbc6148234c17 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -16,7 +16,7 @@ #ifndef _TD_UTIL_TAOS_ERROR_H_ #define _TD_UTIL_TAOS_ERROR_H_ -#include "os.h" +#include #ifdef __cplusplus extern "C" { @@ -78,6 +78,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C) #define TSDB_CODE_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D) #define TSDB_CODE_OUT_OF_SHM_MEM TAOS_DEF_ERROR_CODE(0, 0x010E) +#define TSDB_CODE_INVALID_SHM_ID TAOS_DEF_ERROR_CODE(0, 0x010F) #define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111) #define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112) @@ -478,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 838b175a287f3b1ae408f5be549a1fa8082f7b28..3f00c79f46f28826177c5a38f32b5eb0daa69c9b 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 193be4a3e64c463f96d2932e82c36a49b12bc32b..517cb8baeece2fabf37b178e99d26fed1be2e37c 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -224,6 +224,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 +304,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 (1 * 1440) // 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 +328,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 @@ -381,6 +382,15 @@ typedef enum ELogicConditionType { #define TSDB_MAX_DB_DELAY 10 #define TSDB_DEFAULT_DB_DELAY 2 +#define TSDB_DEFAULT_EXPLAIN_VERBOSE false + +#define TSDB_MIN_EXPLAIN_RATIO 0 +#define TSDB_MAX_EXPLAIN_RATIO 1 +#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 @@ -471,6 +481,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 51ce0243b7ea5d5a5386374cc730f66fee29b8f4..3a47450eecc5d56e346bb0664fc8dc9748118e68 100644 --- a/include/util/tprocess.h +++ b/include/util/tprocess.h @@ -32,29 +32,25 @@ typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int16_t headLen, void ProcFuncType ftype); typedef struct { - int32_t childQueueSize; ProcConsumeFp childConsumeFp; ProcMallocFp childMallocHeadFp; ProcFreeFp childFreeHeadFp; ProcMallocFp childMallocBodyFp; ProcFreeFp childFreeBodyFp; - int32_t parentQueueSize; ProcConsumeFp parentConsumeFp; - ProcMallocFp parentdMallocHeadFp; + ProcMallocFp parentMallocHeadFp; ProcFreeFp parentFreeHeadFp; ProcMallocFp parentMallocBodyFp; ProcFreeFp parentFreeBodyFp; - bool testFlag; + SShm shm; void *pParent; const char *name; + bool isChild; } SProcCfg; SProcObj *taosProcInit(const SProcCfg *pCfg); void taosProcCleanup(SProcObj *pProc); int32_t taosProcRun(SProcObj *pProc); -void taosProcStop(SProcObj *pProc); -bool taosProcIsChild(SProcObj *pProc); -int32_t taosProcChildId(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, diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index a632337d4af61304b6cb9e3ebe3315367aaf0722..8ee6c31ba1d0a64f5ff74dbdb425d720eda33fd5 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 49cb12cccd3de9ffd193c25677c3fc34bed5523c..0749ce9e7dd6bcfdd7b25d9a5eb629c5a56cea0b 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 8e67703ce56d5cf1fad9150f001d4c8e63947913..769870ada8b4338ec6391d2483ce3da753c83dc6 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) { @@ -200,6 +201,9 @@ static void doDestroyRequest(void *p) { taosArrayDestroy(pRequest->body.showInfo.pArray); } + taosArrayDestroy(pRequest->tableList); + taosArrayDestroy(pRequest->dbList); + deregisterRequest(pRequest); taosMemoryFreeClear(pRequest); } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index d8017a8727af05c947323f424c41abc642b91d6d..4e68b5331ff9653502e5256f66200a8c4bb75da8 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; @@ -767,6 +804,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 b1ada016e80a86c507ee203a568599cbd7ff372b..0ca6169883b74398af387d0a25f075f41e8be58a 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -71,6 +71,12 @@ void taos_cleanup(void) { tscInfo("all local resources released"); } +setConfRet taos_set_config(const char *config) { + // TODO + setConfRet ret = {SET_CONF_RET_SUCC, {0}}; + return ret; +} + TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db); if (user == NULL) { @@ -140,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) { @@ -257,6 +263,11 @@ int *taos_fetch_lengths(TAOS_RES *res) { return ((SRequestObj *)res)->body.resInfo.length; } +TAOS_ROW *taos_result_block(TAOS_RES *res) { + // TODO + return NULL; +} + // todo intergrate with tDataTypes const char *taos_data_type(int type) { switch (type) { @@ -353,6 +364,10 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { return colDataIsNull_f(pCol->nullbitmap, row); } +bool taos_is_update_query(TAOS_RES *res) { + return taos_num_fields(res) == 0; +} + int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { if (res == NULL) { return 0; @@ -376,6 +391,14 @@ 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) { + if (taos == NULL) { + return; + } + + resetConnectDB(taos); +} + const char *taos_get_server_info(TAOS *taos) { if (taos == NULL) { return NULL; @@ -407,6 +430,11 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { // TODO } +int taos_load_table_info(TAOS *taos, const char *tableNameList) { + // TODO + return -1; +} + TAOS_STMT *taos_stmt_init(TAOS *taos) { // TODO return NULL; diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index f7593595b0dbb5635214188c4ffb13640d5175fd..426a62433b640d7075a3c09c4e707a9cd3abfee6 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 @@ -241,6 +242,10 @@ void tmq_list_destroy(tmq_list_t* list) { taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree); } +static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) { + return sprintf(dst, "%s:%d", topicName, vg); +} + void tmqClearUnhandleMsg(tmq_t* tmq) { tmq_message_t* msg = NULL; while (1) { @@ -251,6 +256,7 @@ void tmqClearUnhandleMsg(tmq_t* tmq) { break; } + msg = NULL; taosReadAllQitems(tmq->mqueue, tmq->qall); while (1) { taosGetQitem(tmq->qall, (void**)&msg); @@ -306,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); @@ -783,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++) { @@ -827,20 +834,21 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqClientVg* pVg = pParam->pVg; tmq_t* tmq = pParam->tmq; if (code != 0) { - printf("msg discard, code:%x\n", code); - goto WRITE_QUEUE_FAIL; + tscWarn("msg discard, code:%x", code); + 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); - printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch); + tscWarn("discard rsp epoch %d, current epoch %d", msgEpoch, tmqEpoch); return 0; } if (msgEpoch != tmqEpoch) { - printf("mismatch rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch); + tscWarn("mismatch rsp epoch %d, current epoch %d", msgEpoch, tmqEpoch); } else { atomic_sub_fetch_32(&tmq->waitingRequest, 1); } @@ -867,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); @@ -876,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); @@ -888,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); } @@ -898,20 +911,60 @@ 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 sz = taosArrayGetSize(pRsp->topics); - SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic)); - for (int32_t i = 0; i < sz; i++) { + int32_t topicNumGet = taosArrayGetSize(pRsp->topics); + char vgKey[TSDB_TOPIC_FNAME_LEN + 22]; + SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic)); + if (newTopics == NULL) { + return false; + } + SHashObj* pHash = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK); + if (pHash == NULL) { + taosArrayDestroy(newTopics); + return false; + } + + // find topic, build hash + for (int32_t i = 0; i < topicNumGet; i++) { SMqClientTopic topic = {0}; SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i); + taosHashClear(pHash); topic.topicName = strdup(pTopicEp->topic); - int32_t vgSz = taosArrayGetSize(pTopicEp->vgs); - topic.vgs = taosArrayInit(vgSz, sizeof(SMqClientVg)); - for (int32_t j = 0; j < vgSz; j++) { + + int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics); + for (int32_t j = 0; j < topicNumCur; j++) { + // find old topic + SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, j); + if (pTopicCur->vgs && strcmp(pTopicCur->topicName, pTopicEp->topic) == 0) { + int32_t vgNumCur = taosArrayGetSize(pTopicCur->vgs); + if (vgNumCur == 0) break; + 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; + } + } + + int32_t vgNumGet = taosArrayGetSize(pTopicEp->vgs); + topic.vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg)); + for (int32_t j = 0; j < vgNumGet; j++) { SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j); + 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 = pVgEp->offset, + .currentOffset = offset, .vgId = pVgEp->vgId, .epSet = pVgEp->epSet, .vgStatus = TMQ_VG_STATUS__IDLE, @@ -922,6 +975,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { taosArrayPush(newTopics, &topic); } if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics); + taosHashCleanup(pHash); tmq->clientTopics = newTopics; atomic_store_32(&tmq->epoch, epoch); return set; @@ -930,8 +984,9 @@ 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) { - printf("get topic endpoint error, not ready, wait:%d\n", pParam->sync); + tscError("get topic endpoint error, not ready, wait:%d\n", pParam->sync); goto END; } @@ -968,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); } @@ -975,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); @@ -989,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; @@ -1000,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; } @@ -1017,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); @@ -1155,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); @@ -1198,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++; @@ -1207,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; @@ -1244,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");*/ @@ -1252,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); } } @@ -1302,6 +1376,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { while (1) { /*printf("cycle\n");*/ + tmqAskEp(tmq, false); tmqPollImpl(tmq, blocking_time); tsem_wait(&tmq->rspSem); @@ -1493,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 7a958136e7b85c32bbcf894c0c3a82696ce1a65f..fb6640e59eaf129b701249cb87220695c60f6fd9 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -331,7 +331,6 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) { return 0; } - ASSERT(pColInfoData->nullbitmap == NULL); pDataBlock->info.window.skey = *(TSKEY*)colDataGetData(pColInfoData, 0); pDataBlock->info.window.ekey = *(TSKEY*)colDataGetData(pColInfoData, (pDataBlock->info.rows - 1)); return 0; @@ -609,22 +608,6 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) { return sizeof(int32_t) + pBlock->info.numOfCols * sizeof(int32_t); } -SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols) { - SSchema* pSchema = taosMemoryCalloc(pBlock->info.numOfCols, sizeof(SSchema)); - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); - pSchema[i].bytes = pColInfoData->info.bytes; - pSchema[i].type = pColInfoData->info.type; - pSchema[i].colId = pColInfoData->info.colId; - } - - if (numOfCols != NULL) { - *numOfCols = pBlock->info.numOfCols; - } - - return pSchema; -} - double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { ASSERT(pBlock != NULL); double rowSize = 0; @@ -1156,7 +1139,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; } @@ -1198,7 +1181,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; } @@ -1250,6 +1233,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; @@ -1389,6 +1429,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 7fd66e95ad3f0194a1b66953cf0952695e7820d4..1d7a4aeb8fc44e3336e33e6cdc31f4d477157817 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/tglobal.c b/source/common/src/tglobal.c index efd790ade8c143dd40b5cb9b0bfe749e0f57b06f..c79e1531229330ab4611319b77f5305d81d80b95 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -45,7 +45,7 @@ float tsRatioOfQueryCores = 1.0f; int32_t tsMaxBinaryDisplayWidth = 30; bool tsEnableSlaveQuery = 1; bool tsPrintAuth = 0; -int32_t tsMultiProcess = 0; +bool tsMultiProcess = 0; // monitor bool tsEnableMonitor = 1; @@ -347,7 +347,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1; if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1; if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1; + if (cfgAddBool(pCfg, "multiProcess", tsMultiProcess, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1; @@ -466,7 +466,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval; tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval; tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval; - tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->i32; + tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval; tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval; tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c85184ffba5e54dd103713d6613a41e5237e91fe..d75fa6e9c5930934df24230965ded2c9299eaaf2 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -296,24 +296,22 @@ 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); @@ -330,17 +328,15 @@ 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); @@ -370,31 +366,24 @@ 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; @@ -418,23 +407,16 @@ 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; @@ -1629,6 +1611,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 +1633,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/ttime.c b/source/common/src/ttime.c index 510a2809e74b92acecc510b928d9fe288ba9f7db..a65352f2b919f85894996193796f4d2efde15b16 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 0c1bafbeb86f9dc04521d7245193c620b6f42dda..ef75adeb5d69bdd03ca1bd724cdc7bb793364262 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/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 35ea16698378da156fa2caec708944bdef0c1336..81c434eb273e3776bdbb72f24620d9ce1449e61c 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,12 +1,10 @@ -aux_source_directory(src DNODE_SRC) -aux_source_directory(dnode/src DNODE_SRC) -aux_source_directory(qnode/src DNODE_SRC) -aux_source_directory(bnode/src DNODE_SRC) -aux_source_directory(snode/src DNODE_SRC) -aux_source_directory(vnode/src DNODE_SRC) -aux_source_directory(mnode/src DNODE_SRC) -aux_source_directory(container/src DNODE_SRC) - +aux_source_directory(dm/src DNODE_SRC) +aux_source_directory(qm/src DNODE_SRC) +aux_source_directory(bm/src DNODE_SRC) +aux_source_directory(sm/src DNODE_SRC) +aux_source_directory(vm/src DNODE_SRC) +aux_source_directory(mm/src DNODE_SRC) +aux_source_directory(main/src DNODE_SRC) add_library(dnode STATIC ${DNODE_SRC}) target_link_libraries( dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor @@ -14,16 +12,22 @@ target_link_libraries( target_include_directories( dnode PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/snode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/container/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dm/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qm/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bm/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/sm/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vm/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mm/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/main/inc" ) -add_subdirectory(main) +aux_source_directory(main/exe EXEC_SRC) +add_executable(taosd ${EXEC_SRC}) +target_include_directories( + taosd + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/main/inc" +) +target_link_libraries(taosd dnode) if(${BUILD_TEST}) add_subdirectory(test) diff --git a/source/dnode/mgmt/bnode/inc/bm.h b/source/dnode/mgmt/bm/inc/bm.h similarity index 100% rename from source/dnode/mgmt/bnode/inc/bm.h rename to source/dnode/mgmt/bm/inc/bm.h diff --git a/source/dnode/mgmt/bnode/inc/bmInt.h b/source/dnode/mgmt/bm/inc/bmInt.h similarity index 100% rename from source/dnode/mgmt/bnode/inc/bmInt.h rename to source/dnode/mgmt/bm/inc/bmInt.h diff --git a/source/dnode/mgmt/bnode/src/bmInt.c b/source/dnode/mgmt/bm/src/bmInt.c similarity index 100% rename from source/dnode/mgmt/bnode/src/bmInt.c rename to source/dnode/mgmt/bm/src/bmInt.c diff --git a/source/dnode/mgmt/bnode/src/bmMsg.c b/source/dnode/mgmt/bm/src/bmMsg.c similarity index 100% rename from source/dnode/mgmt/bnode/src/bmMsg.c rename to source/dnode/mgmt/bm/src/bmMsg.c diff --git a/source/dnode/mgmt/bnode/src/bmWorker.c b/source/dnode/mgmt/bm/src/bmWorker.c similarity index 100% rename from source/dnode/mgmt/bnode/src/bmWorker.c rename to source/dnode/mgmt/bm/src/bmWorker.c diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c deleted file mode 100644 index 5a9077a93794c36fe356b75c96469b4cc17bd4d4..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/container/src/dndExec.c +++ /dev/null @@ -1,285 +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 void dndResetLog(SMgmtWrapper *pMgmt) { - char logname[24] = {0}; - snprintf(logname, sizeof(logname), "%slog", pMgmt->name); - - dInfo("node:%s, reset log to %s in child process", pMgmt->name, logname); - taosCloseLog(); - taosInitLog(logname, 1); -} - -static bool dndRequireNode(SMgmtWrapper *pWrapper) { - bool required = false; - int32_t code =(*pWrapper->fp.requiredFp)(pWrapper, &required); - if (!required) { - dDebug("node:%s, no need to start", pWrapper->name); - } else { - dDebug("node:%s, need to start", pWrapper->name); - } - return required; -} - -int32_t dndOpenNode(SMgmtWrapper *pWrapper) { - int32_t code = (*pWrapper->fp.openFp)(pWrapper); - if (code != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); - return -1; - } else { - dDebug("node:%s, has been opened", pWrapper->name); - } - - pWrapper->deployed = true; - return 0; -} - -void dndCloseNode(SMgmtWrapper *pWrapper) { - dDebug("node:%s, start to close", pWrapper->name); - pWrapper->required = false; - taosWLockLatch(&pWrapper->latch); - if (pWrapper->deployed) { - (*pWrapper->fp.closeFp)(pWrapper); - pWrapper->deployed = false; - } - taosWUnLockLatch(&pWrapper->latch); - - while (pWrapper->refCount > 0) { - taosMsleep(10); - } - - if (pWrapper->pProc) { - taosProcCleanup(pWrapper->pProc); - pWrapper->pProc = NULL; - } - dDebug("node:%s, has been closed", pWrapper->name); -} - -static int32_t dndRunInSingleProcess(SDnode *pDnode) { - dInfo("dnode run in single process mode"); - - for (ENodeType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); - if (!pWrapper->required) continue; - SMsgCb msgCb = dndCreateMsgcb(pWrapper); - tmsgSetDefaultMsgCb(&msgCb); - - if (taosMkDir(pWrapper->path) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); - return -1; - } - - dInfo("node:%s, will start in single process", pWrapper->name); - pWrapper->procType = PROC_SINGLE; - 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; - } - } - - return 0; -} - -static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) { - // dndCleanupServer(pDnode); - for (ENodeType n = 0; n < NODE_MAX; ++n) { - if (except == n) continue; - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = false; - } -} - -static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, - ProcFuncType ftype) { - SRpcMsg *pRpc = &pMsg->rpcMsg; - pRpc->pCont = pCont; - dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle); - - NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; - int32_t code = (*msgFp)(pWrapper, pMsg); - - if (code != 0) { - dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); - if (pRpc->msgType & 1U) { - SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; - dndSendRsp(pWrapper, &rsp); - } - - dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); - rpcFreeCont(pCont); - } -} - -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); - - switch (ftype) { - case PROC_REG: - rpcRegisterBrokenLinkArg(pMsg); - break; - case PROC_RELEASE: - rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); - rpcFreeCont(pCont); - break; - case PROC_REQ: - // todo send to dnode - dndSendReqToMnode(pWrapper, pMsg); - default: - dndSendRpcRsp(pWrapper, pMsg); - break; - } - taosMemoryFree(pMsg); -} - -static int32_t dndRunInMultiProcess(SDnode *pDnode) { - dInfo("dnode run in multi process mode"); - - for (ENodeType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); - if (!pWrapper->required) continue; - - SMsgCb msgCb = dndCreateMsgcb(pWrapper); - tmsgSetDefaultMsgCb(&msgCb); - - if (taosMkDir(pWrapper->path) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); - return -1; - } - - if (n == DNODE) { - dInfo("node:%s, will start in parent process", pWrapper->name); - pWrapper->procType = PROC_SINGLE; - if (dndOpenNode(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - continue; - } - - SProcCfg cfg = {.childQueueSize = 1024 * 1024 * 2, // size will be a configuration item - .childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, - .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, - .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, - .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .parentQueueSize = 1024 * 1024 * 2, // size will be a configuration item - .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, - .parentdMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, - .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, - .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .pParent = pWrapper, - .name = pWrapper->name}; - SProcObj *pProc = taosProcInit(&cfg); - if (pProc == NULL) { - dError("node:%s, failed to fork since %s", pWrapper->name, terrstr()); - return -1; - } - - pWrapper->pProc = pProc; - - if (taosProcIsChild(pProc)) { - dInfo("node:%s, will start in child process", pWrapper->name); - pWrapper->procType = PROC_CHILD; - dndResetLog(pWrapper); - - dInfo("node:%s, clean up resources inherited from parent", pWrapper->name); - dndClearNodesExecpt(pDnode, n); - - dInfo("node:%s, will be initialized in child process", pWrapper->name); - if (dndOpenNode(pWrapper) != 0) { - dInfo("node:%s, failed to init in child process since %s", pWrapper->name, terrstr()); - return -1; - } - - if (taosProcRun(pProc) != 0) { - dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); - return -1; - } - break; - } else { - dInfo("node:%s, will not start in parent process, child pid:%d", pWrapper->name, taosProcChildId(pProc)); - pWrapper->procType = PROC_PARENT; - if (taosProcRun(pProc) != 0) { - dError("node:%s, failed to run proc 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->procType == PROC_PARENT && n != DNODE) continue; - if (pWrapper->procType == PROC_CHILD && n == DNODE) continue; - if ((*pWrapper->fp.startFp)(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - return 0; -} - -int32_t dndRun(SDnode *pDnode) { - if (tsMultiProcess == 0) { - if (dndRunInSingleProcess(pDnode) != 0) { - dError("failed to run dnode in single process mode since %s", terrstr()); - return -1; - } - } else { - if (dndRunInMultiProcess(pDnode) != 0) { - dError("failed to run dnode in multi process mode since %s", terrstr()); - return -1; - } - } - - dndReportStartup(pDnode, "TDengine", "initialized successfully"); - - while (1) { - if (pDnode->event == DND_EVENT_STOP) { - dInfo("dnode is about to stop"); - break; - } - taosMsleep(100); - } - - return 0; -} diff --git a/source/dnode/mgmt/container/src/dndFile.c b/source/dnode/mgmt/container/src/dndFile.c deleted file mode 100644 index ab04040b57b710c19b33410dbeab87c221b5b243..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/container/src/dndFile.c +++ /dev/null @@ -1,103 +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" - -#define MAXLEN 1024 - -int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { - int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; - int32_t len = 0; - const int32_t maxLen = MAXLEN; - char content[MAXLEN + 1] = {0}; - cJSON *root = NULL; - char file[PATH_MAX]; - TdFilePtr pFile = NULL; - - snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); - pFile = taosOpenFile(file, TD_FILE_READ); - if (pFile == NULL) { - dDebug("file %s not exist", file); - code = 0; - goto _OVER; - } - - len = (int32_t)taosReadFile(pFile, content, maxLen); - if (len <= 0) { - dError("failed to read %s since content is null", file); - goto _OVER; - } - - content[len] = 0; - root = cJSON_Parse(content); - if (root == NULL) { - dError("failed to read %s since invalid json format", file); - goto _OVER; - } - - cJSON *deployed = cJSON_GetObjectItem(root, "deployed"); - if (!deployed || deployed->type != cJSON_Number) { - dError("failed to read %s since deployed not found", file); - goto _OVER; - } - *pDeployed = deployed->valueint != 0; - - code = 0; - dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed); - -_OVER: - if (root != NULL) cJSON_Delete(root); - if (pFile != NULL) taosCloseFile(&pFile); - - terrno = code; - return code; -} - -int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { - char file[PATH_MAX] = {0}; - snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); - - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); - if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to write %s since %s", file, terrstr()); - return -1; - } - - int32_t len = 0; - const int32_t maxLen = MAXLEN; - char content[MAXLEN + 1] = {0}; - - len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed); - len += snprintf(content + len, maxLen - len, "}\n"); - - taosWriteFile(pFile, content, len); - taosFsyncFile(pFile); - taosCloseFile(&pFile); - - char realfile[PATH_MAX] = {0}; - snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); - - if (taosRenameFile(file, realfile) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to rename %s since %s", file, terrstr()); - return -1; - } - - dInfo("successed to write %s, deployed:%d", realfile, deployed); - return 0; -} diff --git a/source/dnode/mgmt/dnode/inc/dm.h b/source/dnode/mgmt/dm/inc/dm.h similarity index 100% rename from source/dnode/mgmt/dnode/inc/dm.h rename to source/dnode/mgmt/dm/inc/dm.h diff --git a/source/dnode/mgmt/dnode/inc/dmInt.h b/source/dnode/mgmt/dm/inc/dmInt.h similarity index 100% rename from source/dnode/mgmt/dnode/inc/dmInt.h rename to source/dnode/mgmt/dm/inc/dmInt.h diff --git a/source/dnode/mgmt/dnode/src/dmFile.c b/source/dnode/mgmt/dm/src/dmFile.c similarity index 98% rename from source/dnode/mgmt/dnode/src/dmFile.c rename to source/dnode/mgmt/dm/src/dmFile.c index d44b1222a32f71a1273fb147166a59182aa65150..d5105bcb1b6fe6eb05dcb7ac499948492b3cc9c0 100644 --- a/source/dnode/mgmt/dnode/src/dmFile.c +++ b/source/dnode/mgmt/dm/src/dmFile.c @@ -130,7 +130,7 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { } code = 0; - dInfo("succcessed to read file %s", file); + dDebug("succcessed to read file %s", file); dmPrintDnodes(pMgmt); PRASE_DNODE_OVER: @@ -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/dnode/src/dmInt.c b/source/dnode/mgmt/dm/src/dmInt.c similarity index 93% rename from source/dnode/mgmt/dnode/src/dmInt.c rename to source/dnode/mgmt/dm/src/dmInt.c index b729888a72e56abac583fa0b1d935bc0822cec95..3c5f394d5e6878bb9b6bc9717f5e3f0b6b8deb43 100644 --- a/source/dnode/mgmt/dnode/src/dmInt.c +++ b/source/dnode/mgmt/dm/src/dmInt.c @@ -112,6 +112,16 @@ int32_t dmInit(SMgmtWrapper *pWrapper) { return -1; } + if (dndInitServer(pDnode) != 0) { + dError("failed to init trans server since %s", terrstr()); + return -1; + } + + if (dndInitClient(pDnode) != 0) { + dError("failed to init trans client since %s", terrstr()); + return -1; + } + pWrapper->pMgmt = pMgmt; dInfo("dnode-mgmt is initialized"); return 0; @@ -122,6 +132,7 @@ void dmCleanup(SMgmtWrapper *pWrapper) { if (pMgmt == NULL) return; dInfo("dnode-mgmt start to clean up"); + SDnode *pDnode = pMgmt->pDnode; dmStopWorker(pMgmt); taosWLockLatch(&pMgmt->latch); @@ -140,6 +151,9 @@ void dmCleanup(SMgmtWrapper *pWrapper) { taosMemoryFree(pMgmt); pWrapper->pMgmt = NULL; + dndCleanupServer(pDnode); + dndCleanupClient(pDnode); + dInfo("dnode-mgmt is cleaned up"); } diff --git a/source/dnode/mgmt/dnode/src/dmMsg.c b/source/dnode/mgmt/dm/src/dmMsg.c similarity index 99% rename from source/dnode/mgmt/dnode/src/dmMsg.c rename to source/dnode/mgmt/dm/src/dmMsg.c index b301ef478b0430f3a09b65f8e17aa6f62fb92052..3795cffbfa2c43ea73f0c211e0e32a9d5284756c 100644 --- a/source/dnode/mgmt/dnode/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/dnode/src/dmWorker.c b/source/dnode/mgmt/dm/src/dmWorker.c similarity index 100% rename from source/dnode/mgmt/dnode/src/dmWorker.c rename to source/dnode/mgmt/dm/src/dmWorker.c diff --git a/source/dnode/mgmt/main/CMakeLists.txt b/source/dnode/mgmt/main/CMakeLists.txt deleted file mode 100644 index baa486b91fe3d039a127b47c76576ded80d3c1b9..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/main/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -aux_source_directory(src EXEC_SRC) -add_executable(taosd ${EXEC_SRC}) - -target_include_directories( - taosd - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) - -target_link_libraries(taosd dnode) diff --git a/source/dnode/mgmt/main/exe/dndMain.c b/source/dnode/mgmt/main/exe/dndMain.c new file mode 100644 index 0000000000000000000000000000000000000000..0d2ddbfbbc3f55268e4e3fa1d9263ec70ae3f03f --- /dev/null +++ b/source/dnode/mgmt/main/exe/dndMain.c @@ -0,0 +1,211 @@ +/* + * 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 "dnd.h" +#include "tconfig.h" + +static struct { + bool dumpConfig; + bool generateGrant; + bool printAuth; + bool printVersion; + char envFile[PATH_MAX]; + char apolloUrl[PATH_MAX]; + SArray *pArgs; // SConfigPair + SDnode *pDnode; + ENodeType ntype; +} global = {0}; + +static void dndStopDnode(int signum, void *info, void *ctx) { + dInfo("system signal:%d received", signum); + SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); + if (pDnode != NULL) { + dndHandleEvent(pDnode, DND_EVENT_STOP); + } +} + +static void dndSetSignalHandle() { + taosSetSignal(SIGTERM, dndStopDnode); + taosSetSignal(SIGHUP, dndStopDnode); + taosSetSignal(SIGINT, dndStopDnode); + taosSetSignal(SIGABRT, dndStopDnode); + taosSetSignal(SIGBREAK, dndStopDnode); + + if (!tsMultiProcess) { + } else if (global.ntype == DNODE || global.ntype == NODE_MAX) { + taosIgnSignal(SIGCHLD); + } else { + taosKillChildOnParentStopped(); + } +} + +static int32_t dndParseArgs(int32_t argc, char const *argv[]) { + for (int32_t i = 1; i < argc; ++i) { + if (strcmp(argv[i], "-c") == 0) { + if (i < argc - 1) { + if (strlen(argv[++i]) >= PATH_MAX) { + printf("config file path overflow"); + return -1; + } + tstrncpy(configDir, argv[i], PATH_MAX); + } else { + printf("'-c' requires a parameter, default is %s\n", configDir); + return -1; + } + } else if (strcmp(argv[i], "-a") == 0) { + 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], "-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"); + 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) { + global.printVersion = true; + } else { + } + } + + return 0; +} + +static void dndGenerateGrant() { + // grantParseParameter(); + printf("this feature is not implemented yet\n"); +} + +static void dndPrintVersion() { +#ifdef TD_ENTERPRISE + char *releaseName = "enterprise"; +#else + char *releaseName = "community"; +#endif + printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); + printf("gitinfo: %s\n", gitinfo); + printf("buildInfo: %s\n", buildinfo); +} + +static void dndDumpCfg() { + SConfig *pCfg = taosGetCfg(); + cfgDumpCfg(pCfg, 0, 1); +} + +static SDnodeOpt dndGetOpt() { + SConfig *pCfg = taosGetCfg(); + SDnodeOpt option = {0}; + + option.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; + tstrncpy(option.dataDir, tsDataDir, sizeof(option.dataDir)); + tstrncpy(option.firstEp, tsFirst, sizeof(option.firstEp)); + tstrncpy(option.secondEp, tsSecond, sizeof(option.firstEp)); + option.serverPort = tsServerPort; + tstrncpy(option.localFqdn, tsLocalFqdn, sizeof(option.localFqdn)); + snprintf(option.localEp, sizeof(option.localEp), "%s:%u", option.localFqdn, option.serverPort); + option.disks = tsDiskCfg; + option.numOfDisks = tsDiskCfgNum; + option.ntype = global.ntype; + return option; +} + +static int32_t dndInitLog() { + char logName[12] = {0}; + snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype)); + return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); +} + +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(argc, argv, name); + } +} + +static int32_t dndRunDnode() { + if (dndInit() != 0) { + 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 since %s", terrstr()); + return -1; + } else { + global.pDnode = pDnode; + dndSetSignalHandle(); + } + + dInfo("start the service"); + int32_t code = dndRun(pDnode); + dInfo("start shutting down the service"); + + global.pDnode = NULL; + dndClose(pDnode); + dndCleanup(); + taosCloseLog(); + taosCleanupCfg(); + return code; +} + +int main(int argc, char const *argv[]) { + if (!taosCheckSystemIsSmallEnd()) { + printf("failed to start since on non-small-end machines\n"); + return -1; + } + + if (dndParseArgs(argc, argv) != 0) { + printf("failed to start since parse args error\n"); + return -1; + } + + if (global.generateGrant) { + dndGenerateGrant(); + return 0; + } + + if (global.printVersion) { + dndPrintVersion(); + return 0; + } + + if (dndInitLog() != 0) { + printf("failed to start since init log error\n"); + return -1; + } + + if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { + dError("failed to start since read config error"); + return -1; + } + + if (global.dumpConfig) { + dndDumpCfg(); + taosCleanupCfg(); + taosCloseLog(); + return 0; + } + + dndSetProcInfo(argc, (char **)argv); + return dndRunDnode(); +} diff --git a/source/dnode/mgmt/container/inc/dnd.h b/source/dnode/mgmt/main/inc/dnd.h similarity index 85% rename from source/dnode/mgmt/container/inc/dnd.h rename to source/dnode/mgmt/main/inc/dnd.h index 57f127ec26729f50ce33fd4c6e7c528a7d3727f1..b9c760c980f214a82bf557bcd3a7196b2b37a9c6 100644 --- a/source/dnode/mgmt/container/inc/dnd.h +++ b/source/dnode/mgmt/main/inc/dnd.h @@ -95,12 +95,14 @@ typedef struct SMgmtWrapper { bool deployed; bool required; EProcType procType; + int32_t procId; SProcObj *pProc; + SShm shm; void *pMgmt; SDnode *pDnode; - NodeMsgFp msgFps[TDMT_MAX]; - int32_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode SMgmtFp fp; + int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode + NodeMsgFp msgFps[TDMT_MAX]; } SMgmtWrapper; typedef struct { @@ -119,31 +121,39 @@ typedef struct SDnode { char *firstEp; char *secondEp; char *dataDir; - SDiskCfg *pDisks; + SDiskCfg *disks; int32_t numOfDisks; uint16_t serverPort; bool dropped; + ENodeType ntype; EDndStatus status; EDndEvent event; SStartupReq startup; - TdFilePtr pLockFile; + TdFilePtr lockfile; STransMgmt trans; SMgmtWrapper wrappers[NODE_MAX]; } SDnode; -EDndStatus dndGetStatus(SDnode *pDnode); -void dndSetStatus(SDnode *pDnode, EDndStatus stat); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndSendMonitorReport(SDnode *pDnode); - +const char *dndNodeLogStr(ENodeType ntype); +const char *dndNodeProcStr(ENodeType ntype); +const char *dndEventStr(EDndEvent ev); +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); + +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); void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); -int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg); int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); diff --git a/source/dnode/mgmt/container/inc/dndInt.h b/source/dnode/mgmt/main/inc/dndInt.h similarity index 87% rename from source/dnode/mgmt/container/inc/dndInt.h rename to source/dnode/mgmt/main/inc/dndInt.h index 0f0cc78a1d088474c5ae04043f38df64f31a5b08..612d35d513ec8b78bdecd91602225c3c69cbdcfa 100644 --- a/source/dnode/mgmt/container/inc/dndInt.h +++ b/source/dnode/mgmt/main/inc/dndInt.h @@ -34,7 +34,6 @@ int32_t dndInit(); void dndCleanup(); const char *dndStatStr(EDndStatus stat); void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup); -TdFilePtr dndCheckRunning(const char *dataDir); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); // dndMsg.c @@ -51,13 +50,14 @@ void dndClose(SDnode *pDnode); void dndHandleEvent(SDnode *pDnode, EDndEvent event); // dndTransport.c -int32_t dndInitServer(SDnode *pDnode); -void dndCleanupServer(SDnode *pDnode); -int32_t dndInitClient(SDnode *pDnode); -void dndCleanupClient(SDnode *pDnode); int32_t dndInitMsgHandle(SDnode *pDnode); void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); +// dndFile.c +TdFilePtr dndCheckRunning(const char *dataDir); +int32_t dndReadShmFile(SDnode *pDnode); +int32_t dndWriteShmFile(SDnode *pDnode); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/main/inc/dndMain.h b/source/dnode/mgmt/main/inc/dndMain.h deleted file mode 100644 index 1958d628a0ad2ba2a2c28c4a835ee6a5ff13f37e..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/main/inc/dndMain.h +++ /dev/null @@ -1,48 +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 . - */ - -#ifndef _TD_DND_MAIN_H_ -#define _TD_DND_MAIN_H_ - -#include "dnode.h" - -#include "taoserror.h" -#include "tconfig.h" -#include "tglobal.h" -#include "tlog.h" -#include "version.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} -#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} -#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} -#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }} -#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} -#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} - -void dndDumpCfg(); -void dndPrintVersion(); -void dndGenerateGrant(); -SDnodeOpt dndGetOpt(); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DND_MAIN_H_*/ diff --git a/source/dnode/mgmt/container/src/dndInt.c b/source/dnode/mgmt/main/src/dndEnv.c similarity index 70% rename from source/dnode/mgmt/container/src/dndInt.c rename to source/dnode/mgmt/main/src/dndEnv.c index 33d6bb0ee33822a0ce758b4a1887047e6a711c73..879214782289449015a2c7dcc01ed4c9a1c2afbd 100644 --- a/source/dnode/mgmt/container/src/dndInt.c +++ b/source/dnode/mgmt/main/src/dndEnv.c @@ -20,7 +20,7 @@ static int8_t once = DND_ENV_INIT; int32_t dndInit() { - dInfo("start to init dnode env"); + 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()); @@ -31,12 +31,6 @@ int32_t dndInit() { taosBlockSIGPIPE(); taosResolveCRC(); - if (rpcInit() != 0) { - dError("failed to init rpc since %s", terrstr()); - dndCleanup(); - return -1; - } - SMonCfg monCfg = {0}; monCfg.maxLogs = tsMonitorMaxLogs; monCfg.port = tsMonitorPort; @@ -44,7 +38,6 @@ int32_t dndInit() { monCfg.comp = tsMonitorComp; if (monInit(&monCfg) != 0) { dError("failed to init monitor since %s", terrstr()); - dndCleanup(); return -1; } @@ -53,20 +46,19 @@ int32_t dndInit() { } void dndCleanup() { - dInfo("start to cleanup dnode env"); + 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(); - rpcCleanup(); walCleanUp(); taosStopCacheRefreshWorker(); dInfo("dnode env is cleaned up"); } -void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId) { +void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp; pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; } @@ -80,19 +72,6 @@ void dndSetStatus(SDnode *pDnode, EDndStatus status) { } } -const char *dndStatStr(EDndStatus status) { - switch (status) { - case DND_STAT_INIT: - return "init"; - case DND_STAT_RUNNING: - return "running"; - case DND_STAT_STOPPED: - return "stopped"; - default: - return "unknown"; - } -} - void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { SStartupReq *pStartup = &pDnode->startup; tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); @@ -105,29 +84,6 @@ void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); } -TdFilePtr dndCheckRunning(const char *dataDir) { - char filepath[PATH_MAX] = {0}; - snprintf(filepath, sizeof(filepath), "%s/.running", dataDir); - - TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); - if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to lock file:%s since %s", filepath, terrstr()); - return NULL; - } - - int32_t ret = taosLockFile(pFile); - if (ret != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to lock file:%s since %s", filepath, terrstr()); - taosCloseFile(&pFile); - return NULL; - } - - dDebug("file:%s is locked", filepath); - return pFile; -} - void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { dDebug("startup req is received"); SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); diff --git a/source/dnode/mgmt/main/src/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c new file mode 100644 index 0000000000000000000000000000000000000000..b37893aa6f3dee977c9219b198a7c2d34b6174fa --- /dev/null +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -0,0 +1,360 @@ +/* + * 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 bool dndRequireNode(SMgmtWrapper *pWrapper) { + bool required = false; + int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required); + if (!required) { + dDebug("node:%s, does not require startup", pWrapper->name); + } else { + dDebug("node:%s, needs to be started", pWrapper->name); + } + return required; +} + +int32_t dndOpenNode(SMgmtWrapper *pWrapper) { + if (taosMkDir(pWrapper->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr()); + return -1; + } + + if ((*pWrapper->fp.openFp)(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; + } + + dDebug("node:%s, has been opened", pWrapper->name); + pWrapper->deployed = true; + return 0; +} + +void dndCloseNode(SMgmtWrapper *pWrapper) { + dDebug("node:%s, start to close", pWrapper->name); + pWrapper->required = false; + taosWLockLatch(&pWrapper->latch); + if (pWrapper->deployed) { + (*pWrapper->fp.closeFp)(pWrapper); + pWrapper->deployed = false; + } + taosWUnLockLatch(&pWrapper->latch); + + while (pWrapper->refCount > 0) { + taosMsleep(10); + } + + if (pWrapper->pProc) { + taosProcCleanup(pWrapper->pProc); + pWrapper->pProc = NULL; + } + dDebug("node:%s, has been closed", pWrapper->name); +} + +static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + ProcFuncType ftype) { + SRpcMsg *pRpc = &pMsg->rpcMsg; + pRpc->pCont = pCont; + dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle); + + NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; + int32_t code = (*msgFp)(pWrapper, pMsg); + + if (code != 0) { + dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); + if (pRpc->msgType & 1U) { + SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; + dndSendRsp(pWrapper, &rsp); + } + + dTrace("msg:%p, is freed", pMsg); + taosFreeQitem(pMsg); + rpcFreeCont(pCont); + } +} + +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); + + switch (ftype) { + case PROC_REG: + rpcRegisterBrokenLinkArg(pMsg); + break; + case PROC_RELEASE: + rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); + rpcFreeCont(pCont); + break; + case PROC_REQ: + // todo send to dnode + dndSendReqToMnode(pWrapper, pMsg); + default: + dndSendRpcRsp(pWrapper, pMsg); + 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"); + break; + } + taosMsleep(100); + } + + return 0; +} + +static int32_t dndRunInParentProcess(SDnode *pDnode) { + 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()); + return -1; + } + + for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + pWrapper->required = dndRequireNode(pWrapper); + if (!pWrapper->required) continue; + + int32_t shmsize = 1024 * 1024 * 2; // size will be a configuration item + if (taosCreateShm(&pWrapper->shm, shmsize) != 0) { + terrno = TAOS_SYSTEM_ERROR(terrno); + 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 = dndGenProcCfg(pWrapper); + cfg.isChild = false; + pWrapper->procType = PROC_PARENT; + pWrapper->pProc = taosProcInit(&cfg); + if (pWrapper->pProc == NULL) { + dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); + return -1; + } + } + + if (dndWriteShmFile(pDnode) != 0) { + dError("failed to write runtime file since %s", terrstr()); + return -1; + } + + for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + + if (pDnode->ntype == NODE_MAX) { + dInfo("node:%s, should be started manually", pWrapper->name); + } else { + if (dndNewProc(pWrapper, n) != 0) { + return -1; + } + } + + if (taosProcRun(pWrapper->pProc) != 0) { + dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); + return -1; + } + } + + dndSetStatus(pDnode, DND_STAT_RUNNING); + + if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) { + dError("node:%s, failed to start since %s", pDWrapper->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"); + 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); + } + } + + 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, 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) { + 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); + pWrapper->procType = PROC_CHILD; + + if (dndOpenNode(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + + 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()); + return -1; + } + + if (pWrapper->fp.startFp != NULL) { + if ((*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + + if (taosProcRun(pWrapper->pProc) != 0) { + dError("node:%s, failed to run proc 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"); + break; + } + taosMsleep(100); + } +} + +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 new file mode 100644 index 0000000000000000000000000000000000000000..92e6cea3e1372c95bb3d763a979d90b7399b211d --- /dev/null +++ b/source/dnode/mgmt/main/src/dndFile.c @@ -0,0 +1,269 @@ +/* + * 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" + +#define MAXLEN 1024 + +int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { + int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; + int64_t len = 0; + char content[MAXLEN + 1] = {0}; + cJSON *root = NULL; + char file[PATH_MAX]; + TdFilePtr pFile = NULL; + + snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); + pFile = taosOpenFile(file, TD_FILE_READ); + if (pFile == NULL) { + dDebug("file %s not exist", file); + code = 0; + goto _OVER; + } + + len = taosReadFile(pFile, content, MAXLEN); + if (len <= 0) { + dError("failed to read %s since content is null", file); + goto _OVER; + } + + root = cJSON_Parse(content); + if (root == NULL) { + dError("failed to read %s since invalid json format", file); + goto _OVER; + } + + cJSON *deployed = cJSON_GetObjectItem(root, "deployed"); + if (!deployed || deployed->type != cJSON_Number) { + dError("failed to read %s since deployed not found", file); + goto _OVER; + } + *pDeployed = deployed->valueint != 0; + + dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed); + code = 0; + +_OVER: + if (root != NULL) cJSON_Delete(root); + if (pFile != NULL) taosCloseFile(&pFile); + + terrno = code; + return code; +} + +int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { + int32_t code = -1; + int32_t len = 0; + char content[MAXLEN + 1] = {0}; + char file[PATH_MAX] = {0}; + char realfile[PATH_MAX] = {0}; + TdFilePtr pFile = NULL; + + snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); + snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); + + pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to write %s since %s", file, terrstr()); + goto _OVER; + } + + len += snprintf(content + len, MAXLEN - len, "{\n"); + len += snprintf(content + len, MAXLEN - len, " \"deployed\": %d\n", deployed); + len += snprintf(content + len, MAXLEN - len, "}\n"); + + if (taosWriteFile(pFile, content, len) != len) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to write file:%s since %s", file, terrstr()); + goto _OVER; + } + + if (taosFsyncFile(pFile) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to fsync file:%s since %s", file, terrstr()); + goto _OVER; + } + + taosCloseFile(&pFile); + + if (taosRenameFile(file, realfile) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to rename %s since %s", file, terrstr()); + return -1; + } + + dInfo("successed to write %s, deployed:%d", realfile, deployed); + code = 0; + +_OVER: + if (pFile != NULL) { + taosCloseFile(&pFile); + } + + return code; +} + +TdFilePtr dndCheckRunning(const char *dataDir) { + char filepath[PATH_MAX] = {0}; + snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP); + + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to lock file:%s since %s", filepath, terrstr()); + return NULL; + } + + int32_t ret = taosLockFile(pFile); + if (ret != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to lock file:%s since %s", filepath, terrstr()); + taosCloseFile(&pFile); + return NULL; + } + + dDebug("file:%s is locked", filepath); + return pFile; +} + +int32_t dndReadShmFile(SDnode *pDnode) { + int32_t code = -1; + char itemName[24] = {0}; + char content[MAXLEN + 1] = {0}; + char file[PATH_MAX] = {0}; + cJSON *root = NULL; + TdFilePtr pFile = NULL; + + snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); + pFile = taosOpenFile(file, TD_FILE_READ); + if (pFile == NULL) { + dDebug("file %s not exist", file); + code = 0; + goto _OVER; + } + + if (taosReadFile(pFile, content, MAXLEN) > 0) { + root = cJSON_Parse(content); + if (root == NULL) { + terrno = TSDB_CODE_NODE_PARSE_FILE_ERROR; + dError("failed to read %s since invalid json format", file); + goto _OVER; + } + + for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { + snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype)); + cJSON *shmid = cJSON_GetObjectItem(root, itemName); + if (shmid && shmid->type == cJSON_Number) { + pDnode->wrappers[ntype].shm.id = shmid->valueint; + } + + snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype)); + cJSON *shmsize = cJSON_GetObjectItem(root, itemName); + if (shmsize && shmsize->type == cJSON_Number) { + pDnode->wrappers[ntype].shm.size = shmsize->valueint; + } + } + } + + 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) { + dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size); + taosDropShm(&pWrapper->shm); + } + } + } else { + SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; + if (taosAttachShm(&pWrapper->shm) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr()); + goto _OVER; + } + dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->shm.id, pWrapper->shm.size); + } + + dDebug("successed to load %s", file); + code = 0; + +_OVER: + if (root != NULL) cJSON_Delete(root); + if (pFile != NULL) taosCloseFile(&pFile); + + return code; +} + +int32_t dndWriteShmFile(SDnode *pDnode) { + int32_t code = -1; + int32_t len = 0; + char content[MAXLEN + 1] = {0}; + char file[PATH_MAX] = {0}; + char realfile[PATH_MAX] = {0}; + TdFilePtr pFile = NULL; + + snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); + + pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to open file:%s since %s", file, terrstr()); + goto _OVER; + } + + len += snprintf(content + len, MAXLEN - len, "{\n"); + for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; + len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.id); + if (ntype == NODE_MAX - 1) { + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->shm.size); + } else { + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.size); + } + } + len += snprintf(content + len, MAXLEN - len, "}\n"); + + if (taosWriteFile(pFile, content, len) != len) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to write file:%s since %s", file, terrstr()); + goto _OVER; + } + + if (taosFsyncFile(pFile) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to fsync file:%s since %s", file, terrstr()); + goto _OVER; + } + + taosCloseFile(&pFile); + + if (taosRenameFile(file, realfile) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to rename %s to %s since %s", file, realfile, terrstr()); + return -1; + } + + dInfo("successed to write %s", realfile); + code = 0; + +_OVER: + if (pFile != NULL) { + taosCloseFile(&pFile); + } + + return code; +} diff --git a/source/dnode/mgmt/container/src/dndObj.c b/source/dnode/mgmt/main/src/dndInt.c similarity index 77% rename from source/dnode/mgmt/container/src/dndObj.c rename to source/dnode/mgmt/main/src/dndInt.c index b9ea8df8080f6cd63ec738f1a65a9b9398d3dd0e..602ebc6b3cfcfa2177b511bd48b49ba68272ceca 100644 --- a/source/dnode/mgmt/container/src/dndObj.c +++ b/source/dnode/mgmt/main/src/dndInt.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "dndInt.h" -static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { +static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes; pDnode->serverPort = pOption->serverPort; pDnode->dataDir = strdup(pOption->dataDir); @@ -24,8 +24,9 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->localFqdn = strdup(pOption->localFqdn); pDnode->firstEp = strdup(pOption->firstEp); pDnode->secondEp = strdup(pOption->secondEp); - pDnode->pDisks = pOption->pDisks; + 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 || @@ -33,18 +34,26 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { 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 dndClearMemory(SDnode *pDnode) { +static void dndClearVars(SDnode *pDnode) { for (ENodeType n = 0; n < NODE_MAX; ++n) { SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; taosMemoryFreeClear(pMgmt->path); } - if (pDnode->pLockFile != NULL) { - taosUnLockFile(pDnode->pLockFile); - taosCloseFile(&pDnode->pLockFile); - pDnode->pLockFile = NULL; + if (pDnode->lockfile != NULL) { + taosUnLockFile(pDnode->lockfile); + taosCloseFile(&pDnode->lockfile); + pDnode->lockfile = NULL; } taosMemoryFreeClear(pDnode->localEp); taosMemoryFreeClear(pDnode->localFqdn); @@ -52,11 +61,11 @@ static void dndClearMemory(SDnode *pDnode) { taosMemoryFreeClear(pDnode->secondEp); taosMemoryFreeClear(pDnode->dataDir); taosMemoryFree(pDnode); - dDebug("dnode object memory is cleared, data:%p", pDnode); + dDebug("dnode memory is cleared, data:%p", pDnode); } SDnode *dndCreate(const SDnodeOpt *pOption) { - dInfo("start to create dnode object"); + dDebug("start to create dnode object"); int32_t code = -1; char path[PATH_MAX] = {0}; SDnode *pDnode = NULL; @@ -67,26 +76,12 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { goto _OVER; } - if (dndInitMemory(pDnode, pOption) != 0) { + if (dndInitVars(pDnode, pOption) != 0) { + dError("failed to init variables since %s", terrstr()); goto _OVER; } dndSetStatus(pDnode, DND_STAT_INIT); - pDnode->pLockFile = dndCheckRunning(pDnode->dataDir); - if (pDnode->pLockFile == NULL) { - goto _OVER; - } - - if (dndInitServer(pDnode) != 0) { - dError("failed to init trans server since %s", terrstr()); - goto _OVER; - } - - if (dndInitClient(pDnode) != 0) { - dError("failed to init trans client since %s", terrstr()); - goto _OVER; - } - dmGetMgmtFp(&pDnode->wrappers[DNODE]); mmGetMgmtFp(&pDnode->wrappers[MNODE]); vmGetMgmtFp(&pDnode->wrappers[VNODES]); @@ -94,14 +89,11 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { smGetMgmtFp(&pDnode->wrappers[SNODE]); bmGetMgmtFp(&pDnode->wrappers[BNODE]); - if (dndInitMsgHandle(pDnode) != 0) { - goto _OVER; - } - 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; @@ -112,15 +104,27 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { 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) { - dndClearMemory(pDnode); + dndClearVars(pDnode); pDnode = NULL; - dError("failed to create dnode object since %s", terrstr()); - } else { - dInfo("dnode object is created, data:%p", pDnode); + dError("failed to create dnode since %s", terrstr()); } return pDnode; @@ -137,21 +141,20 @@ void dndClose(SDnode *pDnode) { dInfo("start to close dnode, data:%p", pDnode); dndSetStatus(pDnode, DND_STAT_STOPPED); - dndCleanupServer(pDnode); - dndCleanupClient(pDnode); - for (ENodeType n = 0; n < NODE_MAX; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; dndCloseNode(pWrapper); } - dndClearMemory(pDnode); - dInfo("dnode object is closed, data:%p", pDnode); + dndClearVars(pDnode); + dInfo("dnode is closed, data:%p", pDnode); } void dndHandleEvent(SDnode *pDnode, EDndEvent event) { - dInfo("dnode object receive event %d, data:%p", event, pDnode); - pDnode->event = event; + dInfo("dnode receive %s event, data:%p", dndEventStr(event), pDnode); + if (event == DND_EVENT_STOP) { + pDnode->event = event; + } } SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType ntype) { diff --git a/source/dnode/mgmt/main/src/dndMain.c b/source/dnode/mgmt/main/src/dndMain.c deleted file mode 100644 index 3aff3446dac278ff38636c6dfca633b25c0a2afd..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/main/src/dndMain.c +++ /dev/null @@ -1,138 +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 "dndMain.h" - -static struct { - bool dumpConfig; - bool generateGrant; - bool printAuth; - bool printVersion; - char envFile[PATH_MAX]; - char apolloUrl[PATH_MAX]; - SDnode *pDnode; -} global = {0}; - -static void dndSigintHandle(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 dndSetSignalHandle() { - taosSetSignal(SIGTERM, dndSigintHandle); - taosSetSignal(SIGHUP, dndSigintHandle); - taosSetSignal(SIGINT, dndSigintHandle); - taosSetSignal(SIGABRT, dndSigintHandle); - taosSetSignal(SIGBREAK, dndSigintHandle); -} - -static int32_t dndParseOption(int32_t argc, char const *argv[]) { - for (int32_t i = 1; i < argc; ++i) { - if (strcmp(argv[i], "-c") == 0) { - if (i < argc - 1) { - if (strlen(argv[++i]) >= PATH_MAX) { - printf("config file path overflow"); - return -1; - } - tstrncpy(configDir, argv[i], PATH_MAX); - } else { - printf("'-c' requires a parameter, default is %s\n", configDir); - return -1; - } - } else if (strcmp(argv[i], "-C") == 0) { - global.dumpConfig = true; - } else if (strcmp(argv[i], "-k") == 0) { - global.generateGrant = true; - } else if (strcmp(argv[i], "-V") == 0) { - global.printVersion = true; - } else { - } - } - - return 0; -} - -static int32_t dndRunDnode() { - if (dndInit() != 0) { - dInfo("failed to initialize dnode 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()); - return -1; - } else { - global.pDnode = pDnode; - dndSetSignalHandle(); - } - - dInfo("start the TDengine service"); - int32_t code = dndRun(pDnode); - dInfo("start shutting down the TDengine service"); - - global.pDnode = NULL; - dndClose(pDnode); - dndCleanup(); - taosCloseLog(); - taosCleanupCfg(); - return code; -} - -int main(int argc, char const *argv[]) { - if (!taosCheckSystemIsSmallEnd()) { - dError("failed to start TDengine since on non-small-end machines"); - return -1; - } - - if (dndParseOption(argc, argv) != 0) { - return -1; - } - - if (global.generateGrant) { - dndGenerateGrant(); - return 0; - } - - if (global.printVersion) { - dndPrintVersion(); - return 0; - } - - if (taosCreateLog("taosdlog", 1, configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) { - dError("failed to start TDengine since read log config error"); - return -1; - } - - if (taosInitCfg(configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) { - dError("failed to start TDengine since read config error"); - return -1; - } - - if (global.dumpConfig) { - dndDumpCfg(); - taosCleanupCfg(); - taosCloseLog(); - return 0; - } - - return dndRunDnode(); -} diff --git a/source/dnode/mgmt/container/src/dndMonitor.c b/source/dnode/mgmt/main/src/dndMonitor.c similarity index 100% rename from source/dnode/mgmt/container/src/dndMonitor.c rename to source/dnode/mgmt/main/src/dndMonitor.c diff --git a/source/dnode/mgmt/container/src/dndMsg.c b/source/dnode/mgmt/main/src/dndMsg.c similarity index 98% rename from source/dnode/mgmt/container/src/dndMsg.c rename to source/dnode/mgmt/main/src/dndMsg.c index 3aafa5a5e381b616b194fc31ac583ffdbfa80142..2ab1e401c7385c377a410608c40736a898406f39 100644 --- a/source/dnode/mgmt/container/src/dndMsg.c +++ b/source/dnode/mgmt/main/src/dndMsg.c @@ -66,7 +66,7 @@ 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, + 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 { diff --git a/source/dnode/mgmt/main/src/dndStr.c b/source/dnode/mgmt/main/src/dndStr.c new file mode 100644 index 0000000000000000000000000000000000000000..8a5af68b4fb33101f9c8a954942253e9700ca092 --- /dev/null +++ b/source/dnode/mgmt/main/src/dndStr.c @@ -0,0 +1,77 @@ +/* + * 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" + +const char *dndStatStr(EDndStatus status) { + switch (status) { + case DND_STAT_INIT: + return "init"; + case DND_STAT_RUNNING: + return "running"; + case DND_STAT_STOPPED: + return "stopped"; + default: + return "unknown"; + } +} + +const char *dndNodeLogStr(ENodeType ntype) { + switch (ntype) { + case VNODES: + return "vnode"; + case QNODE: + return "qnode"; + case SNODE: + return "snode"; + case MNODE: + return "mnode"; + case BNODE: + return "bnode"; + default: + return "taosd"; + } +} + +const char *dndNodeProcStr(ENodeType ntype) { + switch (ntype) { + case VNODES: + return "taosv"; + case QNODE: + return "taosq"; + case SNODE: + return "taoss"; + case MNODE: + return "taosm"; + case BNODE: + return "taosb"; + default: + 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/container/src/dndTransport.c b/source/dnode/mgmt/main/src/dndTransport.c similarity index 100% rename from source/dnode/mgmt/container/src/dndTransport.c rename to source/dnode/mgmt/main/src/dndTransport.c diff --git a/source/dnode/mgmt/main/src/dndUtil.c b/source/dnode/mgmt/main/src/dndUtil.c deleted file mode 100644 index e07ef68c774fb70f789cd00d43d37a0a21b504f9..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/main/src/dndUtil.c +++ /dev/null @@ -1,55 +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 "dndMain.h" - -void dndGenerateGrant() { -#if 0 - grantParseParameter(); -#endif -} - -void dndPrintVersion() { -#ifdef TD_ENTERPRISE - char *releaseName = "enterprise"; -#else - char *releaseName = "community"; -#endif - printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); - printf("gitinfo: %s\n", gitinfo); - printf("builuInfo: %s\n", buildinfo); -} - -void dndDumpCfg() { - SConfig *pCfg = taosGetCfg(); - cfgDumpCfg(pCfg, 0, 1); -} - -SDnodeOpt dndGetOpt() { - SConfig *pCfg = taosGetCfg(); - SDnodeOpt option = {0}; - - option.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; - tstrncpy(option.dataDir, tsDataDir, sizeof(option.dataDir)); - tstrncpy(option.firstEp, tsFirst, sizeof(option.firstEp)); - tstrncpy(option.secondEp, tsSecond, sizeof(option.firstEp)); - option.serverPort = tsServerPort; - tstrncpy(option.localFqdn, tsLocalFqdn, sizeof(option.localFqdn)); - snprintf(option.localEp, sizeof(option.localEp), "%s:%u", option.localFqdn, option.serverPort); - option.pDisks = tsDiskCfg; - option.numOfDisks = tsDiskCfgNum; - return option; -} diff --git a/source/dnode/mgmt/mnode/inc/mm.h b/source/dnode/mgmt/mm/inc/mm.h similarity index 100% rename from source/dnode/mgmt/mnode/inc/mm.h rename to source/dnode/mgmt/mm/inc/mm.h diff --git a/source/dnode/mgmt/mnode/inc/mmInt.h b/source/dnode/mgmt/mm/inc/mmInt.h similarity index 100% rename from source/dnode/mgmt/mnode/inc/mmInt.h rename to source/dnode/mgmt/mm/inc/mmInt.h diff --git a/source/dnode/mgmt/mnode/src/mmFile.c b/source/dnode/mgmt/mm/src/mmFile.c similarity index 100% rename from source/dnode/mgmt/mnode/src/mmFile.c rename to source/dnode/mgmt/mm/src/mmFile.c diff --git a/source/dnode/mgmt/mnode/src/mmInt.c b/source/dnode/mgmt/mm/src/mmInt.c similarity index 100% rename from source/dnode/mgmt/mnode/src/mmInt.c rename to source/dnode/mgmt/mm/src/mmInt.c diff --git a/source/dnode/mgmt/mnode/src/mmMsg.c b/source/dnode/mgmt/mm/src/mmMsg.c similarity index 100% rename from source/dnode/mgmt/mnode/src/mmMsg.c rename to source/dnode/mgmt/mm/src/mmMsg.c diff --git a/source/dnode/mgmt/mnode/src/mmWorker.c b/source/dnode/mgmt/mm/src/mmWorker.c similarity index 100% rename from source/dnode/mgmt/mnode/src/mmWorker.c rename to source/dnode/mgmt/mm/src/mmWorker.c diff --git a/source/dnode/mgmt/qnode/inc/qm.h b/source/dnode/mgmt/qm/inc/qm.h similarity index 100% rename from source/dnode/mgmt/qnode/inc/qm.h rename to source/dnode/mgmt/qm/inc/qm.h diff --git a/source/dnode/mgmt/qnode/inc/qmInt.h b/source/dnode/mgmt/qm/inc/qmInt.h similarity index 100% rename from source/dnode/mgmt/qnode/inc/qmInt.h rename to source/dnode/mgmt/qm/inc/qmInt.h diff --git a/source/dnode/mgmt/qnode/src/qmInt.c b/source/dnode/mgmt/qm/src/qmInt.c similarity index 100% rename from source/dnode/mgmt/qnode/src/qmInt.c rename to source/dnode/mgmt/qm/src/qmInt.c diff --git a/source/dnode/mgmt/qnode/src/qmMsg.c b/source/dnode/mgmt/qm/src/qmMsg.c similarity index 100% rename from source/dnode/mgmt/qnode/src/qmMsg.c rename to source/dnode/mgmt/qm/src/qmMsg.c diff --git a/source/dnode/mgmt/qnode/src/qmWorker.c b/source/dnode/mgmt/qm/src/qmWorker.c similarity index 100% rename from source/dnode/mgmt/qnode/src/qmWorker.c rename to source/dnode/mgmt/qm/src/qmWorker.c diff --git a/source/dnode/mgmt/snode/inc/sm.h b/source/dnode/mgmt/sm/inc/sm.h similarity index 100% rename from source/dnode/mgmt/snode/inc/sm.h rename to source/dnode/mgmt/sm/inc/sm.h diff --git a/source/dnode/mgmt/snode/inc/smInt.h b/source/dnode/mgmt/sm/inc/smInt.h similarity index 100% rename from source/dnode/mgmt/snode/inc/smInt.h rename to source/dnode/mgmt/sm/inc/smInt.h diff --git a/source/dnode/mgmt/snode/src/smInt.c b/source/dnode/mgmt/sm/src/smInt.c similarity index 100% rename from source/dnode/mgmt/snode/src/smInt.c rename to source/dnode/mgmt/sm/src/smInt.c diff --git a/source/dnode/mgmt/snode/src/smMsg.c b/source/dnode/mgmt/sm/src/smMsg.c similarity index 100% rename from source/dnode/mgmt/snode/src/smMsg.c rename to source/dnode/mgmt/sm/src/smMsg.c diff --git a/source/dnode/mgmt/snode/src/smWorker.c b/source/dnode/mgmt/sm/src/smWorker.c similarity index 100% rename from source/dnode/mgmt/snode/src/smWorker.c rename to source/dnode/mgmt/sm/src/smWorker.c diff --git a/source/dnode/mgmt/test/vnode/vnode.cpp b/source/dnode/mgmt/test/vnode/vnode.cpp index e2de3fc33ae473b76cfea9c83ccfb4e03d2e8f82..39de533b733739ca67b0c2e63adb0167467e2f5f 100644 --- a/source/dnode/mgmt/test/vnode/vnode.cpp +++ b/source/dnode/mgmt/test/vnode/vnode.cpp @@ -164,37 +164,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 +204,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 +236,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 +276,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/vnode/inc/vm.h b/source/dnode/mgmt/vm/inc/vm.h similarity index 100% rename from source/dnode/mgmt/vnode/inc/vm.h rename to source/dnode/mgmt/vm/inc/vm.h diff --git a/source/dnode/mgmt/vnode/inc/vmInt.h b/source/dnode/mgmt/vm/inc/vmInt.h similarity index 100% rename from source/dnode/mgmt/vnode/inc/vmInt.h rename to source/dnode/mgmt/vm/inc/vmInt.h diff --git a/source/dnode/mgmt/vnode/src/vmFile.c b/source/dnode/mgmt/vm/src/vmFile.c similarity index 100% rename from source/dnode/mgmt/vnode/src/vmFile.c rename to source/dnode/mgmt/vm/src/vmFile.c diff --git a/source/dnode/mgmt/vnode/src/vmInt.c b/source/dnode/mgmt/vm/src/vmInt.c similarity index 99% rename from source/dnode/mgmt/vnode/src/vmInt.c rename to source/dnode/mgmt/vm/src/vmInt.c index e40c2658e4cd8a97fd1bbe14fea0c0524796ce89..b52c6253dc9e06026acb7a3656c691a46d1a89a3 100644 --- a/source/dnode/mgmt/vnode/src/vmInt.c +++ b/source/dnode/mgmt/vm/src/vmInt.c @@ -285,7 +285,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) { tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN); dCfg.level = 0; dCfg.primary = 1; - SDiskCfg *pDisks = pDnode->pDisks; + SDiskCfg *pDisks = pDnode->disks; int32_t numOfDisks = pDnode->numOfDisks; if (numOfDisks <= 0 || pDisks == NULL) { pDisks = &dCfg; diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vm/src/vmMsg.c similarity index 100% rename from source/dnode/mgmt/vnode/src/vmMsg.c rename to source/dnode/mgmt/vm/src/vmMsg.c diff --git a/source/dnode/mgmt/vnode/src/vmWorker.c b/source/dnode/mgmt/vm/src/vmWorker.c similarity index 98% rename from source/dnode/mgmt/vnode/src/vmWorker.c rename to source/dnode/mgmt/vm/src/vmWorker.c index 193807317f508cd143cf6fdf65be41689b3d3f12..4be6311cf8d597cdf2303c11298b83e2e842cf70 100644 --- a/source/dnode/mgmt/vnode/src/vmWorker.c +++ b/source/dnode/mgmt/vm/src/vmWorker.c @@ -76,7 +76,7 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SVnodeObj *pVnode = pInfo->ahandle; dTrace("msg:%p, will be processed in vnode-fetch queue", pMsg); - int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg); + int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg, pInfo); if (code != 0) { vmSendRsp(pVnode->pWrapper, pMsg, code); dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); @@ -168,7 +168,7 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO taosGetQitem(qall, (void **)&pMsg); dTrace("msg:%p, will be processed in vnode-merge queue", pMsg); - int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg); + int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg, pInfo); if (code != 0) { vmSendRsp(pVnode->pWrapper, pMsg, code); dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); @@ -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; @@ -414,8 +414,7 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) { pWPool->max = maxMergeThreads; if (tWWorkerInit(pWPool) != 0) return -1; - SSingleWorkerCfg cfg = { - .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt}; + SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) { dError("failed to start vnode-mgmt worker since %s", terrstr()); return -1; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 6976d83abdeb56fca28000aeeb4ddd2b230de7ba..f418ec22904a5e5ddd9150fd330bb0bdf02cfd67 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/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 8eceea3d06b43b66bf3ef0ba482c16e6d008170f..c4c93b7fc9e61c4454b22b54ce3a3e99c0e49d43 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 bd66bdeae92747bd87a55764aaca928d75179d80..462f0eb85a6a534ec6a907485da3b17e3dbe7ef1 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 ce08dfaaa3a256fa329fdf21cfb7172601bd3f7f..92b854157b170954644e6315b07b8656a79b4e8c 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/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index dff918f13558b886067a99d8234f069c9b8ffae5..5c3167dd79852634b147ebf686341ef918abf365 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/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 7799ac75625bf601429cf071680412e9dc8ff5e4..f3fda102f497ff5dc7b3cacd57bc0177f4ae861a 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); @@ -348,13 +357,58 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt 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; + } + + 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; + } + } - int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); + int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { + taosMemoryFreeClear(req.stbCfg.pSchema); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -366,6 +420,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt tSerializeSVCreateTbReq(&pBuf, &req); *pContLen = contLen; + taosMemoryFreeClear(req.stbCfg.pSchema); return pHead; } @@ -498,7 +553,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 +613,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; } } @@ -625,7 +679,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 +1115,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 +1661,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 +1705,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 806415ccd90bea0a80fd202e50cb03d8e818b1f1..211163ce35e5e79d5c8cba611ec6ee76b0104ca9 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/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index c0f591d1f2671a06ba5d40dd6ecbb759075dbb76..13ccc912d6f792763d9ccec3ca77293748b4ef89 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -26,7 +26,7 @@ #include "parser.h" #include "tname.h" -#define MND_TOPIC_VER_NUMBER 1 +#define MND_TOPIC_VER_NUMBER 1 #define MND_TOPIC_RESERVE_SIZE 64 static int32_t mndTopicActionInsert(SSdb *pSdb, SMqTopicObj *pTopic); diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp index 85f6a86183e21d7c041ff4e18124f1a36a9e3037..4b0e33a323b51a68092b3d679e48ec958f37b740 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 73eefd875d28b48fb6e62601bba3dfaa857e8c79..5d603ab5b2059f384975234ad46a0c5af877d968 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 61b99beeb7b6b17e9c57ab29fdce5c544fe9192f..97a144fdeecd1fd2064caeea0f44a73b52f61703 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 204cd870f4b01683891f6b04155f7a2b402292b0..dc2c12a2c4f8f07aaf39a00d6e8423fd0682cc45 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/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index bdc8a71b0483b390f4284064071fe267ba066378..56a8698d77f6f5aec8c829fee337fc5f45edf0f3 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -46,14 +46,11 @@ target_link_libraries( PUBLIC stream PUBLIC qworker PUBLIC sync + # TODO: get rid of BDB + PUBLIC bdb + PUBLIC tdb ) -if(${META_DB_IMPL} STREQUAL "BDB") - target_link_libraries(vnode PUBLIC bdb) -elseif(${META_DB_IMPL} STREQUAL "TDB") - target_link_libraries(vnode PUBLIC tdb) -endif() - if(${BUILD_TEST}) add_subdirectory(test) endif(${BUILD_TEST}) diff --git a/source/dnode/vnode/inc/tsdb.h b/source/dnode/vnode/inc/tsdb.h index f1083c0d918d9a158cc5013f6b0eaa993590ac62..0d3fcffe7d1aa38fc8dac2dc993240b61e572b19 100644 --- a/source/dnode/vnode/inc/tsdb.h +++ b/source/dnode/vnode/inc/tsdb.h @@ -100,10 +100,11 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, const char *msg); * @brief Insert tSma(Time-range-wise SMA) data from stream computing engine * * @param pTsdb + * @param indexUid * @param msg * @return int32_t */ -int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg); +int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); /** * @brief Drop tSma data and local cache. @@ -130,16 +131,11 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); * @param pTsdb * @param pData * @param indexUid - * @param interval - * @param intervalUnit - * @param tableUid - * @param colId * @param querySKey * @param nMaxResult * @return int32_t */ -int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit, - tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult); +int32_t tsdbGetTSmaData(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult); // STsdbCfg int tsdbOptionsInit(STsdbCfg *); diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index dd4b8d84ca1a7a39a949d384b9bc2253a71b5d43..c1c000295a6de4734a8abd7bc9a74aea47ee5e01 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -17,8 +17,9 @@ #define _TD_VNODE_H_ #include "os.h" -#include "trpc.h" #include "tmsgcb.h" +#include "tqueue.h" +#include "trpc.h" #include "meta.h" #include "tarray.h" @@ -166,7 +167,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); * @param pMsg The request message * @return int 0 for success, -1 for failure */ -int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg); +int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); /* ------------------------ SVnodeCfg ------------------------ */ /** @@ -185,7 +186,6 @@ void vnodeOptionsClear(SVnodeCfg *pOptions); int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName); - /* ------------------------ FOR COMPILE ------------------------ */ int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); diff --git a/source/dnode/vnode/src/inc/tsdbCommit.h b/source/dnode/vnode/src/inc/tsdbCommit.h index 699aeaa133442adcf63a50c7ae796fe3f227aa89..2c6dd75e031b6dfca4b7a803e5be651b35ad8d92 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 02aba95517ceb6f639b91586150692b598c62b3e..3e42cb627a7456beff75bee8efc1340407f566af 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/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h index e0170c90e72441a3a634f753ff77c15ca53c8cdc..da0a6856ab02ff255bc7546dacc604a0bae8e7e7 100644 --- a/source/dnode/vnode/src/inc/tsdbSma.h +++ b/source/dnode/vnode/src/inc/tsdbSma.h @@ -44,15 +44,14 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); #endif // internal func -static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) { +static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) { int32_t len = 0; - len += taosEncodeFixedI64(pData, tableUid); - len += taosEncodeFixedU16(pData, colId); len += taosEncodeFixedI64(pData, tsKey); + len += taosEncodeFixedI64(pData, groupId); return len; } -static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) { +static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) { int code = taosThreadRwlockRdlock(&(pEnv->lock)); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); @@ -61,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) { return 0; } -static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) { +static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) { int code = taosThreadRwlockWrlock(&(pEnv->lock)); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); @@ -70,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) { return 0; } -static FORCE_INLINE int tsdbUnLockSma(SSmaEnv *pEnv) { +static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) { int code = taosThreadRwlockUnlock(&(pEnv->lock)); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 5ec5b1d58fdb742fe7d8b61e673885f2117b01ec..aa4a9fc1de9b71ed0b6ac420d7ab0ce989f36ab5 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -194,12 +194,12 @@ 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 tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId); int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); -int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); +int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId); // sma void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index b91c6cd9e31055360c4799ee61bb77f85711e090..9485c291aec41a5b7ba19841b5b5c218f205d8e7 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 f4b450b4a8ee326c965d78e52dcab41940b9bd5a..8e82cf1abce775d69605c00f1bb22dc482ac1346 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -15,131 +15,689 @@ #include "metaDef.h" -#include "tdb.h" +#include "tdbInt.h" struct SMetaDB { TENV *pEnv; - TDB * pTbDB; - TDB * pSchemaDB; - TDB * pNameIdx; - TDB * pStbIdx; - TDB * pNtbIdx; - TDB * pCtbIdx; - // tag index hash table - // suid+colid --> TDB * - struct { - } tagIdxHt; + TDB *pTbDB; + TDB *pSchemaDB; + TDB *pNameIdx; + TDB *pStbIdx; + TDB *pNtbIdx; + TDB *pCtbIdx; }; -#define A(op, flag) \ - do { \ - if ((ret = op) != 0) goto flag; \ - } while (0) +typedef struct __attribute__((__packed__)) { + tb_uid_t uid; + int32_t sver; +} SSchemaDbKey; + +typedef struct { + char *name; + tb_uid_t uid; +} SNameIdxKey; + +typedef struct { + tb_uid_t suid; + tb_uid_t uid; +} SCtbIdxKey; + +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; + + ASSERT(len1 == sizeof(tb_uid_t)); + ASSERT(len2 == sizeof(tb_uid_t)); + + uid1 = ((tb_uid_t *)arg1)[0]; + uid2 = ((tb_uid_t *)arg2)[0]; + + if (uid1 < uid2) { + return -1; + } + if (uid1 == uid2) { + return 0; + } else { + return 1; + } +} + +static inline int metaSchemaKeyCmpr(const void *arg1, int len1, const void *arg2, int len2) { + int c; + SSchemaDbKey *pKey1 = (SSchemaDbKey *)arg1; + SSchemaDbKey *pKey2 = (SSchemaDbKey *)arg2; + + c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t)); + if (c) return c; + + if (pKey1->sver > pKey2->sver) { + return 1; + } else if (pKey1->sver == pKey2->sver) { + return 0; + } else { + return -1; + } +} + +static inline int metaNameIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) { + return strcmp((char *)arg1, (char *)arg2); +} + +static inline int metaCtbIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) { + int c; + SCtbIdxKey *pKey1 = (SCtbIdxKey *)arg1; + SCtbIdxKey *pKey2 = (SCtbIdxKey *)arg2; + + c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t)); + if (c) return c; + + return metaUidCmpr(&pKey1->uid, sizeof(tb_uid_t), &pKey2->uid, sizeof(tb_uid_t)); +} int metaOpenDB(SMeta *pMeta) { - SMetaDB *pDb; - TENV * pEnv; - TDB * pTbDB; - TDB * pSchemaDB; - TDB * pNameIdx; - TDB * pStbIdx; - TDB * pNtbIdx; - TDB * pCtbIdx; + SMetaDB *pMetaDb; int ret; - pDb = (SMetaDB *)taosMemoryCalloc(1, sizeof(*pDb)); - if (pDb == NULL) { + // allocate DB handle + pMetaDb = taosMemoryCalloc(1, sizeof(*pMetaDb)); + if (pMetaDb == NULL) { + // TODO + ASSERT(0); return -1; } - // Create and open the ENV - A((tdbEnvCreate(&pEnv)), _err); -#if 0 - // Set options of the environment - A(tdbEnvSetPageSize(pEnv, 8192), _err); - A(tdbEnvSetCacheSize(pEnv, 16 * 1024 * 1024), _err); -#endif - A((tdbEnvOpen(&pEnv)), _err); + // open the ENV + ret = tdbEnvOpen(pMeta->path, 4096, 256, &(pMetaDb->pEnv)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } - // Create and open each DB - A(tdbCreate(&pTbDB), _err); - A(tdbOpen(&pTbDB, "table.db", NULL, pEnv), _err); + // open table DB + ret = tdbDbOpen("table.db", sizeof(tb_uid_t), TDB_VARIANT_LEN, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pTbDB)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } - A(tdbCreate(&pSchemaDB), _err); - A(tdbOpen(&pSchemaDB, "schema.db", NULL, pEnv), _err); + // open schema DB + ret = tdbDbOpen("schema.db", sizeof(SSchemaDbKey), TDB_VARIANT_LEN, metaSchemaKeyCmpr, pMetaDb->pEnv, + &(pMetaDb->pSchemaDB)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } - A(tdbCreate(&pNameIdx), _err); - A(tdbOpen(&pNameIdx, "name.db", NULL, pEnv), _err); - // tdbAssociate(); + ret = tdbDbOpen("name.idx", TDB_VARIANT_LEN, 0, metaNameIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pNameIdx)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } - pDb->pEnv = pEnv; - pDb->pTbDB = pTbDB; - pDb->pSchemaDB = pSchemaDB; - pMeta->pDB = pDb; - return 0; + ret = tdbDbOpen("stb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pStbIdx)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } -_err: - return -1; + ret = tdbDbOpen("ntb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pNtbIdx)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } + + ret = tdbDbOpen("ctb.idx", sizeof(SCtbIdxKey), 0, metaCtbIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pCtbIdx)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } + + pMeta->pDB = pMetaDb; + return 0; } void metaCloseDB(SMeta *pMeta) { - // TODO + if (pMeta->pDB) { + tdbDbClose(pMeta->pDB->pCtbIdx); + tdbDbClose(pMeta->pDB->pNtbIdx); + tdbDbClose(pMeta->pDB->pStbIdx); + tdbDbClose(pMeta->pDB->pNameIdx); + tdbDbClose(pMeta->pDB->pSchemaDB); + tdbDbClose(pMeta->pDB->pTbDB); + taosMemoryFree(pMeta->pDB); + } } int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { - // TODO + tb_uid_t uid; + SMetaDB *pMetaDb; + void *pKey; + void *pVal; + int kLen; + int vLen; + int ret; + char buf[512]; + void *pBuf; + SCtbIdxKey ctbIdxKey; + SSchemaDbKey schemaDbKey; + SSchemaWrapper schemaWrapper; + + pMetaDb = pMeta->pDB; + + // TODO: make this operation pre-process + if (pTbCfg->type == META_SUPER_TABLE) { + uid = pTbCfg->stbCfg.suid; + } else { + uid = metaGenerateUid(pMeta); + } + + // save to table.db + pKey = &uid; + kLen = sizeof(uid); + pVal = pBuf = buf; + metaEncodeTbInfo(&pBuf, pTbCfg); + vLen = POINTER_DISTANCE(pBuf, buf); + ret = tdbDbInsert(pMetaDb->pTbDB, pKey, kLen, pVal, vLen); + if (ret < 0) { + return -1; + } + + // save to schema.db for META_SUPER_TABLE and META_NORMAL_TABLE + if (pTbCfg->type != META_CHILD_TABLE) { + schemaDbKey.uid = uid; + schemaDbKey.sver = 0; // TODO + pKey = &schemaDbKey; + kLen = sizeof(schemaDbKey); + + if (pTbCfg->type == META_SUPER_TABLE) { + schemaWrapper.nCols = pTbCfg->stbCfg.nCols; + schemaWrapper.pSchema = pTbCfg->stbCfg.pSchema; + } else { + schemaWrapper.nCols = pTbCfg->ntbCfg.nCols; + schemaWrapper.pSchema = pTbCfg->ntbCfg.pSchema; + } + pVal = pBuf = buf; + metaEncodeSchemaEx(&pBuf, &schemaWrapper); + vLen = POINTER_DISTANCE(pBuf, buf); + ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen); + if (ret < 0) { + return -1; + } + } + + // update name.idx + int nameLen = strlen(pTbCfg->name); + memcpy(buf, pTbCfg->name, nameLen + 1); + ((tb_uid_t *)(buf + nameLen + 1))[0] = uid; + pKey = buf; + kLen = nameLen + 1 + sizeof(uid); + pVal = NULL; + vLen = 0; + ret = tdbDbInsert(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen); + if (ret < 0) { + return -1; + } + + // update other index + if (pTbCfg->type == META_SUPER_TABLE) { + pKey = &uid; + kLen = sizeof(uid); + pVal = NULL; + vLen = 0; + ret = tdbDbInsert(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen); + if (ret < 0) { + return -1; + } + } else if (pTbCfg->type == META_CHILD_TABLE) { + ctbIdxKey.suid = pTbCfg->ctbCfg.suid; + ctbIdxKey.uid = uid; + pKey = &ctbIdxKey; + kLen = sizeof(ctbIdxKey); + pVal = NULL; + vLen = 0; + ret = tdbDbInsert(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen); + if (ret < 0) { + return -1; + } + } else if (pTbCfg->type == META_NORMAL_TABLE) { + pKey = &uid; + kLen = sizeof(uid); + pVal = NULL; + vLen = 0; + ret = tdbDbInsert(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen); + if (ret < 0) { + return -1; + } + } + return 0; } int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) { // TODO + ASSERT(0); return 0; } STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { - // TODO - return NULL; + int ret; + SMetaDB *pMetaDb = pMeta->pDB; + void *pKey; + void *pVal; + int kLen; + int vLen; + STbCfg *pTbCfg; + + // Fetch + pKey = &uid; + kLen = sizeof(uid); + pVal = NULL; + ret = tdbDbGet(pMetaDb->pTbDB, pKey, kLen, &pVal, &vLen); + if (ret < 0) { + return NULL; + } + + // Decode + pTbCfg = taosMemoryMalloc(sizeof(*pTbCfg)); + metaDecodeTbInfo(pVal, pTbCfg); + + TDB_FREE(pVal); + + return pTbCfg; } STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { - // TODO - return NULL; + void *pKey; + void *pVal; + void *ppKey; + int pkLen; + int kLen; + int vLen; + int ret; + + pKey = tbname; + kLen = strlen(tbname) + 1; + pVal = NULL; + ppKey = NULL; + ret = tdbDbPGet(pMeta->pDB->pNameIdx, pKey, kLen, &ppKey, &pkLen, &pVal, &vLen); + if (ret < 0) { + return NULL; + } + + ASSERT(pkLen == kLen + sizeof(uid)); + + *uid = *(tb_uid_t *)POINTER_SHIFT(ppKey, kLen); + TDB_FREE(ppKey); + TDB_FREE(pVal); + + return metaGetTbInfoByUid(pMeta, *uid); } SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { - // TODO - return NULL; + 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; + int vLen; + int ret; + SSchemaDbKey schemaDbKey; + SSchemaWrapper *pSchemaWrapper; + void *pBuf; + + // fetch + schemaDbKey.uid = uid; + schemaDbKey.sver = sver; + pKey = &schemaDbKey; + kLen = sizeof(schemaDbKey); + pVal = NULL; + ret = tdbDbGet(pMeta->pDB->pSchemaDB, pKey, kLen, &pVal, &vLen); + if (ret < 0) { + return NULL; + } + + // decode + pBuf = pVal; + pSchemaWrapper = taosMemoryMalloc(sizeof(*pSchemaWrapper)); + metaDecodeSchemaEx(pBuf, pSchemaWrapper, isGetEx); + + TDB_FREE(pVal); + + return pSchemaWrapper; } STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { - // TODO - return NULL; + tb_uid_t quid; + SSchemaWrapper *pSW; + STSchemaBuilder sb; + SSchemaEx *pSchema; + STSchema *pTSchema; + STbCfg *pTbCfg; + + pTbCfg = metaGetTbInfoByUid(pMeta, uid); + if (pTbCfg->type == META_CHILD_TABLE) { + quid = pTbCfg->ctbCfg.suid; + } else { + quid = uid; + } + + 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->pSchemaEx + i; + tdAddColToSchema(&sb, pSchema->type, pSchema->sma, pSchema->colId, pSchema->bytes); + } + pTSchema = tdGetSchemaFromBuilder(&sb); + tdDestroyTSchemaBuilder(&sb); + + return pTSchema; } +struct SMTbCursor { + TDBC *pDbc; +}; + SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { - // TODO - return NULL; + SMTbCursor *pTbCur = NULL; + SMetaDB *pDB = pMeta->pDB; + + pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur)); + if (pTbCur == NULL) { + return NULL; + } + + tdbDbcOpen(pDB->pTbDB, &pTbCur->pDbc); + + return pTbCur; } void metaCloseTbCursor(SMTbCursor *pTbCur) { - // TODO + if (pTbCur) { + if (pTbCur->pDbc) { + tdbDbcClose(pTbCur->pDbc); + } + taosMemoryFree(pTbCur); + } } char *metaTbCursorNext(SMTbCursor *pTbCur) { - // TODO + void *pKey = NULL; + void *pVal = NULL; + int kLen; + int vLen; + int ret; + void *pBuf; + STbCfg tbCfg; + + for (;;) { + ret = tdbDbNext(pTbCur->pDbc, &pKey, &kLen, &pVal, &vLen); + if (ret < 0) break; + pBuf = pVal; + metaDecodeTbInfo(pBuf, &tbCfg); + if (tbCfg.type == META_SUPER_TABLE) { + taosMemoryFree(tbCfg.name); + taosMemoryFree(tbCfg.stbCfg.pTagSchema); + continue; + ; + } else if (tbCfg.type == META_CHILD_TABLE) { + kvRowFree(tbCfg.ctbCfg.pTag); + } + + return tbCfg.name; + } + return NULL; } +struct SMCtbCursor { + TDBC *pCur; + tb_uid_t suid; + void *pKey; + void *pVal; + int kLen; + int vLen; +}; + SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { + SMCtbCursor *pCtbCur = NULL; + SMetaDB *pDB = pMeta->pDB; + int ret; + + pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur)); + if (pCtbCur == NULL) { + return NULL; + } + + pCtbCur->suid = uid; + ret = tdbDbcOpen(pDB->pCtbIdx, &pCtbCur->pCur); + if (ret < 0) { + taosMemoryFree(pCtbCur); + return NULL; + } + + // TODO: move the cursor to the suid there + + return pCtbCur; +} + +void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) { + if (pCtbCur) { + if (pCtbCur->pCur) { + tdbDbcClose(pCtbCur->pCur); + + TDB_FREE(pCtbCur->pKey); + TDB_FREE(pCtbCur->pVal); + } + + taosMemoryFree(pCtbCur); + } +} + +tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) { + int ret; + SCtbIdxKey *pCtbIdxKey; + + ret = tdbDbNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen); + if (ret < 0) { + return 0; + } + + pCtbIdxKey = pCtbCur->pVal; + + return pCtbIdxKey->uid; +} + +int metaGetTbNum(SMeta *pMeta) { + // TODO + // ASSERT(0); + return 0; +} + +STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { // TODO + ASSERT(0); return NULL; } -void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) { +int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) { // TODO + ASSERT(0); + return 0; } -tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) { +int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { // TODO + ASSERT(0); return 0; -} \ No newline at end of file +} + +STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { + // TODO + ASSERT(0); + return NULL; +} + +const char *metaSmaCursorNext(SMSmaCursor *pCur) { + // TODO + ASSERT(0); + return NULL; +} + +void metaCloseSmaCurosr(SMSmaCursor *pCur) { + // TODO + ASSERT(0); +} + +SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) { + // TODO + ASSERT(0); + return NULL; +} + +SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { + // TODO + ASSERT(0); + return NULL; +} + +static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) { + int tlen = 0; + SSchema *pSchema; + + tlen += taosEncodeFixedU32(buf, pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + pSchema = pSW->pSchema + i; + tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI16(buf, pSchema->colId); + tlen += taosEncodeFixedI32(buf, pSchema->bytes); + tlen += taosEncodeString(buf, pSchema->name); + } + + return tlen; +} + +static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { + SSchema *pSchema; + + buf = taosDecodeFixedU32(buf, &pSW->nCols); + pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + pSchema = pSW->pSchema + i; + buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosDecodeFixedI16(buf, &pSchema->colId); + buf = taosDecodeFixedI32(buf, &pSchema->bytes); + buf = taosDecodeStringTo(buf, pSchema->name); + } + + 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; + + tsize += taosEncodeString(buf, pTbCfg->name); + tsize += taosEncodeFixedU32(buf, pTbCfg->ttl); + tsize += taosEncodeFixedU32(buf, pTbCfg->keep); + tsize += taosEncodeFixedU8(buf, pTbCfg->info); + + if (pTbCfg->type == META_SUPER_TABLE) { + SSchemaWrapper sw = {.nCols = pTbCfg->stbCfg.nTagCols, .pSchema = pTbCfg->stbCfg.pTagSchema}; + tsize += metaEncodeSchema(buf, &sw); + } else if (pTbCfg->type == META_CHILD_TABLE) { + tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid); + tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag); + } else if (pTbCfg->type == META_NORMAL_TABLE) { + // TODO + } else { + ASSERT(0); + } + + return tsize; +} + +static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) { + buf = taosDecodeString(buf, &(pTbCfg->name)); + buf = taosDecodeFixedU32(buf, &(pTbCfg->ttl)); + buf = taosDecodeFixedU32(buf, &(pTbCfg->keep)); + buf = taosDecodeFixedU8(buf, &(pTbCfg->info)); + + if (pTbCfg->type == META_SUPER_TABLE) { + SSchemaWrapper sw; + buf = metaDecodeSchema(buf, &sw); + pTbCfg->stbCfg.nTagCols = sw.nCols; + pTbCfg->stbCfg.pTagSchema = sw.pSchema; + } else if (pTbCfg->type == META_CHILD_TABLE) { + buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid)); + buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag)); + } else if (pTbCfg->type == META_NORMAL_TABLE) { + // TODO + } else { + ASSERT(0); + } + return buf; +} diff --git a/source/dnode/vnode/src/meta/metaTbUid.c b/source/dnode/vnode/src/meta/metaTbUid.c index cad1eba134ca5f0f3ce3a9e63bf3711827fb5562..1f57d1396ad77ba9a55e6138cf0f20435507f225 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 fce423d8119d83f69802e51a76d555d21f9cb93f..68ade46efdb06d6de6a25fdd017594da8769d029 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; + if (taosArrayGetSize(pRes) == 0) { + fetchOffset++; + rsp.skipLogNum++; + taosArrayDestroy(pRes); + continue; + } + rsp.schema = pTopic->buffer.output[workerId].pReadHandle->pSchemaWrapper; + rsp.rspOffset = fetchOffset; - 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; + 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++; } @@ -356,11 +370,11 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { void* buf = rpcMallocCont(tlen); if (buf == NULL) { pMsg->code = -1; - ASSERT(0); return -1; } ((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); @@ -369,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; @@ -433,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); @@ -490,7 +507,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { return 0; } -int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { +int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId) { void* pIter = NULL; while (1) { @@ -498,14 +515,14 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { if (pIter == NULL) break; SStreamTask* pTask = (SStreamTask*)pIter; - if (streamExecTask(pTask, &pTq->pVnode->msgCb, data, STREAM_DATA_TYPE_SUBMIT_BLOCK, 0) < 0) { + if (streamExecTask(pTask, &pTq->pVnode->msgCb, data, STREAM_DATA_TYPE_SUBMIT_BLOCK, workerId) < 0) { // TODO } } return 0; } -int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) { +int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId) { SStreamTaskExecReq req; tDecodeSStreamTaskExecReq(msg, &req); @@ -515,7 +532,7 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) { SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); ASSERT(pTask); - if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, 0) < 0) { + if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, workerId) < 0) { // TODO } return 0; diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 3d9d9a90dd1d106f0b7b47c99a7351c6a37f0f6b..a18374015b5f5f32c2e08cc88038328ea8d62c23 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,8 +167,11 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { break; } - // TODO handle null - colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL); + 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; + } } curRow++; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 3e0b03f3318ea5f10e224da58bd842404df3e9ab..d5e9b55a7167818d75a3b7a8935c89ecc0c9f968 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 bac5255d17fd8de08dc19a0060321630b5c3caff..7f2605ae2c70b3982c405e91ac7e0fc968acbc7e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -403,7 +403,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; } @@ -4068,4 +4068,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/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 07eafd6df06d6e4d3e9223f21068976183482a2e..f04f4791b5491dfd3eebf3c08f5bf8aff1af8845 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -24,7 +24,7 @@ static const char *TSDB_SMA_DNAME[] = { #define SMA_STORAGE_TSDB_DAYS 30 #define SMA_STORAGE_TSDB_TIMES 10 #define SMA_STORAGE_SPLIT_HOURS 24 -#define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8 +#define SMA_KEY_LEN 16 // TSKEY+groupId 8+8 #define SMA_DROP_EXPIRED_TIME 10 // default is 10 seconds #define SMA_STATE_HASH_SLOT 4 @@ -38,10 +38,10 @@ typedef enum { } ESmaStorageLevel; typedef struct { - STsdb *pTsdb; - SDBFile dFile; - SSDataBlock *pData; // sma data - int32_t interval; // interval with the precision of DB + STsdb *pTsdb; + SDBFile dFile; + const SArray *pDataBlocks; // sma data + int32_t interval; // interval with the precision of DB } STSmaWriteH; typedef struct { @@ -94,26 +94,24 @@ static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat); // read data // TODO: This is the basic params, and should wrap the params to a queryHandle. -static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, - int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, - int32_t nMaxResult); +static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult); // insert data -static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, +static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, const SArray *pDataBlocks, int64_t interval, int8_t intervalUnit); static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH); static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit); static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit); -static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData); +static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid); static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen); -static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision); +static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted); static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel); -static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int64_t indexUid, int32_t fid); +static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid); static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey); static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey); static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]); -static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg); -static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg); +static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg); +static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg); // mgmt interface static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid); @@ -387,7 +385,6 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { return TSDB_CODE_SUCCESS; }; - static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey) { SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid)); if (pItem == NULL) { @@ -480,18 +477,15 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, const char *msg) { TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE]; #endif - // Firstly, assume that tSma can only be created on super table/normal table. // getActiveTimeWindow - - SSmaEnv *pEnv = REPO_SMA_ENV(pTsdb, TSDB_SMA_TYPE_TIME_RANGE); + SSmaEnv *pEnv = REPO_SMA_ENV(pTsdb, TSDB_SMA_TYPE_TIME_RANGE); SSmaStat *pStat = SMA_ENV_STAT(pEnv); SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv); TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL); - // basic procedure // TODO: optimization tsdbRefSmaStat(pTsdb, pStat); @@ -523,11 +517,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, const char *msg) { tdFreeTSmaWrapper(pSW); break; } - if(pSW == NULL) { - if((pSW =metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) { + if (pSW == NULL) { + if ((pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) { break; } - if((pSW->number) <= 0 || (pSW->tSma == NULL)) { + if ((pSW->number) <= 0 || (pSW->tSma == NULL)) { tdFreeTSmaWrapper(pSW); break; } @@ -657,9 +651,8 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) { */ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen) { SDBFile *pDBFile = &pSmaH->dFile; - tsdbDebug("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d", - REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), - *(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen); + printf("\nvgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 "\n", + REPO_ID(pSmaH->pTsdb), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen); // TODO: insert sma data blocks into B+Tree(TDB) if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) { @@ -683,9 +676,15 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k * @param interval * @param intervalUnit * @param precision + * @param adjusted Interval already adjusted according to DB precision * @return int64_t */ -static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision) { +static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted) { + + if (adjusted) { + return interval; + } + switch (intervalUnit) { case TIME_UNIT_YEAR: // approximate value interval *= 365 * 86400 * 1e3; @@ -753,59 +752,12 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit return interval; } -/** - * @brief Split the TSma data blocks into expected size and insert into B+Tree. - * - * @param pSmaH - * @param pData - * @param nOffset The nOffset of blocks since fid changes. - * @param nBlocks The nBlocks with the same fid since nOffset. - * @return int32_t - */ -static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData) { - STsdb *pTsdb = pSmaH->pTsdb; - - tsdbDebug("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64, pData->indexUid, pData->skey); - - // TODO: check the data integrity - - int32_t len = 0; - while (true) { - if (len >= pData->dataLen) { - break; - } - assert(pData->dataLen > 0); - STSmaTbData *pTbData = (STSmaTbData *)POINTER_SHIFT(pData->data, len); - - int32_t tbLen = 0; - while (true) { - if (tbLen >= pTbData->dataLen) { - break; - } - assert(pTbData->dataLen > 0); - STSmaColData *pColData = (STSmaColData *)POINTER_SHIFT(pTbData->data, tbLen); - char smaKey[SMA_KEY_LEN] = {0}; - void *pSmaKey = &smaKey; -#if 0 - printf("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64 " table[%" PRIi64 "]col[%" PRIu16 "]\n", - pData->indexUid, pData->skey, pTbData->tableUid, pColData->colId); -#endif - tsdbEncodeTSmaKey(pTbData->tableUid, pColData->colId, pData->skey, (void **)&pSmaKey); - if (tsdbInsertTSmaBlocks(pSmaH, smaKey, SMA_KEY_LEN, pColData->data, pColData->blockSize) < 0) { - tsdbWarn("vgId:%d insert tSma blocks failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); - } - tbLen += (sizeof(STSmaColData) + pColData->blockSize); - } - len += (sizeof(STSmaTbData) + pTbData->dataLen); - } - - return TSDB_CODE_SUCCESS; -} - -static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, int8_t intervalUnit) { +static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, const SArray *pDataBlocks, int64_t interval, + int8_t intervalUnit) { pSmaH->pTsdb = pTsdb; - pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision); - pSmaH->pData = pData; + pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision, true); + pSmaH->pDataBlocks = pDataBlocks; + pSmaH->dFile.fid = TSDB_IVLD_FID; return TSDB_CODE_SUCCESS; } @@ -815,7 +767,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) { } } -static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int64_t indexUid, int32_t fid) { +static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) { STsdb *pTsdb = pSmaH->pTsdb; ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL); @@ -859,11 +811,10 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe * @param msg * @return int32_t */ -static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { - STsdbCfg *pCfg = REPO_CFG(pTsdb); - SSDataBlock *pData = (SSDataBlock *)msg; - SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); - int64_t indexUid = SMA_TEST_INDEX_UID; +static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg) { + STsdbCfg *pCfg = REPO_CFG(pTsdb); + const SArray *pDataBlocks = (const SArray *)msg; + SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); if (pEnv == NULL) { terrno = TSDB_CODE_INVALID_PTR; @@ -871,15 +822,15 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { return terrno; } - if (pData == NULL) { + if (pDataBlocks == NULL) { terrno = TSDB_CODE_INVALID_PTR; - tsdbWarn("vgId:%d insert tSma data failed since pData is NULL", REPO_ID(pTsdb)); + tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb)); return terrno; } - if (taosArrayGetSize(pData->pDataBlock) <= 0) { + if (taosArrayGetSize(pDataBlocks) <= 0) { terrno = TSDB_CODE_INVALID_PARA; - tsdbWarn("vgId:%d insert tSma data failed since pDataBlock is empty", REPO_ID(pTsdb)); + tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is empty", REPO_ID(pTsdb)); return TSDB_CODE_FAILED; } @@ -899,10 +850,9 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { } STSma *pSma = pItem->pSma; - STSmaWriteH tSmaH = {0}; - if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) { + if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pDataBlocks, pSma->interval, pSma->intervalUnit) != 0) { return TSDB_CODE_FAILED; } @@ -921,33 +871,134 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit); int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); + // key: skey + groupId + char smaKey[SMA_KEY_LEN] = {0}; + char dataBuf[512] = {0}; + void *pDataBuf = &dataBuf; + int32_t sz = taosArrayGetSize(pDataBlocks); + for (int32_t i = 0; i < sz; ++i) { + SSDataBlock *pDataBlock = *(SSDataBlock **)taosArrayGet(pDataBlocks, i); + int32_t colNum = pDataBlock->info.numOfCols; + int32_t rows = pDataBlock->info.rows; + int32_t rowSize = pDataBlock->info.rowSize; + int64_t groupId = pDataBlock->info.groupId; + for (int32_t j = 0; j < rows; ++j) { + printf("|"); + TSKEY skey = TSKEY_INITIAL_VAL; // the start key of TS window by interval + void *pSmaKey = &smaKey; + int32_t tlen = 0; + for (int32_t k = 0; k < colNum; ++k) { + SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, k); + void *var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); + switch (pColInfoData->info.type) { + case TSDB_DATA_TYPE_TIMESTAMP: + skey = *(TSKEY *)var; + printf("==> skey = %" PRIi64 " groupId = %" PRId64 "|", skey, groupId); + tsdbEncodeTSmaKey(groupId, skey, &pSmaKey); + break; + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: + printf(" %15d |", *(uint8_t *)var); + tlen += taosEncodeFixedU8(&pDataBuf, *(uint8_t *)var); + break; + case TSDB_DATA_TYPE_TINYINT: + printf(" %15d |", *(int8_t *)var); + tlen += taosEncodeFixedI8(&pDataBuf, *(int8_t *)var); + break; + case TSDB_DATA_TYPE_SMALLINT: + printf(" %15d |", *(int16_t *)var); + tlen += taosEncodeFixedI16(&pDataBuf, *(int16_t *)var); + break; + case TSDB_DATA_TYPE_USMALLINT: + printf(" %15d |", *(uint16_t *)var); + tlen += taosEncodeFixedU16(&pDataBuf, *(uint16_t *)var); + break; + case TSDB_DATA_TYPE_INT: + printf(" %15d |", *(int32_t *)var); + tlen += taosEncodeFixedI32(&pDataBuf, *(int32_t *)var); + break; + case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_UINT: + printf(" %15u |", *(uint32_t *)var); + tlen += taosEncodeFixedU32(&pDataBuf, *(uint32_t *)var); + break; + case TSDB_DATA_TYPE_BIGINT: + printf(" %15ld |", *(int64_t *)var); + tlen += taosEncodeFixedI64(&pDataBuf, *(int64_t *)var); + break; + case TSDB_DATA_TYPE_DOUBLE: + case TSDB_DATA_TYPE_UBIGINT: + printf(" %15lu |", *(uint64_t *)var); + tlen += taosEncodeFixedU64(&pDataBuf, *(uint64_t *)var); + break; + case TSDB_DATA_TYPE_NCHAR: { + char tmpChar[100] = {0}; + strncpy(tmpChar, varDataVal(var), varDataLen(var)); + printf(" %s |", tmpChar); + tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var)); + break; + } + case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY + char tmpChar[100] = {0}; + strncpy(tmpChar, varDataVal(var), varDataLen(var)); + printf(" %s |", tmpChar); + tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var)); + break; + } + case TSDB_DATA_TYPE_VARBINARY: + // TODO: add binary/varbinary + TASSERT(0); + default: + printf("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type); + TASSERT(0); + break; + } + } + if ((tlen > 0) && (skey != TSKEY_INITIAL_VAL)) { + int32_t fid = (int32_t)(TSDB_KEY_FID(skey, daysPerFile, pCfg->precision)); + + // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index + // file + // - Set and open the DFile or the B+Tree file + // TODO: tsdbStartTSmaCommit(); + if (fid != tSmaH.dFile.fid) { + if (tSmaH.dFile.fid != TSDB_IVLD_FID) { + tsdbCloseDBF(&tSmaH.dFile); + } + tsdbSetTSmaDataFile(&tSmaH, indexUid, fid); + if (tsdbOpenDBF(pTsdb->pTSmaEnv->dbEnv, &tSmaH.dFile) != 0) { + tsdbWarn("vgId:%d open DB file %s failed since %s", REPO_ID(pTsdb), + tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno)); + tsdbDestroyTSmaWriteH(&tSmaH); + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_FAILED; + } + } -#if 0 - int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); + if (tsdbInsertTSmaBlocks(&tSmaH, &smaKey, SMA_KEY_LEN, pDataBuf, tlen) != 0) { + tsdbWarn("vgId:%d insert tSma data blocks failed for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64 + " since %s", + REPO_ID(pTsdb), indexUid, skey, groupId, tstrerror(terrno)); + tsdbDestroyTSmaWriteH(&tSmaH); + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_FAILED; + } else { + tsdbWarn("vgId:%d insert tSma data blocks success for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64, + REPO_ID(pTsdb), indexUid, skey, groupId); + } + // TODO:tsdbEndTSmaCommit(); - // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file - // - Set and open the DFile or the B+Tree file - // TODO: tsdbStartTSmaCommit(); - tsdbSetTSmaDataFile(&tSmaH, pData, indexUid, fid); - if (tsdbOpenDBF(pTsdb->pTSmaEnv->dbEnv, &tSmaH.dFile) != 0) { - tsdbWarn("vgId:%d open DB file %s failed since %s", REPO_ID(pTsdb), - tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno)); - tsdbDestroyTSmaWriteH(&tSmaH); - tsdbUnRefSmaStat(pTsdb, pStat); - return TSDB_CODE_FAILED; - } + // Step 3: reset the SSmaStat + tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), indexUid, skey); + } else { + tsdbWarn("vgId:%d invalid data skey:%" PRIi64 ", tlen %" PRIi32 " during insert tSma data for %" PRIi64, + REPO_ID(pTsdb), skey, tlen, indexUid); + } - if (tsdbInsertTSmaDataSection(&tSmaH, pData) != 0) { - tsdbWarn("vgId:%d insert tSma data section failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); - tsdbDestroyTSmaWriteH(&tSmaH); - tsdbUnRefSmaStat(pTsdb, pStat); - return TSDB_CODE_FAILED; + printf("\n"); + } } - // TODO:tsdbEndTSmaCommit(); - // Step 3: reset the SSmaStat - tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey); -#endif tsdbDestroyTSmaWriteH(&tSmaH); tsdbUnRefSmaStat(pTsdb, pStat); return TSDB_CODE_SUCCESS; @@ -1002,7 +1053,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) { // TODO: } -static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t fid) { +static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid) { STsdb *pTsdb = pSmaH->pTsdb; char tSmaFile[TSDB_FILENAME_LEN] = {0}; @@ -1012,11 +1063,11 @@ static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, return TSDB_CODE_SUCCESS; } -static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { - STsdbCfg *pCfg = REPO_CFG(pTsdb); - SSDataBlock *pData = (SSDataBlock *)msg; - SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv); - int64_t indexUid = SMA_TEST_INDEX_UID; +static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) { + STsdbCfg *pCfg = REPO_CFG(pTsdb); + const SArray *pDataBlocks = (const SArray *)msg; + SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv); + int64_t indexUid = SMA_TEST_INDEX_UID; if (pEnv == NULL) { terrno = TSDB_CODE_INVALID_PTR; @@ -1030,15 +1081,15 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { return terrno; } - if (pData == NULL) { + if (pDataBlocks == NULL) { terrno = TSDB_CODE_INVALID_PTR; - tsdbWarn("vgId:%d insert rSma data failed since pData is NULL", REPO_ID(pTsdb)); + tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb)); return terrno; } - if (taosArrayGetSize(pData->pDataBlock) <= 0) { + if (taosArrayGetSize(pDataBlocks) <= 0) { terrno = TSDB_CODE_INVALID_PARA; - tsdbWarn("vgId:%d insert rSma data failed since pDataBlock is empty", REPO_ID(pTsdb)); + tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is empty", REPO_ID(pTsdb)); return TSDB_CODE_FAILED; } @@ -1061,12 +1112,12 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { STSmaWriteH tSmaH = {0}; - if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) { + if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pDataBlocks, pSma->interval, pSma->intervalUnit) != 0) { return TSDB_CODE_FAILED; } - char rPath[TSDB_FILENAME_LEN] = {0}; - char aPath[TSDB_FILENAME_LEN] = {0}; + char rPath[TSDB_FILENAME_LEN] = {0}; + char aPath[TSDB_FILENAME_LEN] = {0}; snprintf(rPath, TSDB_FILENAME_LEN, "%s%s%" PRIi64, SMA_ENV_PATH(pEnv), TD_DIRSEP, indexUid); tfsAbsoluteName(REPO_TFS(pTsdb), SMA_ENV_DID(pEnv), rPath, aPath); if (!taosCheckExistFile(aPath)) { @@ -1078,7 +1129,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { // Step 1: Judge the storage level and days int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit); int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); - #if 0 +#if 0 int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file @@ -1119,7 +1170,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { */ static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit) { pSmaH->pTsdb = pTsdb; - pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision); + pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision, true); pSmaH->storageLevel = tsdbGetSmaStorageLevel(interval, intervalUnit); pSmaH->days = tsdbGetTSmaDays(pTsdb, pSmaH->interval, pSmaH->storageLevel); } @@ -1185,17 +1236,11 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) { * @param pTsdb Return the data between queryWin and fill the pData. * @param pData * @param indexUid - * @param interval - * @param intervalUnit - * @param tableUid - * @param colId * @param pQuerySKey * @param nMaxResult The query invoker should control the nMaxResult need to return to avoid OOM. * @return int32_t */ -static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, - int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, - int32_t nMaxResult) { +static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) { SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); if (!pEnv) { @@ -1243,13 +1288,18 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ tsdbDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, REPO_ID(pTsdb), querySKey, indexUid); } - tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv)); + + STSma *pTSma = pItem->pSma; + + #endif STSmaReadH tReadH = {0}; - tsdbInitTSmaReadH(&tReadH, pTsdb, interval, intervalUnit); + tsdbInitTSmaReadH(&tReadH, pTsdb, pTSma->interval, pTSma->intervalUnit); tsdbCloseDBF(&tReadH.dFile); + + tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv)); tsdbInitTSmaFile(&tReadH, indexUid, querySKey); if (tsdbOpenDBF(SMA_ENV_ENV(pTsdb->pTSmaEnv), &tReadH.dFile) != 0) { @@ -1257,21 +1307,19 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ return TSDB_CODE_FAILED; } - char smaKey[SMA_KEY_LEN] = {0}; - void *pSmaKey = &smaKey; - tsdbEncodeTSmaKey(tableUid, colId, querySKey, (void **)&pSmaKey); + char smaKey[SMA_KEY_LEN] = {0}; + void *pSmaKey = &smaKey; + int64_t queryGroupId = 1; + tsdbEncodeTSmaKey(queryGroupId, querySKey, (void **)&pSmaKey); - tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb), - tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), - *(int64_t *)POINTER_SHIFT(smaKey, 10), SMA_KEY_LEN); + tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb), + tReadH.dFile.path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), SMA_KEY_LEN); void *result = NULL; uint32_t valueSize = 0; if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) { - tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 - " since %s", - REPO_ID(pTsdb), indexUid, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), - *(int64_t *)POINTER_SHIFT(smaKey, 10), tstrerror(terrno)); + tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s", + REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno)); tsdbCloseDBF(&tReadH.dFile); return TSDB_CODE_FAILED; } @@ -1347,11 +1395,10 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, void *smaIndex, STimeWindow *pWin) { } #endif - // TODO: Who is responsible for resource allocate and release? -int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg) { +int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) { int32_t code = TSDB_CODE_SUCCESS; - if ((code = tsdbInsertTSmaDataImpl(pTsdb, msg)) < 0) { + if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) { tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); } return code; @@ -1373,18 +1420,14 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg) { return code; } - -int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit, - tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult) { +int32_t tsdbGetTSmaData(STsdb *pTsdb, char*pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) { int32_t code = TSDB_CODE_SUCCESS; - if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, interval, intervalUnit, tableUid, colId, querySKey, - nMaxResult)) < 0) { + if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, querySKey, nMaxResult)) < 0) { tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); } return code; } - int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid) { int32_t code = TSDB_CODE_SUCCESS; if ((code = tsdbDropTSmaDataImpl(pTsdb, indexUid)) < 0) { diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 8ebdad48f7cf41a7f99b8838f4a3c7d1e17ce568..30c2fe84bf39eab9eb3dd0275af8927448e84f7d 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -41,7 +41,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { } } -int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { +int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { vTrace("message in fetch queue is processing"); char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); @@ -66,12 +66,12 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { 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); + return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0); case TDMT_VND_STREAM_TRIGGER: - return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen); + 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 c220e6001fc43a4886d5b973af5542e62989474c..59b027e370d1b58af5a22e5d081c87989b17a604 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -17,7 +17,9 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { // TODO + blockDebugShowData(data); + tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); } void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { @@ -79,7 +81,6 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO: maybe need to clear the request struct taosMemoryFree(vCreateTbReq.stbCfg.pSchema); taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); - taosMemoryFree(vCreateTbReq.stbCfg.pBSmaCols); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); taosMemoryFree(vCreateTbReq.dbFName); taosMemoryFree(vCreateTbReq.name); @@ -114,13 +115,11 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { if (pCreateTbReq->type == TD_SUPER_TABLE) { taosMemoryFree(pCreateTbReq->stbCfg.pSchema); taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); - taosMemoryFree(pCreateTbReq->stbCfg.pBSmaCols); 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); } } @@ -148,7 +147,6 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vAlterTbReq); taosMemoryFree(vAlterTbReq.stbCfg.pSchema); taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); - taosMemoryFree(vAlterTbReq.stbCfg.pBSmaCols); taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); taosMemoryFree(vAlterTbReq.dbFName); taosMemoryFree(vAlterTbReq.name); @@ -163,6 +161,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 @@ -184,24 +183,25 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } } break; case TDMT_VND_TASK_WRITE_EXEC: { - if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { + if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead), + 0) < 0) { } } break; case TDMT_VND_CREATE_SMA: { // timeRangeSMA #if 1 - + SSmaCfg vCreateSmaReq = {0}; if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - vWarn("vgId%d: TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId, terrstr(terrno)); + vWarn("vgId%d: TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId, + terrstr(terrno)); return -1; } vWarn("vgId%d: TDMT_VND_CREATE_SMA received for %s:%" PRIi64, pVnode->config.vgId, vCreateSmaReq.tSma.indexName, vCreateSmaReq.tSma.indexUid); // record current timezone of server side - tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); + vCreateSmaReq.tSma.timezoneInt = tsTimezone; if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) { // TODO: handle error diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index d010ea4437e948553e8b1cd0d3272c063269eb2e..db31b9f4a3d6ef60a4a893b2f3349d6d5589e57f 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -15,6 +15,7 @@ #include #include + #include #include #include @@ -58,20 +59,21 @@ TEST(testCase, unionEncodeDecodeTest) { void *buf = taosMemoryMalloc(1024); void *pBuf = buf; + void *qBuf = buf; int32_t tlen = 0; - tlen += taosEncodeFixedU8(&buf, sut.info); - tlen += taosEncodeFixedI16(&buf, sut.nBSmaCols); + tlen += taosEncodeFixedU8(&pBuf, sut.info); + tlen += taosEncodeFixedI16(&pBuf, sut.nBSmaCols); for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { - tlen += taosEncodeFixedI16(&buf, sut.pBSmaCols[i]); + tlen += taosEncodeFixedI16(&pBuf, sut.pBSmaCols[i]); } SUnionTest dut = {0}; - pBuf = taosDecodeFixedU8(pBuf, &dut.info); - pBuf = taosDecodeFixedI16(pBuf, &dut.nBSmaCols); + qBuf = taosDecodeFixedU8(qBuf, &dut.info); + qBuf = taosDecodeFixedI16(qBuf, &dut.nBSmaCols); if (dut.nBSmaCols > 0) { dut.pBSmaCols = (col_id_t *)taosMemoryMalloc(dut.nBSmaCols * sizeof(col_id_t)); for (col_id_t i = 0; i < dut.nBSmaCols; ++i) { - pBuf = taosDecodeFixedI16(pBuf, dut.pBSmaCols + i); + qBuf = taosDecodeFixedI16(qBuf, dut.pBSmaCols + i); } } else { dut.pBSmaCols = NULL; @@ -80,13 +82,17 @@ TEST(testCase, unionEncodeDecodeTest) { printf("sut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", sut.rollup, sut.type, sut.info); printf("dut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", dut.rollup, dut.type, dut.info); - ASSERT_EQ(sut.rollup, dut.rollup); - ASSERT_EQ(sut.type, dut.type); - ASSERT_EQ(sut.nBSmaCols, dut.nBSmaCols); + EXPECT_EQ(sut.rollup, dut.rollup); + EXPECT_EQ(sut.type, dut.type); + EXPECT_EQ(sut.nBSmaCols, dut.nBSmaCols); for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { - ASSERT_EQ(*(col_id_t *)(sut.pBSmaCols + i), sut.pBSmaCols[i]); - ASSERT_EQ(*(col_id_t *)(sut.pBSmaCols + i), dut.pBSmaCols[i]); + EXPECT_EQ(*(col_id_t *)(sut.pBSmaCols + i), sut.pBSmaCols[i]); + EXPECT_EQ(*(col_id_t *)(sut.pBSmaCols + i), dut.pBSmaCols[i]); } + + taosMemoryFreeClear(buf); + taosMemoryFreeClear(dut.pBSmaCols); + taosMemoryFreeClear(sut.pBSmaCols); } #if 1 TEST(testCase, tSma_Meta_Encode_Decode_Test) { @@ -106,37 +112,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) { uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper); void *buf = taosMemoryCalloc(1, bufLen); - ASSERT_NE(buf, nullptr); + EXPECT_NE(buf, nullptr); STSmaWrapper *pSW = (STSmaWrapper *)buf; uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper); - ASSERT_EQ(len, bufLen); + EXPECT_EQ(len, bufLen); // decode STSmaWrapper dstTSmaWrapper = {0}; void *result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper); - ASSERT_NE(result, nullptr); + EXPECT_NE(result, nullptr); - ASSERT_EQ(tSmaWrapper.number, dstTSmaWrapper.number); + EXPECT_EQ(tSmaWrapper.number, dstTSmaWrapper.number); for (int i = 0; i < tSmaWrapper.number; ++i) { STSma *pSma = tSmaWrapper.tSma + i; STSma *qSma = dstTSmaWrapper.tSma + i; - ASSERT_EQ(pSma->version, qSma->version); - ASSERT_EQ(pSma->intervalUnit, qSma->intervalUnit); - ASSERT_EQ(pSma->slidingUnit, qSma->slidingUnit); - ASSERT_STRCASEEQ(pSma->indexName, qSma->indexName); - ASSERT_EQ(pSma->timezoneInt, qSma->timezoneInt); - ASSERT_EQ(pSma->indexUid, qSma->indexUid); - ASSERT_EQ(pSma->tableUid, qSma->tableUid); - ASSERT_EQ(pSma->interval, qSma->interval); - ASSERT_EQ(pSma->sliding, qSma->sliding); - ASSERT_EQ(pSma->exprLen, qSma->exprLen); - ASSERT_STRCASEEQ(pSma->expr, qSma->expr); - ASSERT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen); - ASSERT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter); + EXPECT_EQ(pSma->version, qSma->version); + EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit); + EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit); + EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName); + EXPECT_EQ(pSma->timezoneInt, qSma->timezoneInt); + EXPECT_EQ(pSma->indexUid, qSma->indexUid); + EXPECT_EQ(pSma->tableUid, qSma->tableUid); + EXPECT_EQ(pSma->interval, qSma->interval); + EXPECT_EQ(pSma->sliding, qSma->sliding); + EXPECT_EQ(pSma->exprLen, qSma->exprLen); + EXPECT_STRCASEEQ(pSma->expr, qSma->expr); + EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen); + EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter); } // resource release @@ -172,12 +178,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { tSma.exprLen = strlen(expr); tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1); - ASSERT_NE(tSma.expr, nullptr); + EXPECT_NE(tSma.expr, nullptr); tstrncpy(tSma.expr, expr, tSma.exprLen + 1); tSma.tagsFilterLen = strlen(tagsFilter); tSma.tagsFilter = (char *)taosMemoryCalloc(tSma.tagsFilterLen + 1, 1); - ASSERT_NE(tSma.tagsFilter, nullptr); + EXPECT_NE(tSma.tagsFilter, nullptr); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1); SMeta *pMeta = NULL; @@ -189,7 +195,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { pMeta = metaOpen(smaTestDir, pMetaCfg, NULL); assert(pMeta != NULL); // save index 1 - ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); + EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); pSmaCfg->indexUid = indexUid2; tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN); @@ -200,7 +206,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { pSmaCfg->sliding = 5; // save index 2 - ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); + EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); // get value by indexName STSma *qSmaCfg = NULL; @@ -210,8 +216,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("timezone1 = %" PRIi8 "\n", qSmaCfg->timezoneInt); printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : ""); printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); - ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); - ASSERT_EQ(qSmaCfg->tableUid, tSma.tableUid); + EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); + EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid); tdDestroyTSma(qSmaCfg); taosMemoryFreeClear(qSmaCfg); @@ -221,8 +227,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("timezone2 = %" PRIi8 "\n", qSmaCfg->timezoneInt); printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : ""); printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); - ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); - ASSERT_EQ(qSmaCfg->interval, tSma.interval); + EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); + EXPECT_EQ(qSmaCfg->interval, tSma.interval); tdDestroyTSma(qSmaCfg); taosMemoryFreeClear(qSmaCfg); @@ -238,25 +244,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("indexName = %s\n", indexName); ++indexCnt; } - ASSERT_EQ(indexCnt, nCntTSma); + EXPECT_EQ(indexCnt, nCntTSma); metaCloseSmaCurosr(pSmaCur); // get wrapper by table uid STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid); assert(pSW != NULL); - ASSERT_EQ(pSW->number, nCntTSma); - ASSERT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); - ASSERT_EQ(pSW->tSma->timezoneInt, timezone); - ASSERT_STRCASEEQ(pSW->tSma->expr, expr); - ASSERT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter); - ASSERT_EQ(pSW->tSma->indexUid, indexUid1); - ASSERT_EQ(pSW->tSma->tableUid, tbUid); - ASSERT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); - ASSERT_EQ((pSW->tSma + 1)->timezoneInt, timezone); - ASSERT_STRCASEEQ((pSW->tSma + 1)->expr, expr); - ASSERT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter); - ASSERT_EQ((pSW->tSma + 1)->indexUid, indexUid2); - ASSERT_EQ((pSW->tSma + 1)->tableUid, tbUid); + EXPECT_EQ(pSW->number, nCntTSma); + EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); + EXPECT_EQ(pSW->tSma->timezoneInt, timezone); + EXPECT_STRCASEEQ(pSW->tSma->expr, expr); + EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter); + EXPECT_EQ(pSW->tSma->indexUid, indexUid1); + EXPECT_EQ(pSW->tSma->tableUid, tbUid); + EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); + EXPECT_EQ((pSW->tSma + 1)->timezoneInt, timezone); + EXPECT_STRCASEEQ((pSW->tSma + 1)->expr, expr); + EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter); + EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2); + EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid); tdDestroyTSmaWrapper(pSW); taosMemoryFreeClear(pSW); @@ -268,7 +274,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("metaGetSmaTbUids: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i)); // printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i)); } - ASSERT_EQ(taosArrayGetSize(pUids), 1); + EXPECT_EQ(taosArrayGetSize(pUids), 1); taosArrayDestroy(pUids); // resource release @@ -280,7 +286,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { } #endif -#if 0 +#if 1 TEST(testCase, tSma_Data_Insert_Query_Test) { // step 1: prepare meta const char *smaIndexName1 = "sma_index_test_1"; @@ -299,9 +305,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { // encode STSma tSma = {0}; tSma.version = 0; - tSma.intervalUnit = TIME_UNIT_DAY; + tSma.intervalUnit = TIME_UNIT_MINUTE; tSma.interval = 1; - tSma.slidingUnit = TIME_UNIT_HOUR; + tSma.slidingUnit = TIME_UNIT_MINUTE; tSma.sliding = 1; // sliding = interval when it's convert window tSma.indexUid = indexUid1; tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); @@ -310,12 +316,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { tSma.exprLen = strlen(expr); tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1); - ASSERT_NE(tSma.expr, nullptr); + EXPECT_NE(tSma.expr, nullptr); tstrncpy(tSma.expr, expr, tSma.exprLen + 1); tSma.tagsFilterLen = strlen(tagsFilter); tSma.tagsFilter = (char *)taosMemoryCalloc(1, tSma.tagsFilterLen + 1); - ASSERT_NE(tSma.tagsFilter, nullptr); + EXPECT_NE(tSma.tagsFilter, nullptr); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1); SMeta *pMeta = NULL; @@ -327,11 +333,11 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { pMeta = metaOpen(smaTestDir, pMetaCfg, NULL); assert(pMeta != NULL); // save index 1 - ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); + EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); // step 2: insert data - STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb)); - STsdbCfg *pCfg = &pTsdb->config; + STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb)); + STsdbCfg *pCfg = &pTsdb->config; pTsdb->pMeta = pMeta; pTsdb->vgId = 2; @@ -364,7 +370,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { strncpy(pDisks.dir, "/var/lib/taos", TSDB_FILENAME_LEN); int32_t numOfDisks = 1; pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks); - ASSERT_NE(pTsdb->pTfs, nullptr); + EXPECT_NE(pTsdb->pTfs, nullptr); // generate SSubmitReq msg and update expired window int16_t schemaVer = 0; @@ -374,7 +380,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { uint32_t msgLen = sizeof(SSubmitReq) + mockBlkNum * sizeof(SSubmitBlk) + mockBlkNum * mockRowNum * mockRowLen; SSubmitReq *pMsg = (SSubmitReq *)taosMemoryCalloc(1, msgLen); - ASSERT_NE(pMsg, nullptr); + EXPECT_NE(pMsg, nullptr); pMsg->version = htobe64(schemaVer); pMsg->numOfBlocks = htonl(mockBlkNum); pMsg->length = htonl(msgLen); @@ -400,20 +406,99 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { } } - ASSERT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS); + EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS); - ASSERT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0); + EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0); // init - int32_t allocCnt = 0; - int32_t allocStep = 16384; - int32_t buffer = 1024; - void *buf = NULL; - ASSERT_EQ(tsdbMakeRoom(&buf, allocStep), 0); - int32_t bufSize = taosTSizeof(buf); - int32_t numOfTables = 10; - col_id_t numOfCols = 4096; - ASSERT_GT(numOfCols, 0); + const int32_t tSmaGroupSize = 4; + const int32_t tSmaNumOfTags = 2; + const int64_t tSmaGroupId = 12345670; + const col_id_t tSmaNumOfCols = 9; // binary/nchar/varbinary/varchar are only used for tags for group by conditions. + const int32_t tSmaNumOfRows = 2; + + SArray *pDataBlocks = taosArrayInit(tSmaGroupSize, sizeof(SSDataBlock *)); + EXPECT_NE(pDataBlocks, nullptr); + int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_INT, + TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_FLOAT, + TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_VARCHAR, TSDB_DATA_TYPE_NCHAR}; + // last 2 columns for group by tags + // int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL}; + const char *tSmaGroupbyTags[tSmaGroupSize * tSmaNumOfTags] = {"BeiJing", "HaiDian", "BeiJing", "ChaoYang", + "ShangHai", "PuDong", "ShangHai", "MinHang"}; + TSKEY tSmaSKeyMs = (int64_t)1648535332 * 1000; + int64_t tSmaIntervalMs = tSma.interval * 60 * 1000; + int64_t tSmaInitVal = 0; + + for (int32_t g = 0; g < tSmaGroupSize; ++g) { + SSDataBlock *pDataBlock = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); + EXPECT_NE(pDataBlock, nullptr); + pDataBlock->pBlockAgg = NULL; + pDataBlock->info.numOfCols = tSmaNumOfCols; + pDataBlock->info.rows = tSmaNumOfRows; + pDataBlock->info.groupId = tSmaGroupId + g; + + pDataBlock->pDataBlock = taosArrayInit(tSmaNumOfCols, sizeof(SColumnInfoData *)); + EXPECT_NE(pDataBlock->pDataBlock, nullptr); + for (int32_t c = 0; c < tSmaNumOfCols; ++c) { + + SColumnInfoData *pColInfoData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData)); + EXPECT_NE(pColInfoData, nullptr); + + pColInfoData->info.type = tSmaTypeArray[c]; + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + pColInfoData->info.bytes = 100; // update accordingly + } else { + pColInfoData->info.bytes = TYPE_BYTES[pColInfoData->info.type]; + } + pColInfoData->pData = (char *)taosMemoryCalloc(1, tSmaNumOfRows * pColInfoData->info.bytes); + + for (int32_t r = 0; r < tSmaNumOfRows; ++r) { + void *pCellData = pColInfoData->pData + r * pColInfoData->info.bytes; + switch (pColInfoData->info.type) { + case TSDB_DATA_TYPE_TIMESTAMP: + *(TSKEY *)pCellData = tSmaSKeyMs + tSmaIntervalMs * r; + break; + case TSDB_DATA_TYPE_BOOL: + *(bool *)pCellData = (bool)tSmaInitVal++; + break; + case TSDB_DATA_TYPE_INT: + *(int *)pCellData = (int)tSmaInitVal++; + break; + case TSDB_DATA_TYPE_UBIGINT: + *(uint64_t *)pCellData = (uint64_t)tSmaInitVal++; + break; + case TSDB_DATA_TYPE_SMALLINT: + *(int16_t *)pCellData = (int16_t)tSmaInitVal++; + break; + case TSDB_DATA_TYPE_FLOAT: + *(float *)pCellData = (float)tSmaInitVal++; + break; + case TSDB_DATA_TYPE_DOUBLE: + *(double *)pCellData = (double)tSmaInitVal++; + break; + case TSDB_DATA_TYPE_VARCHAR: // city + varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2])); + memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2], varDataLen(pCellData)); + break; + case TSDB_DATA_TYPE_NCHAR: // district + varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2 + 1])); + memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2 + 1], varDataLen(pCellData)); + break; + default: + EXPECT_EQ(0, 1); // add definition + break; + } + } + // push SColumnInfoData + taosArrayPush(pDataBlock->pDataBlock, &pColInfoData); + } + // push SSDataBlock + taosArrayPush(pDataBlocks, &pDataBlock); + } + + // execute + EXPECT_EQ(tsdbInsertTSmaData(pTsdb, tSma.indexUid, (const char *)pDataBlocks), TSDB_CODE_SUCCESS); #if 0 STSmaDataWrapper *pSmaData = NULL; @@ -432,7 +517,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { int32_t tableDataLen = sizeof(STSmaTbData); for (col_id_t c = 0; c < numOfCols; ++c) { if (bufSize - len - tableDataLen < buffer) { - ASSERT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0); + EXPECT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0); pSmaData = (STSmaDataWrapper *)buf; pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len); bufSize = taosTSizeof(buf); @@ -459,31 +544,36 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { } pSmaData->dataLen = (len - sizeof(STSmaDataWrapper)); - ASSERT_GE(bufSize, pSmaData->dataLen); + EXPECT_GE(bufSize, pSmaData->dataLen); // execute - ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); + EXPECT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); #endif - SSDataBlock *pSmaData = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); - - - // step 3: query uint32_t checkDataCnt = 0; - for (int32_t t = 0; t < numOfTables; ++t) { - for (col_id_t c = 0; c < numOfCols; ++c) { - ASSERT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t, - c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1), - TSDB_CODE_SUCCESS); - ++checkDataCnt; - } - } + EXPECT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, skey1, 1), TSDB_CODE_SUCCESS); + ++checkDataCnt; printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt); // release data taosMemoryFreeClear(pMsg); - taosTZfree(buf); + + for (int32_t i = 0; i < taosArrayGetSize(pDataBlocks); ++i) { + SSDataBlock *pDataBlock = *(SSDataBlock **)taosArrayGet(pDataBlocks, i); + int32_t numOfOutput = taosArrayGetSize(pDataBlock->pDataBlock); + for (int32_t j = 0; j < numOfOutput; ++j) { + SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, j); + colDataDestroy(pColInfoData); + taosMemoryFreeClear(pColInfoData); + } + + taosArrayDestroy(pDataBlock->pDataBlock); + taosMemoryFreeClear(pDataBlock->pBlockAgg); + taosMemoryFreeClear(pDataBlock); + } + taosArrayDestroy(pDataBlocks); + // release meta tdDestroyTSma(&tSma); tfsClose(pTsdb->pTfs); diff --git a/source/libs/CMakeLists.txt b/source/libs/CMakeLists.txt index a1b9337fa80c050b9078b602a9d5545c2c037dbf..b1e8be6528e07a960aac3aec5b1d2ac8a091b0cd 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 9bd5c1c016e9f0483b36c83131c482087d84f4e3..09f51dc03e6e926e8599fcc65f3dca0314145e65 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 e87fdba71db969a11ddd19e92a9100e766083ac5..e1f533289970c653fb1e78ff39b71f9f709269a0 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 0000000000000000000000000000000000000000..1d4ad0082c7e0736dc2ccad54609319e29e426f7 --- /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 e62819b07857aaab9bdedfbdaee6cfb2826aa6f8..73d0dc20117914fabe9af470d59cfa5ea84e6711 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 0000000000000000000000000000000000000000..db3766d1452317b7419d962f6fe3e2bdfd614ff5 --- /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 0000000000000000000000000000000000000000..771baca2abeaac621a4da7c6bf7a5a5272bbab47 --- /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 0000000000000000000000000000000000000000..7ffbd4f80aa90e55412ad39a065ce05f56f5d387 --- /dev/null +++ b/source/libs/command/src/command.c @@ -0,0 +1,115 @@ +/* + * 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" + +// #define SET_VARSTR(pData, val, pOffset) + +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 = pMeta->schema[i].bytes; + 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 0000000000000000000000000000000000000000..847a863e7678ed66aecdb198da0a2f20690485aa --- /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 0000000000000000000000000000000000000000..6d2335d2e36239d31c7764171d66cb84ad3b6a02 --- /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/client/consumer/consumer.c b/source/libs/command/test/commandTest.cpp similarity index 83% rename from source/client/consumer/consumer.c rename to source/libs/command/test/commandTest.cpp index 4ba1f9514444f8972bcb4c72cdb8a3c3c681eeec..59118c501ae8ec9225d310760d71973b22036ce7 100644 --- a/source/client/consumer/consumer.c +++ b/source/libs/command/test/commandTest.cpp @@ -13,4 +13,9 @@ * along with this program. If not, see . */ -#include "consumer.h" +#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 bcbfeb7015390bc8ddadd08349cd858e93a9bdc1..3faf208c0ef9b5966089276d09a5afd1f5d099e3 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,25 +94,33 @@ 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, int32_t offset) { assert(rowOffset >= 0 && pQueryAttr != NULL); - + ASSERT(0); // int32_t numOfRows = (int32_t)getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery); // return ((char *)page->data) + rowOffset + offset * numOfRows; } @@ -139,23 +132,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 2bbd16fbd02648d136164eb090088355c2210395..64e2b2c1d37bc4c78a556e708f31c84f166f7efa 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; /** @@ -161,20 +161,8 @@ typedef struct STaskCostInfo { typedef struct SOperatorCostInfo { uint64_t openCost; uint64_t execCost; -// uint64_t totalRows; -// uint64_t totalBytes; } SOperatorCostInfo; -typedef struct { - int64_t vgroupLimit; - int64_t ts; -} SOrderedPrjQueryInfo; - -typedef struct { - char* tags; - SArray* pResult; // SArray -} SInterResult; - // The basic query information extracted from the SQueryInfo tree to support the // execution of query in a data node. typedef struct STaskAttr { @@ -230,7 +218,6 @@ typedef struct STaskAttr { SColumnInfo* tagColList; int32_t numOfFilterCols; int64_t* fillVal; - SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query. SSingleColumnFilterInfo* pFilterInfo; // SFilterInfo *pFilters; @@ -245,8 +232,9 @@ struct SOperatorInfo; typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length); typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length); -typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* param); -typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* param, bool* newgroup); + +typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr); +typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup); typedef void (*__optr_close_fn_t)(void* param, int32_t num); typedef struct STaskIdInfo { @@ -267,7 +255,8 @@ typedef struct SExecTaskInfo { uint64_t totalRows; // total number of rows STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray structure char* sql; // query sql string - jmp_buf env; // + jmp_buf env; // jump to this position when error happens. + EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] struct SOperatorInfo* pRoot; } SExecTaskInfo; @@ -288,8 +277,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; @@ -330,11 +317,12 @@ typedef struct SOperatorInfo { SResultInfo resultInfo; struct SOperatorInfo** pDownstream; // downstram pointer list int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator + __optr_open_fn_t _openFn; // DO NOT invoke this function directly __optr_fn_t getNextFn; - __optr_fn_t cleanupFn; + __optr_fn_t getStreamResFn; // execute the aggregate in the stream model. + __optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP __optr_close_fn_t closeFn; - __optr_open_fn_t _openFn; // DO NOT invoke this function directly - __optr_encode_fn_t encodeResultRow; // + __optr_encode_fn_t encodeResultRow; __optr_decode_fn_t decodeResultRow; } SOperatorInfo; @@ -363,18 +351,19 @@ typedef struct SQInfo { STaskCostInfo summary; } SQInfo; -enum { - DATA_NOT_READY = 0x1, - DATA_READY = 0x2, - DATA_EXHAUSTED = 0x3, -}; +typedef enum { + EX_SOURCE_DATA_NOT_READY = 0x1, + EX_SOURCE_DATA_READY = 0x2, + EX_SOURCE_DATA_EXHAUSTED = 0x3, +} EX_SOURCE_STATUS; typedef struct SSourceDataInfo { struct SExchangeInfo *pEx; - int32_t index; - SRetrieveTableRsp *pRsp; - uint64_t totalRows; - int32_t status; + int32_t index; + SRetrieveTableRsp *pRsp; + uint64_t totalRows; + int32_t code; + EX_SOURCE_STATUS status; } SSourceDataInfo; typedef struct SLoadRemoteDataInfo { @@ -383,12 +372,6 @@ typedef struct SLoadRemoteDataInfo { uint64_t totalElapsed; // total elapsed time } SLoadRemoteDataInfo; -enum { - EX_SOURCE_DATA_NOT_READY = 0x1, - EX_SOURCE_DATA_READY = 0x2, - EX_SOURCE_DATA_EXHAUSTED = 0x3, -}; - typedef struct SExchangeInfo { SArray* pSources; SArray* pSourceDataInfo; @@ -410,6 +393,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; @@ -438,6 +422,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 { @@ -484,16 +469,18 @@ typedef struct SAggSupporter { } SAggSupporter; typedef struct STableIntervalOperatorInfo { - SOptrBasicInfo binfo; - SGroupResInfo groupResInfo; - SInterval interval; - STimeWindow win; - int32_t precision; - bool timeWindowInterpo; - char **pRow; - SAggSupporter aggSup; - STableQueryInfo *pCurrent; - int32_t order; + SOptrBasicInfo binfo; // basic info + SGroupResInfo groupResInfo; // multiple results build supporter + SInterval interval; // interval info + STimeWindow win; // query time range + bool timeWindowInterpo; // interpolation needed or not + char **pRow; // previous row/tuple of already processed datablock + SAggSupporter aggSup; // aggregate supporter + STableQueryInfo *pCurrent; // current tableQueryInfo struct + int32_t order; // current SSDataBlock scan order + EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] + SArray *pUpdatedWindow; // updated time window due to the input data block from the downstream operator. + SColumnInfoData timeWindowData; // query time window info for scalar function execution. } STableIntervalOperatorInfo; typedef struct SAggOperatorInfo { @@ -510,14 +497,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; @@ -536,11 +520,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; @@ -650,17 +629,15 @@ 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); @@ -668,6 +645,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); 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); @@ -687,36 +665,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 doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, SSDataBlock* pBlock); -bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, int32_t numOfRows, int8_t* p); -void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p); - -SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numOfRows); - -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); @@ -734,7 +695,7 @@ int32_t getMaximumIdleDurationSec(); void doInvokeUdf(struct SUdfInfo* pUdfInfo, SqlFunctionCtx* pCtx, int32_t idx, int32_t type); void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status); -int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId); +int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model); #ifdef __cplusplus } diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 2c6468a13f239bd50a797e99460460c6dc3834f3..40e86c7840c43dccc801fe9117bb7273ad6ce461 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/executor.c b/source/libs/executor/src/executor.c index 615bcdcdbbd0e6b2282852d0bfc28485cf5205ec..15203d91cafc3611fd316c91db8f0f4a895cfb02 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -113,7 +113,7 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) { } qTaskInfo_t pTaskInfo = NULL; - code = qCreateExecTask(streamReadHandle, 0, 0, plan, &pTaskInfo, NULL); + code = qCreateExecTask(streamReadHandle, 0, 0, plan, &pTaskInfo, NULL, OPTR_EXEC_MODEL_STREAM); if (code != TSDB_CODE_SUCCESS) { // TODO: destroy SSubplan & pTaskInfo terrno = code; diff --git a/source/libs/executor/src/executorMain.c b/source/libs/executor/src/executorMain.c index cc9921ce73c655508a395733a43170d78c0ebf3a..6d78fa835ac143849c1e83fccd009354a4dccae9 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -51,11 +51,12 @@ static void freeqinfoFn(void *qhandle) { qDestroyTask(*handle); } -int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle) { +int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan, + qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, EOPTR_EXEC_MODEL model) { assert(readHandle != NULL && pSubplan != NULL); SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo; - int32_t code = createExecTaskInfoImpl(pSubplan, pTask, readHandle, taskId); + int32_t code = createExecTaskInfoImpl(pSubplan, pTask, readHandle, taskId, model); if (code != TSDB_CODE_SUCCESS) { goto _error; } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 09cf1473352134d0dd6178711e574dd68342e031..6cb95b9a3e9ac21fab94b64ca91c8977d2a69998 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); @@ -264,10 +259,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); @@ -352,7 +343,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; @@ -426,18 +417,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; } @@ -458,9 +441,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 = @@ -479,6 +461,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; @@ -496,16 +479,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; @@ -555,6 +538,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; @@ -599,65 +583,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 (!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); + } - SResultRow* pResult = NULL; + prepareResultListBuffer(pResultRowInfo, pTaskInfo->env); 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); - } + initResultRow(pResult); // 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}; + 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 = *p1; + 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); @@ -669,7 +663,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, @@ -693,7 +687,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}; @@ -701,7 +695,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) { @@ -730,7 +724,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); @@ -742,7 +736,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; } /* @@ -752,6 +746,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; } @@ -816,8 +811,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; @@ -840,8 +835,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, @@ -859,7 +853,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; } @@ -909,9 +903,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]; @@ -963,6 +957,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, @@ -1014,8 +1009,37 @@ static int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* p return num; } -static void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, int32_t offset, int32_t forwardStep, TSKEY* tsCol, +// query_range_start, query_range_end, window_duration, window_start, window_end +static void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) { + pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP; + pColData->info.bytes = sizeof(int64_t); + + colInfoDataEnsureCapacity(pColData, 5); + colDataAppendInt64(pColData, 0, &pQueryWindow->skey); + colDataAppendInt64(pColData, 1, &pQueryWindow->ekey); + + int64_t interval = 0; + colDataAppendInt64(pColData, 2, &interval); // this value may be variable in case of 'n' and 'y'. + colDataAppendInt64(pColData, 3, &pQueryWindow->skey); + colDataAppendInt64(pColData, 4, &pQueryWindow->ekey); +} + +static void updateTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pWin) { + int64_t* ts = (int64_t*)pColData->pData; + + int64_t duration = pWin->ekey - pWin->skey + 1; + ts[2] = duration; // set the duration + ts[3] = pWin->skey; // window start key + ts[4] = pWin->ekey + 1; // 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 + if (pTimeWindowData != NULL) { + updateTimeWindowInfo(pTimeWindowData, pWin); + } + for (int32_t k = 0; k < numOfOutput; ++k) { pCtx[k].startTs = pWin->skey; @@ -1038,6 +1062,21 @@ static void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, int32_t of pCtx[k].isAggSet = false; } + if (fmIsWindowPseudoColumnFunc(pCtx[k].functionId)) { + 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); + pEntryInfo->numOfRes = 1; + pEntryInfo->hasResult = ','; + continue; + } + if (functionNeedToExecute(&pCtx[k])) { pCtx[k].fpSet.process(&pCtx[k]); } @@ -1054,7 +1093,7 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, int32_t order = pInfo->order; bool ascQuery = (order == TSDB_ORDER_ASC); - int32_t precision = pInfo->precision; + int32_t precision = pInterval->precision; getNextTimeWindow(pInterval, precision, order, pNext); // next time window is not in current block @@ -1211,8 +1250,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)*/) { @@ -1489,15 +1528,19 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc } } -static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, - int32_t tableGroupId) { +static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, int32_t tableGroupId) { STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*)pOperatorInfo->info; SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo; int32_t numOfOutput = pOperatorInfo->numOfOutput; + SArray* pUpdated = NULL; + if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) { + pUpdated = taosArrayInit(4, sizeof(SResultRowPosition)); + } + int32_t step = 1; - bool ascQuery = true; + bool ascScan = true; int32_t prevIndex = pResultRowInfo->curPos; @@ -1505,14 +1548,14 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul 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 = ascQuery ? 0 : (pSDataBlock->info.rows - 1); - TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols, pSDataBlock->info.rows, ascQuery); + 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->precision, &pInfo->win); + STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->interval.precision, &pInfo->win); bool masterScan = true; SResultRow* pResult = NULL; @@ -1523,6 +1566,11 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } + if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) { + SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset}; + taosArrayPush(pUpdated, &pos); + } + int32_t forwardStep = 0; TSKEY ekey = win.ekey; forwardStep = @@ -1530,12 +1578,13 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul // 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); if (pRes->closed) { - assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && - resultRowInterpolated(pRes, RESULT_ROW_END_INTERP)); + assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && resultRowInterpolated(pRes, RESULT_ROW_END_INTERP)); continue; } @@ -1548,14 +1597,13 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul } assert(!resultRowInterpolated(pResult, RESULT_ROW_END_INTERP)); - doTimeWindowInterpolation(pOperatorInfo, &pInfo->binfo, pSDataBlock->pDataBlock, *(TSKEY*)pInfo->pRow[0], -1, tsCols[startPos], startPos, w.ekey, RESULT_ROW_END_INTERP); setResultRowInterpo(pResult, RESULT_ROW_END_INTERP); setNotInterpoWindowKey(pInfo->binfo.pCtx, pOperatorInfo->numOfOutput, RESULT_ROW_START_INTERP); - doApplyFunctions(pInfo->binfo.pCtx, &w, startPos, 0, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); + doApplyFunctions(pInfo->binfo.pCtx, &w, &pInfo->timeWindowData, startPos, 0, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); } // restore current time window @@ -1566,12 +1614,12 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul 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); - doApplyFunctions(pInfo->binfo.pCtx, &win, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, - TSDB_ORDER_ASC); + doApplyFunctions(pInfo->binfo.pCtx, &win, &pInfo->timeWindowData, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); STimeWindow nextWin = win; while (1) { @@ -1589,6 +1637,11 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } + if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) { + SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset}; + taosArrayPush(pUpdated, &pos); + } + ekey = nextWin.ekey; // reviseWindowEkey(pQueryAttr, &nextWin); forwardStep = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); @@ -1596,15 +1649,15 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul // window start(end) key interpolation doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardStep, pInfo->order, false); - doApplyFunctions(pInfo->binfo.pCtx, &nextWin, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, - TSDB_ORDER_ASC); + doApplyFunctions(pInfo->binfo.pCtx, &nextWin, &pInfo->timeWindowData, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); } if (pInfo->timeWindowInterpo) { - int32_t rowIndex = ascQuery ? (pSDataBlock->info.rows - 1) : 0; + int32_t rowIndex = ascScan ? (pSDataBlock->info.rows - 1) : 0; saveDataBlockLastRow(pInfo->pRow, pSDataBlock->pDataBlock, rowIndex, pSDataBlock->info.numOfCols); } + return pUpdated; // updateResultRowInfoActiveIndex(pResultRowInfo, &pInfo->win, pRuntimeEnv->current->lastKey, true, false); } @@ -1833,15 +1886,13 @@ 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); } int32_t rowIndex = j - num; - doApplyFunctions(pCtx, &w, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); + doApplyFunctions(pCtx, &w, NULL, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); // assign the group keys or user input constant values if required doAssignGroupKeys(pCtx, pOperator->numOfOutput, pBlock->info.rows, rowIndex); @@ -1859,7 +1910,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } int32_t rowIndex = pBlock->info.rows - num; - doApplyFunctions(pCtx, &w, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); + doApplyFunctions(pCtx, &w, NULL, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); doAssignGroupKeys(pCtx, pOperator->numOfOutput, pBlock->info.rows, rowIndex); } } @@ -1910,8 +1961,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator } // pInfo->numOfRows data belong to the current session window - doApplyFunctions(pInfo->binfo.pCtx, &window, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, - TSDB_ORDER_ASC); + doApplyFunctions(pInfo->binfo.pCtx, &window, NULL, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); pInfo->curWindow.skey = tsList[j]; pInfo->curWindow.ekey = tsList[j]; @@ -1931,8 +1981,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } - doApplyFunctions(pInfo->binfo.pCtx, &window, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, - TSDB_ORDER_ASC); + doApplyFunctions(pInfo->binfo.pCtx, &window, NULL, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); } static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { @@ -1959,12 +2008,11 @@ 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; } @@ -1999,11 +2047,7 @@ static bool functionNeedToExecute(SqlFunctionCtx* pCtx) { return false; } - if (functionId == FUNCTION_TS) { - return true; - } - - if (isRowEntryCompleted(pResInfo) || functionId == FUNCTION_TAG_DUMMY || functionId == FUNCTION_TS_DUMMY) { + if (isRowEntryCompleted(pResInfo)) { return false; } @@ -2118,10 +2162,13 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num pCtx->fpSet.getEnv(pExpr->pExpr->_function.pFunctNode, &env); } else { fmGetScalarFuncExecFuncs(pCtx->functionId, &pCtx->sfp); + if (pCtx->sfp.getEnv != NULL) { + pCtx->sfp.getEnv(pExpr->pExpr->_function.pFunctNode, &env); + } } 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; @@ -2969,6 +3016,23 @@ 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); + +// filterSetColFieldData(pQueryAttr->pFilters, pBlock->info.numOfCols, pBlock->pDataBlock); + +// if (pQueryAttr->pFilters != NULL) { +// filterColRowsInDataBlock(pRuntimeEnv, pBlock, ascQuery); +// } + } + return TSDB_CODE_SUCCESS; } @@ -3288,11 +3352,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 @@ -3380,10 +3439,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; } /* @@ -3399,7 +3456,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; @@ -3488,19 +3547,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]); @@ -3560,10 +3606,48 @@ 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); + + struct SResultRowEntryInfo* pResInfo = pCtx[j].resultInfo; + if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) { + continue; + } + + if (pCtx[j].fpSet.process) { // TODO set the dummy function, to avoid the check for null ptr. + pCtx[j].fpSet.finalize(&pCtx[j]); + } + + if (pRow->numOfRows < pResInfo->numOfRes) { + pRow->numOfRows = pResInfo->numOfRes; + } } + releaseBufPage(pBuf, bufPage); + /* + * set the number of output results for group by normal columns, the number of output rows usually is 1 except + * the top and bottom query + */ + // buf->numOfRows = (uint16_t)getNumOfResult(pCtx, numOfOutput); + } +} + +void finalizeUpdatedResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SArray* pUpdateList, + int32_t* rowCellInfoOffset) { + size_t num = taosArrayGetSize(pUpdateList); + + for (int32_t i = 0; i < num; ++i) { + SResultRowPosition* pPos = taosArrayGet(pUpdateList, i); + + SFilePage* bufPage = getBufPage(pBuf, pPos->pageId); + SResultRow* pRow = (SResultRow*)((char*)bufPage + pPos->offset); + for (int32_t j = 0; j < numOfOutput; ++j) { pCtx[j].resultInfo = getResultCell(pRow, j, rowCellInfoOffset); @@ -3574,6 +3658,7 @@ void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SD if (pCtx[j].fpSet.process) { // TODO set the dummy function. pCtx[j].fpSet.finalize(&pCtx[j]); + pResInfo->initialized = true; } if (pRow->numOfRows < pResInfo->numOfRes) { @@ -3619,23 +3704,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; @@ -3678,9 +3746,7 @@ void setResultRowOutputBufInitCtx(STaskRuntimeEnv* pRuntimeEnv, SResultRow* pRes } } -void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, SqlFunctionCtx* pCtx, - int32_t numOfOutput, int32_t* rowCellInfoOffset) { - // Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group +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); @@ -3688,13 +3754,10 @@ void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, S if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) { 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 (fmIsWindowPseudoColumnFunc(pCtx[i].functionId)) { + continue; + } if (!pResInfo->initialized && pCtx[i].functionId != -1) { pCtx[i].fpSet.init(&pCtx[i], pResInfo); @@ -3702,8 +3765,7 @@ void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, S } } -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; @@ -3722,14 +3784,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, @@ -3746,30 +3807,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; @@ -4032,8 +4069,7 @@ static void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDa return; } - int32_t orderType = - TSDB_ORDER_ASC; //(pQueryAttr->pGroupbyExpr != NULL) ? pQueryAttr->pGroupbyExpr->orderType : TSDB_ORDER_ASC; + int32_t orderType = TSDB_ORDER_ASC; doCopyToSDataBlock(pBuf, pGroupResInfo, orderType, pBlock, rowCapacity, rowCellOffset); // add condition (pBlock->info.rows >= 1) just to runtime happy @@ -4046,7 +4082,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]; @@ -4060,6 +4096,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) { @@ -4537,73 +4575,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) { @@ -4701,7 +4672,6 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { // break; // } // - // pRuntimeEnv->current = *pTableQueryInfo; // doTableQueryInfoTimeWindowCheck(pTaskInfo, *pTableQueryInfo, pTableScanInfo->order); // } @@ -4882,7 +4852,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; @@ -4902,12 +4885,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); @@ -5074,12 +5061,12 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SEx for (int32_t i = 0; i < totalSources; ++i) { SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, i); - if (pDataInfo->status == DATA_EXHAUSTED) { + if (pDataInfo->status == EX_SOURCE_DATA_EXHAUSTED) { completed += 1; continue; } - if (pDataInfo->status != DATA_READY) { + if (pDataInfo->status != EX_SOURCE_DATA_READY) { continue; } @@ -5093,7 +5080,7 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SEx " try next", GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, i + 1, pDataInfo->totalRows, pExchangeInfo->loadInfo.totalRows); - pDataInfo->status = DATA_EXHAUSTED; + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; completed += 1; continue; } @@ -5111,16 +5098,15 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SEx ", totalRows:%" PRIu64 ", totalBytes:%" PRIu64 " try next %d/%" PRIzu, GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize, i + 1, totalSources); - pDataInfo->status = DATA_EXHAUSTED; + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; } else { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 - ", totalBytes:%" PRIu64, + qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 ", totalBytes:%" PRIu64, GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pLoadInfo->totalRows, pLoadInfo->totalSize); } - if (pDataInfo->status != DATA_EXHAUSTED) { - pDataInfo->status = DATA_NOT_READY; + if (pDataInfo->status != EX_SOURCE_DATA_EXHAUSTED) { + pDataInfo->status = EX_SOURCE_DATA_NOT_READY; code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -5164,7 +5150,6 @@ static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo* pOperator) { totalSources, endTs - startTs); tsem_wait(&pExchangeInfo->ready); - pOperator->status = OP_RES_TO_RETURN; return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); } @@ -5208,22 +5193,26 @@ 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); - pDataInfo->status = DATA_EXHAUSTED; + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; pExchangeInfo->current += 1; continue; } @@ -5240,7 +5229,7 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo* pOperator) { GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize, pExchangeInfo->current + 1, totalSources); - pDataInfo->status = DATA_EXHAUSTED; + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; pExchangeInfo->current += 1; } else { qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 @@ -5440,7 +5429,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)); @@ -5459,21 +5448,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->pTsdbReadHandle = 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; } @@ -5537,8 +5527,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); @@ -5577,9 +5577,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; } @@ -5720,7 +5720,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 { @@ -5736,6 +5736,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; @@ -5775,6 +5779,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", @@ -6676,7 +6684,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; @@ -6698,6 +6706,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) return pRes; } } +#endif SOperatorInfo* downstream = pOperator->pDownstream[0]; @@ -6737,98 +6746,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 SSDataBlock* doFilter(void* param, bool* newgroup) { - SOperatorInfo* pOperator = (SOperatorInfo*)param; - if (pOperator->status == OP_EXEC_DONE) { - return NULL; - } - - SFilterOperatorInfo* pCondInfo = pOperator->info; - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; - - while (1) { - publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC); - SSDataBlock* pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup); - publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC); - - if (pBlock == NULL) { - break; - } - - doSetFilterColumnInfo(pCondInfo->pFilterInfo, pCondInfo->numOfFilterCols, pBlock); - assert(pRuntimeEnv->pTsBuf == NULL); - filterRowsInDataBlock(pRuntimeEnv, pCondInfo->pFilterInfo, pCondInfo->numOfFilterCols, pBlock, true); - - if (pBlock->info.rows > 0) { - return pBlock; - } - } - - doSetOperatorCompleted(pOperator); - return NULL; -} - static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { if (OPTR_IS_OPENED(pOperator)) { return TSDB_CODE_SUCCESS; @@ -6837,8 +6780,8 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { STableIntervalOperatorInfo* pInfo = pOperator->info; int32_t order = TSDB_ORDER_ASC; - // STimeWindow win = pQueryAttr->window; - bool newgroup = false; + // STimeWindow win = {0}; + bool newgroup = false; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { @@ -6851,7 +6794,6 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { } // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfOutput); - // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0); @@ -6874,6 +6816,10 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro return NULL; } + if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) { + return pOperator->getStreamResFn(pOperator, newgroup); + } + pTaskInfo->code = pOperator->_openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS) { return NULL; @@ -6890,7 +6836,61 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; } -static SSDataBlock* doAllIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { +static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { + STableIntervalOperatorInfo* pInfo = pOperator->info; + int32_t order = TSDB_ORDER_ASC; + + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + if (pOperator->status == OP_RES_TO_RETURN) { + toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, + pInfo->binfo.rowCellInfoOffset); + if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { + pOperator->status = OP_EXEC_DONE; + } + return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; + } + + // STimeWindow win = {0}; + *newgroup = false; + SOperatorInfo* downstream = pOperator->pDownstream[0]; + + SArray* pUpdated = NULL; + + while (1) { + publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); + SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); + publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); + + if (pBlock == NULL) { + break; + } + + // The timewindows that overlaps the timestamps of the input pBlock need to be recalculated and return to the caller. + // Note that all the time window are not close till now. + + // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfOutput); + // the pDataBlock are always the same one, no need to call this again + setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); + pUpdated = hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0); + } + + 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); + + ASSERT(pInfo->binfo.pRes->info.rows > 0); + pOperator->status = OP_RES_TO_RETURN; + + return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; +} + +static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } @@ -7142,22 +7142,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); @@ -7167,28 +7167,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; } @@ -7443,10 +7444,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 || @@ -7514,8 +7515,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* //(int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); int32_t numOfRows = 1; - int32_t code = - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, pTaskInfo->id.str); + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -7523,18 +7523,18 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, pTaskInfo); - pOperator->name = "TableAggregate"; + pOperator->name = "TableAggregate"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_AGG; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = numOfCols; - - pOperator->pTaskInfo = pTaskInfo; - pOperator->_openFn = doOpenAggregateOptr; - pOperator->getNextFn = getAggregateResult; - pOperator->closeFn = destroyAggOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + + pOperator->pTaskInfo = pTaskInfo; + pOperator->_openFn = doOpenAggregateOptr; + pOperator->getNextFn = getAggregateResult; + pOperator->closeFn = destroyAggOperatorInfo; pOperator->encodeResultRow = aggEncodeResultRow; pOperator->decodeResultRow = aggDecodeResultRow; @@ -7621,11 +7621,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); @@ -7695,32 +7690,33 @@ _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); - pOperator->name = "ProjectOperator"; + pOperator->name = "ProjectOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = num; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doProjectOperation; - pOperator->closeFn = destroyProjectOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = num; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doProjectOperation; + pOperator->closeFn = destroyProjectOperatorInfo; pOperator->pTaskInfo = pTaskInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); @@ -7735,67 +7731,6 @@ _error: return NULL; } -SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int32_t* numOfFilterCols) { -#if 0 - SColumnInfo* pCols = taosMemoryCalloc(numOfOutput, sizeof(SColumnInfo)); - - int32_t numOfFilter = 0; - for(int32_t i = 0; i < numOfOutput; ++i) { - if (pExpr[i].base.flist.numOfFilters > 0) { - numOfFilter += 1; - } - - pCols[i].type = pExpr[i].base.resSchema.type; - pCols[i].bytes = pExpr[i].base.resSchema.bytes; - pCols[i].colId = pExpr[i].base.resSchema.colId; - - pCols[i].flist.numOfFilters = pExpr[i].base.flist.numOfFilters; - if (pCols[i].flist.numOfFilters != 0) { - pCols[i].flist.filterInfo = taosMemoryCalloc(pCols[i].flist.numOfFilters, sizeof(SColumnFilterInfo)); - memcpy(pCols[i].flist.filterInfo, pExpr[i].base.flist.filterInfo, pCols[i].flist.numOfFilters * sizeof(SColumnFilterInfo)); - } else { - // avoid runtime error - pCols[i].flist.filterInfo = NULL; - } - } - - assert(numOfFilter > 0); - - *numOfFilterCols = numOfFilter; - return pCols; -#endif - - return 0; -} - -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) { @@ -7805,17 +7740,18 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* goto _error; } - pInfo->order = TSDB_ORDER_ASC; - pInfo->precision = TSDB_TIME_PRECISION_MILLI; - pInfo->win = pTaskInfo->window; - pInfo->interval = *pInterval; + pInfo->order = TSDB_ORDER_ASC; + pInfo->interval = *pInterval; + pInfo->execModel = pTaskInfo->execModel; - pInfo->win.skey = INT64_MIN; - pInfo->win.ekey = INT64_MAX; + pInfo->win = pTaskInfo->window; + pInfo->win.skey = 0; + pInfo->win.ekey = INT64_MAX; 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); + initExecTimeWindowInfo(&pInfo->timeWindowData, &pInfo->win); + // pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS /* || pInfo->pTableQueryInfo == NULL*/) { goto _error; @@ -7823,17 +7759,18 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); - pOperator->name = "TimeIntervalAggOperator"; + pOperator->name = "TimeIntervalAggOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INTERVAL; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->numOfOutput = numOfCols; - pOperator->info = pInfo; - pOperator->_openFn = doOpenIntervalAgg; - pOperator->getNextFn = doBuildIntervalResult; - pOperator->closeFn = destroyIntervalOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->_openFn = doOpenIntervalAgg; + pOperator->getNextFn = doBuildIntervalResult; + pOperator->getStreamResFn= doStreamIntervalAgg; + pOperator->closeFn = destroyIntervalOperatorInfo; code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -7875,9 +7812,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); @@ -7888,13 +7825,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; @@ -8555,6 +8493,23 @@ static SResSchema createResSchema(int32_t type, int32_t bytes, int32_t slotId, i return s; } +static SColumn* createColumn(int32_t blockId, int32_t slotId, SDataType* pType) { + SColumn* pCol = taosMemoryCalloc(1, sizeof(SColumn)); + if (pCol == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pCol->slotId = slotId; + pCol->bytes = pType->bytes; + pCol->type = pType->type; + pCol->scale = pType->scale; + pCol->precision = pType->precision; + pCol->dataBlockId = blockId; + + return pCol; +} + SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* numOfExprs) { int32_t numOfFuncs = LIST_LENGTH(pNodeList); int32_t numOfGroupKeys = 0; @@ -8586,18 +8541,11 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); pExp->base.numOfParams = 1; - pExp->base.pParam[0].pCol = taosMemoryCalloc(1, sizeof(SColumn)); - pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; SDataType* pType = &pColNode->node.resType; pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pColNode->colName); - - SColumn* pCol = pExp->base.pParam[0].pCol; - pCol->slotId = pColNode->slotId; // TODO refactor - pCol->bytes = pType->bytes; - pCol->type = pType->type; - pCol->scale = pType->scale; - pCol->precision = pType->precision; + pExp->base.pParam[0].pCol = createColumn(pColNode->dataBlockId, pColNode->slotId, pType); + pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; } else if (nodeType(pTargetNode->pExpr) == QUERY_NODE_FUNCTION) { pExp->pExpr->nodeType = QUERY_NODE_FUNCTION; SFunctionNode* pFuncNode = (SFunctionNode*)pTargetNode->pExpr; @@ -8608,8 +8556,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* pExp->pExpr->_function.functionId = pFuncNode->funcId; pExp->pExpr->_function.pFunctNode = pFuncNode; - strncpy(pExp->pExpr->_function.functionName, pFuncNode->functionName, - tListLen(pExp->pExpr->_function.functionName)); + strncpy(pExp->pExpr->_function.functionName, pFuncNode->functionName, tListLen(pExp->pExpr->_function.functionName)); // TODO: value parameter needs to be handled int32_t numOfParam = LIST_LENGTH(pFuncNode->pParameterList); @@ -8620,21 +8567,12 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* for (int32_t j = 0; j < numOfParam; ++j) { SNode* p1 = nodesListGetNode(pFuncNode->pParameterList, j); if (p1->type == QUERY_NODE_COLUMN) { - SColumnNode* pcn = (SColumnNode*)p1; // TODO refactor + SColumnNode* pcn = (SColumnNode*) p1; pExp->base.pParam[j].type = FUNC_PARAM_TYPE_COLUMN; - pExp->base.pParam[j].pCol = taosMemoryCalloc(1, sizeof(SColumn)); - SColumn* pCol = pExp->base.pParam[j].pCol; - - pCol->slotId = pcn->slotId; - pCol->bytes = pcn->node.resType.bytes; - pCol->type = pcn->node.resType.type; - pCol->scale = pcn->node.resType.scale; - pCol->precision = pcn->node.resType.precision; - pCol->dataBlockId = pcn->dataBlockId; + pExp->base.pParam[j].pCol = createColumn(pcn->dataBlockId, pcn->slotId, &pcn->node.resType); } else if (p1->type == QUERY_NODE_VALUE) { SValueNode* pvn = (SValueNode*)p1; - pExp->base.pParam[j].type = FUNC_PARAM_TYPE_VALUE; } } @@ -8644,21 +8582,14 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); pExp->base.numOfParams = 1; - pExp->base.pParam[0].pCol = taosMemoryCalloc(1, sizeof(SColumn)); - pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; SDataType* pType = &pNode->node.resType; - pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, - pType->precision, pNode->node.aliasName); + pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pNode->node.aliasName); pExp->pExpr->_optrRoot.pRootNode = pTargetNode->pExpr; - SColumn* pCol = pExp->base.pParam[0].pCol; - pCol->slotId = pTargetNode->slotId; // TODO refactor - pCol->bytes = pType->bytes; - pCol->type = pType->type; - pCol->scale = pType->scale; - pCol->precision = pType->precision; +// pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; +// pExp->base.pParam[0].pCol = createColumn(pTargetNode->dataBlockId, pTargetNode->slotId, pType); } else { ASSERT(0); } @@ -8667,12 +8598,13 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* return pExprs; } -static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId) { +static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPTR_EXEC_MODEL model) { SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo)); setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTaskInfo->cost.created = taosGetTimestampMs(); pTaskInfo->id.queryId = queryId; + pTaskInfo->execModel = model; char* p = taosMemoryCalloc(1, 128); snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId); @@ -8692,20 +8624,18 @@ static SArray* extractColumnInfo(SNodeList* pNodeList); static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols); static SArray* createSortInfo(SNodeList* pNodeList); -SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, +SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId, STableGroupInfo* pTableGroupInfo) { if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) { if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(pPhyNode)) { SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; int32_t numOfCols = 0; - tsdbReaderT pDataReader = - doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); - SArray* pColList = - extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); + tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); + 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); @@ -8718,10 +8648,10 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa 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)) { @@ -8745,19 +8675,23 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa assert(size == 1); SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); - SOperatorInfo* op = doCreateOperatorTreeNode(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + 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); for (int32_t i = 0; i < size; ++i) { SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i); - SOperatorInfo* op = doCreateOperatorTreeNode(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); int32_t num = 0; @@ -8778,7 +8712,7 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa for (int32_t i = 0; i < size; ++i) { SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i); - SOperatorInfo* op = doCreateOperatorTreeNode(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode; @@ -8787,11 +8721,12 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num); SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); - SInterval interval = {.interval = pIntervalPhyNode->interval, - .sliding = pIntervalPhyNode->sliding, + SInterval interval = {.interval = pIntervalPhyNode->interval, + .sliding = pIntervalPhyNode->sliding, .intervalUnit = pIntervalPhyNode->intervalUnit, - .slidingUnit = pIntervalPhyNode->slidingUnit, - .offset = pIntervalPhyNode->offset}; + .slidingUnit = pIntervalPhyNode->slidingUnit, + .offset = pIntervalPhyNode->offset, + .precision = TSDB_TIME_PRECISION_MILLI}; return createIntervalOperatorInfo(op, pExprInfo, num, pResBlock, &interval, pTableGroupInfo, pTaskInfo); } } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == nodeType(pPhyNode)) { @@ -8799,7 +8734,7 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa assert(size == 1); SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); - SOperatorInfo* op = doCreateOperatorTreeNode(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode; @@ -8811,7 +8746,7 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa assert(size == 1); SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); - SOperatorInfo* op = doCreateOperatorTreeNode(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode; @@ -8827,7 +8762,7 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa for (int32_t i = 0; i < size; ++i) { SPhysiNode* pChildNode = taosArrayGetP(pPhyNode->pChildren, i); - SOperatorInfo* op = doCreateOperatorTreeNode(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); return createMultiTableAggOperatorInfo(op, pPhyNode->pTargets, pTaskInfo, pTableGroupInfo); } }*/ @@ -8972,11 +8907,11 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod for (int32_t i = 0; i < num; ++i) { SSlotDescNode* pNode = (SSlotDescNode*)nodesListGetNode(pOutputNodeList->pSlots, i); SColMatchInfo* info = taosArrayGet(pList, pNode->slotId); - // if (pNode->output) { - (*numOfOutputCols) += 1; - // } else { - // info->output = false; - // } + if (pNode->output) { + (*numOfOutputCols) += 1; + } else { + info->output = false; + } } return pList; @@ -9034,18 +8969,18 @@ _error: return NULL; } -int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId) { +int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model) { uint64_t queryId = pPlan->id.queryId; int32_t code = TSDB_CODE_SUCCESS; - *pTaskInfo = createExecTaskInfo(queryId, taskId); + *pTaskInfo = createExecTaskInfo(queryId, taskId, model); if (*pTaskInfo == NULL) { code = TSDB_CODE_QRY_OUT_OF_MEMORY; goto _complete; } STableGroupInfo group = {0}; - (*pTaskInfo)->pRoot = doCreateOperatorTreeNode(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &group); + (*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &group); if (NULL == (*pTaskInfo)->pRoot) { code = terrno; goto _complete; @@ -9065,41 +9000,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) { @@ -9122,113 +9022,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; -} - -// 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); diff --git a/source/libs/executor/test/executorTests.cpp b/source/libs/executor/test/executorTests.cpp index c9b0b6201395a079e7915243164589eca071d811..870a0b71fc2fa2ef7cb113752398af276089956c 100644 --- a/source/libs/executor/test/executorTests.cpp +++ b/source/libs/executor/test/executorTests.cpp @@ -944,7 +944,7 @@ TEST(testCase, build_executor_tree_Test) { int32_t code = qStringToSubplan(msg, &plan); ASSERT_EQ(code, 0); - code = qCreateExecTask(&handle, 2, 1, plan, (void**) &pTaskInfo, &sinkHandle); + code = qCreateExecTask(&handle, 2, 1, plan, (void**) &pTaskInfo, &sinkHandle, OPTR_EXEC_MODEL_BATCH); ASSERT_EQ(code, 0); } diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index dc43a3508f019e4f0f1f26f22ea1b8b567bcd9e3..c63c67af2832e0fd698c41db1bf2f948a48de727 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -395,31 +395,31 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "_qstartts", .type = FUNCTION_TYPE_QSTARTTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, .checkFunc = stubCheckAndGetResultType, - .getEnvFunc = NULL, + .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = qStartTsFunction, .finalizeFunc = NULL }, { .name = "_qendts", .type = FUNCTION_TYPE_QENDTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, .checkFunc = stubCheckAndGetResultType, - .getEnvFunc = NULL, + .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = qEndTsFunction, .finalizeFunc = NULL }, { .name = "_wstartts", - .type = FUNCTION_TYPE_QSTARTTS, + .type = FUNCTION_TYPE_WSTARTTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, .checkFunc = stubCheckAndGetResultType, - .getEnvFunc = NULL, + .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = winStartTsFunction, .finalizeFunc = NULL }, { @@ -427,9 +427,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .type = FUNCTION_TYPE_QENDTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, .checkFunc = stubCheckAndGetResultType, - .getEnvFunc = NULL, + .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = winEndTsFunction, .finalizeFunc = NULL }, { @@ -437,9 +437,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .type = FUNCTION_TYPE_WDURATION, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, .checkFunc = stubCheckAndGetResultType, - .getEnvFunc = NULL, + .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = winDurFunction, .finalizeFunc = NULL } }; @@ -448,6 +448,7 @@ const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFun int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { switch(pFunc->funcType) { + case FUNCTION_TYPE_WDURATION: case FUNCTION_TYPE_COUNT: pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT}; break; @@ -479,6 +480,14 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { break; } + case FUNCTION_TYPE_QENDTS: + case FUNCTION_TYPE_QSTARTTS: + case FUNCTION_TYPE_WENDTS: + case FUNCTION_TYPE_WSTARTTS: { + pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP}; + break; + } + case FUNCTION_TYPE_ABS: case FUNCTION_TYPE_CEIL: case FUNCTION_TYPE_FLOOR: @@ -554,14 +563,10 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { } case FUNCTION_TYPE_ROWTS: - case FUNCTION_TYPE_TBNAME: - case FUNCTION_TYPE_QSTARTTS: - case FUNCTION_TYPE_QENDTS: - case FUNCTION_TYPE_WSTARTTS: - case FUNCTION_TYPE_WENDTS: - case FUNCTION_TYPE_WDURATION: + case FUNCTION_TYPE_TBNAME: { // todo break; + } default: ASSERT(0); // to found the fault ASAP. diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 38582583741474788606e99e0fb53c7363de00e0..4034a0eb0fb6536888161b9b7fc5ebc57736df20 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -92,6 +92,7 @@ int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet) { return TSDB_CODE_FAILED; } pFpSet->process = funcMgtBuiltins[funcId].sprocessFunc; + pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/function/src/texpr.c b/source/libs/function/src/texpr.c index 814aa48b556f40a9c5013c19b60a218f3159a133..61ff6bb825741e0f36eeb2fe4321c29036dac06f 100644 --- a/source/libs/function/src/texpr.c +++ b/source/libs/function/src/texpr.c @@ -116,42 +116,6 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp return param->nodeFilterFn(pItem, pExpr->_node.info); } - - -static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) { - tbufWriteUint8(bw, expr->nodeType); - - if (expr->nodeType == TEXPR_VALUE_NODE) { - SVariant* pVal = expr->pVal; - - tbufWriteUint32(bw, pVal->nType); - if (pVal->nType == TSDB_DATA_TYPE_BINARY) { - tbufWriteInt32(bw, pVal->nLen); - tbufWrite(bw, pVal->pz, pVal->nLen); - } else { - tbufWriteInt64(bw, pVal->i); - } - - } else if (expr->nodeType == TEXPR_COL_NODE) { - SSchema* pSchema = expr->pSchema; - tbufWriteInt16(bw, pSchema->colId); - tbufWriteInt16(bw, pSchema->bytes); - tbufWriteUint8(bw, pSchema->type); - tbufWriteString(bw, pSchema->name); - - } else if (expr->nodeType == TEXPR_BINARYEXPR_NODE) { - tbufWriteUint8(bw, expr->_node.optr); - exprTreeToBinaryImpl(bw, expr->_node.pLeft); - exprTreeToBinaryImpl(bw, expr->_node.pRight); - } -} - -void exprTreeToBinary(SBufferWriter* bw, tExprNode* expr) { - if (expr != NULL) { - exprTreeToBinaryImpl(bw, expr); - } -} - // TODO: these three functions should be made global static void* exception_calloc(size_t nmemb, size_t size) { void* p = taosMemoryCalloc(nmemb, size); @@ -230,97 +194,6 @@ tExprNode* exprTreeFromBinary(const void* data, size_t size) { return exprTreeFromBinaryImpl(&br); } -tExprNode* exprTreeFromTableName(const char* tbnameCond) { - if (!tbnameCond) { - return NULL; - } - - int32_t anchor = CLEANUP_GET_ANCHOR(); - - tExprNode* expr = exception_calloc(1, sizeof(tExprNode)); - CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, expr, NULL); - - expr->nodeType = TEXPR_BINARYEXPR_NODE; - - tExprNode* left = exception_calloc(1, sizeof(tExprNode)); - expr->_node.pLeft = left; - - left->nodeType = TEXPR_COL_NODE; - SSchema* pSchema = exception_calloc(1, sizeof(SSchema)); - left->pSchema = pSchema; - -// *pSchema = NULL;//*tGetTbnameColumnSchema(); - - tExprNode* right = exception_calloc(1, sizeof(tExprNode)); - expr->_node.pRight = right; - - if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN) == 0) { - right->nodeType = TEXPR_VALUE_NODE; - expr->_node.optr = OP_TYPE_LIKE; - SVariant* pVal = exception_calloc(1, sizeof(SVariant)); - right->pVal = pVal; - size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN) + 1; - pVal->pz = exception_malloc(len); - memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN, len); - pVal->nType = TSDB_DATA_TYPE_BINARY; - pVal->nLen = (int32_t)len; - - } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_MATCH, QUERY_COND_REL_PREFIX_MATCH_LEN) == 0) { - right->nodeType = TEXPR_VALUE_NODE; - expr->_node.optr = OP_TYPE_MATCH; - SVariant* pVal = exception_calloc(1, sizeof(SVariant)); - right->pVal = pVal; - size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN) + 1; - pVal->pz = exception_malloc(len); - memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN, len); - pVal->nType = TSDB_DATA_TYPE_BINARY; - pVal->nLen = (int32_t)len; - } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_NMATCH, QUERY_COND_REL_PREFIX_NMATCH_LEN) == 0) { - right->nodeType = TEXPR_VALUE_NODE; - expr->_node.optr = OP_TYPE_NMATCH; - SVariant* pVal = exception_calloc(1, sizeof(SVariant)); - right->pVal = pVal; - size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN) + 1; - pVal->pz = exception_malloc(len); - memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN, len); - pVal->nType = TSDB_DATA_TYPE_BINARY; - pVal->nLen = (int32_t)len; - } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) { - right->nodeType = TEXPR_VALUE_NODE; - expr->_node.optr = OP_TYPE_IN; - SVariant* pVal = exception_calloc(1, sizeof(SVariant)); - right->pVal = pVal; - pVal->nType = TSDB_DATA_TYPE_POINTER_ARRAY; - pVal->arr = taosArrayInit(2, POINTER_BYTES); - - const char* cond = tbnameCond + QUERY_COND_REL_PREFIX_IN_LEN; - for (const char *e = cond; *e != 0; e++) { - if (*e == TS_PATH_DELIMITER[0]) { - cond = e + 1; - } else if (*e == ',') { - size_t len = e - cond; - char* p = exception_malloc(len + VARSTR_HEADER_SIZE); - STR_WITH_SIZE_TO_VARSTR(p, cond, (VarDataLenT)len); - cond += len; - taosArrayPush(pVal->arr, &p); - } - } - - if (*cond != 0) { - size_t len = strlen(cond) + VARSTR_HEADER_SIZE; - - char* p = exception_malloc(len); - STR_WITH_SIZE_TO_VARSTR(p, cond, (VarDataLenT)(len - VARSTR_HEADER_SIZE)); - taosArrayPush(pVal->arr, &p); - } - - taosArraySortString(pVal->arr, taosArrayCompareString); - } - - CLEANUP_EXECUTE_TO(anchor, false); - return expr; -} - void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) { SBufferReader br = tbufInitReader(buf, len, false); uint32_t type = tbufReadUint32(&br); diff --git a/source/libs/function/src/tunaryoperator.c b/source/libs/function/src/tunaryoperator.c deleted file mode 100644 index 957f0799c5fb1b259c46612581400de80e452598..0000000000000000000000000000000000000000 --- a/source/libs/function/src/tunaryoperator.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "tunaryoperator.h" - - - - -// TODO dynamic define these functions -//_unary_scalar_fn_t getUnaryScalarOperatorFn(int32_t operator) { -// assert(0); -//} - -//bool isStringOperatorFn(int32_t op) { -// return op == FUNCTION_LENGTH; -//} diff --git a/source/libs/index/inc/index_cache.h b/source/libs/index/inc/indexCache.h similarity index 96% rename from source/libs/index/inc/index_cache.h rename to source/libs/index/inc/indexCache.h index 086e75d99fd85887701daad11b88310c417c9bfe..3ea986ad48c81e57249161fecc8c4610dfb7f8d8 100644 --- a/source/libs/index/inc/index_cache.h +++ b/source/libs/index/inc/indexCache.h @@ -1,6 +1,5 @@ /* - * Copyright (c) 2019 TAOS Data, Inc. - * + * 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. @@ -16,7 +15,7 @@ #define __INDEX_CACHE_H__ #include "indexInt.h" -#include "index_util.h" +#include "indexUtil.h" #include "tskiplist.h" // ----------------- key structure in skiplist --------------------- diff --git a/source/libs/index/inc/index_comm.h b/source/libs/index/inc/indexComm.h similarity index 100% rename from source/libs/index/inc/index_comm.h rename to source/libs/index/inc/indexComm.h diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/indexFst.h similarity index 98% rename from source/libs/index/inc/index_fst.h rename to source/libs/index/inc/indexFst.h index b131aa0d9d2e77dcc131431867f78b7dc899c454..39ad5ffa8c5acddf543982ebba540b7d422f4183 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/indexFst.h @@ -20,12 +20,12 @@ extern "C" { #endif +#include "indexFstAutomation.h" +#include "indexFstCountingWriter.h" +#include "indexFstNode.h" +#include "indexFstRegistry.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_automation.h" -#include "index_fst_counting_writer.h" -#include "index_fst_node.h" -#include "index_fst_registry.h" -#include "index_fst_util.h" #define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) diff --git a/source/libs/index/inc/index_fst_automation.h b/source/libs/index/inc/indexFstAutomation.h similarity index 98% rename from source/libs/index/inc/index_fst_automation.h rename to source/libs/index/inc/indexFstAutomation.h index 786d3eb7d29b404dcbb1a20e4871c8661983e688..3a0f74ee76563d3d3ed2cc1f3a067945eaa0fed8 100644 --- a/source/libs/index/inc/index_fst_automation.h +++ b/source/libs/index/inc/indexFstAutomation.h @@ -19,8 +19,8 @@ extern "C" { #endif +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_util.h" typedef struct AutomationCtx AutomationCtx; diff --git a/source/libs/index/inc/index_fst_common.h b/source/libs/index/inc/indexFstCommon.h similarity index 100% rename from source/libs/index/inc/index_fst_common.h rename to source/libs/index/inc/indexFstCommon.h diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/indexFstCountingWriter.h similarity index 100% rename from source/libs/index/inc/index_fst_counting_writer.h rename to source/libs/index/inc/indexFstCountingWriter.h diff --git a/source/libs/index/inc/indexFstDfa.h b/source/libs/index/inc/indexFstDfa.h new file mode 100644 index 0000000000000000000000000000000000000000..f6c220bcb7a6468d7be58249b54c62dcc2402306 --- /dev/null +++ b/source/libs/index/inc/indexFstDfa.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef __INDEX_FST_DFA_H__ +#define __INDEX_FST_DFA_H__ + +#include "indexFstRegex.h" +#include "indexFstSparse.h" +#include "tarray.h" +#include "thash.h" + +#ifdef __cplusplus + +extern "C" { +#endif + +typedef struct FstDfa FstDfa; + +typedef struct { + SArray * insts; + uint32_t next[256]; + bool isMatch; +} State; + +/* + * dfa builder related func + **/ +typedef struct FstDfaBuilder { + FstDfa * dfa; + SHashObj *cache; +} FstDfaBuilder; + +FstDfaBuilder *dfaBuilderCreate(SArray *insts); + +void dfaBuilderDestroy(FstDfaBuilder *builder); + +FstDfa *dfaBuilderBuild(FstDfaBuilder *builder); + +bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t bytes, + uint32_t *result); + +bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result); + +/* + * dfa related func + **/ +typedef struct FstDfa { + SArray *insts; + SArray *states; +} FstDfa; + +FstDfa *dfaCreate(SArray *insts, SArray *states); +bool dfaIsMatch(FstDfa *dfa, uint32_t si); +bool dfaAccept(FstDfa *dfa, uint32_t si, uint8_t byte, uint32_t *result); +void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip); +bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/libs/index/inc/index_fst_node.h b/source/libs/index/inc/indexFstNode.h similarity index 96% rename from source/libs/index/inc/index_fst_node.h rename to source/libs/index/inc/indexFstNode.h index 4dbf4cea04dcccc44b96d99709f3da287b05e1dd..4bbc739c731c39200549043a1e8caf5bd85d29d7 100644 --- a/source/libs/index/inc/index_fst_node.h +++ b/source/libs/index/inc/indexFstNode.h @@ -20,9 +20,9 @@ extern "C" { #endif +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" #define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal) #define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0) diff --git a/source/libs/index/inc/indexFstRegex.h b/source/libs/index/inc/indexFstRegex.h new file mode 100644 index 0000000000000000000000000000000000000000..8fb545533682c84476b55a447827a5034127f6e5 --- /dev/null +++ b/source/libs/index/inc/indexFstRegex.h @@ -0,0 +1,75 @@ +/* + * 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_INDEX_FST_REGEX_H_ +#define _TD_INDEX_FST_REGEX_H_ + +//#include "indexFstDfa.h" +#include "taos.h" +#include "tarray.h" +#include "tchecksum.h" +#include "thash.h" +#include "tlog.h" +#include "tutil.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { MATCH, JUMP, SPLIT, RANGE } InstType; + +typedef struct MatchValue { +} MatchValue; +typedef struct JumpValue { + uint32_t step; +} JumpValue; + +typedef struct SplitValue { + uint32_t len1; + uint32_t len2; +} SplitValue; + +typedef struct RangeValue { + uint8_t start; + uint8_t end; +} RangeValue; + +typedef struct { + InstType ty; + union { + MatchValue mv; + JumpValue jv; + SplitValue sv; + RangeValue rv; + }; +} Inst; + +typedef struct { + char *orig; + void *dfa; +} FstRegex; + +FstRegex *regexCreate(const char *str); + +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 +} +#endif + +#endif diff --git a/source/libs/index/inc/index_fst_registry.h b/source/libs/index/inc/indexFstRegistry.h similarity index 97% rename from source/libs/index/inc/index_fst_registry.h rename to source/libs/index/inc/indexFstRegistry.h index 20b70e2866615a07c457fbfaa1919bbe1f17ef6c..09cde6c13191a1c6447e650603345b2e9fa8b83e 100644 --- a/source/libs/index/inc/index_fst_registry.h +++ b/source/libs/index/inc/indexFstRegistry.h @@ -19,9 +19,9 @@ extern "C" { #endif +#include "indexFstNode.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_node.h" -#include "index_fst_util.h" typedef struct FstRegistryCell { CompiledAddr addr; diff --git a/source/libs/scalar/inc/sclfunc.h b/source/libs/index/inc/indexFstSparse.h similarity index 56% rename from source/libs/scalar/inc/sclfunc.h rename to source/libs/index/inc/indexFstSparse.h index 679411e0040dc0e581c1dfcbf8882098d2695c66..665fb2ba5cb9c0c426e9f3bf345351deed1d4abb 100644 --- a/source/libs/scalar/inc/sclfunc.h +++ b/source/libs/index/inc/indexFstSparse.h @@ -12,21 +12,32 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef TDENGINE_TSCALARFUNCTION_H -#define TDENGINE_TSCALARFUNCTION_H + +#ifndef _TD_INDEX_FST_SPARSE_H_ +#define _TD_INDEX_FST_SPARSE_H_ + +#include "tarray.h" #ifdef __cplusplus extern "C" { #endif -#include "function.h" -#include "scalar.h" - - +typedef struct FstSparseSet { + uint32_t *dense; + uint32_t *sparse; + int32_t size; +} FstSparseSet; +FstSparseSet *sparSetCreate(int32_t sz); +void sparSetDestroy(FstSparseSet *s); +uint32_t sparSetLen(FstSparseSet *ss); +uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip); +uint32_t sparSetGet(FstSparseSet *ss, uint32_t i); +bool sparSetContains(FstSparseSet *ss, uint32_t ip); +void sparSetClear(FstSparseSet *ss); #ifdef __cplusplus } #endif -#endif // TDENGINE_TSCALARFUNCTION_H +#endif diff --git a/source/libs/index/inc/index_fst_util.h b/source/libs/index/inc/indexFstUtil.h similarity index 99% rename from source/libs/index/inc/index_fst_util.h rename to source/libs/index/inc/indexFstUtil.h index f173dd9a15553b9a1997ff5915fc1e50ea9658a7..d0bbc923d1e6325094a584e58217fa4475b0e3a6 100644 --- a/source/libs/index/inc/index_fst_util.h +++ b/source/libs/index/inc/indexFstUtil.h @@ -20,8 +20,8 @@ extern "C" { #endif +#include "indexFstCommon.h" #include "indexInt.h" -#include "index_fst_common.h" typedef uint64_t FstType; typedef uint64_t CompiledAddr; diff --git a/source/libs/index/inc/index_tfile.h b/source/libs/index/inc/indexTfile.h similarity index 97% rename from source/libs/index/inc/index_tfile.h rename to source/libs/index/inc/indexTfile.h index 3794898d3ad3cf3296a4aa44f79f12365c59c519..9712e4b30f7ecfdabb4e8d3c824190f60319ec69 100644 --- a/source/libs/index/inc/index_tfile.h +++ b/source/libs/index/inc/indexTfile.h @@ -15,11 +15,11 @@ #ifndef __INDEX_TFILE_H__ #define __INDEX_TFILE_H__ +#include "indexFst.h" +#include "indexFstCountingWriter.h" #include "indexInt.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tlockfree.h" #ifdef __cplusplus diff --git a/source/libs/index/inc/index_util.h b/source/libs/index/inc/indexUtil.h similarity index 100% rename from source/libs/index/inc/index_util.h rename to source/libs/index/inc/indexUtil.h diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 61dd9523811d0eb5a0fa330f72fc4a350cf2e2c5..7d52abcd1b8b82fe53c020aa2759e88b741a63f6 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -14,11 +14,11 @@ */ #include "index.h" +#include "indexCache.h" +#include "indexComm.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_comm.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tdef.h" #include "tsched.h" @@ -27,7 +27,7 @@ #endif #define INDEX_NUM_OF_THREADS 4 -#define INDEX_QUEUE_SIZE 200 +#define INDEX_QUEUE_SIZE 200 void* indexQhandle = NULL; @@ -236,11 +236,11 @@ int indexDelete(SIndex* index, SIndexMultiTermQuery* query) { return 1; } -int indexRebuild(SIndex* index, SIndexOpts* opts){ +int indexRebuild(SIndex* index, SIndexOpts* opts) { #ifdef USE_INVERTED_INDEX #endif - return 0; + return 0; } SIndexOpts* indexOptsCreate() { diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/indexCache.c similarity index 98% rename from source/libs/index/src/index_cache.c rename to source/libs/index/src/indexCache.c index bf907726bc974fbf7be7d2b074ba1c1320f38847..df3c0b6e7b81f3f7df6e7a579237e2fbcc0fc9fe 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/indexCache.c @@ -13,16 +13,16 @@ * along with this program. If not, see . */ -#include "index_cache.h" -#include "index_comm.h" -#include "index_util.h" +#include "indexCache.h" +#include "indexComm.h" +#include "indexUtil.h" #include "tcompare.h" #include "tsched.h" #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/index_comm.c b/source/libs/index/src/indexComm.c similarity index 100% rename from source/libs/index/src/index_comm.c rename to source/libs/index/src/indexComm.c diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/indexFst.c similarity index 99% rename from source/libs/index/src/index_fst.c rename to source/libs/index/src/indexFst.c index eaefaca8876b1aef8f99ee55d28b299b2963209b..24bc7a93a222a772a576397ac6e04f7661247de4 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/indexFst.c @@ -13,9 +13,9 @@ * along with this program. If not, see . */ -#include "index_fst.h" +#include "indexFst.h" +#include "indexFstAutomation.h" #include "indexInt.h" -#include "index_fst_automation.h" #include "tchecksum.h" #include "tcoding.h" diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/indexFstAutomation.c similarity index 99% rename from source/libs/index/src/index_fst_automation.c rename to source/libs/index/src/indexFstAutomation.c index 20e981559d3b08738f9ed755e00b1c0147197495..0702e3b94e52f2f1a552f2ed3ca337db86e50bd4 100644 --- a/source/libs/index/src/index_fst_automation.c +++ b/source/libs/index/src/indexFstAutomation.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "index_fst_automation.h" +#include "indexFstAutomation.h" StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) { StartWithStateValue* sv = taosMemoryCalloc(1, sizeof(StartWithStateValue)); diff --git a/source/libs/index/src/index_fst_common.c b/source/libs/index/src/indexFstCommon.c similarity index 73% rename from source/libs/index/src/index_fst_common.c rename to source/libs/index/src/indexFstCommon.c index 2d7586e8d939c8ef6dc80e998e97f3cf0b08f921..902e68ce091c0a7316f5404515a742a911fb603e 100644 --- a/source/libs/index/src/index_fst_common.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 @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_fst_common.h" +#include "indexFstCommon.h" const uint8_t COMMON_INPUTS[] = { 84, // '\x00' @@ -274,20 +274,23 @@ const uint8_t COMMON_INPUTS[] = { }; const char COMMON_INPUTS_INV[] = { - 't', 'e', '/', 'o', 'a', 's', 'r', 'i', 'p', 'c', 'n', 'w', '.', 'h', 'l', 'm', - '-', 'd', 'u', '0', '1', '2', 'g', '=', ':', 'b', 'f', '3', 'y', '5', '&', '_', - '4', 'v', '9', '6', '7', '8', 'k', '%', '?', 'x', 'C', 'D', 'A', 'S', 'F', 'I', - 'B', 'E', 'j', 'P', 'T', 'z', 'R', 'N', 'M', '+', 'L', 'O', 'q', 'H', 'G', 'W', - 'U', 'V', ',', 'Y', 'K', 'J', 'Z', 'X', 'Q', ';', ')', '(', '~', '[', ']', '$', - '!', '\'', '*', '@', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', - '\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', - '\x1c', '\x1d', '\x1e', '\x1f', ' ', '"', '#', '<', '>', '\\', '^', '`', '{', '|', '}', '\x7f', - '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f', - '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', - '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7', '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf', - '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7', '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf', - '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf', - '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf', - '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef', - '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff', + 't', 'e', '/', 'o', 'a', 's', 'r', 'i', 'p', 'c', 'n', 'w', '.', 'h', + 'l', 'm', '-', 'd', 'u', '0', '1', '2', 'g', '=', ':', 'b', 'f', '3', + 'y', '5', '&', '_', '4', 'v', '9', '6', '7', '8', 'k', '%', '?', 'x', + 'C', 'D', 'A', 'S', 'F', 'I', 'B', 'E', 'j', 'P', 'T', 'z', 'R', 'N', + 'M', '+', 'L', 'O', 'q', 'H', 'G', 'W', 'U', 'V', ',', 'Y', 'K', 'J', + 'Z', 'X', 'Q', ';', ')', '(', '~', '[', ']', '$', '!', '\'', '*', '@', + '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', '\x0c', '\r', + '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', + '\x1c', '\x1d', '\x1e', '\x1f', ' ', '"', '#', '<', '>', '\\', '^', '`', '{', '|', + '}', '\x7f', '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', + '\x8c', '\x8d', '\x8e', '\x8f', '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', + '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7', + '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf', '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', + '\xb6', '\xb7', '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf', '\xc0', '\xc1', '\xc2', '\xc3', + '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf', '\xd0', '\xd1', + '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf', + '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', + '\xee', '\xef', '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7', '\xf8', '\xf9', '\xfa', '\xfb', + '\xfc', '\xfd', '\xfe', '\xff', }; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/indexFstCountingWriter.c similarity index 94% rename from source/libs/index/src/index_fst_counting_writer.c rename to source/libs/index/src/indexFstCountingWriter.c index 6a161ba7e954085f753e0137b41fb98e2dc2b230..76ff4309b57f4b6a3d7553fcca5239eef4e6911c 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/indexFstCountingWriter.c @@ -13,10 +13,10 @@ * along with this program. If not, see . */ -#include "os.h" -#include "index_fst_counting_writer.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_util.h" +#include "os.h" #include "tutil.h" static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { @@ -82,7 +82,9 @@ static int writeCtxDoFlush(WriterCtx* ctx) { WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity) { WriterCtx* ctx = taosMemoryCalloc(1, sizeof(WriterCtx)); - if (ctx == NULL) { return NULL; } + if (ctx == NULL) { + return NULL; + } ctx->type = type; if (ctx->type == TFile) { @@ -126,7 +128,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int return ctx; END: - if (ctx->type == TMemory) { taosMemoryFree(ctx->mem.buf); } + if (ctx->type == TMemory) { + taosMemoryFree(ctx->mem.buf); + } taosMemoryFree(ctx); return NULL; } @@ -148,14 +152,18 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { // stat(ctx->file.buf, &fstat); // indexError("write file size: %d", (int)(fstat.st_size)); } - if (remove) { unlink(ctx->file.buf); } + if (remove) { + unlink(ctx->file.buf); + } } taosMemoryFree(ctx); } FstCountingWriter* fstCountingWriterCreate(void* wrt) { FstCountingWriter* cw = taosMemoryCalloc(1, sizeof(FstCountingWriter)); - if (cw == NULL) { return NULL; } + if (cw == NULL) { + return NULL; + } cw->wrt = wrt; //(void *)(writerCtxCreate(TFile, readOnly)); @@ -169,7 +177,9 @@ void fstCountingWriterDestroy(FstCountingWriter* cw) { } int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) { - if (write == NULL) { return 0; } + if (write == NULL) { + return 0; + } // update checksum // write data to file/socket or mem WriterCtx* ctx = write->wrt; @@ -182,7 +192,9 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) return len; } int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len) { - if (write == NULL) { return 0; } + if (write == NULL) { + return 0; + } WriterCtx* ctx = write->wrt; int nRead = ctx->read(ctx, buf, len); // assert(nRead == len); diff --git a/source/libs/index/src/indexFstDfa.c b/source/libs/index/src/indexFstDfa.c new file mode 100644 index 0000000000000000000000000000000000000000..ff6b154c547e9c9f0740b083e3f947c35123f5a2 --- /dev/null +++ b/source/libs/index/src/indexFstDfa.c @@ -0,0 +1,218 @@ +/* + * 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 "indexFstDfa.h" +#include "thash.h" + +const static uint32_t STATE_LIMIT = 1000; + +static int dfaInstsEqual(const void *a, const void *b, size_t size) { + SArray *ar = (SArray *)a; + SArray *br = (SArray *)b; + size_t al = ar != NULL ? taosArrayGetSize(ar) : 0; + size_t bl = br != NULL ? taosArrayGetSize(br) : 0; + if (al != bl) { + return -1; + } + for (int i = 0; i < al; i++) { + uint32_t v1 = *(uint32_t *)taosArrayGet(ar, i); + uint32_t v2 = *(uint32_t *)taosArrayGet(br, i); + if (v1 != v2) { + return -1; + } + } + return 0; +} +FstDfaBuilder *dfaBuilderCreate(SArray *insts) { + FstDfaBuilder *builder = taosMemoryCalloc(1, sizeof(FstDfaBuilder)); + if (builder == NULL) { + return NULL; + } + + SArray *states = taosArrayInit(4, sizeof(State)); + + builder->dfa = dfaCreate(insts, states); + builder->cache = taosHashInit( + 4, taosGetDefaultHashFunction(POINTER_BYTES == sizeof(int64_t) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_INT), + false, HASH_NO_LOCK); + taosHashSetEqualFp(builder->cache, dfaInstsEqual); + return builder; +} +void dfaBuilderDestroy(FstDfaBuilder *builder) { + if (builder == NULL) { + return; + } + void *pIter = builder->cache != NULL ? taosHashIterate(builder->cache, NULL) : NULL; + while (pIter) { + SArray **key = pIter; + taosArrayDestroy(*key); + pIter = taosHashIterate(builder->cache, pIter); + } + taosHashCleanup(builder->cache); +} + +FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) { + uint32_t sz = taosArrayGetSize(builder->dfa->insts); + FstSparseSet *cur = sparSetCreate(sz); + FstSparseSet *nxt = sparSetCreate(sz); + + dfaAdd(builder->dfa, cur, 0); + + SArray * states = taosArrayInit(0, sizeof(uint32_t)); + uint32_t result; + if (dfaBuilderCachedState(builder, cur, &result)) { + taosArrayPush(states, &result); + } + SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + while (taosArrayGetSize(states) != 0) { + result = *(uint32_t *)taosArrayPop(states); + for (int i = 0; i < 256; i++) { + uint32_t ns, dummpy = 0; + if (dfaBuilderRunState(builder, cur, nxt, result, i, &ns)) { + if (taosHashGet(seen, &ns, sizeof(ns)) == NULL) { + taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy)); + taosArrayPush(states, &ns); + } + } + if (taosArrayGetSize(builder->dfa->states) > STATE_LIMIT) { + // Too many state; + // + } + } + } + taosArrayDestroy(states); + taosHashCleanup(seen); + return builder->dfa; +} + +bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t byte, + uint32_t *result) { + sparSetClear(cur); + State *t = taosArrayGet(builder->dfa->states, state); + for (int i = 0; i < taosArrayGetSize(t->insts); i++) { + uint32_t ip = *(int32_t *)taosArrayGet(t->insts, i); + sparSetAdd(cur, ip); + } + dfaRun(builder->dfa, cur, next, byte); + + t = taosArrayGet(builder->dfa->states, state); + + uint32_t nxtState; + if (dfaBuilderCachedState(builder, next, &nxtState)) { + t->next[byte] = nxtState; + *result = nxtState; + return true; + } + return false; +} + +bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) { + SArray *tinsts = taosArrayInit(4, sizeof(uint32_t)); + bool isMatch = false; + + for (int i = 0; i < sparSetLen(set); i++) { + uint32_t ip = sparSetGet(set, i); + + Inst *inst = taosArrayGet(builder->dfa->insts, ip); + if (inst->ty == JUMP || inst->ty == SPLIT) { + continue; + } else if (inst->ty == RANGE) { + taosArrayPush(tinsts, &ip); + } else if (inst->ty == MATCH) { + isMatch = true; + taosArrayPush(tinsts, &ip); + } + } + if (taosArrayGetSize(tinsts) == 0) { + return false; + } + uint32_t *v = taosHashGet(builder->cache, &tinsts, sizeof(POINTER_BYTES)); + if (v != NULL) { + *result = *v; + taosArrayDestroy(tinsts); + } else { + State st; + st.insts = tinsts; + st.isMatch = isMatch; + taosArrayPush(builder->dfa->states, &st); + int32_t sz = taosArrayGetSize(builder->dfa->states) - 1; + taosHashPut(builder->cache, &tinsts, sizeof(POINTER_BYTES), &sz, sizeof(sz)); + *result = sz; + } + return true; +} + +FstDfa *dfaCreate(SArray *insts, SArray *states) { + FstDfa *dfa = taosMemoryCalloc(1, sizeof(FstDfa)); + if (dfa == NULL) { + return NULL; + } + + dfa->insts = insts; + dfa->states = states; + return dfa; +} +bool dfaIsMatch(FstDfa *dfa, uint32_t si) { + if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) { + return false; + } + State *st = taosArrayGet(dfa->states, si); + return st != NULL ? st->isMatch : false; +} +bool dfaAccept(FstDfa *dfa, uint32_t si, uint8_t byte, uint32_t *result) { + if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) { + return false; + } + State *st = taosArrayGet(dfa->states, si); + *result = st->next[byte]; + return true; +} +void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) { + if (sparSetContains(set, ip)) { + return; + } + sparSetAdd(set, ip); + Inst *inst = taosArrayGet(dfa->insts, ip); + if (inst->ty == MATCH || inst->ty == RANGE) { + // do nothing + } else if (inst->ty == JUMP) { + dfaAdd(dfa, set, inst->jv.step); + } else if (inst->ty == SPLIT) { + dfaAdd(dfa, set, inst->sv.len1); + dfaAdd(dfa, set, inst->sv.len2); + } + + return; +} +bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte) { + bool isMatch = false; + sparSetClear(to); + for (int i = 0; i < sparSetLen(from); i++) { + uint32_t ip = sparSetGet(from, i); + + Inst *inst = taosArrayGet(dfa->insts, ip); + if (inst->ty == JUMP || inst->ty == SPLIT) { + continue; + } else if (inst->ty == MATCH) { + isMatch = true; + } else if (inst->ty == RANGE) { + if (inst->rv.start <= byte && byte <= inst->rv.end) { + dfaAdd(dfa, to, ip + 1); + } + } + } + + return isMatch; +} diff --git a/source/libs/index/src/index_fst_node.c b/source/libs/index/src/indexFstNode.c similarity index 89% rename from source/libs/index/src/index_fst_node.c rename to source/libs/index/src/indexFstNode.c index a0d59150d73231cddd2781ad6627e5d29c5e0422..e11f9dd37dc7ef8afd26e898bcd2c9a08afa1e8c 100644 --- a/source/libs/index/src/index_fst_node.c +++ b/source/libs/index/src/indexFstNode.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_fst_node.h" +#include "indexFstNode.h" FstBuilderNode* fstBuilderNodeDefault() { FstBuilderNode* bn = taosMemoryMalloc(sizeof(FstBuilderNode)); @@ -22,31 +22,45 @@ FstBuilderNode* fstBuilderNodeDefault() { return bn; } void fstBuilderNodeDestroy(FstBuilderNode* node) { - if (node == NULL) { return; } + if (node == NULL) { + return; + } taosArrayDestroy(node->trans); taosMemoryFree(node); } bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) { - if (n1 == n2) { return true; } - if (n1 == NULL || n2 == NULL) { return false; } + if (n1 == n2) { + return true; + } + if (n1 == NULL || n2 == NULL) { + return false; + } - if (n1->isFinal != n2->isFinal || n1->finalOutput != n2->finalOutput) { return false; } + if (n1->isFinal != n2->isFinal || n1->finalOutput != n2->finalOutput) { + return false; + } size_t s1 = n1->trans ? taosArrayGetSize(n1->trans) : 0; size_t s2 = n2->trans ? taosArrayGetSize(n2->trans) : 0; - if (s1 != s2) { return false; } + if (s1 != s2) { + return false; + } for (size_t i = 0; i < s1; i++) { FstTransition* t1 = taosArrayGet(n1->trans, i); FstTransition* t2 = taosArrayGet(n2->trans, i); - if (t1->inp != t2->inp || t1->out != t2->out || t1->addr != t2->addr) { return false; } + if (t1->inp != t2->inp || t1->out != t2->out || t1->addr != t2->addr) { + return false; + } } return true; } FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode)); - if (node == NULL) { return NULL; } + if (node == NULL) { + return NULL; + } // size_t sz = taosArrayGetSize(src->trans); @@ -64,7 +78,9 @@ FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { } // not destroy src, User's bussiness void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) { - if (dst == NULL || src == NULL) { return; } + if (dst == NULL || src == NULL) { + return; + } dst->isFinal = src->isFinal; dst->finalOutput = src->finalOutput; diff --git a/source/libs/index/src/indexFstRegex.c b/source/libs/index/src/indexFstRegex.c new file mode 100644 index 0000000000000000000000000000000000000000..33eeae802e536a74c59748816ce09f1140dab0ff --- /dev/null +++ b/source/libs/index/src/indexFstRegex.c @@ -0,0 +1,61 @@ +/* + * 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 "indexFstRegex.h" +#include "indexFstDfa.h" +#include "indexFstSparse.h" + +FstRegex *regexCreate(const char *str) { + FstRegex *regex = taosMemoryCalloc(1, sizeof(FstRegex)); + if (regex == NULL) { + return NULL; + } + int32_t sz = (int32_t)strlen(str); + char * orig = taosMemoryCalloc(1, sz); + 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; +} + +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/index_fst_registry.c b/source/libs/index/src/indexFstRegister.c similarity index 93% rename from source/libs/index/src/index_fst_registry.c rename to source/libs/index/src/indexFstRegister.c index 7b6b8df25f5b7ad85d3d181a3a9ba6b9d8c9fbe8..34efee0d0db510ea1ce50de26c418ae1fd08761e 100644 --- a/source/libs/index/src/index_fst_registry.c +++ b/source/libs/index/src/indexFstRegister.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ +#include "indexFstRegistry.h" #include "os.h" -#include "index_fst_registry.h" uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { // TODO(yihaoDeng): refactor later @@ -35,7 +35,9 @@ uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { } static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) { size_t sz = taosArrayGetSize(arr); - if (a >= sz || b >= sz) { return; } + if (a >= sz || b >= sz) { + return; + } FstRegistryCell* cell1 = (FstRegistryCell*)taosArrayGet(arr, a); FstRegistryCell* cell2 = (FstRegistryCell*)taosArrayGet(arr, b); @@ -52,7 +54,9 @@ static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) { static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { size_t sz = taosArrayGetSize(arr); - if (start >= sz && end >= sz) { return; } + if (start >= sz && end >= sz) { + return; + } assert(start >= end); @@ -66,7 +70,9 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { FstRegistry* registry = taosMemoryMalloc(sizeof(FstRegistry)); - if (registry == NULL) { return NULL; } + if (registry == NULL) { + return NULL; + } uint64_t nCells = tableSize * mruSize; SArray* tb = (SArray*)taosArrayInit(nCells, sizeof(FstRegistryCell)); @@ -87,7 +93,9 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { } void fstRegistryDestroy(FstRegistry* registry) { - if (registry == NULL) { return; } + if (registry == NULL) { + return; + } SArray* tb = registry->table; size_t sz = taosArrayGetSize(tb); @@ -100,7 +108,9 @@ void fstRegistryDestroy(FstRegistry* registry) { } FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNode) { - if (taosArrayGetSize(registry->table) <= 0) { return NULL; } + if (taosArrayGetSize(registry->table) <= 0) { + return NULL; + } uint64_t bucket = fstRegistryHash(registry, bNode); uint64_t start = registry->mruSize * bucket; uint64_t end = start + registry->mruSize; @@ -165,6 +175,4 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo } return entry; } -void fstRegistryEntryDestroy(FstRegistryEntry* entry) { - taosMemoryFree(entry); -} +void fstRegistryEntryDestroy(FstRegistryEntry* entry) { taosMemoryFree(entry); } diff --git a/source/libs/index/src/indexFstSparse.c b/source/libs/index/src/indexFstSparse.c new file mode 100644 index 0000000000000000000000000000000000000000..e8ab3be2fe2d257544573d9fc39675b7bf86751b --- /dev/null +++ b/source/libs/index/src/indexFstSparse.c @@ -0,0 +1,68 @@ +/* + * 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 "indexFstSparse.h" + +FstSparseSet *sparSetCreate(int32_t sz) { + FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet)); + if (ss = NULL) { + return NULL; + } + + 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; + } + taosMemoryFree(ss->dense); + taosMemoryFree(ss->sparse); + taosMemoryFree(ss); +} +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; + ss->dense[i] = ip; + ss->sparse[ip] = i; + ss->size += 1; + return i; +} +uint32_t sparSetGet(FstSparseSet *ss, uint32_t i) { + // check later + return ss->dense[i]; +} +bool sparSetContains(FstSparseSet *ss, uint32_t ip) { + uint32_t i = ss->sparse[ip]; + if (i < ss->size && ss->dense[i] == ip) { + return true; + } else { + return false; + } +} +void sparSetClear(FstSparseSet *ss) { + if (ss == NULL) { + return; + } + ss->size = 0; +} diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/indexFstUtil.c similarity index 98% rename from source/libs/index/src/index_fst_util.c rename to source/libs/index/src/indexFstUtil.c index f9581f7202dc127d62f09ca5bf8b67f3ff4341b2..ec9a6943dc573ecfbffe487859d69031dbb38241 100644 --- a/source/libs/index/src/index_fst_util.c +++ b/source/libs/index/src/indexFstUtil.c @@ -12,8 +12,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_fst_util.h" -#include "index_fst_common.h" +#include "indexFstUtil.h" +#include "indexFstCommon.h" // A sentinel value used to indicate an empty final state const CompiledAddr EMPTY_ADDRESS = 0; diff --git a/source/libs/index/src/index_json.c b/source/libs/index/src/indexJson.c similarity index 100% rename from source/libs/index/src/index_json.c rename to source/libs/index/src/indexJson.c diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/indexTfile.c similarity index 99% rename from source/libs/index/src/index_tfile.c rename to source/libs/index/src/indexTfile.c index 53813e13e6920cacd435ef9ebc65525a2c80760d..058c33b725f84dfa509b0f8dacb6a6ff18562dfe 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/indexTfile.c @@ -13,12 +13,12 @@ p * * along with this program. If not, see . */ -#include "index_tfile.h" +#include "indexTfile.h" #include "index.h" -#include "index_comm.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_util.h" +#include "indexComm.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexUtil.h" #include "taosdef.h" #include "tcoding.h" #include "tcompare.h" diff --git a/source/libs/index/src/index_util.c b/source/libs/index/src/indexUtil.c similarity index 99% rename from source/libs/index/src/index_util.c rename to source/libs/index/src/indexUtil.c index 65c16ca65ba5b54de2f3492abe4314a6419c4e16..7b83cf465db951847ca45fd72327aa24a9ba9890 100644 --- a/source/libs/index/src/index_util.c +++ b/source/libs/index/src/indexUtil.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_util.h" +#include "indexUtil.h" #include "index.h" #include "tcompare.h" diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index e0b12a6f33b98f13231b102222088f604d8180fb..eff53108cd6436125f9e9eb83f0d54df7226e2d0 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -5,12 +5,12 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" +#include "indexTfile.h" #include "tskiplist.h" #include "tutil.h" void* callback(void* s) { return s; } diff --git a/source/libs/index/test/fstUT.cc b/source/libs/index/test/fstUT.cc index e7efbaf21f31dadb0d99cb97ac307a2d447c0bbe..ab6c1a47045ea4957dcfd57ccda8c9bbcd8d7a90 100644 --- a/source/libs/index/test/fstUT.cc +++ b/source/libs/index/test/fstUT.cc @@ -6,12 +6,12 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" +#include "indexTfile.h" #include "tglobal.h" #include "tlog.h" #include "tskiplist.h" diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 0e4eb060cf06e8414cd41b048ff44fdc7feab751..ee9da50ab222e754903cb921215024b208e5cb0c 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -18,13 +18,13 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tskiplist.h" #include "tutil.h" using namespace std; diff --git a/source/libs/index/test/jsonUT.cc b/source/libs/index/test/jsonUT.cc index df9f8b8439db379e99cfc96b69ea150b7a51577a..9b0452425a7be6fe51f9543ac9e1dc2db15d8871 100644 --- a/source/libs/index/test/jsonUT.cc +++ b/source/libs/index/test/jsonUT.cc @@ -5,13 +5,13 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tglobal.h" #include "tskiplist.h" #include "tutil.h" diff --git a/source/libs/index/test/utilUT.cc b/source/libs/index/test/utilUT.cc index 6ba8cc9525d83de1e8ab8b352f9e81e0153cc772..30f1a089f7cb200713d32a4d1efc0d10dbfd402e 100644 --- a/source/libs/index/test/utilUT.cc +++ b/source/libs/index/test/utilUT.cc @@ -5,13 +5,13 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tglobal.h" #include "tskiplist.h" #include "tutil.h" diff --git a/source/libs/nodes/inc/nodesUtil.h b/source/libs/nodes/inc/nodesUtil.h index de00b6bca4d9203bf260ea3b55945061a3264d4c..976044c16fa435977425ebf370da2e1b376b4f1c 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 e728078a38bdd28a3e25acd78ad56a593fbb35ca..f8bc99b9756cf9a0e37a740d06349db1d5062681 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 01d49cb3641234b421cd255418e77faeaf96f7f0..533796516474b6753c7885924c1d2f05ac5e3904 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -1057,6 +1057,7 @@ static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit"; static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; static const char* jkIntervalPhysiPlanFill = "Fill"; static const char* jkIntervalPhysiPlanTsPk = "TsPk"; +static const char* jkIntervalPhysiPlanPrecision = "Precision"; static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { const SIntervalPhysiNode* pNode = (const SIntervalPhysiNode*)pObj; @@ -1083,6 +1084,9 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanPrecision, pNode->precision); + } return code; } @@ -1112,6 +1116,9 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUTinyIntValue(pJson, jkIntervalPhysiPlanPrecision, &pNode->precision); + } return code; } @@ -2008,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"; @@ -2321,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: @@ -2424,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 0000000000000000000000000000000000000000..68f38bb6a7db3a2b1a703dae02c279626f553414 --- /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 7eaa049946c842cdb6dd76fc415bd515ee921aa1..bbd0473eddd081706b3830ae0755e81c46b7286a 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 bd8e9a7518c63805d6ad04c7de7acb5c27568dec..732d9acfbefc50c0cea175732d6c0c2d5a435ce9 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -82,6 +82,8 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(STableOptions)); case QUERY_NODE_INDEX_OPTIONS: return makeNode(type, sizeof(SIndexOptions)); + case QUERY_NODE_EXPLAIN_OPTIONS: + return makeNode(type, sizeof(SExplainOptions)); case QUERY_NODE_SET_OPERATOR: return makeNode(type, sizeof(SSetOperator)); case QUERY_NODE_SELECT_STMT: @@ -132,6 +134,12 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SCreateTopicStmt)); case QUERY_NODE_DROP_TOPIC_STMT: 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: @@ -204,49 +212,159 @@ SNodeptr nodesMakeNode(ENodeType type) { return NULL; } -static EDealRes destroyNode(SNode** pNode, void* pContext) { - switch (nodeType(*pNode)) { +static void destroyVgDataBlockArray(SArray* pArray) { + size_t size = taosArrayGetSize(pArray); + for (size_t i = 0; i < size; ++i) { + SVgDataBlocks* pVg = taosArrayGetP(pArray, i); + taosMemoryFreeClear(pVg->pData); + taosMemoryFreeClear(pVg); + } + taosArrayDestroy(pArray); +} + +static void destroyLogicNode(SLogicNode* pNode) { + nodesDestroyList(pNode->pChildren); + nodesDestroyNode(pNode->pConditions); + nodesDestroyList(pNode->pTargets); +} + +static void destroyPhysiNode(SPhysiNode* pNode) { + nodesDestroyList(pNode->pChildren); + nodesDestroyNode(pNode->pConditions); + nodesDestroyNode(pNode->pOutputDataBlockDesc); +} + +static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) { + destroyPhysiNode((SPhysiNode*)pNode); + nodesDestroyList(pNode->pExprs); + nodesDestroyList(pNode->pFuncs); +} + +static void destroyScanPhysiNode(SScanPhysiNode* pNode) { + destroyPhysiNode((SPhysiNode*)pNode); + nodesDestroyList(pNode->pScanCols); +} + +static void destroyDataSinkNode(SDataSinkNode* pNode) { + nodesDestroyNode(pNode->pInputDataBlockDesc); +} + +void nodesDestroyNode(SNodeptr pNode) { + if (NULL == pNode) { + return; + } + + switch (nodeType(pNode)) { + case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release + break; case QUERY_NODE_VALUE: { - SValueNode* pValue = (SValueNode*)*pNode; - + SValueNode* pValue = (SValueNode*)pNode; taosMemoryFreeClear(pValue->literal); if (IS_VAR_DATA_TYPE(pValue->node.resType.type)) { taosMemoryFreeClear(pValue->datum.p); } - + break; + } + case QUERY_NODE_OPERATOR: { + SOperatorNode* pOp = (SOperatorNode*)pNode; + nodesDestroyNode(pOp->pLeft); + nodesDestroyNode(pOp->pRight); break; } case QUERY_NODE_LOGIC_CONDITION: - nodesClearList(((SLogicConditionNode*)(*pNode))->pParameterList); + nodesDestroyList(((SLogicConditionNode*)pNode)->pParameterList); break; case QUERY_NODE_FUNCTION: - nodesClearList(((SFunctionNode*)(*pNode))->pParameterList); + nodesDestroyList(((SFunctionNode*)pNode)->pParameterList); break; case QUERY_NODE_REAL_TABLE: { - SRealTableNode* pReal = (SRealTableNode*)*pNode; + SRealTableNode* pReal = (SRealTableNode*)pNode; taosMemoryFreeClear(pReal->pMeta); taosMemoryFreeClear(pReal->pVgroupList); break; } case QUERY_NODE_TEMP_TABLE: - nodesDestroyNode(((STempTableNode*)(*pNode))->pSubquery); + nodesDestroyNode(((STempTableNode*)pNode)->pSubquery); break; + case QUERY_NODE_JOIN_TABLE: { + SJoinTableNode* pJoin = (SJoinTableNode*)pNode; + nodesDestroyNode(pJoin->pLeft); + nodesDestroyNode(pJoin->pRight); + nodesDestroyNode(pJoin->pOnCond); + break; + } case QUERY_NODE_GROUPING_SET: - nodesClearList(((SGroupingSetNode*)(*pNode))->pParameterList); + nodesDestroyList(((SGroupingSetNode*)pNode)->pParameterList); + break; + case QUERY_NODE_ORDER_BY_EXPR: + nodesDestroyNode(((SOrderByExprNode*)pNode)->pExpr); + break; + case QUERY_NODE_LIMIT: // no pointer field + break; + case QUERY_NODE_STATE_WINDOW: + nodesDestroyNode(((SStateWindowNode*)pNode)->pCol); + break; + case QUERY_NODE_SESSION_WINDOW: { + SSessionWindowNode* pSession = (SSessionWindowNode*)pNode; + nodesDestroyNode(pSession->pCol); + nodesDestroyNode(pSession->pGap); + break; + } + case QUERY_NODE_INTERVAL_WINDOW: { + SIntervalWindowNode* pJoin = (SIntervalWindowNode*)pNode; + nodesDestroyNode(pJoin->pCol); + nodesDestroyNode(pJoin->pInterval); + nodesDestroyNode(pJoin->pOffset); + nodesDestroyNode(pJoin->pSliding); + nodesDestroyNode(pJoin->pFill); break; + } case QUERY_NODE_NODE_LIST: - nodesClearList(((SNodeListNode*)(*pNode))->pNodeList); + nodesDestroyList(((SNodeListNode*)pNode)->pNodeList); break; + case QUERY_NODE_FILL: + nodesDestroyNode(((SFillNode*)pNode)->pValues); + break; + case QUERY_NODE_RAW_EXPR: + nodesDestroyNode(((SRawExprNode*)pNode)->pNode); + break; + case QUERY_NODE_TARGET: + nodesDestroyNode(((STargetNode*)pNode)->pExpr); + break; + case QUERY_NODE_DATABLOCK_DESC: + nodesDestroyList(((SDataBlockDescNode*)pNode)->pSlots); + break; + case QUERY_NODE_SLOT_DESC: // no pointer field + case QUERY_NODE_COLUMN_DEF: // no pointer field + case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field + break; + case QUERY_NODE_DATABASE_OPTIONS: + nodesDestroyList(((SDatabaseOptions*)pNode)->pRetentions); + break; + case QUERY_NODE_TABLE_OPTIONS: { + STableOptions* pStmt = (STableOptions*)pNode; + nodesDestroyList(pStmt->pSma); + nodesDestroyList(pStmt->pFuncs); + break; + } case QUERY_NODE_INDEX_OPTIONS: { - SIndexOptions* pStmt = (SIndexOptions*)*pNode; + SIndexOptions* pStmt = (SIndexOptions*)pNode; nodesDestroyList(pStmt->pFuncs); nodesDestroyNode(pStmt->pInterval); nodesDestroyNode(pStmt->pOffset); nodesDestroyNode(pStmt->pSliding); break; } + case QUERY_NODE_SET_OPERATOR: { + SSetOperator* pStmt = (SSetOperator*)pNode; + nodesDestroyNode(pStmt->pLeft); + nodesDestroyNode(pStmt->pRight); + nodesDestroyList(pStmt->pOrderByList); + nodesDestroyNode(pStmt->pLimit); + break; + } case QUERY_NODE_SELECT_STMT: { - SSelectStmt* pStmt = (SSelectStmt*)*pNode; + SSelectStmt* pStmt = (SSelectStmt*)pNode; nodesDestroyList(pStmt->pProjectionList); nodesDestroyNode(pStmt->pFromTable); nodesDestroyNode(pStmt->pWhere); @@ -259,50 +377,255 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { nodesDestroyNode(pStmt->pSlimit); break; } - case QUERY_NODE_VNODE_MODIF_STMT: { - SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)*pNode; - size_t size = taosArrayGetSize(pStmt->pDataBlocks); - for (size_t i = 0; i < size; ++i) { - SVgDataBlocks* pVg = taosArrayGetP(pStmt->pDataBlocks, i); - taosMemoryFreeClear(pVg->pData); - taosMemoryFreeClear(pVg); - } - taosArrayDestroy(pStmt->pDataBlocks); + case QUERY_NODE_VNODE_MODIF_STMT: + destroyVgDataBlockArray(((SVnodeModifOpStmt*)pNode)->pDataBlocks); + break; + case QUERY_NODE_CREATE_DATABASE_STMT: + nodesDestroyNode(((SCreateDatabaseStmt*)pNode)->pOptions); + break; + case QUERY_NODE_DROP_DATABASE_STMT: // no pointer field + break; + case QUERY_NODE_ALTER_DATABASE_STMT: + nodesDestroyNode(((SAlterDatabaseStmt*)pNode)->pOptions); break; - } case QUERY_NODE_CREATE_TABLE_STMT: { - SCreateTableStmt* pStmt = (SCreateTableStmt*)*pNode; + SCreateTableStmt* pStmt = (SCreateTableStmt*)pNode; nodesDestroyList(pStmt->pCols); nodesDestroyList(pStmt->pTags); + nodesDestroyNode(pStmt->pOptions); break; } case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: { - SCreateSubTableClause* pStmt = (SCreateSubTableClause*)*pNode; + SCreateSubTableClause* pStmt = (SCreateSubTableClause*)pNode; nodesDestroyList(pStmt->pSpecificTags); nodesDestroyList(pStmt->pValsOfTags); break; } case QUERY_NODE_CREATE_MULTI_TABLE_STMT: - nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables); + nodesDestroyList(((SCreateMultiTableStmt*)pNode)->pSubTables); + break; + case QUERY_NODE_DROP_TABLE_CLAUSE: // no pointer field + break; + case QUERY_NODE_DROP_TABLE_STMT: + nodesDestroyNode(((SDropTableStmt*)pNode)->pTables); + break; + case QUERY_NODE_DROP_SUPER_TABLE_STMT: // no pointer field + break; + case QUERY_NODE_ALTER_TABLE_STMT: { + SAlterTableStmt* pStmt = (SAlterTableStmt*)pNode; + nodesDestroyNode(pStmt->pOptions); + nodesDestroyNode(pStmt->pVal); + break; + } + case QUERY_NODE_CREATE_USER_STMT: // no pointer field + case QUERY_NODE_ALTER_USER_STMT: // no pointer field + case QUERY_NODE_DROP_USER_STMT: // no pointer field + case QUERY_NODE_USE_DATABASE_STMT: // no pointer field + case QUERY_NODE_CREATE_DNODE_STMT: // no pointer field + case QUERY_NODE_DROP_DNODE_STMT: // no pointer field + case QUERY_NODE_ALTER_DNODE_STMT: // no pointer field break; case QUERY_NODE_CREATE_INDEX_STMT: { - SCreateIndexStmt* pStmt = (SCreateIndexStmt*)*pNode; + SCreateIndexStmt* pStmt = (SCreateIndexStmt*)pNode; nodesDestroyNode(pStmt->pOptions); nodesDestroyList(pStmt->pCols); break; } + case QUERY_NODE_DROP_INDEX_STMT: // no pointer field + case QUERY_NODE_CREATE_QNODE_STMT: // no pointer field + case QUERY_NODE_DROP_QNODE_STMT: // no pointer field + break; + case QUERY_NODE_CREATE_TOPIC_STMT: + nodesDestroyNode(((SCreateTopicStmt*)pNode)->pQuery); + break; + case QUERY_NODE_DROP_TOPIC_STMT: // no pointer field + case QUERY_NODE_ALTER_LOCAL_STMT: // no pointer field + break; + case QUERY_NODE_SHOW_DATABASES_STMT: + case QUERY_NODE_SHOW_TABLES_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_MODULES_STMT: + case QUERY_NODE_SHOW_QNODES_STMT: + case QUERY_NODE_SHOW_FUNCTIONS_STMT: + case QUERY_NODE_SHOW_INDEXES_STMT: + case QUERY_NODE_SHOW_STREAMS_STMT: { + SShowStmt* pStmt = (SShowStmt*)pNode; + nodesDestroyNode(pStmt->pDbName); + nodesDestroyNode(pStmt->pTbNamePattern); + break; + } + case QUERY_NODE_LOGIC_PLAN_SCAN: { + SScanLogicNode* pLogicNode = (SScanLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyList(pLogicNode->pScanCols); + taosMemoryFreeClear(pLogicNode->pMeta); + taosMemoryFreeClear(pLogicNode->pVgroupList); + break; + } + case QUERY_NODE_LOGIC_PLAN_JOIN: { + SJoinLogicNode* pLogicNode = (SJoinLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyNode(pLogicNode->pOnConditions); + break; + } + case QUERY_NODE_LOGIC_PLAN_AGG: { + SAggLogicNode* pLogicNode = (SAggLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyList(pLogicNode->pAggFuncs); + nodesDestroyList(pLogicNode->pGroupKeys); + break; + } + case QUERY_NODE_LOGIC_PLAN_PROJECT: { + SProjectLogicNode* pLogicNode = (SProjectLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyList(pLogicNode->pProjections); + break; + } + case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF: { + SVnodeModifLogicNode* pLogicNode = (SVnodeModifLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + destroyVgDataBlockArray(pLogicNode->pDataBlocks); + // pVgDataBlocks is weak reference + break; + } + case QUERY_NODE_LOGIC_PLAN_EXCHANGE: + destroyLogicNode((SLogicNode*)pNode); + break; + case QUERY_NODE_LOGIC_PLAN_WINDOW: { + SWindowLogicNode* pLogicNode = (SWindowLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyList(pLogicNode->pFuncs); + nodesDestroyNode(pLogicNode->pFill); + nodesDestroyNode(pLogicNode->pTspk); + break; + } + case QUERY_NODE_LOGIC_PLAN_SORT: { + SSortLogicNode* pLogicNode = (SSortLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyList(pLogicNode->pSortKeys); + break; + } + case QUERY_NODE_LOGIC_PLAN_PARTITION: { + SPartitionLogicNode* pLogicNode = (SPartitionLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyList(pLogicNode->pPartitionKeys); + break; + } + case QUERY_NODE_LOGIC_SUBPLAN: { + SLogicSubplan* pSubplan = (SLogicSubplan*)pNode; + nodesDestroyList(pSubplan->pChildren); + nodesDestroyNode(pSubplan->pNode); + nodesClearList(pSubplan->pParents); + taosMemoryFreeClear(pSubplan->pVgroupList); + break; + } + case QUERY_NODE_LOGIC_PLAN: + nodesDestroyList(((SQueryLogicPlan*)pNode)->pTopSubplans); + break; + case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: + destroyScanPhysiNode((SScanPhysiNode*)pNode); + break; + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: + destroyScanPhysiNode((SScanPhysiNode*)pNode); + break; + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: + destroyScanPhysiNode((SScanPhysiNode*)pNode); + break; + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: + destroyScanPhysiNode((SScanPhysiNode*)pNode); + break; + case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: + destroyScanPhysiNode((SScanPhysiNode*)pNode); + break; + case QUERY_NODE_PHYSICAL_PLAN_PROJECT: { + SProjectPhysiNode* pPhyNode = (SProjectPhysiNode*)pNode; + destroyPhysiNode((SPhysiNode*)pPhyNode); + nodesDestroyList(pPhyNode->pProjections); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_JOIN: { + SJoinPhysiNode* pPhyNode = (SJoinPhysiNode*)pNode; + destroyPhysiNode((SPhysiNode*)pPhyNode); + nodesDestroyNode(pPhyNode->pOnConditions); + nodesDestroyList(pPhyNode->pTargets); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_AGG: { + SAggPhysiNode* pPhyNode = (SAggPhysiNode*)pNode; + destroyPhysiNode((SPhysiNode*)pPhyNode); + nodesDestroyList(pPhyNode->pExprs); + nodesDestroyList(pPhyNode->pAggFuncs); + nodesDestroyList(pPhyNode->pGroupKeys); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: { + SExchangePhysiNode* pPhyNode = (SExchangePhysiNode*)pNode; + destroyPhysiNode((SPhysiNode*)pPhyNode); + nodesDestroyList(pPhyNode->pSrcEndPoints); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SORT: { + SSortPhysiNode* pPhyNode = (SSortPhysiNode*)pNode; + destroyPhysiNode((SPhysiNode*)pPhyNode); + nodesDestroyNode(pPhyNode->pExprs); + nodesDestroyNode(pPhyNode->pSortKeys); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_INTERVAL: { + SIntervalPhysiNode* pPhyNode = (SIntervalPhysiNode*)pNode; + destroyWinodwPhysiNode((SWinodwPhysiNode*)pPhyNode); + nodesDestroyNode(pPhyNode->pFill); + nodesDestroyNode(pPhyNode->pTspk); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: + destroyWinodwPhysiNode((SWinodwPhysiNode*)pNode); + break; + case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: + destroyDataSinkNode((SDataSinkNode*)pNode); + break; + case QUERY_NODE_PHYSICAL_PLAN_INSERT: { + SDataInserterNode* pSink = (SDataInserterNode*)pNode; + destroyDataSinkNode((SDataSinkNode*)pSink); + taosMemoryFreeClear(pSink->pData); + break; + } + case QUERY_NODE_PHYSICAL_SUBPLAN: { + SSubplan* pSubplan = (SSubplan*)pNode; + nodesDestroyList(pSubplan->pChildren); + nodesDestroyNode(pSubplan->pNode); + nodesDestroyNode(pSubplan->pDataSink); + nodesClearList(pSubplan->pParents); + break; + } + case QUERY_NODE_PHYSICAL_PLAN: { + SQueryPlan* pPlan = (SQueryPlan*)pNode; + if (NULL != pPlan->pSubplans) { + // only need to destroy the top-level subplans, because they will recurse to all the subplans below + bool first = true; + SNode* pElement = NULL; + FOREACH(pElement, pPlan->pSubplans) { + if (first) { + first = false; + nodesDestroyNode(pElement); + } else { + nodesClearList(((SNodeListNode*)pElement)->pNodeList); + taosMemoryFreeClear(pElement); + } + } + nodesClearList(pPlan->pSubplans); + } + break; + } default: break; } - taosMemoryFreeClear(*pNode); - return DEAL_RES_CONTINUE; -} - -void nodesDestroyNode(SNodeptr pNode) { - if (NULL == pNode) { - return; - } - nodesRewriteNodePostOrder((SNode**)&pNode, destroyNode, NULL); + taosMemoryFreeClear(pNode); + return; } SNodeList* nodesMakeList() { @@ -467,6 +790,71 @@ 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); diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 0fe5df183d704e64e754021157318a6f1882bab5..1fce11acdfc0bf22bf4c217631590f0c0780dd3b 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); @@ -159,6 +166,22 @@ SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId); SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName); SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName); SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue); +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 a38d64c58c859a04ea9fcd874e6507231335554c..dbf7d379ec7bf81567aa44cb0cb4ac3a62c8f055 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -78,8 +78,6 @@ typedef struct STableDataBlocks { char *pData; bool cloned; STagData tagData; - char tableName[TSDB_TABLE_NAME_LEN]; - char dbFName[TSDB_DB_FNAME_LEN]; SParsedDataColInfo boundColumnInfo; SRowBuilder rowBuilder; diff --git a/source/libs/parser/inc/parInt.h b/source/libs/parser/inc/parInt.h index af0d78717e1341d4b73b0d69a72fb74d7fd61375..9bad3e9eb92727440972a91d972e38660bbb3e19 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 7556684e8bc419891f651e1bf0cebd860026887e..29b1d8857a4ce2c456f2a4217aa09ea01133e78c 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,6 +356,64 @@ 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); } +/************************************************ 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 } +%destructor analyze_opt { } +analyze_opt(A) ::= . { A = false; } +analyze_opt(A) ::= ANALYZE. { A = true; } + +explain_options(A) ::= . { A = createDefaultExplainOptions(pCxt); } +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; } @@ -417,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; } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index fcabd4614cc32850cca1aed806880ac51f730a4e..18a0ae8cfa34cfcdea433bb56155c3deb406c7f5 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)) { @@ -1316,3 +1400,108 @@ SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, cons } return (SNode*)pStmt; } + +SNode* createDefaultExplainOptions(SAstCreateContext* pCxt) { + SExplainOptions* pOptions = nodesMakeNode(QUERY_NODE_EXPLAIN_OPTIONS); + CHECK_OUT_OF_MEM(pOptions); + pOptions->verbose = TSDB_DEFAULT_EXPLAIN_VERBOSE; + pOptions->ratio = TSDB_DEFAULT_EXPLAIN_RATIO; + return (SNode*)pOptions; +} + +SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) { + ((SExplainOptions*)pOptions)->verbose = (0 == strncasecmp(pVal->z, "true", pVal->n)); + return pOptions; +} + +SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) { + ((SExplainOptions*)pOptions)->ratio = strtod(pVal->z, NULL); + return pOptions; +} + +SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery) { + SExplainStmt* pStmt = nodesMakeNode(QUERY_NODE_EXPLAIN_STMT); + CHECK_OUT_OF_MEM(pStmt); + pStmt->analyze = analyze; + pStmt->pOptions = (SExplainOptions*)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 ed67de17e0d223087c20852f4e88654decec12b9..11b552fb941c7a3cf3c44bd66e2aed75af3146be 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -52,8 +52,6 @@ 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 @@ -65,7 +63,7 @@ typedef struct SInsertParseContext { 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 +229,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 +439,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 +472,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 +482,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 +492,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 +502,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 +512,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 +522,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 +531,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 +541,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 +553,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 +564,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 +573,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 +586,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 +600,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 +612,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 +711,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 +724,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); @@ -973,8 +972,6 @@ 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); if (TK_NK_LP == sToken.type) { // pSql -> field1_name, ...) diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 3751041ef7db619aa0a9e3dbfc3c62b455fde1cf..d89bee6fdc4dd7013e73da0e19d96b83f891129b 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -29,9 +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}, @@ -39,23 +44,32 @@ 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}, {"DOUBLE", TK_DOUBLE}, {"DROP", TK_DROP}, {"EXISTS", TK_EXISTS}, + {"EXPLAIN", TK_EXPLAIN}, {"FILE_FACTOR", TK_FILE_FACTOR}, {"FILL", TK_FILL}, {"FLOAT", TK_FLOAT}, @@ -80,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}, @@ -99,9 +117,11 @@ 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}, @@ -109,13 +129,20 @@ static SKeyword keywordTable[] = { {"QNODE", TK_QNODE}, {"QNODES", TK_QNODES}, {"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}, + {"SCORES", TK_SCORES}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, + {"SET", TK_SET}, {"SHOW", TK_SHOW}, {"SINGLE_STABLE", TK_SINGLE_STABLE}, {"SLIDING", TK_SLIDING}, @@ -125,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}, @@ -142,9 +176,13 @@ 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}, @@ -175,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}, @@ -199,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}, @@ -224,7 +238,6 @@ static SKeyword keywordTable[] = { // {"DETACH", TK_DETACH}, // {"EACH", TK_EACH}, // {"END", TK_END}, - // {"EXPLAIN", TK_EXPLAIN}, // {"FAIL", TK_FAIL}, // {"FOR", TK_FOR}, // {"IGNORE", TK_IGNORE}, @@ -241,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}, }; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 0f26bec9b22aff319a2a21f7c28fc3fdc01a684a..4191e3dae0c34919cf5df580e026f1db6ce1b4b9 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -32,6 +32,7 @@ typedef struct STranslateContext { SCmdMsgInfo* pCmdMsg; SHashObj* pDbs; SHashObj* pTables; + SExplainOptions* pExplainOpt; } STranslateContext; typedef struct SFullDatabaseName { @@ -228,6 +229,9 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p pCol->colType = isTag ? COLUMN_TYPE_TAG : COLUMN_TYPE_COLUMN; pCol->node.resType.type = pColSchema->type; pCol->node.resType.bytes = pColSchema->bytes; + if (TSDB_DATA_TYPE_TIMESTAMP == pCol->node.resType.type) { + pCol->node.resType.precision = pTable->pMeta->tableInfo.precision; + } } static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) { @@ -236,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; @@ -670,6 +678,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { switch (nodeType(pTable)) { case QUERY_NODE_REAL_TABLE: { SRealTableNode* pRealTable = (SRealTableNode*)pTable; + pRealTable->ratio = (NULL != pCxt->pExplainOpt ? pCxt->pExplainOpt->ratio : 1.0); SName name; code = getTableMetaImpl(pCxt, toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name), &(pRealTable->pMeta)); @@ -677,10 +686,9 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, pRealTable->table.tableName); } code = setTableVgroupList(pCxt, &name, pRealTable); - if (TSDB_CODE_SUCCESS != code) { - return code; + if (TSDB_CODE_SUCCESS == code) { + code = addNamespace(pCxt, pRealTable); } - code = addNamespace(pCxt, pRealTable); break; } case QUERY_NODE_TEMP_TABLE: { @@ -952,9 +960,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; @@ -1037,13 +1045,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; } @@ -1090,10 +1099,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) { @@ -1115,7 +1120,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) { @@ -1144,7 +1149,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; } @@ -1156,10 +1161,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); @@ -1213,6 +1223,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); @@ -1462,20 +1475,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; } @@ -1501,30 +1514,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); @@ -1801,6 +1790,17 @@ static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pSt return TSDB_CODE_SUCCESS; } +static int32_t translateExplain(STranslateContext* pCxt, SExplainStmt* pStmt) { + if (pStmt->analyze) { + pCxt->pExplainOpt = pStmt->pOptions; + } + 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)) { @@ -1849,17 +1849,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); @@ -1882,6 +1884,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_ALTER_LOCAL_STMT: code = translateAlterLocal(pCxt, (SAlterLocalStmt*)pNode); break; + case QUERY_NODE_EXPLAIN_STMT: + code = translateExplain(pCxt, (SExplainStmt*)pNode); + break; + case QUERY_NODE_DESCRIBE_STMT: + code = translateDescribe(pCxt, (SDescribeStmt*)pNode); + break; default: break; } @@ -1899,30 +1907,84 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) { return code; } -int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { - if (NULL != pRoot && 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; - } +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; - } + 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; + } + + 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_FAILED; +} + static void destroyTranslateContext(STranslateContext* pCxt) { if (NULL != pCxt->pNsLevel) { size_t size = taosArrayGetSize(pCxt->pNsLevel); @@ -2090,10 +2152,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); } @@ -2115,7 +2178,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; @@ -2126,6 +2189,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); @@ -2370,9 +2434,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) { @@ -2502,26 +2576,34 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { switch (nodeType(pQuery->pRoot)) { 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; + 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->haveResultSet = false; pQuery->directRpc = true; - pQuery->pCmdMsg = pCxt->pCmdMsg; - pCxt->pCmdMsg = NULL; - pQuery->msgType = pQuery->pCmdMsg->msgType; + 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) { pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 80d04c5ee4f98ea1c09fedba4c1690bd7fceabef..aeed7719f38d673dadb9dfe6816ad13d2c4a7b4d 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 92bd6f111b03ccf7b9b3232eefae50a934d61032..d410aa2e1794572f5ad51d813fb51e5f7d93f5b3 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -58,5 +58,11 @@ void qDestroyQuery(SQuery* pQueryNode) { taosMemoryFreeClear(pQueryNode->pCmdMsg->pMsg); taosMemoryFreeClear(pQueryNode->pCmdMsg); } + taosArrayDestroy(pQueryNode->pDbList); + 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 ef2c547e44faac22afb4b214f6f43306b040cd45..618e80cbfe837f0ff73ddacb121c4fbb5a565ff7 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 268 +#define YYNOCODE 304 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - EOrder yy106; - EFillMode yy142; - SNode* yy176; - SToken yy225; - EJoinType yy236; - SAlterOption yy325; - EOperatorType yy404; - SDataType yy448; - ENullOrder yy465; - bool yy505; - int32_t yy508; - SNodeList* yy512; + 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 432 -#define YYNRULE 348 -#define YYNTOKEN 172 -#define YY_MAX_SHIFT 431 -#define YY_MIN_SHIFTREDUCE 675 -#define YY_MAX_SHIFTREDUCE 1022 -#define YY_ERROR_ACTION 1023 -#define YY_ACCEPT_ACTION 1024 -#define YY_NO_ACTION 1025 -#define YY_MIN_REDUCE 1026 -#define YY_MAX_REDUCE 1373 +#define YYNSTATE 512 +#define YYNRULE 389 +#define YYNTOKEN 201 +#define YY_MAX_SHIFT 511 +#define YY_MIN_SHIFTREDUCE 762 +#define YY_MAX_SHIFTREDUCE 1150 +#define YY_ERROR_ACTION 1151 +#define YY_ACCEPT_ACTION 1152 +#define YY_NO_ACTION 1153 +#define YY_MIN_REDUCE 1154 +#define YY_MAX_REDUCE 1542 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -209,405 +209,452 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1282) +#define YY_ACTTAB_COUNT (1412) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1230, 43, 306, 1243, 1118, 350, 1226, 1233, 238, 1114, - /* 10 */ 89, 1205, 31, 29, 27, 26, 25, 1259, 1124, 24, - /* 20 */ 170, 1352, 226, 1259, 347, 31, 29, 27, 26, 25, - /* 30 */ 347, 363, 363, 251, 1351, 362, 66, 270, 1350, 1230, - /* 40 */ 349, 1243, 307, 280, 1217, 1226, 1232, 212, 1069, 335, - /* 50 */ 321, 362, 1129, 1129, 61, 1244, 1245, 1248, 1291, 210, - /* 60 */ 212, 1259, 211, 1287, 246, 363, 1065, 1352, 347, 898, - /* 70 */ 1126, 1196, 1198, 239, 1352, 106, 1096, 928, 349, 350, - /* 80 */ 117, 104, 1217, 12, 1350, 1206, 1129, 117, 293, 1131, - /* 90 */ 928, 1350, 107, 1244, 1245, 1248, 1027, 416, 415, 414, - /* 100 */ 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, - /* 110 */ 403, 402, 401, 400, 399, 189, 929, 77, 1159, 1120, - /* 120 */ 76, 75, 74, 73, 72, 71, 70, 69, 68, 929, - /* 130 */ 336, 1365, 424, 423, 23, 233, 923, 924, 925, 926, - /* 140 */ 927, 931, 932, 933, 27, 26, 25, 23, 233, 923, - /* 150 */ 924, 925, 926, 927, 931, 932, 933, 9, 8, 1243, - /* 160 */ 1217, 784, 386, 385, 384, 788, 383, 790, 791, 382, - /* 170 */ 793, 379, 883, 799, 376, 801, 802, 373, 370, 1259, - /* 180 */ 30, 28, 105, 1176, 1038, 243, 334, 1049, 235, 225, - /* 190 */ 863, 30, 28, 965, 1174, 271, 349, 362, 1259, 235, - /* 200 */ 1217, 863, 1230, 1243, 885, 347, 861, 1107, 1226, 1232, - /* 210 */ 62, 1244, 1245, 1248, 1291, 11, 363, 861, 228, 1287, - /* 220 */ 112, 360, 712, 1259, 711, 941, 11, 339, 1217, 1105, - /* 230 */ 347, 324, 166, 30, 28, 1024, 1, 1129, 313, 1318, - /* 240 */ 349, 235, 713, 863, 1217, 12, 320, 1, 31, 29, - /* 250 */ 27, 26, 25, 271, 62, 1244, 1245, 1248, 1291, 861, - /* 260 */ 428, 338, 228, 1287, 1364, 1310, 960, 1048, 11, 363, - /* 270 */ 930, 428, 862, 1325, 66, 398, 1176, 326, 322, 1243, - /* 280 */ 1047, 286, 240, 862, 250, 242, 241, 1174, 21, 1, - /* 290 */ 1129, 864, 867, 868, 201, 876, 911, 934, 118, 1259, - /* 300 */ 325, 109, 864, 867, 868, 201, 334, 911, 1217, 1352, - /* 310 */ 340, 869, 1169, 428, 118, 1243, 349, 1046, 1176, 1045, - /* 320 */ 1217, 1217, 117, 118, 247, 862, 1350, 259, 1060, 1174, - /* 330 */ 62, 1244, 1245, 1248, 1291, 1259, 363, 1305, 228, 1287, - /* 340 */ 112, 361, 347, 363, 864, 867, 868, 201, 184, 911, - /* 350 */ 295, 1243, 349, 30, 28, 1302, 1217, 1129, 1217, 1319, - /* 360 */ 1217, 235, 1305, 863, 1129, 364, 62, 1244, 1245, 1248, - /* 370 */ 1291, 1259, 122, 121, 228, 1287, 1364, 872, 347, 861, - /* 380 */ 1301, 30, 28, 348, 972, 1348, 1044, 389, 349, 235, - /* 390 */ 885, 863, 1217, 118, 363, 331, 877, 880, 868, 249, - /* 400 */ 1043, 1042, 62, 1244, 1245, 1248, 1291, 861, 1041, 7, - /* 410 */ 228, 1287, 1364, 964, 245, 1129, 92, 886, 30, 28, - /* 420 */ 337, 1309, 104, 398, 30, 28, 235, 1217, 863, 59, - /* 430 */ 1131, 1243, 235, 428, 863, 1040, 1176, 7, 1037, 93, - /* 440 */ 248, 1217, 1217, 90, 861, 862, 1121, 1197, 104, 1217, - /* 450 */ 861, 1259, 333, 113, 1298, 1299, 1131, 1303, 347, 1036, - /* 460 */ 1035, 428, 884, 1193, 864, 867, 868, 201, 349, 911, - /* 470 */ 120, 1034, 1217, 862, 7, 887, 1217, 335, 1176, 1217, - /* 480 */ 1, 1033, 202, 1244, 1245, 1248, 284, 118, 297, 1175, - /* 490 */ 283, 1116, 864, 867, 868, 201, 43, 911, 428, 1112, - /* 500 */ 1217, 1217, 1352, 305, 428, 1032, 1243, 1106, 1031, 1030, - /* 510 */ 862, 285, 1217, 1125, 1029, 117, 862, 145, 888, 1350, - /* 520 */ 300, 1305, 1217, 9, 8, 294, 1259, 52, 144, 864, - /* 530 */ 867, 868, 201, 347, 911, 864, 867, 868, 201, 1300, - /* 540 */ 911, 989, 1243, 349, 1122, 104, 1217, 1217, 6, 1217, - /* 550 */ 1217, 40, 342, 1132, 39, 1217, 963, 63, 1244, 1245, - /* 560 */ 1248, 1291, 1259, 331, 395, 1290, 1287, 304, 394, 347, - /* 570 */ 863, 388, 317, 987, 988, 990, 991, 165, 1243, 349, - /* 580 */ 302, 871, 137, 1217, 92, 135, 861, 194, 139, 396, - /* 590 */ 1039, 138, 196, 63, 1244, 1245, 1248, 1291, 1259, 318, - /* 600 */ 711, 345, 1287, 335, 195, 347, 309, 1243, 393, 392, - /* 610 */ 391, 90, 390, 1058, 123, 349, 278, 346, 98, 1217, - /* 620 */ 151, 163, 1298, 330, 1104, 329, 1243, 1259, 1352, 63, - /* 630 */ 1244, 1245, 1248, 1291, 347, 298, 141, 343, 1288, 140, - /* 640 */ 428, 117, 986, 156, 349, 1350, 1259, 874, 1217, 1243, - /* 650 */ 960, 234, 862, 347, 41, 154, 1021, 1022, 206, 1244, - /* 660 */ 1245, 1248, 143, 349, 58, 142, 1097, 1217, 1243, 1259, - /* 670 */ 314, 864, 867, 868, 54, 64, 347, 206, 1244, 1245, - /* 680 */ 1248, 395, 870, 1170, 935, 394, 349, 895, 1259, 167, - /* 690 */ 1217, 160, 277, 1321, 920, 347, 32, 883, 1237, 32, - /* 700 */ 205, 1244, 1245, 1248, 252, 349, 396, 264, 1243, 1217, - /* 710 */ 1235, 856, 175, 1243, 332, 118, 265, 169, 355, 107, - /* 720 */ 1244, 1245, 1248, 32, 173, 393, 392, 391, 1259, 390, - /* 730 */ 95, 1260, 327, 1259, 2, 347, 883, 1195, 119, 253, - /* 740 */ 347, 181, 261, 260, 266, 349, 891, 262, 873, 1217, - /* 750 */ 349, 777, 232, 96, 1217, 1072, 268, 236, 1366, 206, - /* 760 */ 1244, 1245, 1248, 98, 206, 1244, 1245, 1248, 1026, 267, - /* 770 */ 124, 77, 890, 772, 76, 75, 74, 73, 72, 71, - /* 780 */ 70, 69, 68, 127, 263, 41, 42, 258, 257, 256, - /* 790 */ 255, 254, 86, 85, 84, 83, 82, 81, 80, 79, - /* 800 */ 78, 431, 1243, 272, 292, 269, 287, 1243, 130, 291, - /* 810 */ 889, 805, 290, 279, 288, 187, 281, 289, 88, 87, - /* 820 */ 809, 308, 1259, 368, 420, 224, 186, 1259, 292, 347, - /* 830 */ 287, 310, 96, 291, 347, 815, 290, 1243, 288, 349, - /* 840 */ 1119, 289, 134, 1217, 349, 1243, 1115, 97, 1217, 60, - /* 850 */ 814, 136, 182, 204, 1244, 1245, 1248, 1259, 207, 1244, - /* 860 */ 1245, 1248, 98, 99, 347, 1259, 31, 29, 27, 26, - /* 870 */ 25, 100, 347, 101, 349, 96, 1117, 146, 1217, 1113, - /* 880 */ 102, 1243, 349, 359, 103, 149, 1217, 311, 199, 1244, - /* 890 */ 1245, 1248, 888, 1322, 319, 1332, 208, 1244, 1245, 1248, - /* 900 */ 312, 1259, 353, 147, 1243, 152, 316, 227, 347, 1243, - /* 910 */ 31, 29, 27, 26, 25, 1331, 868, 155, 349, 323, - /* 920 */ 5, 328, 1217, 898, 1259, 315, 1312, 159, 4, 1259, - /* 930 */ 110, 347, 200, 1244, 1245, 1248, 347, 960, 91, 887, - /* 940 */ 33, 349, 161, 1306, 1243, 1217, 349, 162, 344, 341, - /* 950 */ 1217, 17, 1243, 229, 1367, 209, 1244, 1245, 1248, 331, - /* 960 */ 1256, 1244, 1245, 1248, 1259, 1273, 356, 357, 179, 1349, - /* 970 */ 168, 347, 1259, 1204, 1243, 1203, 351, 177, 352, 347, - /* 980 */ 92, 349, 51, 237, 358, 1217, 188, 1130, 53, 349, - /* 990 */ 190, 366, 185, 1217, 1259, 1255, 1244, 1245, 1248, 427, - /* 1000 */ 197, 347, 1243, 1254, 1244, 1245, 1248, 90, 198, 193, - /* 1010 */ 1243, 349, 192, 1211, 839, 1217, 1188, 114, 1298, 1299, - /* 1020 */ 94, 1303, 1259, 1187, 1186, 215, 1244, 1245, 1248, 347, - /* 1030 */ 1259, 1185, 1243, 1184, 1183, 1182, 1181, 347, 126, 349, - /* 1040 */ 1243, 841, 1180, 1217, 1179, 1178, 1177, 349, 1071, 1210, - /* 1050 */ 1201, 1217, 1259, 214, 1244, 1245, 1248, 1108, 724, 347, - /* 1060 */ 1259, 216, 1244, 1245, 1248, 1018, 1019, 347, 1070, 349, - /* 1070 */ 1068, 132, 275, 1217, 111, 219, 1057, 349, 331, 273, - /* 1080 */ 276, 1217, 131, 213, 1244, 1245, 1248, 274, 1056, 1053, - /* 1090 */ 1110, 203, 1244, 1245, 1248, 67, 133, 284, 822, 92, - /* 1100 */ 821, 283, 820, 1109, 752, 44, 1066, 751, 129, 750, - /* 1110 */ 749, 220, 748, 218, 217, 747, 282, 20, 221, 1061, - /* 1120 */ 222, 296, 285, 1059, 223, 299, 90, 31, 29, 27, - /* 1130 */ 26, 25, 22, 1052, 301, 1051, 115, 1298, 1299, 303, - /* 1140 */ 1303, 65, 31, 29, 27, 26, 25, 910, 1209, 912, - /* 1150 */ 913, 914, 915, 916, 1208, 128, 1200, 148, 14, 125, - /* 1160 */ 45, 36, 3, 153, 150, 32, 37, 158, 985, 108, - /* 1170 */ 34, 1235, 157, 164, 979, 46, 19, 978, 47, 48, - /* 1180 */ 15, 35, 957, 1007, 1006, 956, 8, 1012, 230, 116, - /* 1190 */ 1011, 1010, 16, 10, 896, 231, 13, 921, 172, 18, - /* 1200 */ 171, 983, 174, 354, 176, 49, 1199, 178, 50, 878, - /* 1210 */ 38, 367, 244, 806, 180, 369, 54, 371, 803, 1234, - /* 1220 */ 800, 183, 365, 372, 374, 783, 375, 377, 794, 378, - /* 1230 */ 380, 792, 817, 381, 813, 812, 811, 55, 722, 56, - /* 1240 */ 57, 744, 397, 743, 736, 742, 741, 740, 739, 738, - /* 1250 */ 387, 737, 1067, 735, 798, 734, 733, 797, 732, 731, - /* 1260 */ 796, 795, 730, 729, 728, 727, 417, 418, 1055, 1054, - /* 1270 */ 421, 422, 419, 1050, 816, 425, 426, 1025, 865, 191, - /* 1280 */ 429, 430, + /* 0 */ 1398, 24, 191, 442, 442, 504, 503, 253, 1307, 72, + /* 10 */ 72, 270, 1394, 1401, 252, 307, 349, 355, 233, 1305, + /* 20 */ 1010, 1197, 1155, 442, 1398, 1260, 1260, 319, 1398, 305, + /* 30 */ 331, 31, 29, 27, 26, 25, 1394, 1400, 429, 332, + /* 40 */ 1394, 1400, 234, 84, 1348, 1260, 83, 82, 81, 80, + /* 50 */ 79, 78, 77, 76, 75, 273, 31, 29, 27, 26, + /* 60 */ 25, 429, 1338, 1340, 265, 213, 236, 1347, 1290, 441, + /* 70 */ 496, 495, 494, 493, 492, 491, 490, 489, 207, 486, + /* 80 */ 485, 484, 483, 482, 481, 480, 479, 478, 998, 1026, + /* 90 */ 31, 29, 27, 26, 25, 84, 441, 1056, 83, 82, + /* 100 */ 81, 80, 79, 78, 77, 76, 75, 330, 1154, 442, + /* 110 */ 325, 324, 323, 322, 321, 306, 318, 317, 316, 315, + /* 120 */ 311, 310, 309, 308, 442, 236, 27, 26, 25, 340, + /* 130 */ 312, 1260, 93, 92, 91, 90, 89, 88, 87, 86, + /* 140 */ 85, 1428, 362, 1057, 357, 12, 1260, 361, 426, 1012, + /* 150 */ 160, 442, 358, 356, 1001, 359, 1056, 313, 404, 399, + /* 160 */ 410, 1061, 874, 465, 464, 463, 878, 462, 880, 881, + /* 170 */ 461, 883, 458, 1260, 889, 455, 891, 892, 452, 449, + /* 180 */ 400, 126, 98, 1010, 23, 260, 1051, 1052, 1053, 1054, + /* 190 */ 1055, 1059, 1060, 20, 112, 1412, 300, 1013, 299, 219, + /* 200 */ 385, 266, 1057, 31, 29, 27, 26, 25, 442, 111, + /* 210 */ 111, 217, 405, 401, 339, 96, 1428, 1262, 1263, 292, + /* 220 */ 1061, 136, 1251, 426, 412, 121, 1467, 1468, 1177, 1472, + /* 230 */ 1260, 477, 301, 428, 294, 126, 113, 1385, 1166, 1412, + /* 240 */ 1011, 386, 414, 23, 260, 1051, 1052, 1053, 1054, 1055, + /* 250 */ 1059, 1060, 126, 68, 1413, 1414, 1417, 1460, 30, 28, + /* 260 */ 1428, 235, 1456, 1521, 1385, 442, 262, 426, 990, 468, + /* 270 */ 1385, 1257, 1521, 1521, 1249, 1412, 125, 428, 990, 159, + /* 280 */ 1519, 1385, 67, 352, 988, 125, 125, 1260, 1117, 1519, + /* 290 */ 1519, 1374, 49, 11, 988, 6, 1428, 70, 1413, 1414, + /* 300 */ 1417, 1460, 95, 413, 354, 1459, 1456, 45, 44, 304, + /* 310 */ 1255, 130, 1245, 428, 1200, 1, 298, 1385, 396, 1115, + /* 320 */ 1116, 1118, 1119, 410, 242, 442, 290, 284, 286, 282, + /* 330 */ 127, 439, 441, 69, 1413, 1414, 1417, 1460, 508, 126, + /* 340 */ 326, 255, 1456, 120, 1428, 98, 1247, 1260, 508, 49, + /* 350 */ 989, 426, 126, 442, 1014, 187, 30, 28, 1093, 440, + /* 360 */ 989, 392, 1487, 362, 262, 357, 990, 1256, 361, 30, + /* 370 */ 28, 160, 1412, 358, 356, 1260, 359, 262, 96, 990, + /* 380 */ 1243, 12, 988, 403, 991, 135, 134, 1176, 122, 1467, + /* 390 */ 1468, 11, 1472, 1428, 991, 988, 9, 8, 117, 1238, + /* 400 */ 413, 994, 995, 224, 11, 1039, 114, 272, 1224, 1300, + /* 410 */ 428, 994, 995, 1, 1385, 111, 1412, 31, 29, 27, + /* 420 */ 26, 25, 126, 1262, 65, 1412, 1, 1088, 1152, 1385, + /* 430 */ 69, 1413, 1414, 1417, 1460, 99, 508, 1428, 255, 1456, + /* 440 */ 120, 1307, 1252, 1521, 426, 340, 1428, 267, 989, 508, + /* 450 */ 165, 1307, 1305, 426, 428, 1058, 1520, 274, 1385, 1488, + /* 460 */ 1519, 989, 1305, 428, 186, 1069, 1038, 1385, 1040, 1041, + /* 470 */ 1042, 1043, 1044, 1062, 227, 1413, 1414, 1417, 277, 467, + /* 480 */ 30, 28, 991, 69, 1413, 1414, 1417, 1460, 262, 1412, + /* 490 */ 990, 255, 1456, 1533, 131, 991, 21, 1175, 1236, 994, + /* 500 */ 995, 224, 1494, 1039, 1412, 384, 988, 275, 417, 1521, + /* 510 */ 1428, 1174, 994, 995, 224, 111, 1039, 426, 47, 410, + /* 520 */ 1015, 46, 125, 1262, 1307, 1428, 1519, 428, 1173, 798, + /* 530 */ 1092, 1385, 426, 1412, 1474, 1339, 1147, 7, 799, 1385, + /* 540 */ 798, 98, 428, 1167, 477, 347, 1385, 69, 1413, 1414, + /* 550 */ 1417, 1460, 1471, 1385, 1428, 255, 1456, 1533, 800, 188, + /* 560 */ 508, 426, 230, 1413, 1414, 1417, 1517, 1100, 1225, 1172, + /* 570 */ 1385, 428, 989, 1012, 96, 1385, 442, 1171, 1474, 30, + /* 580 */ 28, 427, 205, 1335, 123, 1467, 1468, 262, 1472, 990, + /* 590 */ 133, 69, 1413, 1414, 1417, 1460, 1470, 1170, 1260, 255, + /* 600 */ 1456, 1533, 1146, 1474, 22, 988, 991, 1412, 1169, 376, + /* 610 */ 1478, 1385, 30, 28, 31, 29, 27, 26, 25, 1385, + /* 620 */ 262, 1469, 990, 994, 995, 224, 442, 1039, 1428, 58, + /* 630 */ 172, 1168, 276, 1165, 1164, 426, 7, 1163, 988, 1385, + /* 640 */ 1521, 1162, 1161, 487, 126, 428, 295, 1253, 1260, 1385, + /* 650 */ 1385, 269, 268, 125, 414, 1479, 1088, 1519, 1160, 508, + /* 660 */ 418, 1003, 30, 28, 511, 225, 1413, 1414, 1417, 7, + /* 670 */ 262, 989, 990, 1385, 421, 1385, 1385, 996, 210, 1385, + /* 680 */ 397, 94, 1307, 1385, 1385, 1521, 1159, 500, 988, 209, + /* 690 */ 1158, 1157, 508, 1306, 9, 8, 152, 416, 125, 150, + /* 700 */ 1385, 1301, 1519, 1091, 989, 991, 1412, 154, 156, 158, + /* 710 */ 153, 155, 157, 66, 1193, 1188, 203, 1186, 104, 1, + /* 720 */ 425, 388, 994, 995, 224, 64, 1039, 1428, 1385, 1149, + /* 730 */ 1150, 443, 1385, 1385, 426, 60, 363, 365, 991, 368, + /* 740 */ 181, 1405, 508, 999, 428, 374, 438, 43, 1385, 175, + /* 750 */ 1114, 997, 177, 1403, 989, 994, 995, 224, 372, 1039, + /* 760 */ 410, 346, 1412, 411, 70, 1413, 1414, 1417, 1460, 1490, + /* 770 */ 1429, 391, 424, 1456, 168, 32, 32, 1004, 1063, 1023, + /* 780 */ 190, 1010, 98, 1428, 2, 279, 283, 419, 991, 974, + /* 790 */ 426, 164, 241, 841, 1007, 995, 32, 243, 966, 957, + /* 800 */ 428, 414, 314, 422, 1385, 994, 995, 224, 211, 1039, + /* 810 */ 1412, 194, 132, 101, 196, 96, 434, 1000, 1337, 320, + /* 820 */ 115, 1413, 1414, 1417, 328, 184, 1467, 409, 1048, 408, + /* 830 */ 333, 1428, 1521, 31, 29, 27, 26, 25, 426, 102, + /* 840 */ 1019, 246, 202, 104, 147, 125, 867, 119, 428, 1519, + /* 850 */ 327, 43, 1385, 345, 862, 146, 329, 447, 415, 1534, + /* 860 */ 895, 334, 102, 159, 1412, 899, 335, 352, 70, 1413, + /* 870 */ 1414, 1417, 1460, 1412, 1018, 336, 139, 1457, 247, 50, + /* 880 */ 245, 244, 144, 351, 103, 1428, 337, 905, 354, 1017, + /* 890 */ 104, 1026, 426, 904, 1428, 102, 338, 142, 105, 48, + /* 900 */ 341, 426, 428, 145, 1016, 348, 1385, 1412, 350, 261, + /* 910 */ 377, 428, 353, 1250, 149, 1385, 74, 1246, 393, 151, + /* 920 */ 106, 107, 229, 1413, 1414, 1417, 1248, 1244, 1428, 108, + /* 930 */ 109, 229, 1413, 1414, 1417, 426, 143, 360, 138, 251, + /* 940 */ 140, 379, 378, 1412, 167, 428, 170, 1015, 389, 1385, + /* 950 */ 398, 1412, 383, 1501, 367, 390, 995, 137, 432, 1500, + /* 960 */ 5, 387, 380, 1481, 1428, 228, 1413, 1414, 1417, 375, + /* 970 */ 407, 426, 1428, 173, 395, 4, 254, 1412, 176, 426, + /* 980 */ 1491, 428, 402, 162, 394, 1385, 370, 1088, 97, 428, + /* 990 */ 1014, 364, 1237, 1385, 161, 33, 259, 406, 1428, 1235, + /* 1000 */ 1475, 115, 1413, 1414, 1417, 426, 1412, 118, 180, 229, + /* 1010 */ 1413, 1414, 1417, 256, 183, 428, 1518, 182, 41, 1385, + /* 1020 */ 423, 40, 263, 420, 189, 1536, 17, 1428, 1442, 1346, + /* 1030 */ 1412, 430, 431, 264, 426, 229, 1413, 1414, 1417, 1345, + /* 1040 */ 1535, 435, 436, 200, 428, 198, 437, 57, 1385, 206, + /* 1050 */ 212, 1428, 59, 473, 1412, 474, 206, 488, 426, 1261, + /* 1060 */ 473, 445, 214, 507, 222, 1413, 1414, 1417, 428, 208, + /* 1070 */ 220, 39, 1385, 216, 475, 1428, 1379, 221, 1412, 218, + /* 1080 */ 1378, 475, 426, 278, 1375, 280, 281, 984, 231, 1413, + /* 1090 */ 1414, 1417, 428, 472, 471, 470, 1385, 469, 985, 1428, + /* 1100 */ 472, 471, 470, 128, 469, 285, 426, 1412, 1373, 287, + /* 1110 */ 288, 289, 223, 1413, 1414, 1417, 428, 1372, 1371, 291, + /* 1120 */ 1385, 293, 1362, 129, 296, 297, 969, 968, 1428, 1356, + /* 1130 */ 1355, 303, 302, 1412, 1354, 426, 232, 1413, 1414, 1417, + /* 1140 */ 1353, 1412, 940, 1330, 1329, 428, 1328, 1327, 1326, 1385, + /* 1150 */ 1325, 1324, 1323, 1322, 1428, 1321, 1320, 1319, 1318, 100, + /* 1160 */ 1317, 426, 1428, 1316, 1315, 1425, 1413, 1414, 1417, 426, + /* 1170 */ 1314, 428, 1313, 1312, 1311, 1385, 1412, 1310, 1309, 428, + /* 1180 */ 1308, 942, 1412, 1385, 1199, 1370, 1364, 1352, 1343, 1239, + /* 1190 */ 811, 1424, 1413, 1414, 1417, 1198, 1196, 1428, 1185, 1423, + /* 1200 */ 1413, 1414, 1417, 1428, 426, 141, 342, 343, 344, 1184, + /* 1210 */ 426, 1412, 1181, 1241, 428, 73, 487, 1412, 1385, 912, + /* 1220 */ 428, 148, 910, 1240, 1385, 1194, 248, 1189, 840, 839, + /* 1230 */ 838, 837, 1428, 249, 239, 1413, 1414, 1417, 1428, 426, + /* 1240 */ 238, 1413, 1414, 1417, 835, 426, 834, 1187, 250, 428, + /* 1250 */ 1180, 371, 369, 1385, 366, 428, 1179, 373, 71, 1385, + /* 1260 */ 1369, 42, 163, 1412, 1363, 381, 976, 110, 382, 240, + /* 1270 */ 1413, 1414, 1417, 1351, 1350, 237, 1413, 1414, 1417, 1342, + /* 1280 */ 169, 166, 14, 1403, 1428, 51, 171, 3, 32, 174, + /* 1290 */ 15, 426, 1113, 116, 34, 54, 36, 37, 185, 124, + /* 1300 */ 178, 428, 1107, 52, 1135, 1385, 1106, 179, 53, 19, + /* 1310 */ 1134, 1085, 35, 10, 1084, 16, 1140, 8, 257, 1139, + /* 1320 */ 1138, 226, 1413, 1414, 1417, 258, 1341, 1024, 13, 433, + /* 1330 */ 1049, 18, 192, 193, 60, 1111, 195, 197, 55, 199, + /* 1340 */ 56, 1005, 1402, 446, 38, 271, 450, 896, 893, 453, + /* 1350 */ 456, 204, 448, 451, 459, 890, 444, 454, 201, 884, + /* 1360 */ 882, 457, 460, 873, 901, 907, 903, 61, 809, 476, + /* 1370 */ 62, 63, 831, 830, 829, 828, 827, 826, 825, 823, + /* 1380 */ 888, 466, 824, 842, 821, 820, 819, 818, 887, 886, + /* 1390 */ 817, 885, 816, 815, 814, 1195, 497, 498, 1183, 1182, + /* 1400 */ 501, 502, 499, 1178, 906, 505, 506, 1153, 992, 215, + /* 1410 */ 509, 510, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 216, 183, 181, 175, 196, 212, 222, 223, 215, 196, - /* 10 */ 192, 218, 12, 13, 14, 15, 16, 195, 200, 231, - /* 20 */ 232, 246, 199, 195, 202, 12, 13, 14, 15, 16, - /* 30 */ 202, 181, 181, 181, 259, 20, 186, 186, 263, 216, - /* 40 */ 212, 175, 221, 193, 216, 222, 223, 47, 0, 221, - /* 50 */ 228, 20, 202, 202, 226, 227, 228, 229, 230, 207, - /* 60 */ 47, 195, 234, 235, 204, 181, 0, 246, 202, 69, - /* 70 */ 186, 211, 212, 187, 246, 184, 185, 77, 212, 212, - /* 80 */ 259, 195, 216, 68, 263, 218, 202, 259, 22, 203, - /* 90 */ 77, 263, 226, 227, 228, 229, 0, 49, 50, 51, - /* 100 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - /* 110 */ 62, 63, 64, 65, 66, 188, 116, 21, 191, 175, - /* 120 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 116, - /* 130 */ 264, 265, 178, 179, 134, 135, 136, 137, 138, 139, - /* 140 */ 140, 141, 142, 143, 14, 15, 16, 134, 135, 136, - /* 150 */ 137, 138, 139, 140, 141, 142, 143, 1, 2, 175, - /* 160 */ 216, 83, 84, 85, 86, 87, 88, 89, 90, 91, - /* 170 */ 92, 93, 20, 95, 96, 97, 98, 99, 100, 195, - /* 180 */ 12, 13, 174, 195, 176, 199, 202, 175, 20, 201, - /* 190 */ 22, 12, 13, 14, 206, 46, 212, 20, 195, 20, - /* 200 */ 216, 22, 216, 175, 20, 202, 38, 0, 222, 223, - /* 210 */ 226, 227, 228, 229, 230, 47, 181, 38, 234, 235, - /* 220 */ 236, 186, 20, 195, 22, 69, 47, 81, 216, 0, - /* 230 */ 202, 228, 248, 12, 13, 172, 68, 202, 254, 255, - /* 240 */ 212, 20, 40, 22, 216, 68, 120, 68, 12, 13, - /* 250 */ 14, 15, 16, 46, 226, 227, 228, 229, 230, 38, - /* 260 */ 92, 3, 234, 235, 236, 144, 145, 175, 47, 181, - /* 270 */ 116, 92, 104, 245, 186, 46, 195, 151, 152, 175, - /* 280 */ 175, 193, 201, 104, 221, 12, 13, 206, 134, 68, - /* 290 */ 202, 123, 124, 125, 126, 22, 128, 143, 146, 195, - /* 300 */ 20, 194, 123, 124, 125, 126, 202, 128, 216, 246, - /* 310 */ 164, 38, 205, 92, 146, 175, 212, 175, 195, 175, - /* 320 */ 216, 216, 259, 146, 201, 104, 263, 63, 0, 206, - /* 330 */ 226, 227, 228, 229, 230, 195, 181, 224, 234, 235, - /* 340 */ 236, 186, 202, 181, 123, 124, 125, 126, 186, 128, - /* 350 */ 22, 175, 212, 12, 13, 242, 216, 202, 216, 255, - /* 360 */ 216, 20, 224, 22, 202, 92, 226, 227, 228, 229, - /* 370 */ 230, 195, 108, 109, 234, 235, 236, 104, 202, 38, - /* 380 */ 242, 12, 13, 14, 14, 245, 175, 79, 212, 20, - /* 390 */ 20, 22, 216, 146, 181, 181, 123, 124, 125, 186, - /* 400 */ 175, 175, 226, 227, 228, 229, 230, 38, 175, 68, - /* 410 */ 234, 235, 236, 4, 187, 202, 202, 20, 12, 13, - /* 420 */ 162, 245, 195, 46, 12, 13, 20, 216, 22, 180, - /* 430 */ 203, 175, 20, 92, 22, 175, 195, 68, 175, 190, - /* 440 */ 187, 216, 216, 229, 38, 104, 197, 206, 195, 216, - /* 450 */ 38, 195, 238, 239, 240, 241, 203, 243, 202, 175, - /* 460 */ 175, 92, 20, 202, 123, 124, 125, 126, 212, 128, - /* 470 */ 209, 175, 216, 104, 68, 20, 216, 221, 195, 216, - /* 480 */ 68, 175, 226, 227, 228, 229, 57, 146, 4, 206, - /* 490 */ 61, 196, 123, 124, 125, 126, 183, 128, 92, 196, - /* 500 */ 216, 216, 246, 19, 92, 175, 175, 0, 175, 175, - /* 510 */ 104, 82, 216, 200, 175, 259, 104, 33, 20, 263, - /* 520 */ 36, 224, 216, 1, 2, 41, 195, 180, 44, 123, - /* 530 */ 124, 125, 126, 202, 128, 123, 124, 125, 126, 242, - /* 540 */ 128, 124, 175, 212, 197, 195, 216, 216, 43, 216, - /* 550 */ 216, 67, 81, 203, 70, 216, 147, 226, 227, 228, - /* 560 */ 229, 230, 195, 181, 57, 234, 235, 21, 61, 202, - /* 570 */ 22, 196, 155, 156, 157, 158, 159, 122, 175, 212, - /* 580 */ 34, 38, 72, 216, 202, 75, 38, 18, 72, 82, - /* 590 */ 176, 75, 23, 226, 227, 228, 229, 230, 195, 257, - /* 600 */ 22, 234, 235, 221, 35, 202, 69, 175, 101, 102, - /* 610 */ 103, 229, 105, 0, 45, 212, 38, 47, 81, 216, - /* 620 */ 122, 239, 240, 241, 0, 243, 175, 195, 246, 226, - /* 630 */ 227, 228, 229, 230, 202, 22, 72, 166, 235, 75, - /* 640 */ 92, 259, 69, 69, 212, 263, 195, 104, 216, 175, - /* 650 */ 145, 219, 104, 202, 81, 81, 170, 171, 226, 227, - /* 660 */ 228, 229, 72, 212, 68, 75, 185, 216, 175, 195, - /* 670 */ 219, 123, 124, 125, 78, 106, 202, 226, 227, 228, - /* 680 */ 229, 57, 38, 205, 69, 61, 212, 69, 195, 266, - /* 690 */ 216, 251, 178, 225, 124, 202, 81, 20, 68, 81, - /* 700 */ 226, 227, 228, 229, 27, 212, 82, 30, 175, 216, - /* 710 */ 80, 69, 69, 175, 244, 146, 39, 260, 69, 226, - /* 720 */ 227, 228, 229, 81, 81, 101, 102, 103, 195, 105, - /* 730 */ 81, 195, 258, 195, 247, 202, 20, 181, 115, 210, - /* 740 */ 202, 69, 116, 208, 181, 212, 20, 208, 104, 216, - /* 750 */ 212, 69, 219, 81, 216, 0, 202, 219, 265, 226, - /* 760 */ 227, 228, 229, 81, 226, 227, 228, 229, 0, 220, - /* 770 */ 183, 21, 20, 69, 24, 25, 26, 27, 28, 29, - /* 780 */ 30, 31, 32, 183, 107, 81, 183, 110, 111, 112, - /* 790 */ 113, 114, 24, 25, 26, 27, 28, 29, 30, 31, - /* 800 */ 32, 19, 175, 181, 49, 213, 51, 175, 183, 54, - /* 810 */ 20, 69, 57, 177, 59, 33, 195, 62, 36, 181, - /* 820 */ 69, 220, 195, 81, 42, 177, 44, 195, 49, 202, - /* 830 */ 51, 202, 81, 54, 202, 69, 57, 175, 59, 212, - /* 840 */ 195, 62, 195, 216, 212, 175, 195, 81, 216, 67, - /* 850 */ 69, 195, 70, 226, 227, 228, 229, 195, 226, 227, - /* 860 */ 228, 229, 81, 69, 202, 195, 12, 13, 14, 15, - /* 870 */ 16, 195, 202, 195, 212, 81, 195, 180, 216, 195, - /* 880 */ 195, 175, 212, 101, 195, 180, 216, 213, 226, 227, - /* 890 */ 228, 229, 20, 225, 154, 256, 226, 227, 228, 229, - /* 900 */ 118, 195, 153, 121, 175, 217, 216, 216, 202, 175, - /* 910 */ 12, 13, 14, 15, 16, 256, 125, 217, 212, 216, - /* 920 */ 161, 160, 216, 69, 195, 149, 253, 252, 148, 195, - /* 930 */ 250, 202, 226, 227, 228, 229, 202, 145, 202, 20, - /* 940 */ 115, 212, 249, 224, 175, 216, 212, 237, 165, 163, - /* 950 */ 216, 68, 175, 169, 267, 226, 227, 228, 229, 181, - /* 960 */ 226, 227, 228, 229, 195, 233, 119, 214, 180, 262, - /* 970 */ 261, 202, 195, 217, 175, 217, 216, 202, 216, 202, - /* 980 */ 202, 212, 180, 216, 213, 216, 191, 202, 68, 212, - /* 990 */ 181, 198, 180, 216, 195, 226, 227, 228, 229, 177, - /* 1000 */ 189, 202, 175, 226, 227, 228, 229, 229, 189, 173, - /* 1010 */ 175, 212, 182, 0, 80, 216, 0, 239, 240, 241, - /* 1020 */ 115, 243, 195, 0, 0, 226, 227, 228, 229, 202, - /* 1030 */ 195, 0, 175, 0, 0, 0, 0, 202, 43, 212, - /* 1040 */ 175, 22, 0, 216, 0, 0, 0, 212, 0, 0, - /* 1050 */ 0, 216, 195, 226, 227, 228, 229, 0, 48, 202, - /* 1060 */ 195, 226, 227, 228, 229, 167, 168, 202, 0, 212, - /* 1070 */ 0, 33, 43, 216, 36, 35, 0, 212, 181, 38, - /* 1080 */ 42, 216, 44, 226, 227, 228, 229, 36, 0, 0, - /* 1090 */ 0, 226, 227, 228, 229, 77, 75, 57, 38, 202, - /* 1100 */ 38, 61, 22, 0, 38, 67, 0, 38, 70, 38, - /* 1110 */ 38, 71, 38, 73, 74, 38, 76, 2, 22, 0, - /* 1120 */ 22, 39, 82, 0, 22, 38, 229, 12, 13, 14, - /* 1130 */ 15, 16, 2, 0, 22, 0, 239, 240, 241, 22, - /* 1140 */ 243, 20, 12, 13, 14, 15, 16, 127, 0, 129, - /* 1150 */ 130, 131, 132, 133, 0, 117, 0, 43, 150, 121, - /* 1160 */ 68, 122, 81, 69, 117, 81, 81, 81, 69, 68, - /* 1170 */ 144, 80, 68, 80, 69, 68, 81, 69, 68, 4, - /* 1180 */ 150, 81, 69, 38, 38, 69, 2, 69, 38, 80, - /* 1190 */ 38, 38, 81, 150, 69, 38, 68, 124, 69, 68, - /* 1200 */ 80, 69, 68, 120, 68, 68, 0, 43, 68, 22, - /* 1210 */ 68, 38, 38, 69, 117, 68, 78, 38, 69, 80, - /* 1220 */ 69, 80, 79, 68, 38, 22, 68, 38, 69, 68, - /* 1230 */ 38, 69, 38, 68, 38, 38, 22, 68, 48, 68, - /* 1240 */ 68, 22, 47, 38, 22, 38, 38, 38, 38, 38, - /* 1250 */ 82, 38, 0, 38, 94, 38, 38, 94, 38, 38, - /* 1260 */ 94, 94, 38, 38, 38, 38, 38, 36, 0, 0, - /* 1270 */ 38, 37, 43, 0, 104, 22, 21, 268, 22, 22, - /* 1280 */ 21, 20, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1290 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1300 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1310 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1320 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1330 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1340 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1350 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1360 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1370 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1380 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1390 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1400 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1410 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1420 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1430 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1440 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 1450 */ 268, 268, 268, 268, + /* 0 */ 246, 267, 268, 210, 210, 207, 208, 229, 225, 216, + /* 10 */ 216, 229, 258, 259, 231, 210, 223, 223, 18, 236, + /* 20 */ 20, 0, 0, 210, 246, 232, 232, 27, 246, 216, + /* 30 */ 30, 12, 13, 14, 15, 16, 258, 259, 242, 39, + /* 40 */ 258, 259, 237, 21, 248, 232, 24, 25, 26, 27, + /* 50 */ 28, 29, 30, 31, 32, 234, 12, 13, 14, 15, + /* 60 */ 16, 242, 241, 242, 245, 218, 47, 248, 221, 20, + /* 70 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + /* 80 */ 59, 60, 61, 62, 63, 64, 65, 66, 38, 70, + /* 90 */ 12, 13, 14, 15, 16, 21, 20, 78, 24, 25, + /* 100 */ 26, 27, 28, 29, 30, 31, 32, 107, 0, 210, + /* 110 */ 110, 111, 112, 113, 114, 216, 116, 117, 118, 119, + /* 120 */ 120, 121, 122, 123, 210, 47, 14, 15, 16, 46, + /* 130 */ 216, 232, 24, 25, 26, 27, 28, 29, 30, 31, + /* 140 */ 32, 225, 49, 124, 51, 69, 232, 54, 232, 20, + /* 150 */ 57, 210, 59, 60, 104, 62, 78, 216, 20, 128, + /* 160 */ 210, 142, 83, 84, 85, 86, 87, 88, 89, 90, + /* 170 */ 91, 92, 93, 232, 95, 96, 97, 98, 99, 100, + /* 180 */ 264, 176, 232, 20, 165, 166, 167, 168, 169, 170, + /* 190 */ 171, 172, 173, 2, 18, 204, 137, 20, 139, 23, + /* 200 */ 210, 217, 124, 12, 13, 14, 15, 16, 210, 225, + /* 210 */ 225, 35, 181, 182, 216, 265, 225, 233, 233, 134, + /* 220 */ 142, 45, 204, 232, 274, 275, 276, 277, 204, 279, + /* 230 */ 232, 46, 251, 242, 149, 176, 203, 246, 205, 204, + /* 240 */ 20, 251, 251, 165, 166, 167, 168, 169, 170, 171, + /* 250 */ 172, 173, 176, 262, 263, 264, 265, 266, 12, 13, + /* 260 */ 225, 270, 271, 282, 246, 210, 20, 232, 22, 80, + /* 270 */ 246, 216, 282, 282, 226, 204, 295, 242, 22, 57, + /* 280 */ 299, 246, 106, 61, 38, 295, 295, 232, 155, 299, + /* 290 */ 299, 0, 212, 47, 38, 43, 225, 262, 263, 264, + /* 300 */ 265, 266, 222, 232, 82, 270, 271, 131, 132, 133, + /* 310 */ 230, 135, 226, 242, 0, 69, 140, 246, 185, 186, + /* 320 */ 187, 188, 189, 210, 148, 210, 150, 36, 152, 153, + /* 330 */ 154, 216, 20, 262, 263, 264, 265, 266, 92, 176, + /* 340 */ 63, 270, 271, 272, 225, 232, 226, 232, 92, 212, + /* 350 */ 104, 232, 176, 210, 20, 284, 12, 13, 14, 216, + /* 360 */ 104, 290, 291, 49, 20, 51, 22, 230, 54, 12, + /* 370 */ 13, 57, 204, 59, 60, 232, 62, 20, 265, 22, + /* 380 */ 226, 69, 38, 264, 138, 108, 109, 204, 275, 276, + /* 390 */ 277, 47, 279, 225, 138, 38, 1, 2, 224, 0, + /* 400 */ 232, 155, 156, 157, 47, 159, 213, 217, 215, 235, + /* 410 */ 242, 155, 156, 69, 246, 225, 204, 12, 13, 14, + /* 420 */ 15, 16, 176, 233, 209, 204, 69, 175, 201, 246, + /* 430 */ 262, 263, 264, 265, 266, 220, 92, 225, 270, 271, + /* 440 */ 272, 225, 227, 282, 232, 46, 225, 231, 104, 92, + /* 450 */ 226, 225, 236, 232, 242, 124, 295, 231, 246, 291, + /* 460 */ 299, 104, 236, 242, 130, 70, 158, 246, 160, 161, + /* 470 */ 162, 163, 164, 142, 262, 263, 264, 265, 251, 226, + /* 480 */ 12, 13, 138, 262, 263, 264, 265, 266, 20, 204, + /* 490 */ 22, 270, 271, 272, 44, 138, 165, 204, 0, 155, + /* 500 */ 156, 157, 281, 159, 204, 254, 38, 217, 3, 282, + /* 510 */ 225, 204, 155, 156, 157, 225, 159, 232, 68, 210, + /* 520 */ 20, 71, 295, 233, 225, 225, 299, 242, 204, 22, + /* 530 */ 4, 246, 232, 204, 260, 236, 131, 69, 20, 246, + /* 540 */ 22, 232, 242, 205, 46, 38, 246, 262, 263, 264, + /* 550 */ 265, 266, 278, 246, 225, 270, 271, 272, 40, 302, + /* 560 */ 92, 232, 262, 263, 264, 265, 281, 14, 215, 204, + /* 570 */ 246, 242, 104, 20, 265, 246, 210, 204, 260, 12, + /* 580 */ 13, 14, 216, 232, 275, 276, 277, 20, 279, 22, + /* 590 */ 239, 262, 263, 264, 265, 266, 278, 204, 232, 270, + /* 600 */ 271, 272, 197, 260, 2, 38, 138, 204, 204, 251, + /* 610 */ 281, 246, 12, 13, 12, 13, 14, 15, 16, 246, + /* 620 */ 20, 278, 22, 155, 156, 157, 210, 159, 225, 209, + /* 630 */ 130, 204, 216, 204, 204, 232, 69, 204, 38, 246, + /* 640 */ 282, 204, 204, 67, 176, 242, 70, 227, 232, 246, + /* 650 */ 246, 12, 13, 295, 251, 174, 175, 299, 204, 92, + /* 660 */ 67, 22, 12, 13, 19, 262, 263, 264, 265, 69, + /* 670 */ 20, 104, 22, 246, 67, 246, 246, 38, 33, 246, + /* 680 */ 293, 36, 225, 246, 246, 282, 204, 42, 38, 44, + /* 690 */ 204, 204, 92, 236, 1, 2, 73, 192, 295, 76, + /* 700 */ 246, 235, 299, 177, 104, 138, 204, 73, 73, 73, + /* 710 */ 76, 76, 76, 68, 0, 0, 71, 0, 67, 69, + /* 720 */ 47, 70, 155, 156, 157, 69, 159, 225, 246, 199, + /* 730 */ 200, 92, 246, 246, 232, 79, 22, 22, 138, 22, + /* 740 */ 287, 69, 92, 104, 242, 21, 101, 67, 246, 67, + /* 750 */ 70, 38, 70, 81, 104, 155, 156, 157, 34, 159, + /* 760 */ 210, 207, 204, 280, 262, 263, 264, 265, 266, 261, + /* 770 */ 225, 126, 270, 271, 129, 67, 67, 138, 70, 70, + /* 780 */ 296, 20, 232, 225, 283, 210, 36, 194, 138, 144, + /* 790 */ 232, 146, 257, 38, 155, 156, 67, 214, 136, 70, + /* 800 */ 242, 251, 210, 196, 246, 155, 156, 157, 252, 159, + /* 810 */ 204, 67, 115, 67, 70, 265, 70, 104, 210, 240, + /* 820 */ 262, 263, 264, 265, 124, 275, 276, 277, 155, 279, + /* 830 */ 210, 225, 282, 12, 13, 14, 15, 16, 232, 67, + /* 840 */ 20, 35, 70, 67, 33, 295, 70, 36, 242, 299, + /* 850 */ 238, 67, 246, 42, 70, 44, 238, 67, 300, 301, + /* 860 */ 70, 256, 67, 57, 204, 70, 242, 61, 262, 263, + /* 870 */ 264, 265, 266, 204, 20, 250, 212, 271, 72, 68, + /* 880 */ 74, 75, 71, 77, 67, 225, 232, 70, 82, 20, + /* 890 */ 67, 70, 232, 70, 225, 67, 243, 212, 70, 212, + /* 900 */ 210, 232, 242, 212, 20, 206, 246, 204, 225, 249, + /* 910 */ 232, 242, 214, 225, 225, 246, 210, 225, 249, 225, + /* 920 */ 225, 225, 262, 263, 264, 265, 225, 225, 225, 225, + /* 930 */ 225, 262, 263, 264, 265, 232, 125, 214, 127, 206, + /* 940 */ 129, 145, 256, 204, 209, 242, 209, 20, 232, 246, + /* 950 */ 184, 204, 242, 292, 4, 243, 156, 146, 183, 292, + /* 960 */ 191, 250, 255, 289, 225, 262, 263, 264, 265, 19, + /* 970 */ 190, 232, 225, 247, 246, 178, 246, 204, 247, 232, + /* 980 */ 261, 242, 246, 33, 179, 246, 36, 175, 232, 242, + /* 990 */ 20, 41, 0, 246, 44, 115, 249, 294, 225, 0, + /* 1000 */ 260, 262, 263, 264, 265, 232, 204, 286, 288, 262, + /* 1010 */ 263, 264, 265, 198, 273, 242, 298, 285, 68, 246, + /* 1020 */ 195, 71, 249, 193, 297, 303, 69, 225, 269, 247, + /* 1030 */ 204, 246, 246, 246, 232, 262, 263, 264, 265, 247, + /* 1040 */ 301, 127, 244, 209, 242, 232, 243, 209, 246, 57, + /* 1050 */ 221, 225, 69, 61, 204, 214, 57, 214, 232, 232, + /* 1060 */ 61, 228, 210, 206, 262, 263, 264, 265, 242, 209, + /* 1070 */ 219, 253, 246, 211, 82, 225, 0, 219, 204, 202, + /* 1080 */ 0, 82, 232, 60, 0, 38, 151, 38, 262, 263, + /* 1090 */ 264, 265, 242, 101, 102, 103, 246, 105, 38, 225, + /* 1100 */ 101, 102, 103, 38, 105, 151, 232, 204, 0, 38, + /* 1110 */ 38, 151, 262, 263, 264, 265, 242, 0, 0, 38, + /* 1120 */ 246, 38, 0, 69, 142, 141, 104, 138, 225, 0, + /* 1130 */ 0, 134, 50, 204, 0, 232, 262, 263, 264, 265, + /* 1140 */ 0, 204, 81, 0, 0, 242, 0, 0, 0, 246, + /* 1150 */ 0, 0, 0, 0, 225, 0, 0, 0, 0, 115, + /* 1160 */ 0, 232, 225, 0, 0, 262, 263, 264, 265, 232, + /* 1170 */ 0, 242, 0, 0, 0, 246, 204, 0, 0, 242, + /* 1180 */ 0, 22, 204, 246, 0, 0, 0, 0, 0, 0, + /* 1190 */ 48, 262, 263, 264, 265, 0, 0, 225, 0, 262, + /* 1200 */ 263, 264, 265, 225, 232, 43, 38, 36, 43, 0, + /* 1210 */ 232, 204, 0, 0, 242, 78, 67, 204, 246, 38, + /* 1220 */ 242, 76, 22, 0, 246, 0, 22, 0, 38, 38, + /* 1230 */ 38, 38, 225, 22, 262, 263, 264, 265, 225, 232, + /* 1240 */ 262, 263, 264, 265, 38, 232, 38, 0, 22, 242, + /* 1250 */ 0, 22, 38, 246, 39, 242, 0, 22, 20, 246, + /* 1260 */ 0, 130, 147, 204, 0, 22, 38, 143, 130, 262, + /* 1270 */ 263, 264, 265, 0, 0, 262, 263, 264, 265, 0, + /* 1280 */ 43, 127, 180, 81, 225, 69, 125, 67, 67, 70, + /* 1290 */ 180, 232, 70, 69, 174, 4, 130, 67, 81, 81, + /* 1300 */ 69, 242, 70, 69, 38, 246, 70, 67, 69, 67, + /* 1310 */ 38, 70, 67, 180, 70, 67, 70, 2, 38, 38, + /* 1320 */ 38, 262, 263, 264, 265, 38, 0, 70, 69, 128, + /* 1330 */ 155, 69, 81, 70, 79, 70, 69, 69, 69, 43, + /* 1340 */ 69, 22, 81, 38, 69, 38, 38, 70, 70, 38, + /* 1350 */ 38, 81, 69, 69, 38, 70, 80, 69, 125, 70, + /* 1360 */ 70, 69, 69, 22, 22, 38, 38, 69, 48, 47, + /* 1370 */ 69, 69, 22, 38, 38, 38, 38, 38, 38, 22, + /* 1380 */ 94, 82, 38, 38, 38, 38, 38, 38, 94, 94, + /* 1390 */ 38, 94, 38, 38, 38, 0, 38, 36, 0, 0, + /* 1400 */ 38, 37, 43, 0, 104, 22, 21, 304, 22, 22, + /* 1410 */ 21, 20, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1420 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1430 */ 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + /* 1440 */ 304, 304, 304, 304, 304, 304, 304, 304, 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, }; -#define YY_SHIFT_COUNT (431) +#define YY_SHIFT_COUNT (511) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1273) +#define YY_SHIFT_MAX (1403) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 569, 168, 179, 221, 221, 221, 221, 341, 221, 221, - /* 10 */ 406, 412, 177, 369, 406, 406, 406, 406, 406, 406, - /* 20 */ 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, - /* 30 */ 406, 406, 406, 15, 15, 15, 152, 273, 273, 31, - /* 40 */ 31, 273, 31, 31, 149, 184, 280, 280, 247, 397, - /* 50 */ 184, 31, 31, 184, 31, 184, 397, 184, 184, 31, - /* 60 */ 377, 0, 13, 13, 677, 750, 1040, 548, 548, 548, - /* 70 */ 548, 548, 548, 548, 548, 548, 548, 548, 548, 548, - /* 80 */ 548, 548, 548, 548, 548, 548, 548, 779, 202, 207, - /* 90 */ 455, 455, 455, 229, 442, 397, 184, 184, 184, 308, - /* 100 */ 78, 78, 78, 78, 78, 96, 755, 898, 417, 429, - /* 110 */ 126, 578, 498, 121, 505, 121, 370, 258, 409, 716, - /* 120 */ 623, 626, 626, 716, 726, 149, 442, 752, 149, 149, - /* 130 */ 716, 149, 790, 184, 184, 184, 184, 184, 184, 184, - /* 140 */ 184, 184, 184, 184, 716, 790, 726, 377, 442, 752, - /* 150 */ 377, 872, 740, 749, 791, 740, 749, 791, 791, 759, - /* 160 */ 761, 776, 780, 792, 442, 919, 825, 784, 783, 786, - /* 170 */ 883, 184, 749, 791, 791, 749, 791, 847, 442, 752, - /* 180 */ 377, 308, 377, 442, 920, 716, 377, 790, 1282, 1282, - /* 190 */ 1282, 1282, 48, 768, 782, 1038, 484, 507, 624, 1115, - /* 200 */ 1130, 1020, 854, 236, 236, 236, 236, 236, 236, 236, - /* 210 */ 264, 156, 154, 130, 130, 130, 130, 510, 516, 564, - /* 220 */ 590, 66, 328, 613, 546, 537, 573, 574, 522, 486, - /* 230 */ 146, 471, 615, 570, 618, 630, 642, 643, 649, 672, - /* 240 */ 682, 543, 644, 704, 742, 751, 766, 781, 794, 596, - /* 250 */ 1013, 934, 1016, 1023, 905, 1024, 1031, 1033, 1034, 1035, - /* 260 */ 1036, 1019, 1042, 1044, 1045, 1046, 1048, 1049, 1050, 995, - /* 270 */ 1057, 1010, 1068, 1070, 1041, 1051, 1029, 1076, 1088, 1089, - /* 280 */ 1090, 1018, 1021, 1060, 1062, 1080, 1103, 1066, 1069, 1071, - /* 290 */ 1072, 1074, 1077, 1106, 1096, 1119, 1098, 1082, 1123, 1102, - /* 300 */ 1087, 1133, 1112, 1135, 1117, 1121, 1148, 1154, 1039, 1156, - /* 310 */ 1092, 1114, 1047, 1081, 1084, 1008, 1094, 1085, 1099, 1101, - /* 320 */ 1104, 1105, 1107, 1108, 1086, 1091, 1110, 1095, 1030, 1113, - /* 330 */ 1116, 1093, 1026, 1100, 1109, 1118, 1111, 1043, 1175, 1145, - /* 340 */ 1146, 1150, 1152, 1153, 1157, 1184, 1073, 1120, 1125, 1128, - /* 350 */ 1131, 1129, 1132, 1134, 1136, 1083, 1137, 1206, 1164, 1097, - /* 360 */ 1140, 1138, 1139, 1141, 1187, 1142, 1143, 1144, 1173, 1174, - /* 370 */ 1147, 1149, 1179, 1155, 1151, 1186, 1158, 1159, 1189, 1161, - /* 380 */ 1162, 1192, 1165, 1160, 1163, 1166, 1167, 1203, 1168, 1169, - /* 390 */ 1194, 1170, 1171, 1172, 1196, 1197, 1214, 1190, 1195, 1219, - /* 400 */ 1205, 1207, 1208, 1209, 1210, 1211, 1213, 1222, 1215, 1217, - /* 410 */ 1218, 1220, 1221, 1224, 1225, 1226, 1227, 1252, 1228, 1231, - /* 420 */ 1229, 1268, 1232, 1234, 1269, 1273, 1253, 1255, 1256, 1257, - /* 430 */ 1259, 1261, + /* 0 */ 176, 246, 344, 357, 357, 357, 357, 468, 357, 357, + /* 10 */ 600, 650, 76, 567, 600, 600, 600, 600, 600, 600, + /* 20 */ 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, + /* 30 */ 600, 600, 600, 312, 312, 312, 163, 639, 639, 59, + /* 40 */ 49, 49, 5, 639, 49, 49, 49, 49, 49, 49, + /* 50 */ 83, 129, 138, 138, 5, 177, 129, 49, 49, 129, + /* 60 */ 49, 129, 177, 129, 129, 49, 185, 0, 19, 78, + /* 70 */ 78, 74, 806, 256, 93, 256, 256, 256, 256, 256, + /* 80 */ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, + /* 90 */ 256, 256, 256, 256, 518, 399, 334, 334, 334, 498, + /* 100 */ 220, 177, 129, 129, 129, 189, 79, 79, 79, 79, + /* 110 */ 79, 79, 645, 22, 314, 405, 133, 222, 31, 507, + /* 120 */ 500, 481, 252, 481, 553, 505, 526, 761, 750, 755, + /* 130 */ 662, 761, 761, 697, 700, 700, 761, 820, 177, 854, + /* 140 */ 83, 220, 869, 83, 83, 761, 83, 884, 129, 129, + /* 150 */ 129, 129, 129, 129, 129, 129, 129, 129, 129, 755, + /* 160 */ 755, 761, 884, 220, 820, 796, 177, 854, 185, 220, + /* 170 */ 869, 185, 927, 766, 775, 800, 766, 775, 800, 800, + /* 180 */ 769, 780, 805, 797, 812, 220, 970, 880, 815, 825, + /* 190 */ 830, 957, 129, 775, 800, 800, 775, 800, 914, 220, + /* 200 */ 869, 185, 189, 185, 220, 983, 755, 755, 761, 185, + /* 210 */ 884, 1412, 1412, 1412, 1412, 1412, 21, 811, 108, 950, + /* 220 */ 992, 999, 191, 602, 308, 821, 44, 44, 44, 44, + /* 230 */ 44, 44, 44, 450, 277, 395, 331, 112, 112, 112, + /* 240 */ 112, 291, 85, 576, 623, 634, 635, 636, 714, 715, + /* 250 */ 717, 724, 651, 680, 682, 693, 530, 593, 607, 708, + /* 260 */ 673, 709, 672, 729, 744, 746, 772, 776, 50, 713, + /* 270 */ 784, 790, 795, 817, 823, 828, 656, 1076, 1080, 1023, + /* 280 */ 1084, 1047, 935, 1049, 1060, 1065, 954, 1108, 1071, 1072, + /* 290 */ 960, 1117, 1081, 1118, 1083, 1122, 1054, 982, 984, 1022, + /* 300 */ 989, 1129, 1130, 1082, 997, 1134, 1140, 1061, 1143, 1144, + /* 310 */ 1146, 1147, 1148, 1150, 1151, 1152, 1153, 1155, 1156, 1157, + /* 320 */ 1158, 1044, 1160, 1163, 1164, 1170, 1172, 1173, 1159, 1174, + /* 330 */ 1177, 1178, 1180, 1184, 1185, 1186, 1187, 1188, 1162, 1189, + /* 340 */ 1142, 1195, 1196, 1168, 1171, 1165, 1198, 1209, 1212, 1213, + /* 350 */ 1137, 1145, 1181, 1149, 1200, 1223, 1190, 1191, 1192, 1193, + /* 360 */ 1149, 1206, 1208, 1225, 1204, 1227, 1211, 1215, 1247, 1226, + /* 370 */ 1214, 1250, 1229, 1256, 1235, 1238, 1260, 1131, 1115, 1228, + /* 380 */ 1264, 1124, 1243, 1138, 1154, 1273, 1274, 1166, 1279, 1216, + /* 390 */ 1237, 1161, 1220, 1221, 1102, 1219, 1230, 1222, 1224, 1231, + /* 400 */ 1232, 1234, 1236, 1240, 1202, 1239, 1242, 1110, 1241, 1244, + /* 410 */ 1217, 1120, 1245, 1218, 1246, 1248, 1133, 1291, 1266, 1272, + /* 420 */ 1280, 1281, 1282, 1287, 1315, 1175, 1251, 1257, 1259, 1262, + /* 430 */ 1263, 1265, 1267, 1268, 1201, 1269, 1326, 1296, 1233, 1271, + /* 440 */ 1255, 1261, 1270, 1319, 1275, 1276, 1277, 1305, 1307, 1283, + /* 450 */ 1278, 1308, 1284, 1285, 1311, 1288, 1289, 1312, 1292, 1290, + /* 460 */ 1316, 1293, 1286, 1294, 1295, 1297, 1341, 1299, 1298, 1327, + /* 470 */ 1300, 1301, 1302, 1328, 1149, 1342, 1320, 1322, 1350, 1335, + /* 480 */ 1336, 1337, 1338, 1339, 1340, 1344, 1357, 1345, 1149, 1346, + /* 490 */ 1347, 1348, 1349, 1352, 1354, 1355, 1356, 1395, 1358, 1361, + /* 500 */ 1359, 1398, 1362, 1364, 1399, 1403, 1383, 1385, 1386, 1387, + /* 510 */ 1389, 1391, }; -#define YY_REDUCE_COUNT (191) -#define YY_REDUCE_MIN (-225) -#define YY_REDUCE_MAX (897) +#define YY_REDUCE_COUNT (215) +#define YY_REDUCE_MIN (-266) +#define YY_REDUCE_MAX (1059) static const short yy_reduce_ofst[] = { - /* 0 */ 63, -172, -16, 104, 28, 140, 176, 256, 331, 367, - /* 10 */ -134, 403, 382, 432, 451, 474, 493, 533, 538, 627, - /* 20 */ 632, 662, 670, 706, 729, 734, 769, 777, 799, 827, - /* 30 */ 835, 857, 865, 214, 778, 897, -179, -177, -14, -150, - /* 40 */ 88, -216, -149, -116, -182, -12, -178, 3, -225, -207, - /* 50 */ -114, 35, 155, 81, 162, 227, -140, 123, 253, 213, - /* 60 */ 249, -212, -212, -212, -148, 8, 107, -56, 12, 92, - /* 70 */ 105, 142, 144, 211, 225, 226, 233, 260, 263, 284, - /* 80 */ 285, 296, 306, 330, 333, 334, 339, -109, -46, 313, - /* 90 */ 113, 138, 297, 347, 261, -133, 350, 241, 283, -73, - /* 100 */ -192, -187, 295, 303, 375, 414, 481, 423, 342, 478, - /* 110 */ 440, 514, 468, 470, 470, 470, 536, 457, 487, 556, - /* 120 */ 529, 535, 539, 563, 549, 587, 554, 592, 600, 603, - /* 130 */ 622, 625, 636, 621, 645, 647, 651, 656, 676, 678, - /* 140 */ 681, 684, 685, 689, 638, 648, 601, 697, 629, 674, - /* 150 */ 705, 668, 639, 688, 690, 659, 700, 691, 703, 673, - /* 160 */ 675, 680, 693, 470, 736, 719, 710, 687, 707, 709, - /* 170 */ 732, 536, 756, 760, 762, 758, 767, 753, 775, 771, - /* 180 */ 788, 795, 802, 785, 793, 809, 812, 822, 811, 819, - /* 190 */ 830, 836, + /* 0 */ 227, -9, 71, 168, 221, 285, 329, 403, 35, 502, + /* 10 */ 558, 606, 550, 660, 669, 703, 739, 747, 773, 212, + /* 20 */ 300, 802, 826, 850, 874, 903, 929, 937, 972, 978, + /* 30 */ 1007, 1013, 1059, -50, 113, 309, -10, -222, -218, -19, + /* 40 */ -207, -206, 358, -246, -187, -101, -86, -59, -2, 55, + /* 50 */ 80, -217, -84, 119, 161, -181, -16, 115, 143, 216, + /* 60 */ 366, 190, -179, 226, 290, 416, 215, -195, -266, -266, + /* 70 */ -266, 33, 174, 18, 193, 24, 183, 293, 307, 324, + /* 80 */ 365, 373, 393, 404, 427, 429, 430, 433, 437, 438, + /* 90 */ 454, 482, 486, 487, -202, 137, 274, 318, 343, 420, + /* 100 */ 351, -204, -15, 299, 457, -153, 48, 86, 120, 154, + /* 110 */ 224, 253, 251, 338, 353, 257, 387, 466, 453, 554, + /* 120 */ 508, 483, 483, 483, 545, 484, 501, 575, 535, 583, + /* 130 */ 556, 592, 608, 579, 612, 618, 620, 605, 624, 625, + /* 140 */ 664, 654, 653, 685, 687, 690, 691, 699, 683, 688, + /* 150 */ 689, 692, 694, 695, 696, 701, 702, 704, 705, 698, + /* 160 */ 723, 706, 733, 678, 686, 707, 710, 711, 735, 716, + /* 170 */ 712, 737, 719, 661, 726, 728, 667, 731, 730, 736, + /* 180 */ 674, 720, 721, 732, 483, 756, 740, 741, 722, 718, + /* 190 */ 727, 759, 545, 782, 785, 786, 792, 787, 798, 813, + /* 200 */ 803, 834, 829, 838, 827, 833, 841, 843, 852, 860, + /* 210 */ 857, 818, 851, 858, 862, 877, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 10 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 20 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 30 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 40 */ 1023, 1023, 1023, 1023, 1076, 1023, 1023, 1023, 1023, 1023, - /* 50 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 60 */ 1074, 1023, 1293, 1023, 1189, 1023, 1023, 1023, 1023, 1023, - /* 70 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 80 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1076, - /* 90 */ 1304, 1304, 1304, 1074, 1023, 1023, 1023, 1023, 1023, 1158, - /* 100 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1368, 1023, 1111, - /* 110 */ 1328, 1023, 1320, 1296, 1310, 1297, 1023, 1353, 1313, 1023, - /* 120 */ 1194, 1191, 1191, 1023, 1023, 1076, 1023, 1023, 1076, 1076, - /* 130 */ 1023, 1076, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 140 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1074, 1023, 1023, - /* 150 */ 1074, 1023, 1335, 1333, 1023, 1335, 1333, 1023, 1023, 1347, - /* 160 */ 1343, 1326, 1324, 1310, 1023, 1023, 1023, 1371, 1359, 1355, - /* 170 */ 1023, 1023, 1333, 1023, 1023, 1333, 1023, 1202, 1023, 1023, - /* 180 */ 1074, 1023, 1074, 1023, 1127, 1023, 1074, 1023, 1161, 1161, - /* 190 */ 1077, 1028, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 200 */ 1023, 1023, 1023, 1258, 1346, 1345, 1257, 1270, 1269, 1268, - /* 210 */ 1023, 1023, 1023, 1252, 1253, 1251, 1250, 1023, 1023, 1023, - /* 220 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1294, 1023, - /* 230 */ 1356, 1360, 1023, 1023, 1023, 1236, 1023, 1023, 1023, 1023, - /* 240 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 250 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 260 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 270 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 280 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 290 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 300 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 310 */ 1023, 1023, 1023, 1317, 1327, 1023, 1023, 1023, 1023, 1023, - /* 320 */ 1023, 1023, 1023, 1023, 1023, 1236, 1023, 1344, 1023, 1303, - /* 330 */ 1299, 1023, 1023, 1295, 1023, 1023, 1354, 1023, 1023, 1023, - /* 340 */ 1023, 1023, 1023, 1023, 1023, 1289, 1023, 1023, 1023, 1023, - /* 350 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 360 */ 1023, 1023, 1235, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 370 */ 1155, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 380 */ 1023, 1023, 1023, 1140, 1138, 1137, 1136, 1023, 1133, 1023, - /* 390 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 400 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 410 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 420 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - /* 430 */ 1023, 1023, + /* 0 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 10 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 20 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 30 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 40 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 50 */ 1204, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 60 */ 1151, 1151, 1151, 1151, 1151, 1151, 1202, 1331, 1151, 1462, + /* 70 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 80 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 90 */ 1151, 1151, 1151, 1151, 1151, 1204, 1473, 1473, 1473, 1202, + /* 100 */ 1151, 1151, 1151, 1151, 1151, 1289, 1151, 1151, 1151, 1151, + /* 110 */ 1151, 1151, 1365, 1151, 1151, 1537, 1151, 1242, 1497, 1151, + /* 120 */ 1489, 1465, 1479, 1466, 1151, 1522, 1482, 1151, 1151, 1151, + /* 130 */ 1357, 1151, 1151, 1336, 1333, 1333, 1151, 1151, 1151, 1151, + /* 140 */ 1204, 1151, 1151, 1204, 1204, 1151, 1204, 1151, 1151, 1151, + /* 150 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 160 */ 1151, 1151, 1151, 1151, 1151, 1367, 1151, 1151, 1202, 1151, + /* 170 */ 1151, 1202, 1151, 1504, 1502, 1151, 1504, 1502, 1151, 1151, + /* 180 */ 1516, 1512, 1495, 1493, 1479, 1151, 1151, 1151, 1540, 1528, + /* 190 */ 1524, 1151, 1151, 1502, 1151, 1151, 1502, 1151, 1344, 1151, + /* 200 */ 1151, 1202, 1151, 1202, 1151, 1258, 1151, 1151, 1151, 1202, + /* 210 */ 1151, 1359, 1292, 1292, 1205, 1156, 1151, 1151, 1151, 1151, + /* 220 */ 1151, 1151, 1151, 1151, 1151, 1151, 1427, 1515, 1514, 1426, + /* 230 */ 1439, 1438, 1437, 1151, 1151, 1151, 1151, 1421, 1422, 1420, + /* 240 */ 1419, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 250 */ 1151, 1151, 1151, 1151, 1151, 1463, 1151, 1525, 1529, 1151, + /* 260 */ 1151, 1151, 1404, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 270 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 280 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 290 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 300 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 310 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 320 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 330 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 340 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 350 */ 1151, 1151, 1151, 1303, 1151, 1151, 1151, 1151, 1151, 1151, + /* 360 */ 1228, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 370 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 380 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 390 */ 1151, 1151, 1486, 1496, 1151, 1151, 1151, 1151, 1151, 1151, + /* 400 */ 1151, 1151, 1151, 1151, 1404, 1151, 1513, 1151, 1472, 1468, + /* 410 */ 1151, 1151, 1464, 1151, 1151, 1523, 1151, 1151, 1151, 1151, + /* 420 */ 1151, 1151, 1151, 1151, 1458, 1151, 1151, 1151, 1151, 1151, + /* 430 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 440 */ 1151, 1403, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1286, + /* 450 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 460 */ 1151, 1151, 1271, 1269, 1268, 1267, 1151, 1264, 1151, 1151, + /* 470 */ 1151, 1151, 1151, 1151, 1294, 1151, 1151, 1151, 1151, 1151, + /* 480 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1214, 1151, + /* 490 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 500 */ 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, 1151, + /* 510 */ 1151, 1151, }; /********** End of lemon-generated parsing tables *****************************/ @@ -781,21 +828,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", @@ -830,158 +877,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 */ "NK_BOOL", - /* 124 */ "NULL", - /* 125 */ "NK_VARIABLE", - /* 126 */ "NK_UNDERLINE", - /* 127 */ "ROWTS", - /* 128 */ "TBNAME", - /* 129 */ "QSTARTTS", - /* 130 */ "QENDTS", - /* 131 */ "WSTARTTS", - /* 132 */ "WENDTS", - /* 133 */ "WDURATION", - /* 134 */ "BETWEEN", - /* 135 */ "IS", - /* 136 */ "NK_LT", - /* 137 */ "NK_GT", - /* 138 */ "NK_LE", - /* 139 */ "NK_GE", - /* 140 */ "NK_NE", - /* 141 */ "MATCH", - /* 142 */ "NMATCH", - /* 143 */ "IN", - /* 144 */ "JOIN", - /* 145 */ "INNER", - /* 146 */ "SELECT", - /* 147 */ "DISTINCT", - /* 148 */ "WHERE", - /* 149 */ "PARTITION", - /* 150 */ "BY", - /* 151 */ "SESSION", - /* 152 */ "STATE_WINDOW", - /* 153 */ "SLIDING", - /* 154 */ "FILL", - /* 155 */ "VALUE", - /* 156 */ "NONE", - /* 157 */ "PREV", - /* 158 */ "LINEAR", - /* 159 */ "NEXT", - /* 160 */ "GROUP", - /* 161 */ "HAVING", - /* 162 */ "ORDER", - /* 163 */ "SLIMIT", - /* 164 */ "SOFFSET", - /* 165 */ "LIMIT", - /* 166 */ "OFFSET", - /* 167 */ "ASC", - /* 168 */ "DESC", - /* 169 */ "NULLS", - /* 170 */ "FIRST", - /* 171 */ "LAST", - /* 172 */ "cmd", - /* 173 */ "account_options", - /* 174 */ "alter_account_options", - /* 175 */ "literal", - /* 176 */ "alter_account_option", - /* 177 */ "user_name", - /* 178 */ "dnode_endpoint", - /* 179 */ "dnode_host_name", - /* 180 */ "not_exists_opt", - /* 181 */ "db_name", - /* 182 */ "db_options", - /* 183 */ "exists_opt", - /* 184 */ "alter_db_options", - /* 185 */ "alter_db_option", - /* 186 */ "full_table_name", - /* 187 */ "column_def_list", - /* 188 */ "tags_def_opt", - /* 189 */ "table_options", - /* 190 */ "multi_create_clause", - /* 191 */ "tags_def", - /* 192 */ "multi_drop_clause", - /* 193 */ "alter_table_clause", - /* 194 */ "alter_table_options", - /* 195 */ "column_name", - /* 196 */ "type_name", - /* 197 */ "create_subtable_clause", - /* 198 */ "specific_tags_opt", - /* 199 */ "literal_list", - /* 200 */ "drop_table_clause", - /* 201 */ "col_name_list", - /* 202 */ "table_name", - /* 203 */ "column_def", - /* 204 */ "func_name_list", - /* 205 */ "alter_table_option", - /* 206 */ "col_name", - /* 207 */ "db_name_cond_opt", - /* 208 */ "like_pattern_opt", - /* 209 */ "table_name_cond", - /* 210 */ "from_db_opt", - /* 211 */ "func_name", - /* 212 */ "function_name", - /* 213 */ "index_name", - /* 214 */ "index_options", - /* 215 */ "func_list", - /* 216 */ "duration_literal", - /* 217 */ "sliding_opt", - /* 218 */ "func", - /* 219 */ "expression_list", - /* 220 */ "topic_name", - /* 221 */ "query_expression", - /* 222 */ "signed", - /* 223 */ "signed_literal", - /* 224 */ "table_alias", - /* 225 */ "column_alias", - /* 226 */ "expression", - /* 227 */ "pseudo_column", - /* 228 */ "column_reference", - /* 229 */ "subquery", - /* 230 */ "predicate", - /* 231 */ "compare_op", - /* 232 */ "in_op", - /* 233 */ "in_predicate_value", - /* 234 */ "boolean_value_expression", - /* 235 */ "boolean_primary", - /* 236 */ "common_expression", - /* 237 */ "from_clause", - /* 238 */ "table_reference_list", - /* 239 */ "table_reference", - /* 240 */ "table_primary", - /* 241 */ "joined_table", - /* 242 */ "alias_opt", - /* 243 */ "parenthesized_joined_table", - /* 244 */ "join_type", - /* 245 */ "search_condition", - /* 246 */ "query_specification", - /* 247 */ "set_quantifier_opt", - /* 248 */ "select_list", - /* 249 */ "where_clause_opt", - /* 250 */ "partition_by_clause_opt", - /* 251 */ "twindow_clause_opt", - /* 252 */ "group_by_clause_opt", - /* 253 */ "having_clause_opt", - /* 254 */ "select_sublist", - /* 255 */ "select_item", - /* 256 */ "fill_opt", - /* 257 */ "fill_mode", - /* 258 */ "group_by_list", - /* 259 */ "query_expression_body", - /* 260 */ "order_by_clause_opt", - /* 261 */ "slimit_clause_opt", - /* 262 */ "limit_clause_opt", - /* 263 */ "query_primary", - /* 264 */ "sort_specification_list", - /* 265 */ "sort_specification", - /* 266 */ "ordering_specification_opt", - /* 267 */ "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 */ "NK_UNDERLINE", + /* 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) */ @@ -1049,7 +1132,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", @@ -1063,280 +1146,321 @@ 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 ::= query_expression", - /* 186 */ "literal ::= NK_INTEGER", - /* 187 */ "literal ::= NK_FLOAT", - /* 188 */ "literal ::= NK_STRING", - /* 189 */ "literal ::= NK_BOOL", - /* 190 */ "literal ::= TIMESTAMP NK_STRING", - /* 191 */ "literal ::= duration_literal", - /* 192 */ "literal ::= NULL", - /* 193 */ "duration_literal ::= NK_VARIABLE", - /* 194 */ "signed ::= NK_INTEGER", - /* 195 */ "signed ::= NK_PLUS NK_INTEGER", - /* 196 */ "signed ::= NK_MINUS NK_INTEGER", - /* 197 */ "signed ::= NK_FLOAT", - /* 198 */ "signed ::= NK_PLUS NK_FLOAT", - /* 199 */ "signed ::= NK_MINUS NK_FLOAT", - /* 200 */ "signed_literal ::= signed", - /* 201 */ "signed_literal ::= NK_STRING", - /* 202 */ "signed_literal ::= NK_BOOL", - /* 203 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 204 */ "signed_literal ::= duration_literal", - /* 205 */ "signed_literal ::= NULL", - /* 206 */ "literal_list ::= signed_literal", - /* 207 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 208 */ "db_name ::= NK_ID", - /* 209 */ "table_name ::= NK_ID", - /* 210 */ "column_name ::= NK_ID", - /* 211 */ "function_name ::= NK_ID", - /* 212 */ "table_alias ::= NK_ID", - /* 213 */ "column_alias ::= NK_ID", - /* 214 */ "user_name ::= NK_ID", - /* 215 */ "index_name ::= NK_ID", - /* 216 */ "topic_name ::= NK_ID", - /* 217 */ "expression ::= literal", - /* 218 */ "expression ::= pseudo_column", - /* 219 */ "expression ::= column_reference", - /* 220 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 221 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 222 */ "expression ::= subquery", - /* 223 */ "expression ::= NK_LP expression NK_RP", - /* 224 */ "expression ::= NK_PLUS expression", - /* 225 */ "expression ::= NK_MINUS expression", - /* 226 */ "expression ::= expression NK_PLUS expression", - /* 227 */ "expression ::= expression NK_MINUS expression", - /* 228 */ "expression ::= expression NK_STAR expression", - /* 229 */ "expression ::= expression NK_SLASH expression", - /* 230 */ "expression ::= expression NK_REM expression", - /* 231 */ "expression_list ::= expression", - /* 232 */ "expression_list ::= expression_list NK_COMMA expression", - /* 233 */ "column_reference ::= column_name", - /* 234 */ "column_reference ::= table_name NK_DOT column_name", - /* 235 */ "pseudo_column ::= NK_UNDERLINE ROWTS", - /* 236 */ "pseudo_column ::= TBNAME", - /* 237 */ "pseudo_column ::= NK_UNDERLINE QSTARTTS", - /* 238 */ "pseudo_column ::= NK_UNDERLINE QENDTS", - /* 239 */ "pseudo_column ::= NK_UNDERLINE WSTARTTS", - /* 240 */ "pseudo_column ::= NK_UNDERLINE WENDTS", - /* 241 */ "pseudo_column ::= NK_UNDERLINE WDURATION", - /* 242 */ "predicate ::= expression compare_op expression", - /* 243 */ "predicate ::= expression BETWEEN expression AND expression", - /* 244 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 245 */ "predicate ::= expression IS NULL", - /* 246 */ "predicate ::= expression IS NOT NULL", - /* 247 */ "predicate ::= expression in_op in_predicate_value", - /* 248 */ "compare_op ::= NK_LT", - /* 249 */ "compare_op ::= NK_GT", - /* 250 */ "compare_op ::= NK_LE", - /* 251 */ "compare_op ::= NK_GE", - /* 252 */ "compare_op ::= NK_NE", - /* 253 */ "compare_op ::= NK_EQ", - /* 254 */ "compare_op ::= LIKE", - /* 255 */ "compare_op ::= NOT LIKE", - /* 256 */ "compare_op ::= MATCH", - /* 257 */ "compare_op ::= NMATCH", - /* 258 */ "in_op ::= IN", - /* 259 */ "in_op ::= NOT IN", - /* 260 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 261 */ "boolean_value_expression ::= boolean_primary", - /* 262 */ "boolean_value_expression ::= NOT boolean_primary", - /* 263 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 264 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 265 */ "boolean_primary ::= predicate", - /* 266 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 267 */ "common_expression ::= expression", - /* 268 */ "common_expression ::= boolean_value_expression", - /* 269 */ "from_clause ::= FROM table_reference_list", - /* 270 */ "table_reference_list ::= table_reference", - /* 271 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 272 */ "table_reference ::= table_primary", - /* 273 */ "table_reference ::= joined_table", - /* 274 */ "table_primary ::= table_name alias_opt", - /* 275 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 276 */ "table_primary ::= subquery alias_opt", - /* 277 */ "table_primary ::= parenthesized_joined_table", - /* 278 */ "alias_opt ::=", - /* 279 */ "alias_opt ::= table_alias", - /* 280 */ "alias_opt ::= AS table_alias", - /* 281 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 282 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 283 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 284 */ "join_type ::=", - /* 285 */ "join_type ::= INNER", - /* 286 */ "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", - /* 287 */ "set_quantifier_opt ::=", - /* 288 */ "set_quantifier_opt ::= DISTINCT", - /* 289 */ "set_quantifier_opt ::= ALL", - /* 290 */ "select_list ::= NK_STAR", - /* 291 */ "select_list ::= select_sublist", - /* 292 */ "select_sublist ::= select_item", - /* 293 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 294 */ "select_item ::= common_expression", - /* 295 */ "select_item ::= common_expression column_alias", - /* 296 */ "select_item ::= common_expression AS column_alias", - /* 297 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 298 */ "where_clause_opt ::=", - /* 299 */ "where_clause_opt ::= WHERE search_condition", - /* 300 */ "partition_by_clause_opt ::=", - /* 301 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 302 */ "twindow_clause_opt ::=", - /* 303 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 304 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 305 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 306 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 307 */ "sliding_opt ::=", - /* 308 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 309 */ "fill_opt ::=", - /* 310 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 311 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 312 */ "fill_mode ::= NONE", - /* 313 */ "fill_mode ::= PREV", - /* 314 */ "fill_mode ::= NULL", - /* 315 */ "fill_mode ::= LINEAR", - /* 316 */ "fill_mode ::= NEXT", - /* 317 */ "group_by_clause_opt ::=", - /* 318 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 319 */ "group_by_list ::= expression", - /* 320 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 321 */ "having_clause_opt ::=", - /* 322 */ "having_clause_opt ::= HAVING search_condition", - /* 323 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 324 */ "query_expression_body ::= query_primary", - /* 325 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 326 */ "query_primary ::= query_specification", - /* 327 */ "order_by_clause_opt ::=", - /* 328 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 329 */ "slimit_clause_opt ::=", - /* 330 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 331 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 332 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 333 */ "limit_clause_opt ::=", - /* 334 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 335 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 336 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 337 */ "subquery ::= NK_LP query_expression NK_RP", - /* 338 */ "search_condition ::= common_expression", - /* 339 */ "sort_specification_list ::= sort_specification", - /* 340 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 341 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 342 */ "ordering_specification_opt ::=", - /* 343 */ "ordering_specification_opt ::= ASC", - /* 344 */ "ordering_specification_opt ::= DESC", - /* 345 */ "null_ordering_opt ::=", - /* 346 */ "null_ordering_opt ::= NULLS FIRST", - /* 347 */ "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 ::= NK_UNDERLINE ROWTS", + /* 277 */ "pseudo_column ::= TBNAME", + /* 278 */ "pseudo_column ::= NK_UNDERLINE QSTARTTS", + /* 279 */ "pseudo_column ::= NK_UNDERLINE QENDTS", + /* 280 */ "pseudo_column ::= NK_UNDERLINE WSTARTTS", + /* 281 */ "pseudo_column ::= NK_UNDERLINE WENDTS", + /* 282 */ "pseudo_column ::= NK_UNDERLINE WDURATION", + /* 283 */ "predicate ::= expression compare_op expression", + /* 284 */ "predicate ::= expression BETWEEN expression AND expression", + /* 285 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 286 */ "predicate ::= expression IS NULL", + /* 287 */ "predicate ::= expression IS NOT NULL", + /* 288 */ "predicate ::= expression in_op in_predicate_value", + /* 289 */ "compare_op ::= NK_LT", + /* 290 */ "compare_op ::= NK_GT", + /* 291 */ "compare_op ::= NK_LE", + /* 292 */ "compare_op ::= NK_GE", + /* 293 */ "compare_op ::= NK_NE", + /* 294 */ "compare_op ::= NK_EQ", + /* 295 */ "compare_op ::= LIKE", + /* 296 */ "compare_op ::= NOT LIKE", + /* 297 */ "compare_op ::= MATCH", + /* 298 */ "compare_op ::= NMATCH", + /* 299 */ "in_op ::= IN", + /* 300 */ "in_op ::= NOT IN", + /* 301 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 302 */ "boolean_value_expression ::= boolean_primary", + /* 303 */ "boolean_value_expression ::= NOT boolean_primary", + /* 304 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 305 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 306 */ "boolean_primary ::= predicate", + /* 307 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 308 */ "common_expression ::= expression", + /* 309 */ "common_expression ::= boolean_value_expression", + /* 310 */ "from_clause ::= FROM table_reference_list", + /* 311 */ "table_reference_list ::= table_reference", + /* 312 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 313 */ "table_reference ::= table_primary", + /* 314 */ "table_reference ::= joined_table", + /* 315 */ "table_primary ::= table_name alias_opt", + /* 316 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 317 */ "table_primary ::= subquery alias_opt", + /* 318 */ "table_primary ::= parenthesized_joined_table", + /* 319 */ "alias_opt ::=", + /* 320 */ "alias_opt ::= table_alias", + /* 321 */ "alias_opt ::= AS table_alias", + /* 322 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 323 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 324 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 325 */ "join_type ::=", + /* 326 */ "join_type ::= INNER", + /* 327 */ "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", + /* 328 */ "set_quantifier_opt ::=", + /* 329 */ "set_quantifier_opt ::= DISTINCT", + /* 330 */ "set_quantifier_opt ::= ALL", + /* 331 */ "select_list ::= NK_STAR", + /* 332 */ "select_list ::= select_sublist", + /* 333 */ "select_sublist ::= select_item", + /* 334 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 335 */ "select_item ::= common_expression", + /* 336 */ "select_item ::= common_expression column_alias", + /* 337 */ "select_item ::= common_expression AS column_alias", + /* 338 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 339 */ "where_clause_opt ::=", + /* 340 */ "where_clause_opt ::= WHERE search_condition", + /* 341 */ "partition_by_clause_opt ::=", + /* 342 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 343 */ "twindow_clause_opt ::=", + /* 344 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 345 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 346 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 347 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 348 */ "sliding_opt ::=", + /* 349 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 350 */ "fill_opt ::=", + /* 351 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 352 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 353 */ "fill_mode ::= NONE", + /* 354 */ "fill_mode ::= PREV", + /* 355 */ "fill_mode ::= NULL", + /* 356 */ "fill_mode ::= LINEAR", + /* 357 */ "fill_mode ::= NEXT", + /* 358 */ "group_by_clause_opt ::=", + /* 359 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 360 */ "group_by_list ::= expression", + /* 361 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 362 */ "having_clause_opt ::=", + /* 363 */ "having_clause_opt ::= HAVING search_condition", + /* 364 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 365 */ "query_expression_body ::= query_primary", + /* 366 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 367 */ "query_primary ::= query_specification", + /* 368 */ "order_by_clause_opt ::=", + /* 369 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 370 */ "slimit_clause_opt ::=", + /* 371 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 372 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 373 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 374 */ "limit_clause_opt ::=", + /* 375 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 376 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 377 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 378 */ "subquery ::= NK_LP query_expression NK_RP", + /* 379 */ "search_condition ::= common_expression", + /* 380 */ "sort_specification_list ::= sort_specification", + /* 381 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 382 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 383 */ "ordering_specification_opt ::=", + /* 384 */ "ordering_specification_opt ::= ASC", + /* 385 */ "ordering_specification_opt ::= DESC", + /* 386 */ "null_ordering_opt ::=", + /* 387 */ "null_ordering_opt ::= NULLS FIRST", + /* 388 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1463,146 +1587,153 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 172: /* cmd */ - case 175: /* literal */ - case 182: /* db_options */ - case 184: /* alter_db_options */ - case 186: /* full_table_name */ - case 189: /* table_options */ - case 193: /* alter_table_clause */ - case 194: /* alter_table_options */ - case 197: /* create_subtable_clause */ - case 200: /* drop_table_clause */ - case 203: /* column_def */ - case 206: /* col_name */ - case 207: /* db_name_cond_opt */ - case 208: /* like_pattern_opt */ - case 209: /* table_name_cond */ - case 210: /* from_db_opt */ - case 211: /* func_name */ - case 214: /* index_options */ - case 216: /* duration_literal */ - case 217: /* sliding_opt */ - case 218: /* func */ - case 221: /* query_expression */ - case 222: /* signed */ - case 223: /* signed_literal */ - case 226: /* expression */ - case 227: /* pseudo_column */ - case 228: /* column_reference */ - case 229: /* subquery */ - case 230: /* predicate */ - case 233: /* in_predicate_value */ - case 234: /* boolean_value_expression */ - case 235: /* boolean_primary */ - case 236: /* common_expression */ - case 237: /* from_clause */ - case 238: /* table_reference_list */ - case 239: /* table_reference */ - case 240: /* table_primary */ - case 241: /* joined_table */ - case 243: /* parenthesized_joined_table */ - case 245: /* search_condition */ - case 246: /* query_specification */ - case 249: /* where_clause_opt */ - case 251: /* twindow_clause_opt */ - case 253: /* having_clause_opt */ - case 255: /* select_item */ - case 256: /* fill_opt */ - case 259: /* query_expression_body */ - case 261: /* slimit_clause_opt */ - case 262: /* limit_clause_opt */ - case 263: /* query_primary */ - case 265: /* 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->yy176)); + nodesDestroyNode((yypminor->yy104)); } break; - case 173: /* account_options */ - case 174: /* alter_account_options */ - case 176: /* alter_account_option */ + case 202: /* account_options */ + case 203: /* alter_account_options */ + case 205: /* alter_account_option */ + case 255: /* bufsize_opt */ { } break; - case 177: /* user_name */ - case 178: /* dnode_endpoint */ - case 179: /* dnode_host_name */ - case 181: /* db_name */ - case 195: /* column_name */ - case 202: /* table_name */ - case 212: /* function_name */ - case 213: /* index_name */ - case 220: /* topic_name */ - case 224: /* table_alias */ - case 225: /* column_alias */ - case 242: /* 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 180: /* not_exists_opt */ - case 183: /* exists_opt */ - case 247: /* 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 185: /* alter_db_option */ - case 205: /* 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 187: /* column_def_list */ - case 188: /* tags_def_opt */ - case 190: /* multi_create_clause */ - case 191: /* tags_def */ - case 192: /* multi_drop_clause */ - case 198: /* specific_tags_opt */ - case 199: /* literal_list */ - case 201: /* col_name_list */ - case 204: /* func_name_list */ - case 215: /* func_list */ - case 219: /* expression_list */ - case 248: /* select_list */ - case 250: /* partition_by_clause_opt */ - case 252: /* group_by_clause_opt */ - case 254: /* select_sublist */ - case 258: /* group_by_list */ - case 260: /* order_by_clause_opt */ - case 264: /* sort_specification_list */ + case 215: /* alter_db_option */ + case 235: /* alter_table_option */ { - nodesDestroyList((yypminor->yy512)); + } break; - case 196: /* type_name */ + case 226: /* type_name */ { } break; - case 231: /* compare_op */ - case 232: /* in_op */ + case 267: /* compare_op */ + case 268: /* in_op */ { } break; - case 244: /* join_type */ + case 280: /* join_type */ { } break; - case 257: /* fill_mode */ + case 293: /* fill_mode */ { } break; - case 266: /* ordering_specification_opt */ + case 302: /* ordering_specification_opt */ { } break; - case 267: /* null_ordering_opt */ + case 303: /* null_ordering_opt */ { } @@ -1901,354 +2032,395 @@ 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[] = { - { 172, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 172, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 173, 0 }, /* (2) account_options ::= */ - { 173, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 173, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 173, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 173, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 173, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 173, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 173, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 173, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 173, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 174, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 174, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 176, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 176, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 176, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 176, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 176, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 176, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 176, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 176, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 176, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 176, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 172, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 172, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 172, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 172, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 172, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ - { 172, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 172, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ - { 172, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ - { 172, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 172, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 172, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ - { 172, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 178, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ - { 179, -1 }, /* (37) dnode_host_name ::= NK_ID */ - { 179, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ - { 172, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ - { 172, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 172, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 172, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 172, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 172, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ - { 172, -2 }, /* (45) cmd ::= USE db_name */ - { 172, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 180, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ - { 180, 0 }, /* (48) not_exists_opt ::= */ - { 183, -2 }, /* (49) exists_opt ::= IF EXISTS */ - { 183, 0 }, /* (50) exists_opt ::= */ - { 182, 0 }, /* (51) db_options ::= */ - { 182, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ - { 182, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ - { 182, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ - { 182, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ - { 182, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ - { 182, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ - { 182, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ - { 182, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ - { 182, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ - { 182, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ - { 182, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ - { 182, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ - { 182, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ - { 182, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ - { 182, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ - { 182, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 182, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 182, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ - { 184, -1 }, /* (70) alter_db_options ::= alter_db_option */ - { 184, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ - { 185, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ - { 185, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ - { 185, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ - { 185, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ - { 185, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ - { 185, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ - { 172, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 172, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ - { 172, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 172, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ - { 172, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ - { 172, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ - { 172, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ - { 193, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ - { 193, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 193, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 193, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 193, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 193, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 193, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 193, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 193, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 193, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 190, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ - { 190, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 197, -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 */ - { 192, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ - { 192, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 200, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ - { 198, 0 }, /* (101) specific_tags_opt ::= */ - { 198, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 186, -1 }, /* (103) full_table_name ::= table_name */ - { 186, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ - { 187, -1 }, /* (105) column_def_list ::= column_def */ - { 187, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ - { 203, -2 }, /* (107) column_def ::= column_name type_name */ - { 203, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ - { 196, -1 }, /* (109) type_name ::= BOOL */ - { 196, -1 }, /* (110) type_name ::= TINYINT */ - { 196, -1 }, /* (111) type_name ::= SMALLINT */ - { 196, -1 }, /* (112) type_name ::= INT */ - { 196, -1 }, /* (113) type_name ::= INTEGER */ - { 196, -1 }, /* (114) type_name ::= BIGINT */ - { 196, -1 }, /* (115) type_name ::= FLOAT */ - { 196, -1 }, /* (116) type_name ::= DOUBLE */ - { 196, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 196, -1 }, /* (118) type_name ::= TIMESTAMP */ - { 196, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 196, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ - { 196, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ - { 196, -2 }, /* (122) type_name ::= INT UNSIGNED */ - { 196, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ - { 196, -1 }, /* (124) type_name ::= JSON */ - { 196, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 196, -1 }, /* (126) type_name ::= MEDIUMBLOB */ - { 196, -1 }, /* (127) type_name ::= BLOB */ - { 196, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 196, -1 }, /* (129) type_name ::= DECIMAL */ - { 196, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 196, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 188, 0 }, /* (132) tags_def_opt ::= */ - { 188, -1 }, /* (133) tags_def_opt ::= tags_def */ - { 191, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 189, 0 }, /* (135) table_options ::= */ - { 189, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ - { 189, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ - { 189, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ - { 189, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 189, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 189, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ - { 189, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ - { 194, -1 }, /* (143) alter_table_options ::= alter_table_option */ - { 194, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ - { 205, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ - { 205, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ - { 205, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ - { 201, -1 }, /* (148) col_name_list ::= col_name */ - { 201, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ - { 206, -1 }, /* (150) col_name ::= column_name */ - { 172, -2 }, /* (151) cmd ::= SHOW DNODES */ - { 172, -2 }, /* (152) cmd ::= SHOW USERS */ - { 172, -2 }, /* (153) cmd ::= SHOW DATABASES */ - { 172, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 172, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 172, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 172, -2 }, /* (157) cmd ::= SHOW MNODES */ - { 172, -2 }, /* (158) cmd ::= SHOW MODULES */ - { 172, -2 }, /* (159) cmd ::= SHOW QNODES */ - { 172, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ - { 172, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 172, -2 }, /* (162) cmd ::= SHOW STREAMS */ - { 207, 0 }, /* (163) db_name_cond_opt ::= */ - { 207, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ - { 208, 0 }, /* (165) like_pattern_opt ::= */ - { 208, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ - { 209, -1 }, /* (167) table_name_cond ::= table_name */ - { 210, 0 }, /* (168) from_db_opt ::= */ - { 210, -2 }, /* (169) from_db_opt ::= FROM db_name */ - { 204, -1 }, /* (170) func_name_list ::= func_name */ - { 204, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ - { 211, -1 }, /* (172) func_name ::= function_name */ - { 172, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 172, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 172, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 214, 0 }, /* (176) index_options ::= */ - { 214, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 214, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 215, -1 }, /* (179) func_list ::= func */ - { 215, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ - { 218, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ - { 172, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 172, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ - { 172, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ - { 172, -1 }, /* (185) cmd ::= query_expression */ - { 175, -1 }, /* (186) literal ::= NK_INTEGER */ - { 175, -1 }, /* (187) literal ::= NK_FLOAT */ - { 175, -1 }, /* (188) literal ::= NK_STRING */ - { 175, -1 }, /* (189) literal ::= NK_BOOL */ - { 175, -2 }, /* (190) literal ::= TIMESTAMP NK_STRING */ - { 175, -1 }, /* (191) literal ::= duration_literal */ - { 175, -1 }, /* (192) literal ::= NULL */ - { 216, -1 }, /* (193) duration_literal ::= NK_VARIABLE */ - { 222, -1 }, /* (194) signed ::= NK_INTEGER */ - { 222, -2 }, /* (195) signed ::= NK_PLUS NK_INTEGER */ - { 222, -2 }, /* (196) signed ::= NK_MINUS NK_INTEGER */ - { 222, -1 }, /* (197) signed ::= NK_FLOAT */ - { 222, -2 }, /* (198) signed ::= NK_PLUS NK_FLOAT */ - { 222, -2 }, /* (199) signed ::= NK_MINUS NK_FLOAT */ - { 223, -1 }, /* (200) signed_literal ::= signed */ - { 223, -1 }, /* (201) signed_literal ::= NK_STRING */ - { 223, -1 }, /* (202) signed_literal ::= NK_BOOL */ - { 223, -2 }, /* (203) signed_literal ::= TIMESTAMP NK_STRING */ - { 223, -1 }, /* (204) signed_literal ::= duration_literal */ - { 223, -1 }, /* (205) signed_literal ::= NULL */ - { 199, -1 }, /* (206) literal_list ::= signed_literal */ - { 199, -3 }, /* (207) literal_list ::= literal_list NK_COMMA signed_literal */ - { 181, -1 }, /* (208) db_name ::= NK_ID */ - { 202, -1 }, /* (209) table_name ::= NK_ID */ - { 195, -1 }, /* (210) column_name ::= NK_ID */ - { 212, -1 }, /* (211) function_name ::= NK_ID */ - { 224, -1 }, /* (212) table_alias ::= NK_ID */ - { 225, -1 }, /* (213) column_alias ::= NK_ID */ - { 177, -1 }, /* (214) user_name ::= NK_ID */ - { 213, -1 }, /* (215) index_name ::= NK_ID */ - { 220, -1 }, /* (216) topic_name ::= NK_ID */ - { 226, -1 }, /* (217) expression ::= literal */ - { 226, -1 }, /* (218) expression ::= pseudo_column */ - { 226, -1 }, /* (219) expression ::= column_reference */ - { 226, -4 }, /* (220) expression ::= function_name NK_LP expression_list NK_RP */ - { 226, -4 }, /* (221) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 226, -1 }, /* (222) expression ::= subquery */ - { 226, -3 }, /* (223) expression ::= NK_LP expression NK_RP */ - { 226, -2 }, /* (224) expression ::= NK_PLUS expression */ - { 226, -2 }, /* (225) expression ::= NK_MINUS expression */ - { 226, -3 }, /* (226) expression ::= expression NK_PLUS expression */ - { 226, -3 }, /* (227) expression ::= expression NK_MINUS expression */ - { 226, -3 }, /* (228) expression ::= expression NK_STAR expression */ - { 226, -3 }, /* (229) expression ::= expression NK_SLASH expression */ - { 226, -3 }, /* (230) expression ::= expression NK_REM expression */ - { 219, -1 }, /* (231) expression_list ::= expression */ - { 219, -3 }, /* (232) expression_list ::= expression_list NK_COMMA expression */ - { 228, -1 }, /* (233) column_reference ::= column_name */ - { 228, -3 }, /* (234) column_reference ::= table_name NK_DOT column_name */ - { 227, -2 }, /* (235) pseudo_column ::= NK_UNDERLINE ROWTS */ - { 227, -1 }, /* (236) pseudo_column ::= TBNAME */ - { 227, -2 }, /* (237) pseudo_column ::= NK_UNDERLINE QSTARTTS */ - { 227, -2 }, /* (238) pseudo_column ::= NK_UNDERLINE QENDTS */ - { 227, -2 }, /* (239) pseudo_column ::= NK_UNDERLINE WSTARTTS */ - { 227, -2 }, /* (240) pseudo_column ::= NK_UNDERLINE WENDTS */ - { 227, -2 }, /* (241) pseudo_column ::= NK_UNDERLINE WDURATION */ - { 230, -3 }, /* (242) predicate ::= expression compare_op expression */ - { 230, -5 }, /* (243) predicate ::= expression BETWEEN expression AND expression */ - { 230, -6 }, /* (244) predicate ::= expression NOT BETWEEN expression AND expression */ - { 230, -3 }, /* (245) predicate ::= expression IS NULL */ - { 230, -4 }, /* (246) predicate ::= expression IS NOT NULL */ - { 230, -3 }, /* (247) predicate ::= expression in_op in_predicate_value */ - { 231, -1 }, /* (248) compare_op ::= NK_LT */ - { 231, -1 }, /* (249) compare_op ::= NK_GT */ - { 231, -1 }, /* (250) compare_op ::= NK_LE */ - { 231, -1 }, /* (251) compare_op ::= NK_GE */ - { 231, -1 }, /* (252) compare_op ::= NK_NE */ - { 231, -1 }, /* (253) compare_op ::= NK_EQ */ - { 231, -1 }, /* (254) compare_op ::= LIKE */ - { 231, -2 }, /* (255) compare_op ::= NOT LIKE */ - { 231, -1 }, /* (256) compare_op ::= MATCH */ - { 231, -1 }, /* (257) compare_op ::= NMATCH */ - { 232, -1 }, /* (258) in_op ::= IN */ - { 232, -2 }, /* (259) in_op ::= NOT IN */ - { 233, -3 }, /* (260) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 234, -1 }, /* (261) boolean_value_expression ::= boolean_primary */ - { 234, -2 }, /* (262) boolean_value_expression ::= NOT boolean_primary */ - { 234, -3 }, /* (263) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 234, -3 }, /* (264) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 235, -1 }, /* (265) boolean_primary ::= predicate */ - { 235, -3 }, /* (266) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 236, -1 }, /* (267) common_expression ::= expression */ - { 236, -1 }, /* (268) common_expression ::= boolean_value_expression */ - { 237, -2 }, /* (269) from_clause ::= FROM table_reference_list */ - { 238, -1 }, /* (270) table_reference_list ::= table_reference */ - { 238, -3 }, /* (271) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 239, -1 }, /* (272) table_reference ::= table_primary */ - { 239, -1 }, /* (273) table_reference ::= joined_table */ - { 240, -2 }, /* (274) table_primary ::= table_name alias_opt */ - { 240, -4 }, /* (275) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 240, -2 }, /* (276) table_primary ::= subquery alias_opt */ - { 240, -1 }, /* (277) table_primary ::= parenthesized_joined_table */ - { 242, 0 }, /* (278) alias_opt ::= */ - { 242, -1 }, /* (279) alias_opt ::= table_alias */ - { 242, -2 }, /* (280) alias_opt ::= AS table_alias */ - { 243, -3 }, /* (281) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 243, -3 }, /* (282) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 241, -6 }, /* (283) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 244, 0 }, /* (284) join_type ::= */ - { 244, -1 }, /* (285) join_type ::= INNER */ - { 246, -9 }, /* (286) 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 */ - { 247, 0 }, /* (287) set_quantifier_opt ::= */ - { 247, -1 }, /* (288) set_quantifier_opt ::= DISTINCT */ - { 247, -1 }, /* (289) set_quantifier_opt ::= ALL */ - { 248, -1 }, /* (290) select_list ::= NK_STAR */ - { 248, -1 }, /* (291) select_list ::= select_sublist */ - { 254, -1 }, /* (292) select_sublist ::= select_item */ - { 254, -3 }, /* (293) select_sublist ::= select_sublist NK_COMMA select_item */ - { 255, -1 }, /* (294) select_item ::= common_expression */ - { 255, -2 }, /* (295) select_item ::= common_expression column_alias */ - { 255, -3 }, /* (296) select_item ::= common_expression AS column_alias */ - { 255, -3 }, /* (297) select_item ::= table_name NK_DOT NK_STAR */ - { 249, 0 }, /* (298) where_clause_opt ::= */ - { 249, -2 }, /* (299) where_clause_opt ::= WHERE search_condition */ - { 250, 0 }, /* (300) partition_by_clause_opt ::= */ - { 250, -3 }, /* (301) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 251, 0 }, /* (302) twindow_clause_opt ::= */ - { 251, -6 }, /* (303) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 251, -4 }, /* (304) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 251, -6 }, /* (305) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 251, -8 }, /* (306) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 217, 0 }, /* (307) sliding_opt ::= */ - { 217, -4 }, /* (308) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 256, 0 }, /* (309) fill_opt ::= */ - { 256, -4 }, /* (310) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 256, -6 }, /* (311) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 257, -1 }, /* (312) fill_mode ::= NONE */ - { 257, -1 }, /* (313) fill_mode ::= PREV */ - { 257, -1 }, /* (314) fill_mode ::= NULL */ - { 257, -1 }, /* (315) fill_mode ::= LINEAR */ - { 257, -1 }, /* (316) fill_mode ::= NEXT */ - { 252, 0 }, /* (317) group_by_clause_opt ::= */ - { 252, -3 }, /* (318) group_by_clause_opt ::= GROUP BY group_by_list */ - { 258, -1 }, /* (319) group_by_list ::= expression */ - { 258, -3 }, /* (320) group_by_list ::= group_by_list NK_COMMA expression */ - { 253, 0 }, /* (321) having_clause_opt ::= */ - { 253, -2 }, /* (322) having_clause_opt ::= HAVING search_condition */ - { 221, -4 }, /* (323) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 259, -1 }, /* (324) query_expression_body ::= query_primary */ - { 259, -4 }, /* (325) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 263, -1 }, /* (326) query_primary ::= query_specification */ - { 260, 0 }, /* (327) order_by_clause_opt ::= */ - { 260, -3 }, /* (328) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 261, 0 }, /* (329) slimit_clause_opt ::= */ - { 261, -2 }, /* (330) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 261, -4 }, /* (331) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 261, -4 }, /* (332) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 262, 0 }, /* (333) limit_clause_opt ::= */ - { 262, -2 }, /* (334) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 262, -4 }, /* (335) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 262, -4 }, /* (336) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 229, -3 }, /* (337) subquery ::= NK_LP query_expression NK_RP */ - { 245, -1 }, /* (338) search_condition ::= common_expression */ - { 264, -1 }, /* (339) sort_specification_list ::= sort_specification */ - { 264, -3 }, /* (340) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 265, -3 }, /* (341) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 266, 0 }, /* (342) ordering_specification_opt ::= */ - { 266, -1 }, /* (343) ordering_specification_opt ::= ASC */ - { 266, -1 }, /* (344) ordering_specification_opt ::= DESC */ - { 267, 0 }, /* (345) null_ordering_opt ::= */ - { 267, -2 }, /* (346) null_ordering_opt ::= NULLS FIRST */ - { 267, -2 }, /* (347) 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, -2 }, /* (276) pseudo_column ::= NK_UNDERLINE ROWTS */ + { 263, -1 }, /* (277) pseudo_column ::= TBNAME */ + { 263, -2 }, /* (278) pseudo_column ::= NK_UNDERLINE QSTARTTS */ + { 263, -2 }, /* (279) pseudo_column ::= NK_UNDERLINE QENDTS */ + { 263, -2 }, /* (280) pseudo_column ::= NK_UNDERLINE WSTARTTS */ + { 263, -2 }, /* (281) pseudo_column ::= NK_UNDERLINE WENDTS */ + { 263, -2 }, /* (282) pseudo_column ::= NK_UNDERLINE WDURATION */ + { 266, -3 }, /* (283) predicate ::= expression compare_op expression */ + { 266, -5 }, /* (284) predicate ::= expression BETWEEN expression AND expression */ + { 266, -6 }, /* (285) predicate ::= expression NOT BETWEEN expression AND expression */ + { 266, -3 }, /* (286) predicate ::= expression IS NULL */ + { 266, -4 }, /* (287) predicate ::= expression IS NOT NULL */ + { 266, -3 }, /* (288) predicate ::= expression in_op in_predicate_value */ + { 267, -1 }, /* (289) compare_op ::= NK_LT */ + { 267, -1 }, /* (290) compare_op ::= NK_GT */ + { 267, -1 }, /* (291) compare_op ::= NK_LE */ + { 267, -1 }, /* (292) compare_op ::= NK_GE */ + { 267, -1 }, /* (293) compare_op ::= NK_NE */ + { 267, -1 }, /* (294) compare_op ::= NK_EQ */ + { 267, -1 }, /* (295) compare_op ::= LIKE */ + { 267, -2 }, /* (296) compare_op ::= NOT LIKE */ + { 267, -1 }, /* (297) compare_op ::= MATCH */ + { 267, -1 }, /* (298) compare_op ::= NMATCH */ + { 268, -1 }, /* (299) in_op ::= IN */ + { 268, -2 }, /* (300) in_op ::= NOT IN */ + { 269, -3 }, /* (301) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 270, -1 }, /* (302) boolean_value_expression ::= boolean_primary */ + { 270, -2 }, /* (303) boolean_value_expression ::= NOT boolean_primary */ + { 270, -3 }, /* (304) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 270, -3 }, /* (305) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 271, -1 }, /* (306) boolean_primary ::= predicate */ + { 271, -3 }, /* (307) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 272, -1 }, /* (308) common_expression ::= expression */ + { 272, -1 }, /* (309) common_expression ::= boolean_value_expression */ + { 273, -2 }, /* (310) from_clause ::= FROM table_reference_list */ + { 274, -1 }, /* (311) table_reference_list ::= table_reference */ + { 274, -3 }, /* (312) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 275, -1 }, /* (313) table_reference ::= table_primary */ + { 275, -1 }, /* (314) table_reference ::= joined_table */ + { 276, -2 }, /* (315) table_primary ::= table_name alias_opt */ + { 276, -4 }, /* (316) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 276, -2 }, /* (317) table_primary ::= subquery alias_opt */ + { 276, -1 }, /* (318) table_primary ::= parenthesized_joined_table */ + { 278, 0 }, /* (319) alias_opt ::= */ + { 278, -1 }, /* (320) alias_opt ::= table_alias */ + { 278, -2 }, /* (321) alias_opt ::= AS table_alias */ + { 279, -3 }, /* (322) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 279, -3 }, /* (323) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 277, -6 }, /* (324) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 280, 0 }, /* (325) join_type ::= */ + { 280, -1 }, /* (326) join_type ::= INNER */ + { 282, -9 }, /* (327) 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 }, /* (328) set_quantifier_opt ::= */ + { 283, -1 }, /* (329) set_quantifier_opt ::= DISTINCT */ + { 283, -1 }, /* (330) set_quantifier_opt ::= ALL */ + { 284, -1 }, /* (331) select_list ::= NK_STAR */ + { 284, -1 }, /* (332) select_list ::= select_sublist */ + { 290, -1 }, /* (333) select_sublist ::= select_item */ + { 290, -3 }, /* (334) select_sublist ::= select_sublist NK_COMMA select_item */ + { 291, -1 }, /* (335) select_item ::= common_expression */ + { 291, -2 }, /* (336) select_item ::= common_expression column_alias */ + { 291, -3 }, /* (337) select_item ::= common_expression AS column_alias */ + { 291, -3 }, /* (338) select_item ::= table_name NK_DOT NK_STAR */ + { 285, 0 }, /* (339) where_clause_opt ::= */ + { 285, -2 }, /* (340) where_clause_opt ::= WHERE search_condition */ + { 286, 0 }, /* (341) partition_by_clause_opt ::= */ + { 286, -3 }, /* (342) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 287, 0 }, /* (343) twindow_clause_opt ::= */ + { 287, -6 }, /* (344) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 287, -4 }, /* (345) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 287, -6 }, /* (346) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 287, -8 }, /* (347) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 247, 0 }, /* (348) sliding_opt ::= */ + { 247, -4 }, /* (349) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 292, 0 }, /* (350) fill_opt ::= */ + { 292, -4 }, /* (351) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 292, -6 }, /* (352) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 293, -1 }, /* (353) fill_mode ::= NONE */ + { 293, -1 }, /* (354) fill_mode ::= PREV */ + { 293, -1 }, /* (355) fill_mode ::= NULL */ + { 293, -1 }, /* (356) fill_mode ::= LINEAR */ + { 293, -1 }, /* (357) fill_mode ::= NEXT */ + { 288, 0 }, /* (358) group_by_clause_opt ::= */ + { 288, -3 }, /* (359) group_by_clause_opt ::= GROUP BY group_by_list */ + { 294, -1 }, /* (360) group_by_list ::= expression */ + { 294, -3 }, /* (361) group_by_list ::= group_by_list NK_COMMA expression */ + { 289, 0 }, /* (362) having_clause_opt ::= */ + { 289, -2 }, /* (363) having_clause_opt ::= HAVING search_condition */ + { 251, -4 }, /* (364) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 295, -1 }, /* (365) query_expression_body ::= query_primary */ + { 295, -4 }, /* (366) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 299, -1 }, /* (367) query_primary ::= query_specification */ + { 296, 0 }, /* (368) order_by_clause_opt ::= */ + { 296, -3 }, /* (369) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 297, 0 }, /* (370) slimit_clause_opt ::= */ + { 297, -2 }, /* (371) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 297, -4 }, /* (372) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 297, -4 }, /* (373) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 298, 0 }, /* (374) limit_clause_opt ::= */ + { 298, -2 }, /* (375) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 298, -4 }, /* (376) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 298, -4 }, /* (377) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 265, -3 }, /* (378) subquery ::= NK_LP query_expression NK_RP */ + { 281, -1 }, /* (379) search_condition ::= common_expression */ + { 300, -1 }, /* (380) sort_specification_list ::= sort_specification */ + { 300, -3 }, /* (381) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 301, -3 }, /* (382) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 302, 0 }, /* (383) ordering_specification_opt ::= */ + { 302, -1 }, /* (384) ordering_specification_opt ::= ASC */ + { 302, -1 }, /* (385) ordering_specification_opt ::= DESC */ + { 303, 0 }, /* (386) null_ordering_opt ::= */ + { 303, -2 }, /* (387) null_ordering_opt ::= NULLS FIRST */ + { 303, -2 }, /* (388) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2337,11 +2509,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,173,&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,174,&yymsp[0].minor); + yy_destructor(yypParser,203,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2355,20 +2527,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,173,&yymsp[-2].minor); +{ yy_destructor(yypParser,202,&yymsp[-2].minor); { } - yy_destructor(yypParser,175,&yymsp[0].minor); + yy_destructor(yypParser,204,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,176,&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,174,&yymsp[-1].minor); +{ yy_destructor(yypParser,203,&yymsp[-1].minor); { } - yy_destructor(yypParser,176,&yymsp[0].minor); + yy_destructor(yypParser,205,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2382,31 +2554,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,175,&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.yy225, &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.yy225, 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.yy225, 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.yy225); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy129); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy225, 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.yy225, &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.yy225); } +{ 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); } @@ -2423,17 +2595,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 208: /* db_name ::= NK_ID */ yytestcase(yyruleno==208); - case 209: /* table_name ::= NK_ID */ yytestcase(yyruleno==209); - case 210: /* column_name ::= NK_ID */ yytestcase(yyruleno==210); - case 211: /* function_name ::= NK_ID */ yytestcase(yyruleno==211); - case 212: /* table_alias ::= NK_ID */ yytestcase(yyruleno==212); - case 213: /* column_alias ::= NK_ID */ yytestcase(yyruleno==213); - case 214: /* user_name ::= NK_ID */ yytestcase(yyruleno==214); - case 215: /* index_name ::= NK_ID */ yytestcase(yyruleno==215); - case 216: /* topic_name ::= NK_ID */ yytestcase(yyruleno==216); -{ yylhsminor.yy225 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy225 = yylhsminor.yy225; + 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); } @@ -2448,951 +2621,1063 @@ 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.yy505, &yymsp[-1].minor.yy225, yymsp[0].minor.yy176); } +{ 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.yy505, &yymsp[0].minor.yy225); } +{ 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.yy225); } +{ 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.yy225, yymsp[0].minor.yy176); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy129, yymsp[0].minor.yy104); } break; case 47: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy505 = true; } +{ yymsp[-2].minor.yy185 = true; } break; case 48: /* not_exists_opt ::= */ case 50: /* exists_opt ::= */ yytestcase(yyruleno==50); - case 287: /* set_quantifier_opt ::= */ yytestcase(yyruleno==287); -{ yymsp[1].minor.yy505 = false; } + case 203: /* analyze_opt ::= */ yytestcase(yyruleno==203); + case 211: /* agg_func_opt ::= */ yytestcase(yyruleno==211); + case 328: /* set_quantifier_opt ::= */ yytestcase(yyruleno==328); +{ yymsp[1].minor.yy185 = false; } break; case 49: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy505 = true; } +{ yymsp[-1].minor.yy185 = true; } break; case 51: /* db_options ::= */ -{ yymsp[1].minor.yy176 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy104 = createDefaultDatabaseOptions(pCxt); } break; case 52: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy176 = setDatabaseOption(pCxt, yylhsminor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } - yymsp[0].minor.yy176 = yylhsminor.yy176; +{ 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.yy176 = setDatabaseOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; +{ 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.yy325.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy325.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.yy325.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy325.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.yy325.type = DB_OPTION_KEEP; yymsp[-1].minor.yy325.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.yy325.type = DB_OPTION_WAL; yymsp[-1].minor.yy325.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.yy325.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy325.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.yy325.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy325.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.yy505, yymsp[-5].minor.yy176, yymsp[-3].minor.yy512, yymsp[-1].minor.yy512, yymsp[0].minor.yy176); } - break; - case 79: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy512); } - break; - case 81: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy512); } - break; - case 82: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy505, yymsp[0].minor.yy176); } - break; - case 83: /* cmd ::= ALTER TABLE alter_table_clause */ - case 84: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==84); - case 185: /* cmd ::= query_expression */ yytestcase(yyruleno==185); -{ pCxt->pRootNode = yymsp[0].minor.yy176; } - break; - case 85: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy176 = createAlterTableOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; - break; - case 86: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; - break; - case 87: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy176 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy176, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy225); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; - break; - case 88: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; - break; - case 89: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy176 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; - break; - case 90: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; - break; - case 91: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy176 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy176, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy225); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; - break; - case 92: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; - break; - case 93: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy176 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; - break; - case 94: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy176 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy176, &yymsp[-2].minor.yy225, yymsp[0].minor.yy176); } - yymsp[-5].minor.yy176 = yylhsminor.yy176; - 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 206: /* literal_list ::= signed_literal */ yytestcase(yyruleno==206); - case 292: /* select_sublist ::= select_item */ yytestcase(yyruleno==292); - case 339: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==339); -{ yylhsminor.yy512 = createNodeList(pCxt, yymsp[0].minor.yy176); } - yymsp[0].minor.yy512 = yylhsminor.yy512; +{ 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 333: /* select_sublist ::= select_item */ yytestcase(yyruleno==333); + case 380: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==380); +{ 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.yy512 = addNodeToList(pCxt, yymsp[-1].minor.yy512, yymsp[0].minor.yy176); } - yymsp[-1].minor.yy512 = yylhsminor.yy512; + 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.yy176 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy505, yymsp[-7].minor.yy176, yymsp[-5].minor.yy176, yymsp[-4].minor.yy512, yymsp[-1].minor.yy512); } - yymsp[-8].minor.yy176 = yylhsminor.yy176; + 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.yy176 = createDropTableClause(pCxt, yymsp[-1].minor.yy505, yymsp[0].minor.yy176); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + 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 300: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==300); - case 317: /* group_by_clause_opt ::= */ yytestcase(yyruleno==317); - case 327: /* order_by_clause_opt ::= */ yytestcase(yyruleno==327); -{ yymsp[1].minor.yy512 = NULL; } + case 104: /* specific_tags_opt ::= */ + case 135: /* tags_def_opt ::= */ yytestcase(yyruleno==135); + case 341: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==341); + case 358: /* group_by_clause_opt ::= */ yytestcase(yyruleno==358); + case 368: /* order_by_clause_opt ::= */ yytestcase(yyruleno==368); +{ yymsp[1].minor.yy312 = NULL; } break; - case 102: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy512 = yymsp[-1].minor.yy512; } + 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.yy176 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy225, NULL); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + 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.yy176 = createRealTableNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225, NULL); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + 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 207: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==207); - case 293: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==293); - case 340: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==340); -{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, yymsp[0].minor.yy176); } - yymsp[-2].minor.yy512 = yylhsminor.yy512; + 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 334: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==334); + case 381: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==381); +{ 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.yy176 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448, NULL); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + 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.yy176 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-2].minor.yy448, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; + 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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.yy448 = 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 291: /* select_list ::= select_sublist */ yytestcase(yyruleno==291); -{ yylhsminor.yy512 = yymsp[0].minor.yy512; } - yymsp[0].minor.yy512 = yylhsminor.yy512; + case 136: /* tags_def_opt ::= tags_def */ + case 332: /* select_list ::= select_sublist */ yytestcase(yyruleno==332); +{ 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.yy512 = yymsp[-1].minor.yy512; } + 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.yy176 = createDefaultTableOptions(pCxt); } + case 138: /* table_options ::= */ +{ yymsp[1].minor.yy104 = createDefaultTableOptions(pCxt); } break; - case 136: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setTableSmaOption(pCxt, yymsp[-4].minor.yy176, yymsp[-1].minor.yy512); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setTableRollupOption(pCxt, yymsp[-4].minor.yy176, yymsp[-1].minor.yy512); } - yymsp[-4].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + 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.yy176 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy176 = setTableOption(pCxt, yylhsminor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + 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.yy176 = setTableOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + 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.yy325.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy325.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.yy325.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy325.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.yy325.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy325.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.yy176 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy225); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + 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.yy176, yymsp[0].minor.yy176); } + 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.yy176, yymsp[0].minor.yy176); } + 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.yy176, 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.yy176, yymsp[0].minor.yy176); } + 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.yy176 = createDefaultDatabaseCondValue(pCxt); } - break; - case 164: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy225); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; - break; - case 165: /* like_pattern_opt ::= */ - case 176: /* index_options ::= */ yytestcase(yyruleno==176); - case 298: /* where_clause_opt ::= */ yytestcase(yyruleno==298); - case 302: /* twindow_clause_opt ::= */ yytestcase(yyruleno==302); - case 307: /* sliding_opt ::= */ yytestcase(yyruleno==307); - case 309: /* fill_opt ::= */ yytestcase(yyruleno==309); - case 321: /* having_clause_opt ::= */ yytestcase(yyruleno==321); - case 329: /* slimit_clause_opt ::= */ yytestcase(yyruleno==329); - case 333: /* limit_clause_opt ::= */ yytestcase(yyruleno==333); -{ yymsp[1].minor.yy176 = NULL; } - break; - case 166: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - break; - case 167: /* table_name_cond ::= table_name */ -{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy225); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 169: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy225); } - break; - case 172: /* func_name ::= function_name */ -{ yylhsminor.yy176 = createFunctionNode(pCxt, &yymsp[0].minor.yy225, NULL); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - 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.yy505, &yymsp[-3].minor.yy225, &yymsp[-1].minor.yy225, NULL, yymsp[0].minor.yy176); } - 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.yy505, &yymsp[-5].minor.yy225, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512, NULL); } - break; - case 175: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225); } - break; - case 177: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy176 = createIndexOption(pCxt, yymsp[-6].minor.yy512, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), NULL, yymsp[0].minor.yy176); } - 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.yy176 = createIndexOption(pCxt, yymsp[-8].minor.yy512, releaseRawExprNode(pCxt, yymsp[-4].minor.yy176), releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), yymsp[0].minor.yy176); } - break; - case 181: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy176 = createFunctionNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; - break; - case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, yymsp[0].minor.yy176, NULL); } - break; - case 183: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, NULL, &yymsp[0].minor.yy225); } - break; - case 184: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy505, &yymsp[0].minor.yy225); } - break; - case 186: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 187: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 188: /* literal ::= NK_STRING */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 189: /* literal ::= NK_BOOL */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 190: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; - break; - case 191: /* literal ::= duration_literal */ - case 200: /* signed_literal ::= signed */ yytestcase(yyruleno==200); - case 217: /* expression ::= literal */ yytestcase(yyruleno==217); - case 218: /* expression ::= pseudo_column */ yytestcase(yyruleno==218); - case 219: /* expression ::= column_reference */ yytestcase(yyruleno==219); - case 222: /* expression ::= subquery */ yytestcase(yyruleno==222); - case 261: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==261); - case 265: /* boolean_primary ::= predicate */ yytestcase(yyruleno==265); - case 267: /* common_expression ::= expression */ yytestcase(yyruleno==267); - case 268: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==268); - case 270: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==270); - case 272: /* table_reference ::= table_primary */ yytestcase(yyruleno==272); - case 273: /* table_reference ::= joined_table */ yytestcase(yyruleno==273); - case 277: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==277); - case 324: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==324); - case 326: /* query_primary ::= query_specification */ yytestcase(yyruleno==326); -{ yylhsminor.yy176 = yymsp[0].minor.yy176; } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 192: /* literal ::= NULL */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 193: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 194: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 195: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - break; - case 196: /* signed ::= NK_MINUS NK_INTEGER */ + case 166: /* cmd ::= SHOW ACCOUNTS */ +{ pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } + break; + case 167: /* cmd ::= SHOW APPS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } + break; + case 168: /* cmd ::= SHOW CONNECTIONS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } + break; + case 169: /* cmd ::= SHOW LICENCE */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } + break; + case 170: /* cmd ::= SHOW CREATE DATABASE db_name */ +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy129); } + break; + 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: /* 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 ::= SHOW QUERIES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } + break; + case 174: /* cmd ::= SHOW SCORES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } + break; + case 175: /* cmd ::= SHOW TOPICS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } + break; + case 176: /* cmd ::= SHOW VARIABLES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } + break; + case 177: /* db_name_cond_opt ::= */ + case 182: /* from_db_opt ::= */ yytestcase(yyruleno==182); +{ yymsp[1].minor.yy104 = createDefaultDatabaseCondValue(pCxt); } + break; + 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 179: /* like_pattern_opt ::= */ + case 190: /* index_options ::= */ yytestcase(yyruleno==190); + case 339: /* where_clause_opt ::= */ yytestcase(yyruleno==339); + case 343: /* twindow_clause_opt ::= */ yytestcase(yyruleno==343); + case 348: /* sliding_opt ::= */ yytestcase(yyruleno==348); + case 350: /* fill_opt ::= */ yytestcase(yyruleno==350); + case 362: /* having_clause_opt ::= */ yytestcase(yyruleno==362); + case 370: /* slimit_clause_opt ::= */ yytestcase(yyruleno==370); + case 374: /* limit_clause_opt ::= */ yytestcase(yyruleno==374); +{ yymsp[1].minor.yy104 = NULL; } + break; + case 180: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + break; + 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 183: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy129); } + break; + case 186: /* func_name ::= function_name */ +{ yylhsminor.yy104 = createFunctionNode(pCxt, &yymsp[0].minor.yy129, NULL); } + yymsp[0].minor.yy104 = yylhsminor.yy104; + break; + 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 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 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 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 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 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 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 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 198: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy185, &yymsp[0].minor.yy129); } + break; + 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 201: /* cmd ::= RESET QUERY CACHE */ +{ pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } + break; + 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 204: /* analyze_opt ::= ANALYZE */ + case 212: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==212); + case 329: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==329); +{ yymsp[0].minor.yy185 = true; } + break; + 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 302: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==302); + case 306: /* boolean_primary ::= predicate */ yytestcase(yyruleno==306); + case 308: /* common_expression ::= expression */ yytestcase(yyruleno==308); + case 309: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==309); + case 311: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==311); + case 313: /* table_reference ::= table_primary */ yytestcase(yyruleno==313); + case 314: /* table_reference ::= joined_table */ yytestcase(yyruleno==314); + case 318: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==318); + case 365: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==365); + case 367: /* query_primary ::= query_specification */ yytestcase(yyruleno==367); +{ 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.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 197: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + 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 198: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy176 = 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 199: /* 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.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy104 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 201: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + 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 202: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + 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 203: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy176 = 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 204: /* signed_literal ::= duration_literal */ - case 338: /* search_condition ::= common_expression */ yytestcase(yyruleno==338); -{ yylhsminor.yy176 = releaseRawExprNode(pCxt, yymsp[0].minor.yy176); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + case 244: /* signed_literal ::= duration_literal */ + case 379: /* search_condition ::= common_expression */ yytestcase(yyruleno==379); +{ yylhsminor.yy104 = releaseRawExprNode(pCxt, yymsp[0].minor.yy104); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 205: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy176 = 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 220: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy225, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512)); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; + 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 221: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy225, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy225, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; + 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 223: /* expression ::= NK_LP expression NK_RP */ - case 266: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==266); -{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + case 264: /* expression ::= NK_LP expression NK_RP */ + case 307: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==307); +{ 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 224: /* expression ::= NK_PLUS expression */ + case 265: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); + 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.yy176 = yylhsminor.yy176; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 225: /* expression ::= NK_MINUS expression */ + case 266: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy104), NULL)); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 226: /* expression ::= expression NK_PLUS expression */ + case 267: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 227: /* expression ::= expression NK_MINUS expression */ + case 268: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 228: /* expression ::= expression NK_STAR expression */ + case 269: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 229: /* expression ::= expression NK_SLASH expression */ + case 270: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 230: /* expression ::= expression NK_REM expression */ + case 271: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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.yy176 = yylhsminor.yy176; - break; - case 231: /* expression_list ::= expression */ -{ yylhsminor.yy512 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } - yymsp[0].minor.yy512 = yylhsminor.yy512; - break; - case 232: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } - yymsp[-2].minor.yy512 = yylhsminor.yy512; - break; - case 233: /* column_reference ::= column_name */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy225, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy225)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; - break; - case 234: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225, createColumnNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225)); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; - break; - case 235: /* pseudo_column ::= NK_UNDERLINE ROWTS */ - case 237: /* pseudo_column ::= NK_UNDERLINE QSTARTTS */ yytestcase(yyruleno==237); - case 238: /* pseudo_column ::= NK_UNDERLINE QENDTS */ yytestcase(yyruleno==238); - case 239: /* pseudo_column ::= NK_UNDERLINE WSTARTTS */ yytestcase(yyruleno==239); - case 240: /* pseudo_column ::= NK_UNDERLINE WENDTS */ yytestcase(yyruleno==240); - case 241: /* pseudo_column ::= NK_UNDERLINE WDURATION */ yytestcase(yyruleno==241); + yymsp[-2].minor.yy104 = yylhsminor.yy104; + break; + case 272: /* expression_list ::= expression */ +{ yylhsminor.yy312 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy104)); } + yymsp[0].minor.yy312 = yylhsminor.yy312; + break; + 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 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 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 276: /* pseudo_column ::= NK_UNDERLINE ROWTS */ + case 278: /* pseudo_column ::= NK_UNDERLINE QSTARTTS */ yytestcase(yyruleno==278); + case 279: /* pseudo_column ::= NK_UNDERLINE QENDTS */ yytestcase(yyruleno==279); + case 280: /* pseudo_column ::= NK_UNDERLINE WSTARTTS */ yytestcase(yyruleno==280); + case 281: /* pseudo_column ::= NK_UNDERLINE WENDTS */ yytestcase(yyruleno==281); + case 282: /* pseudo_column ::= NK_UNDERLINE WDURATION */ yytestcase(yyruleno==282); { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy176 = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + yylhsminor.yy104 = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 236: /* pseudo_column ::= TBNAME */ -{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + case 277: /* pseudo_column ::= TBNAME */ +{ yylhsminor.yy104 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 242: /* predicate ::= expression compare_op expression */ - case 247: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==247); + case 283: /* predicate ::= expression compare_op expression */ + case 288: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==288); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy404, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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[-2].minor.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 243: /* predicate ::= expression BETWEEN expression AND expression */ + case 284: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy176), releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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[-4].minor.yy176 = yylhsminor.yy176; + yymsp[-4].minor.yy104 = yylhsminor.yy104; break; - case 244: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 285: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[-5].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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[-5].minor.yy176 = yylhsminor.yy176; + yymsp[-5].minor.yy104 = yylhsminor.yy104; break; - case 245: /* predicate ::= expression IS NULL */ + case 286: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), NULL)); + 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[-2].minor.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 246: /* predicate ::= expression IS NOT NULL */ + case 287: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), 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[-3].minor.yy176 = yylhsminor.yy176; + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 248: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy404 = OP_TYPE_LOWER_THAN; } + case 289: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy60 = OP_TYPE_LOWER_THAN; } break; - case 249: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy404 = OP_TYPE_GREATER_THAN; } + case 290: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy60 = OP_TYPE_GREATER_THAN; } break; - case 250: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy404 = OP_TYPE_LOWER_EQUAL; } + case 291: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy60 = OP_TYPE_LOWER_EQUAL; } break; - case 251: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy404 = OP_TYPE_GREATER_EQUAL; } + case 292: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy60 = OP_TYPE_GREATER_EQUAL; } break; - case 252: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy404 = OP_TYPE_NOT_EQUAL; } + case 293: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy60 = OP_TYPE_NOT_EQUAL; } break; - case 253: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy404 = OP_TYPE_EQUAL; } + case 294: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy60 = OP_TYPE_EQUAL; } break; - case 254: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy404 = OP_TYPE_LIKE; } + case 295: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy60 = OP_TYPE_LIKE; } break; - case 255: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy404 = OP_TYPE_NOT_LIKE; } + case 296: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy60 = OP_TYPE_NOT_LIKE; } break; - case 256: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy404 = OP_TYPE_MATCH; } + case 297: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy60 = OP_TYPE_MATCH; } break; - case 257: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy404 = OP_TYPE_NMATCH; } + case 298: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy60 = OP_TYPE_NMATCH; } break; - case 258: /* in_op ::= IN */ -{ yymsp[0].minor.yy404 = OP_TYPE_IN; } + case 299: /* in_op ::= IN */ +{ yymsp[0].minor.yy60 = OP_TYPE_IN; } break; - case 259: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy404 = OP_TYPE_NOT_IN; } + case 300: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy60 = OP_TYPE_NOT_IN; } break; - case 260: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy512)); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + case 301: /* 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 262: /* boolean_value_expression ::= NOT boolean_primary */ + case 303: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), 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[-1].minor.yy176 = yylhsminor.yy176; + yymsp[-1].minor.yy104 = yylhsminor.yy104; break; - case 263: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 304: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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[-2].minor.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 264: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 305: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + 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.yy176 = yylhsminor.yy176; + yymsp[-2].minor.yy104 = yylhsminor.yy104; break; - case 269: /* from_clause ::= FROM table_reference_list */ - case 299: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==299); - case 322: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==322); -{ yymsp[-1].minor.yy176 = yymsp[0].minor.yy176; } + case 310: /* from_clause ::= FROM table_reference_list */ + case 340: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==340); + case 363: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==363); +{ yymsp[-1].minor.yy104 = yymsp[0].minor.yy104; } break; - case 271: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy176 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy176, yymsp[0].minor.yy176, NULL); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + case 312: /* 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 274: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy176 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + case 315: /* 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 275: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy176 = createRealTableNode(pCxt, &yymsp[-3].minor.yy225, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; + case 316: /* 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 276: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy176 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176), &yymsp[0].minor.yy225); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + case 317: /* 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 278: /* alias_opt ::= */ -{ yymsp[1].minor.yy225 = nil_token; } + case 319: /* alias_opt ::= */ +{ yymsp[1].minor.yy129 = nil_token; } break; - case 279: /* alias_opt ::= table_alias */ -{ yylhsminor.yy225 = yymsp[0].minor.yy225; } - yymsp[0].minor.yy225 = yylhsminor.yy225; + case 320: /* alias_opt ::= table_alias */ +{ yylhsminor.yy129 = yymsp[0].minor.yy129; } + yymsp[0].minor.yy129 = yylhsminor.yy129; break; - case 280: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy225 = yymsp[0].minor.yy225; } + case 321: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy129 = yymsp[0].minor.yy129; } break; - case 281: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 282: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==282); -{ yymsp[-2].minor.yy176 = yymsp[-1].minor.yy176; } + case 322: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 323: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==323); +{ yymsp[-2].minor.yy104 = yymsp[-1].minor.yy104; } break; - case 283: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy176 = createJoinTableNode(pCxt, yymsp[-4].minor.yy236, yymsp[-5].minor.yy176, yymsp[-2].minor.yy176, yymsp[0].minor.yy176); } - yymsp[-5].minor.yy176 = yylhsminor.yy176; + case 324: /* 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 284: /* join_type ::= */ -{ yymsp[1].minor.yy236 = JOIN_TYPE_INNER; } + case 325: /* join_type ::= */ +{ yymsp[1].minor.yy532 = JOIN_TYPE_INNER; } break; - case 285: /* join_type ::= INNER */ -{ yymsp[0].minor.yy236 = JOIN_TYPE_INNER; } + case 326: /* join_type ::= INNER */ +{ yymsp[0].minor.yy532 = JOIN_TYPE_INNER; } break; - case 286: /* 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 327: /* 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.yy176 = createSelectStmt(pCxt, yymsp[-7].minor.yy505, yymsp[-6].minor.yy512, yymsp[-5].minor.yy176); - yymsp[-8].minor.yy176 = addWhereClause(pCxt, yymsp[-8].minor.yy176, yymsp[-4].minor.yy176); - yymsp[-8].minor.yy176 = addPartitionByClause(pCxt, yymsp[-8].minor.yy176, yymsp[-3].minor.yy512); - yymsp[-8].minor.yy176 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy176, yymsp[-2].minor.yy176); - yymsp[-8].minor.yy176 = addGroupByClause(pCxt, yymsp[-8].minor.yy176, yymsp[-1].minor.yy512); - yymsp[-8].minor.yy176 = addHavingClause(pCxt, yymsp[-8].minor.yy176, yymsp[0].minor.yy176); + 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 288: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy505 = true; } - break; - case 289: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy505 = false; } + case 330: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy185 = false; } break; - case 290: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy512 = NULL; } + case 331: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy312 = NULL; } break; - case 294: /* select_item ::= common_expression */ + case 335: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); - yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy104); + yylhsminor.yy104 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy104), &t); } - yymsp[0].minor.yy176 = yylhsminor.yy176; + yymsp[0].minor.yy104 = yylhsminor.yy104; break; - case 295: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176), &yymsp[0].minor.yy225); } - yymsp[-1].minor.yy176 = yylhsminor.yy176; + case 336: /* 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 296: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), &yymsp[0].minor.yy225); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + case 337: /* 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 297: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy176 = createColumnNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + case 338: /* 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 301: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 318: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==318); - case 328: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==328); -{ yymsp[-2].minor.yy512 = yymsp[0].minor.yy512; } + case 342: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 359: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==359); + case 369: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==369); +{ yymsp[-2].minor.yy312 = yymsp[0].minor.yy312; } break; - case 303: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy176 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } + case 344: /* 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 304: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy176 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } + case 345: /* 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 305: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy176 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), NULL, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } + case 346: /* 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 306: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy176 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy176), releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } + case 347: /* 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 308: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy176 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy176); } + case 349: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy104 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy104); } break; - case 310: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy176 = createFillNode(pCxt, yymsp[-1].minor.yy142, NULL); } + case 351: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy104 = createFillNode(pCxt, yymsp[-1].minor.yy550, NULL); } break; - case 311: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy176 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy512)); } + case 352: /* 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 312: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy142 = FILL_MODE_NONE; } + case 353: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy550 = FILL_MODE_NONE; } break; - case 313: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy142 = FILL_MODE_PREV; } + case 354: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy550 = FILL_MODE_PREV; } break; - case 314: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy142 = FILL_MODE_NULL; } + case 355: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy550 = FILL_MODE_NULL; } break; - case 315: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy142 = FILL_MODE_LINEAR; } + case 356: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy550 = FILL_MODE_LINEAR; } break; - case 316: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy142 = FILL_MODE_NEXT; } + case 357: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy550 = FILL_MODE_NEXT; } break; - case 319: /* group_by_list ::= expression */ -{ yylhsminor.yy512 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[0].minor.yy512 = yylhsminor.yy512; + case 360: /* group_by_list ::= expression */ +{ yylhsminor.yy312 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy104))); } + yymsp[0].minor.yy312 = yylhsminor.yy312; break; - case 320: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy512 = yylhsminor.yy512; + case 361: /* 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 323: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 364: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy176 = addOrderByClause(pCxt, yymsp[-3].minor.yy176, yymsp[-2].minor.yy512); - yylhsminor.yy176 = addSlimitClause(pCxt, yylhsminor.yy176, yymsp[-1].minor.yy176); - yylhsminor.yy176 = addLimitClause(pCxt, yylhsminor.yy176, yymsp[0].minor.yy176); + 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.yy176 = yylhsminor.yy176; + yymsp[-3].minor.yy104 = yylhsminor.yy104; break; - case 325: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy176 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy176, yymsp[0].minor.yy176); } - yymsp[-3].minor.yy176 = yylhsminor.yy176; + case 366: /* 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 330: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 334: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==334); -{ yymsp[-1].minor.yy176 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 371: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 375: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==375); +{ yymsp[-1].minor.yy104 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 331: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 335: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==335); -{ yymsp[-3].minor.yy176 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 372: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 376: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==376); +{ yymsp[-3].minor.yy104 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 332: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 336: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==336); -{ yymsp[-3].minor.yy176 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 373: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 377: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==377); +{ yymsp[-3].minor.yy104 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 337: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy176); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + case 378: /* 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 341: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy176 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), yymsp[-1].minor.yy106, yymsp[0].minor.yy465); } - yymsp[-2].minor.yy176 = yylhsminor.yy176; + case 382: /* 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 342: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy106 = ORDER_ASC; } + case 383: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy354 = ORDER_ASC; } break; - case 343: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy106 = ORDER_ASC; } + case 384: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy354 = ORDER_ASC; } break; - case 344: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy106 = ORDER_DESC; } + case 385: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy354 = ORDER_DESC; } break; - case 345: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy465 = NULL_ORDER_DEFAULT; } + case 386: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy489 = NULL_ORDER_DEFAULT; } break; - case 346: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy465 = NULL_ORDER_FIRST; } + case 387: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy489 = NULL_ORDER_FIRST; } break; - case 347: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy465 = NULL_ORDER_LAST; } + case 388: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy489 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 87f20e8d25b5f4f33fd6cbf558c16562b1e9a829..6dc3b53ae311b3a378d296d4458b3966bdf6e3d0 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -647,3 +647,16 @@ TEST_F(ParserTest, dropTopic) { bind("drop topic if exists tp1"); ASSERT_TRUE(run()); } + +TEST_F(ParserTest, explain) { + setDatabase("root", "test"); + + bind("explain SELECT * FROM t1"); + ASSERT_TRUE(run()); + + bind("explain analyze SELECT * FROM t1"); + ASSERT_TRUE(run()); + + bind("explain analyze verbose true ratio 0.01 SELECT * FROM t1"); + ASSERT_TRUE(run()); +} diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index bd4b6481f14878b8cc5597c7c575f3db563546d4..f57f476d51c23da99bad6062a1f9e844b8949e71 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -197,6 +197,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect strcpy(pScan->tableName.dbname, pRealTable->table.dbName); strcpy(pScan->tableName.tname, pRealTable->table.tableName); pScan->showRewrite = pCxt->pPlanCxt->showRewrite; + pScan->ratio = pRealTable->ratio; // set columns to scan SNodeList* pCols = NULL; @@ -287,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) { @@ -692,7 +693,7 @@ static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpS if (NULL == pModif) { return TSDB_CODE_OUT_OF_MEMORY; } - pModif->pDataBlocks = pStmt->pDataBlocks; + TSWAP(pModif->pDataBlocks, pStmt->pDataBlocks, SArray*); pModif->msgType = getMsgType(pStmt->sqlNodeType); *pLogicNode = (SLogicNode*)pModif; return TSDB_CODE_SUCCESS; @@ -704,6 +705,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi return createSelectLogicNode(pCxt, (SSelectStmt*)pStmt, pLogicNode); case QUERY_NODE_VNODE_MODIF_STMT: return createVnodeModifLogicNode(pCxt, (SVnodeModifOpStmt*)pStmt, pLogicNode); + case QUERY_NODE_EXPLAIN_STMT: + return createQueryLogicNode(pCxt, ((SExplainStmt*)pStmt)->pQuery, pLogicNode); default: break; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index db0201bc81a35a02e2efd0884205cecd664002b3..11baeff04ae3ff74c8ccf9adc79d36b7c08c3142 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -398,6 +398,7 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp pTableScan->scanFlag = pScanLogicNode->scanFlag; pTableScan->scanRange = pScanLogicNode->scanRange; + pTableScan->ratio = pScanLogicNode->ratio; vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode); pSubplan->execNodeStat.tableNum = pScanLogicNode->pVgroupList->vgroups[0].numOfTable; @@ -718,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); } @@ -780,6 +789,7 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil pInterval->sliding = pWindowLogicNode->sliding; pInterval->intervalUnit = pWindowLogicNode->intervalUnit; pInterval->slidingUnit = pWindowLogicNode->slidingUnit; + pInterval->precision = ((SColumnNode*)pWindowLogicNode->pTspk)->node.resType.precision; pInterval->pFill = nodesCloneNode(pWindowLogicNode->pFill); if (NULL != pWindowLogicNode->pFill && NULL == pInterval->pFill) { @@ -1080,6 +1090,30 @@ static int32_t doCreatePhysiPlan(SPhysiPlanContext* pCxt, SQueryLogicPlan* pLogi return code; } +static void destoryLocationHash(void* p) { + SHashObj* pHash = *(SHashObj**)p; + SSlotIndex* pIndex = taosHashIterate(pHash, NULL); + while (NULL != pIndex) { + taosArrayDestroy(pIndex->pSlotIdsInfo); + pIndex = taosHashIterate(pHash, pIndex); + } + taosHashCleanup(pHash); +} + +static void destoryPhysiPlanContext(SPhysiPlanContext* pCxt) { + taosArrayDestroyEx(pCxt->pLocationHelper, destoryLocationHash); +} + +static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) { + if (QUERY_NODE_EXPLAIN_STMT == nodeType(pCxt->pAstRoot)) { + SExplainStmt* pStmt = (SExplainStmt*)pCxt->pAstRoot; + pPlan->explainInfo.mode = pStmt->analyze ? EXPLAIN_MODE_ANALYZE : EXPLAIN_MODE_STATIC; + pPlan->explainInfo.verbose = pStmt->pOptions->verbose; + } else { + pPlan->explainInfo.mode = EXPLAIN_MODE_DISABLE; + } +} + int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) { SPhysiPlanContext cxt = { .pPlanCxt = pCxt, @@ -1091,5 +1125,12 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryP if (NULL == cxt.pLocationHelper) { return TSDB_CODE_OUT_OF_MEMORY; } - return doCreatePhysiPlan(&cxt, pLogicPlan, pPlan); + + int32_t code = doCreatePhysiPlan(&cxt, pLogicPlan, pPlan); + if (TSDB_CODE_SUCCESS == code) { + setExplainInfo(pCxt, *pPlan); + } + + destoryPhysiPlanContext(&cxt); + return code; } diff --git a/source/libs/planner/src/planScaleOut.c b/source/libs/planner/src/planScaleOut.c index ca6c7a2577e3439bcb50c907ea126ea6fb265b46..2b5fd12e226f20571acf47e7f332168bc5159d93 100644 --- a/source/libs/planner/src/planScaleOut.c +++ b/source/libs/planner/src/planScaleOut.c @@ -167,6 +167,8 @@ static int32_t doScaleOut(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32 if (TSDB_CODE_SUCCESS != code) { nodesDestroyList(pCurrentGroup); + } else { + nodesClearList(pCurrentGroup); } return code; diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index df546c32bea1a6f48518ee2698d6ed367fce168b..3ce225ababe943b0a17a7cb8889669ed42c1054f 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -140,6 +140,7 @@ static int32_t stsSplit(SSplitContext* pCxt) { code = stsCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pScan); } ++(pCxt->groupId); + taosMemoryFreeClear(pCxt->pInfo); return code; } diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index ea6498c0c88e0e1d8a198dec1f44e429d55d4b5e..00af808078a53a9560c3e7f800fc29d857308d19 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -190,10 +190,16 @@ TEST_F(PlannerTest, subquery) { TEST_F(PlannerTest, interval) { setDatabase("root", "test"); - bind("SELECT count(*) FROM t1 interval(10s)"); - ASSERT_TRUE(run()); + // bind("SELECT count(*) FROM t1 interval(10s)"); + // ASSERT_TRUE(run()); + + // bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); + // ASSERT_TRUE(run()); - bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); + // 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()); } @@ -248,6 +254,11 @@ TEST_F(PlannerTest, showTables) { bind("show tables"); ASSERT_TRUE(run()); + + setDatabase("root", "information_schema"); + + bind("show tables"); + ASSERT_TRUE(run()); } TEST_F(PlannerTest, showStables) { @@ -277,3 +288,16 @@ TEST_F(PlannerTest, createSmaIndex) { bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)"); ASSERT_TRUE(run()); } + +TEST_F(PlannerTest, explain) { + setDatabase("root", "test"); + + bind("explain SELECT * FROM t1"); + ASSERT_TRUE(run()); + + bind("explain analyze SELECT * FROM t1"); + ASSERT_TRUE(run()); + + bind("explain analyze verbose true ratio 0.01 SELECT * FROM t1"); + ASSERT_TRUE(run()); +} diff --git a/source/libs/qcom/CMakeLists.txt b/source/libs/qcom/CMakeLists.txt index a9bf0f5594cb0bc36c2eee84c4fb373507b4118e..d50047e59248079dd780bae5e2f85c94b8b743a5 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 75c1e134cd8de6dc7cc49fa6d2ad186ba651fcbd..f120bf26cebdac19896c372ea73159e682f72c0d 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/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 34159a1355647e8951e30054fa0324653f610c47..42d10a23619d4180cfc83e0735b4aab19c6fa02e 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -959,7 +959,7 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType) { QW_ERR_JRET(code); } - code = qCreateExecTask(qwMsg->node, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle); + code = qCreateExecTask(qwMsg->node, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle, OPTR_EXEC_MODEL_BATCH); if (code) { QW_TASK_ELOG("qCreateExecTask failed, code:%x - %s", code, tstrerror(code)); QW_ERR_JRET(code); diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h index 834a722bd80e6f8374adf7a3c2ac685c843a61fb..3e04e7b30acb6038da03d8fd3840914f8bb2296d 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 { diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index b0632bbc3423f5cc957ebbc67b1142e229a19766..434316add6ca0a553c38fcc18a706cc69007e468 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3668,7 +3668,6 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData taosArrayPush(pList, &pSrc); FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); - taosArrayDestroy(pList); // TODO Fix it // *p = output.orig.data; diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 7b2cb9ca671a1a3a4fa31374601c598cdec64200..2b869ba2377d238bdc0859603dc6a9f43fd66976 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); @@ -288,7 +288,7 @@ _return: SCL_RET(code); } -int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) { +int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) { if (NULL == node->pParameterList || node->pParameterList->length <= 0) { sclError("invalid function parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); @@ -420,7 +420,7 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)*pNode; SScalarParam output = {0}; - ctx->code = sclExecFuncion(node, ctx, &output); + ctx->code = sclExecFunction(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; } @@ -547,7 +547,7 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)pNode; SScalarParam output = {0}; - ctx->code = sclExecFuncion(node, ctx, &output); + ctx->code = sclExecFunction(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; } @@ -667,7 +667,7 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { int32_t code = 0; SScalarCtx ctx = {0}; - 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); @@ -689,7 +689,7 @@ 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); if (NULL == ctx.pRes) { sclError("taosHashInit failed, num:%d", SCL_DEFAULT_OP_NUM); @@ -716,6 +716,3 @@ _return: sclFreeRes(ctx.pRes); return code; } - - - diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 222f7ac69a7bc7e062a60eafda0fcb5782f84fa0..bc508f6e22d87573dd18c449c2210753c202c281 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1,5 +1,6 @@ -#include "sclfunc.h" -#include +#include "function.h" +#include "scalar.h" +#include "tdatablock.h" #include "sclInt.h" #include "sclvector.h" @@ -33,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; } @@ -46,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; } @@ -59,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; } @@ -72,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; } @@ -85,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; } @@ -98,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; } @@ -327,7 +328,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *)); SColumnInfoData *pOutputData = pOutput->columnData; char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); - char *output = NULL; + char *outputBuf = NULL; int32_t inputLen = 0; int32_t numOfRows = 0; @@ -350,19 +351,15 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu } } - allocate output buf - if (pOutputData->pData == NULL) { - int32_t outputLen = inputLen + numOfRows * VARSTR_HEADER_SIZE; - setVarTypeOutputBuf(pOutputData, outputLen, GET_PARAM_TYPE(pInput)); - } - output = pOutputData->pData; + int32_t outputLen = inputLen + numOfRows * VARSTR_HEADER_SIZE; + outputBuf = taosMemoryCalloc(outputLen, 1); + char *output = outputBuf; bool hasNull = false; - int32_t offset = 0; for (int32_t k = 0; k < numOfRows; ++k) { for (int32_t i = 0; i < inputNum; ++i) { - if (colDataIsNull_f(pInputData[i]->nullbitmap, k)) { - colDataSetNull_f(pOutputData->nullbitmap, k); + if (colDataIsNull_s(pInputData[i], k)) { + colDataAppendNULL(pOutputData, k); hasNull = true; break; } @@ -381,14 +378,13 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu } } varDataSetLen(output, dataLen); - int32_t dataTLen = varDataTLen(output); - output += dataTLen; - pOutputData->varmeta.offset[k] = offset; - offset += dataTLen; + colDataAppend(pOutputData, k, output, false); + output += varDataTLen(output); } pOutput->numOfRows = numOfRows; taosMemoryFree(input); + taosMemoryFree(outputBuf); taosMemoryFree(pInputData); return TSDB_CODE_SUCCESS; @@ -402,7 +398,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *)); SColumnInfoData *pOutputData = pOutput->columnData; char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); - char *output = NULL; + char *outputBuf = NULL; int32_t inputLen = 0; int32_t numOfRows = 0; @@ -428,18 +424,14 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p input[i] = pInputData[i]->pData; } - //allocate output buf - if (pOutputData->pData == NULL) { - int32_t outputLen = inputLen + numOfRows * VARSTR_HEADER_SIZE; - setVarTypeOutputBuf(pOutputData, outputLen, GET_PARAM_TYPE(&pInput[1])); - } - output = pOutputData->pData; + int32_t outputLen = inputLen + numOfRows * VARSTR_HEADER_SIZE; + outputBuf = taosMemoryCalloc(outputLen, 1); + char *output = outputBuf; - int32_t offset = 0; for (int32_t k = 0; k < numOfRows; ++k) { char *sep = pInputData[0]->pData; - if (colDataIsNull_f(pInputData[0]->nullbitmap, k)) { - colDataSetNull_f(pOutputData->nullbitmap, k); + if (colDataIsNull_s(pInputData[0], k)) { + colDataAppendNULL(pOutputData, k); continue; } @@ -462,14 +454,13 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p } } varDataSetLen(output, dataLen); - int32_t dataTLen = varDataTLen(output); - output += dataTLen; - pOutputData->varmeta.offset[k] = offset; - offset += dataTLen; + colDataAppend(pOutputData, k, output, false); + output += varDataTLen(output); } pOutput->numOfRows = numOfRows; taosMemoryFree(input); + taosMemoryFree(outputBuf); taosMemoryFree(pInputData); return TSDB_CODE_SUCCESS; @@ -484,19 +475,16 @@ int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - //allocate output buf - if (pOutputData->pData == NULL) { - int32_t outputLen = pInputData->varmeta.length; - setVarTypeOutputBuf(pOutputData, outputLen, GET_PARAM_TYPE(pInput)); - } - char *input = pInputData->pData; - char *output = pOutputData->pData; + char *output = NULL; + + int32_t outputLen = pInputData->varmeta.length; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + output = outputBuf; - int32_t offset = 0; for (int32_t i = 0; i < pInput->numOfRows; ++i) { - if (colDataIsNull_f(pInputData->nullbitmap, i)) { - colDataSetNull_f(pOutputData->nullbitmap, i); + if (colDataIsNull_s(pInputData, i)) { + colDataAppendNULL(pOutputData, i); continue; } @@ -511,14 +499,13 @@ int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam } } varDataSetLen(output, len); + colDataAppend(pOutputData, i, output, false); input += varDataTLen(input); output += varDataTLen(output); - - pOutputData->varmeta.offset[i] = offset; - offset += len + VARSTR_HEADER_SIZE; } pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); return TSDB_CODE_SUCCESS; } @@ -533,19 +520,16 @@ int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - //allocate output buf - if (pOutputData->pData == NULL) { - int32_t outputLen = pInputData->varmeta.length; - setVarTypeOutputBuf(pOutputData, outputLen, GET_PARAM_TYPE(pInput)); - } - char *input = pInputData->pData; - char *output = pOutputData->pData; + char *output = NULL; + + int32_t outputLen = pInputData->varmeta.length; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + output = outputBuf; - int32_t offset = 0; for (int32_t i = 0; i < pInput->numOfRows; ++i) { - if (colDataIsNull_f(pInputData->nullbitmap, i)) { - colDataSetNull_f(pOutputData->nullbitmap, i); + if (colDataIsNull_s(pInputData, i)) { + colDataAppendNULL(pOutputData, i); continue; } @@ -554,14 +538,13 @@ int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu trimFn(input, output, type, charLen); varDataSetLen(output, len); + colDataAppend(pOutputData, i, output, false); input += varDataTLen(input); output += varDataTLen(output); - - pOutputData->varmeta.offset[i] = offset; - offset += len + VARSTR_HEADER_SIZE; } pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); return TSDB_CODE_SUCCESS; } @@ -589,19 +572,16 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - //allocate output buf - if (pOutputData->pData == NULL) { - int32_t outputLen = pInputData->varmeta.length; - setVarTypeOutputBuf(pOutputData, outputLen, GET_PARAM_TYPE(pInput)); - } - char *input = pInputData->pData; - char *output = pOutputData->pData; + char *output = NULL; + + int32_t outputLen = pInputData->varmeta.length; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + output = outputBuf; - int32_t offset = 0; for (int32_t i = 0; i < pInput->numOfRows; ++i) { - if (colDataIsNull_f(pInputData->nullbitmap, i)) { - colDataSetNull_f(pOutputData->nullbitmap, i); + if (colDataIsNull_s(pInputData, i)) { + colDataAppendNULL(pOutputData, i); continue; } @@ -622,14 +602,13 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu } varDataSetLen(output, subLen); + colDataAppend(pOutputData, i , output, false); input += varDataTLen(input); output += varDataTLen(output); - - pOutputData->varmeta.offset[i] = offset; - offset += subLen + VARSTR_HEADER_SIZE; } pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); return TSDB_CODE_SUCCESS; } @@ -772,3 +751,34 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf } } +bool getTimePseudoFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { + pEnv->calcMemSize = sizeof(int64_t); + return true; +} + +int32_t qStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + ASSERT(inputNum == 1); + colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 0)); +} + +int32_t qEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + ASSERT(inputNum == 1); + colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 1)); +} + +int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + ASSERT(inputNum == 1); + colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 2)); +} + +int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + ASSERT(inputNum == 1); + colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t*) colDataGetData(pInput->columnData, 3)); + return TSDB_CODE_SUCCESS; +} + +int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + ASSERT(inputNum == 1); + colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t*) colDataGetData(pInput->columnData, 4)); + return TSDB_CODE_SUCCESS; +} diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index f22f9a5c3c06c799160ef6ece32e3d0ca9e45513..33be65832cd843f743991f160223d754483afb87 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -720,7 +720,7 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); - if (compareDoubleVal(&zero, &rx)) { + if (isnan(lx) || isinf(lx) || isnan(rx) || isinf(rx)) { colDataAppend(pOutputCol, i, NULL, true); continue; } @@ -729,7 +729,7 @@ 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 + if (colDataIsNull_f(pLeftCol->nullbitmap, 0) || isnan(lx) || isinf(lx)) { // Set pLeft->numOfRows NULL value // TODO set numOfRows NULL value } else { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { @@ -739,7 +739,7 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam } double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); - if (compareDoubleVal(&zero, &rx)) { + if (isnan(rx) || isinf(rx) || FLT_EQUAL(rx, 0)) { colDataAppend(pOutputCol, i, NULL, true); continue; } @@ -749,17 +749,17 @@ 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 + if (colDataIsNull_f(pRightCol->nullbitmap, 0) || FLT_EQUAL(rx, 0)) { // Set pLeft->numOfRows NULL value // TODO set numOfRows NULL value } else { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { - if (colDataIsNull_f(pRightCol->nullbitmap, i)) { + if (colDataIsNull_f(pLeftCol->nullbitmap, i)) { colDataAppend(pOutputCol, i, NULL, true); continue; } - double lx = getVectorDoubleValueFnLeft(pRightCol->pData, i); - if (compareDoubleVal(&zero, &lx)) { + double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); + if (isnan(lx) || isinf(lx)) { colDataAppend(pOutputCol, i, NULL, true); continue; } diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 54f82eae2d2610013d682f2ea187e72f73b67fdc..1a82c8f955913f9235df9c97449ae5dc8cbf19a3 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 153222516c994d7eb481088fdc488ad9bcdf2cbc..61ef2fdce2378bceeb1bc1dc44abf4ccfbafed93 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 a4a299317cbf5ccc875fe5c0b41f3e33d63e2fa0..1a62c7d89d4624c70210fdc68971313ad0104d02 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 518da6e2b8bbf7d21706034e4f28621105bcc7ff..22bd0392191bc8640854e9e8616d585b2b9ef513 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 5af13d97ca0e249f25618abd9950bd26d721fa2e..9c5019aedcafd8536674612ae9f33d1f6a926904 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); } @@ -357,7 +366,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); @@ -587,7 +596,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); } @@ -612,7 +621,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); } @@ -631,7 +640,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)); @@ -643,7 +652,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)); @@ -654,7 +663,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 { @@ -662,14 +672,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; } @@ -706,9 +717,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; } @@ -730,15 +740,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)); } @@ -825,7 +835,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++; @@ -833,9 +843,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); } } @@ -867,7 +877,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++; @@ -965,7 +975,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)); } @@ -985,11 +996,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; @@ -1011,21 +1022,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; @@ -1088,14 +1099,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); } @@ -1114,7 +1125,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: @@ -1173,7 +1184,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); @@ -1187,8 +1199,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); } @@ -1208,7 +1221,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)); @@ -1219,7 +1232,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: @@ -1258,8 +1270,8 @@ void schFreeRpcCtxVal(const void *arg) { if (NULL == arg) { return; } - - SMsgSendInfo* pMsgSendInfo = (SMsgSendInfo *)arg; + + SMsgSendInfo *pMsgSendInfo = (SMsgSendInfo *)arg; taosMemoryFreeClear(pMsgSendInfo->param); taosMemoryFreeClear(pMsgSendInfo); } @@ -1301,11 +1313,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)); @@ -1318,17 +1329,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: @@ -1340,16 +1351,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)); @@ -1362,7 +1373,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)); @@ -1370,7 +1381,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; @@ -1394,11 +1405,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)); @@ -1408,7 +1419,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)); @@ -1421,13 +1432,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; @@ -1450,19 +1461,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; @@ -1475,8 +1485,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)); @@ -1496,16 +1504,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)); @@ -1520,7 +1528,7 @@ int32_t schCloneSMsgSendInfo(void *src, void **dst) { *dst = pDst; return TSDB_CODE_SUCCESS; - + _return: taosMemoryFreeClear(pDst); @@ -1531,7 +1539,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); @@ -1541,16 +1549,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); @@ -1568,8 +1576,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; @@ -1601,11 +1609,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); @@ -1623,18 +1631,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); } @@ -1642,9 +1651,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); @@ -1655,7 +1664,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); @@ -1684,17 +1693,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); } @@ -1712,12 +1722,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; @@ -1741,7 +1751,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); @@ -1822,7 +1832,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; @@ -1856,7 +1866,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)); @@ -1902,7 +1913,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)); } @@ -1911,7 +1922,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 @@ -2071,7 +2082,7 @@ void schFreeJobImpl(void *job) { taosArrayDestroy(pJob->levels); taosArrayDestroy(pJob->nodeList); - + taosMemoryFreeClear(pJob->resData); taosMemoryFreeClear(pJob); @@ -2093,6 +2104,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; @@ -2126,19 +2138,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) { @@ -2158,6 +2175,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"); @@ -2206,13 +2271,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; @@ -2389,18 +2458,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 fb6c0f6c122ea3412d0773c83a1e02665d252a25..8aaaa414ca265f31f09f26f877b2ec3dea7ce5b3 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/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index 0b1378dc5a8ec2d83e432ff9d9f049019feadb34..3a62b19c10453c8f21c3a87da586ad2c11b2d2fd 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -9,9 +9,8 @@ target_sources(tdb "src/db/tdbDb.c" "src/db/tdbEnv.c" "src/db/tdbTxn.c" + "src/db/tdbPage.c" "src/db/tdbOs.c" - "src/page/tdbPage.c" - "src/page/tdbPageL.c" ) target_include_directories( diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index faced8e83993fd72292d7270e1427c156c40d40f..f4e16217429e4ed776d24357cf4b373b3045f3a2 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -18,31 +18,29 @@ #define TDB_BTREE_ROOT 0x1 #define TDB_BTREE_LEAF 0x2 -#define TDB_BTREE_PAGE_IS_ROOT(flags) TDB_FLAG_HAS(flags, TDB_BTREE_ROOT) -#define TDB_BTREE_PAGE_IS_LEAF(flags) TDB_FLAG_HAS(flags, 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)) - struct SBTree { SPgno root; int keyLen; int valLen; SPager *pPager; FKeyComparator kcmpr; - u8 fanout; int pageSize; int maxLocal; 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_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_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)) typedef struct __attribute__((__packed__)) { TDB_BTREE_PAGE_COMMON_HDR @@ -59,15 +57,15 @@ typedef struct { } SBtreeInitPageArg; typedef struct { - int kLen; - u8 *pKey; - int vLen; - u8 *pVal; - SPgno pgno; - u8 *pTmpSpace; + int kLen; + const u8 *pKey; + int vLen; + const u8 *pVal; + SPgno pgno; + u8 *pBuf; } SCellDecoder; -static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst); +static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst); static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeZeroPage(SPage *pPage, void *arg); @@ -78,13 +76,15 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD static int tdbBtreeBalance(SBTC *pBtc); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); static int tdbBtcMoveToNext(SBTC *pBtc); -static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno); +static int tdbBtcMoveDownward(SBTC *pBtc); static int tdbBtcMoveUpward(SBTC *pBtc); int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { SBTree *pBt; int ret; + ASSERT(keyLen != 0); + *ppBt = NULL; pBt = (SBTree *)tdbOsCalloc(1, sizeof(*pBt)); @@ -93,28 +93,21 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S } // pBt->keyLen - pBt->keyLen = keyLen; + pBt->keyLen = keyLen < 0 ? TDB_VARIANT_LEN : keyLen; // pBt->valLen - pBt->valLen = valLen; + pBt->valLen = valLen < 0 ? TDB_VARIANT_LEN : valLen; // pBt->pPager pBt->pPager = pPager; // pBt->kcmpr pBt->kcmpr = kcmpr ? kcmpr : tdbDefaultKeyCmprFn; - // pBt->fanout - if (keyLen == TDB_VARIANT_LEN) { - pBt->fanout = TDB_DEFAULT_FANOUT; - } else { - ASSERT(0); - // TODO: pBt->fanout = 0; - } // pBt->pageSize - pBt->pageSize = tdbPagerGetPageSize(pPager); + pBt->pageSize = pPager->pageSize; // pBt->maxLocal - pBt->maxLocal = (pBt->pageSize - 14) / pBt->fanout; + pBt->maxLocal = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr)) / 4; // pBt->minLocal: Should not be allowed smaller than 15, which is [nPayload][nKey][nData] - pBt->minLocal = (pBt->pageSize - 14) / pBt->fanout / 2; + pBt->minLocal = pBt->maxLocal / 2; // pBt->maxLeaf - pBt->maxLeaf = pBt->pageSize - 14; + pBt->maxLeaf = tdbPageCapacity(pBt->pageSize, sizeof(SLeafHdr)); // pBt->minLeaf pBt->minLeaf = pBt->minLocal; @@ -134,194 +127,143 @@ 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 = tdbBtCursorMoveTo(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); + return -1; } } - // TODO: refact code here - pBt = pBtc->pBt; - if (!pBt->pTmp) { - pBt->pTmp = (u8 *)tdbOsMalloc(pBt->pageSize); - if (pBt->pTmp == NULL) { - return -1; - } + // 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; - pCell = pBt->pTmp; + // encode cell + ret = tdbBtreeEncodeCell(btc.pPage, pKey, kLen, pVal, vLen, pCell, &szCell); + if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); + return -1; + } - // Encode the cell - ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pVal, vLen, pCell, &szCell); + // mark the page dirty + ret = tdbPagerWrite(pBt->pPager, btc.pPage); if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); return -1; } - // Insert the cell to the index - ret = tdbPageInsertCell(pBtc->pPage, idx, pCell, szCell, 0); + // insert the cell + ret = tdbPageInsertCell(btc.pPage, idx, pCell, szCell, 0); if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); return -1; } - // If page is overflow, balance the tree - if (pBtc->pPage->nOverflow > 0) { - ret = tdbBtreeBalance(pBtc); + // 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) { + 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 *pVal; + int ret; + void *pTKey = NULL; + void *pTVal = NULL; SCellDecoder cd; tdbBtcOpen(&btc, pBt); - tdbBtCursorMoveTo(&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); - *vLen = cd.vLen; - pVal = TDB_REALLOC(*ppVal, *vLen); - if (pVal == NULL) { - return -1; - } - - *ppVal = pVal; - memcpy(*ppVal, cd.pVal, cd.vLen); - return 0; -} - -static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { - int ret; - SBTree *pBt; - SPager *pPager; - - pBt = pBtc->pBt; - pPager = pBt->pPager; - - if (pBtc->iPage < 0) { - ASSERT(pBtc->iPage == -1); - ASSERT(pBtc->idx == -1); - - // Move from the root - ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt); - if (ret < 0) { + 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); + } - 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}; - - pPage = pBtc->pPage; - nCells = TDB_PAGE_TOTAL_CELLS(pPage); - lidx = 0; - ridx = nCells - 1; - - ASSERT(nCells > 0); - - 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) { - /* input-key < cell-key */ - ridx = midx - 1; - } else if (c > 0) { - /* input-key > cell-key */ - lidx = midx + 1; - } else { - /* input-key == cell-key */ - break; - } - } - - // Move downward or break - u8 flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); - u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags); - if (leaf) { - pBtc->idx = midx; - *pCRst = c; - break; - } else { - if (c <= 0) { - pBtc->idx = midx; - tdbBtcMoveDownward(pBtc, cd.pgno); - } else { - pBtc->idx = midx + 1; - if (midx == nCells - 1) { - /* Move to right-most child */ - tdbBtcMoveDownward(pBtc, ((SIntHdr *)pBtc->pPage->pData)->pgno); - } else { - pCell = tdbPageGetCell(pPage, pBtc->idx); - tdbBtreeDecodeCell(pPage, pCell, &cd); - tdbBtcMoveDownward(pBtc, cd.pgno); - } - } - } - } - - } else { - // TODO: Move the cursor from a some position instead of a clear state + pTVal = TDB_REALLOC(*ppVal, cd.vLen); + if (pTVal == NULL) { + tdbBtcClose(&btc); ASSERT(0); + return -1; } + *ppVal = pTVal; + *vLen = cd.vLen; + memcpy(*ppVal, cd.pVal, cd.vLen); + + tdbBtcClose(&btc); return 0; } @@ -370,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; @@ -385,7 +328,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { pBt = (SBTree *)arg; flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); - isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); + isLeaf = TDB_BTREE_PAGE_IS_LEAF(pPage); ASSERT(flags == TDB_BTREE_PAGE_GET_FLAGS(pPage)); @@ -411,15 +354,15 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { static int tdbBtreeZeroPage(SPage *pPage, void *arg) { u8 flags; SBTree *pBt; - u8 isLeaf; + u8 leaf; flags = ((SBtreeInitPageArg *)arg)->flags; pBt = ((SBtreeInitPageArg *)arg)->pBt; - isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); + leaf = flags & TDB_BTREE_LEAF; - tdbPageZero(pPage, isLeaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize); + tdbPageZero(pPage, leaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize); - if (isLeaf) { + if (leaf) { SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pData); pLeafHdr->flags = flags; @@ -441,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; @@ -464,7 +397,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { pPager = pRoot->pPager; flags = TDB_BTREE_PAGE_GET_FLAGS(pRoot); - leaf = TDB_BTREE_PAGE_IS_LEAF(flags); + leaf = TDB_BTREE_PAGE_IS_LEAF(pRoot); // Allocate a new child page zArg.flags = TDB_FLAG_REMOVE(flags, TDB_BTREE_ROOT); @@ -478,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); @@ -530,7 +470,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { SPgno pgno; if (sIdx + i == nCells) { - ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pParent))); + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pParent)); pgno = ((SIntHdr *)(pParent->pData))->pgno; } else { pCell = tdbPageGetCell(pParent, sIdx + i); @@ -542,9 +482,16 @@ 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(TDB_BTREE_PAGE_GET_FLAGS(pOlds[0])); + childNotLeaf = !TDB_BTREE_PAGE_IS_LEAF(pOlds[0]); if (childNotLeaf) { for (int i = 0; i < nOlds; i++) { if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) { @@ -562,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); @@ -689,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; + } } } @@ -802,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; @@ -818,13 +790,13 @@ static int tdbBtreeBalance(SBTC *pBtc) { for (;;) { iPage = pBtc->iPage; pPage = pBtc->pPage; - flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); - leaf = TDB_BTREE_PAGE_IS_LEAF(flags); - root = TDB_BTREE_PAGE_IS_ROOT(flags); + 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; } @@ -852,6 +824,8 @@ static int tdbBtreeBalance(SBTC *pBtc) { return -1; } + tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); + pBtc->iPage--; pBtc->pPage = pBtc->pgStack[pBtc->iPage]; } @@ -859,25 +833,19 @@ static int tdbBtreeBalance(SBTC *pBtc) { return 0; } -#endif +// TDB_BTREE_BALANCE -#ifndef TDB_BTREE_CELL // ========================================================= -static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, int kLen, const void *pVal, int vLen, - int *szPayload) { +// TDB_BTREE_CELL ===================== +static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const void *pKey, int kLen, const void *pVal, + int vLen, int *szPayload) { int nPayload; - ASSERT(pKey != NULL); - - if (pVal == NULL) { - vLen = 0; - } - nPayload = kLen + vLen; - if (nPayload <= pPage->maxLocal) { - // General case without overflow - memcpy(pPayload, pKey, kLen); + if (nPayload + nHeader <= pPage->maxLocal) { + // no overflow page is needed + memcpy(pCell + nHeader, pKey, kLen); if (pVal) { - memcpy(pPayload + kLen, pVal, vLen); + memcpy(pCell + nHeader + kLen, pVal, vLen); } *szPayload = nPayload; @@ -892,10 +860,8 @@ static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, i return 0; } -// TODO: allow vLen = 0 static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, int *szCell) { - u8 flags; u8 leaf; int nHeader; int nPayload; @@ -903,11 +869,11 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo ASSERT(pPage->kLen == TDB_VARIANT_LEN || pPage->kLen == kLen); ASSERT(pPage->vLen == TDB_VARIANT_LEN || pPage->vLen == vLen); + ASSERT(pKey != NULL && kLen > 0); nPayload = 0; nHeader = 0; - flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); - leaf = TDB_BTREE_PAGE_IS_LEAF(flags); + leaf = TDB_BTREE_PAGE_IS_LEAF(pPage); // 1. Encode Header part /* Encode SPgno if interior page */ @@ -929,38 +895,42 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo } // 2. Encode payload part - if (leaf) { - ret = tdbBtreeEncodePayload(pPage, pCell + nHeader, pKey, kLen, pVal, vLen, &nPayload); - } else { - ret = tdbBtreeEncodePayload(pPage, pCell + nHeader, pKey, kLen, NULL, 0, &nPayload); + if ((!leaf) || pPage->vLen == 0) { + pVal = NULL; + vLen = 0; } + + ret = tdbBtreeEncodePayload(pPage, pCell, nHeader, pKey, kLen, pVal, vLen, &nPayload); if (ret < 0) { - // TODO: handle error - return -1; + // TODO + ASSERT(0); + return 0; } *szCell = nHeader + nPayload; return 0; } -static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder *pDecoder) { +static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder) { int nPayload; - ASSERT(pDecoder->pKey == NULL); - if (pDecoder->pVal) { - nPayload = pDecoder->kLen + pDecoder->vLen; - } else { + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pPage)); nPayload = pDecoder->kLen; + } else { + nPayload = pDecoder->kLen + pDecoder->vLen; } - if (nPayload <= pPage->maxLocal) { - // General case without overflow - pDecoder->pKey = (void *)pPayload; - if (!pDecoder->pVal) { - pDecoder->pVal = (void *)(pPayload + pDecoder->kLen); + if (nHeader + nPayload <= pPage->maxLocal) { + // no over flow case + pDecoder->pKey = pCell + nHeader; + if (pDecoder->pVal == NULL && pDecoder->vLen > 0) { + pDecoder->pVal = pCell + nHeader + pDecoder->kLen; } - } else { + return 0; + } + + { // TODO: handle overflow case ASSERT(0); } @@ -969,14 +939,12 @@ static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder } static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder) { - u8 flags; u8 leaf; int nHeader; int ret; nHeader = 0; - flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); - leaf = TDB_BTREE_PAGE_IS_LEAF(flags); + leaf = TDB_BTREE_PAGE_IS_LEAF(pPage); // Clear the state of decoder pDecoder->kLen = -1; @@ -1001,13 +969,14 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD } if (pPage->vLen == TDB_VARIANT_LEN) { + ASSERT(leaf); nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->vLen)); } else { pDecoder->vLen = pPage->vLen; } // 2. Decode payload part - ret = tdbBtreeDecodePayload(pPage, pCell + nHeader, pDecoder); + ret = tdbBtreeDecodePayload(pPage, pCell, nHeader, pDecoder); if (ret < 0) { return -1; } @@ -1016,16 +985,14 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD } static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { - u8 flags; - u8 isLeaf; + u8 leaf; int szCell; int kLen = 0, vLen = 0; - flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); - isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); + leaf = TDB_BTREE_PAGE_IS_LEAF(pPage); szCell = 0; - if (!isLeaf) { + if (!leaf) { szCell += sizeof(SPgno); } @@ -1035,21 +1002,28 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { kLen = pPage->kLen; } - if (isLeaf) { - if (pPage->vLen == TDB_VARIANT_LEN) { - szCell += tdbGetVarInt(pCell + szCell, &vLen); - } else { - vLen = pPage->vLen; - } + if (pPage->vLen == TDB_VARIANT_LEN) { + ASSERT(leaf); + szCell += tdbGetVarInt(pCell + szCell, &vLen); + } else if (leaf) { + vLen = pPage->vLen; } szCell = szCell + kLen + vLen; - return szCell; -} + if (szCell <= pPage->maxLocal) { + return szCell; + } -#endif + { + // TODO + ASSERT(0); + return 0; + } +} +// TDB_BTREE_CELL +// TDB_BTREE_CURSOR ===================== int tdbBtcOpen(SBTC *pBtc, SBTree *pBt) { pBtc->pBt = pBt; pBtc->iPage = -1; @@ -1063,7 +1037,6 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { int ret; SBTree *pBt; SPager *pPager; - u8 flags; SCell *pCell; SPgno pgno; @@ -1078,23 +1051,42 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { return -1; } + ASSERT(TDB_BTREE_PAGE_IS_ROOT(pBtc->pPage)); + pBtc->iPage = 0; - pBtc->idx = 0; + if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) > 0) { + pBtc->idx = 0; + } else { + // no any data, 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; + + for (; iPage < pBtc->iPage; iPage++) { + ASSERT(pBtc->idxStack[iPage] >= 0); + if (pBtc->idxStack[iPage]) break; + } + + // move upward + for (;;) { + if (pBtc->iPage == iPage) { + pBtc->idx = 0; + break; + } + + tdbBtcMoveUpward(pBtc); + } } // move downward for (;;) { - flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); - - if (TDB_BTREE_PAGE_IS_LEAF(flags)) break; - - pCell = tdbPageGetCell(pBtc->pPage, 0); - pgno = *(SPgno *)pCell; + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break; - ret = tdbBtcMoveDownward(pBtc, pgno); + ret = tdbBtcMoveDownward(pBtc); if (ret < 0) { ASSERT(0); return -1; @@ -1108,9 +1100,9 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { int tdbBtcMoveToLast(SBTC *pBtc) { int ret; + int nCells; SBTree *pBt; SPager *pPager; - u8 flags; SPgno pgno; pBt = pBtc->pBt; @@ -1124,47 +1116,69 @@ 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 (;;) { - flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break; - if (TDB_BTREE_PAGE_IS_LEAF(flags)) { - // 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); - pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno; + ret = tdbBtcMoveDownward(pBtc); + if (ret < 0) { + ASSERT(0); + return -1; + } - ret = tdbBtcMoveDownward(pBtc, pgno); - 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; } } return 0; } -int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen) { - // TODO - return 0; -} - int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { SCell *pCell; SCellDecoder cd; void *pKey, *pVal; int ret; + // current cursor points to an invalid position if (pBtc->idx < 0) { return -1; } @@ -1195,17 +1209,20 @@ 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; - SPgno pgno; + int ret; SCell *pCell; - u8 flags; - ASSERT(TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage))); + ASSERT(TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)); if (pBtc->idx < 0) return -1; @@ -1214,56 +1231,52 @@ static int tdbBtcMoveToNext(SBTC *pBtc) { return 0; } - if (pBtc->iPage == 0) { - pBtc->idx = -1; - return 0; - } - - // Move upward + // move upward for (;;) { + if (pBtc->iPage == 0) { + pBtc->idx = -1; + return 0; + } + tdbBtcMoveUpward(pBtc); pBtc->idx++; - nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); - if (pBtc->idx <= nCells) { + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)); + if (pBtc->idx <= TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) { break; } - - if (pBtc->iPage == 0) { - pBtc->idx = -1; - return 0; - } } - // Move downward + // move downward for (;;) { - nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); - if (pBtc->idx < nCells) { - pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); - pgno = *(SPgno *)pCell; - } else { - pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno; + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break; + + ret = tdbBtcMoveDownward(pBtc); + if (ret < 0) { + ASSERT(0); + return -1; } - tdbBtcMoveDownward(pBtc, pgno); pBtc->idx = 0; - - flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); - if (TDB_BTREE_PAGE_IS_LEAF(flags)) { - break; - } } return 0; } -int tdbBtcClose(SBTC *pBtc) { - // TODO - return 0; -} +static int tdbBtcMoveDownward(SBTC *pBtc) { + int ret; + SPgno pgno; + SCell *pCell; -static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) { - int ret; + ASSERT(pBtc->idx >= 0); + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)); + + if (pBtc->idx < TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) { + pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); + pgno = ((SPgno *)pCell)[0]; + } else { + pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno; + } pBtc->pgStack[pBtc->iPage] = pBtc->pPage; pBtc->idxStack[pBtc->iPage] = pBtc->idx; @@ -1274,6 +1287,7 @@ static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) { ret = tdbPagerFetchPage(pBtc->pBt->pPager, pgno, &pBtc->pPage, tdbBtreeInitPage, pBtc->pBt); if (ret < 0) { ASSERT(0); + return -1; } return 0; @@ -1282,7 +1296,7 @@ static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) { static int tdbBtcMoveUpward(SBTC *pBtc) { if (pBtc->iPage == 0) return -1; - // tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); + tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); pBtc->iPage--; pBtc->pPage = pBtc->pgStack[pBtc->iPage]; @@ -1291,6 +1305,171 @@ static int tdbBtcMoveUpward(SBTC *pBtc) { return 0; } +static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { + 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) { + // move from a clear cursor + ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt); + if (ret < 0) { + // TODO + ASSERT(0); + return 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; + + // downward search + for (; iPage < pBtc->iPage; iPage++) { + pPage = pBtc->pgStack[iPage]; + idx = pBtc->idxStack[iPage]; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); + + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pPage)); + + // 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) break; + } + + // 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; + } + } + + // 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; +} + +int tdbBtcClose(SBTC *pBtc) { + if (pBtc->iPage < 0) return 0; + + for (;;) { + ASSERT(pBtc->pPage); + + tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); + + pBtc->iPage--; + if (pBtc->iPage < 0) break; + + pBtc->pPage = pBtc->pgStack[pBtc->iPage]; + pBtc->idx = pBtc->idxStack[pBtc->iPage]; + } + + return 0; +} +// TDB_BTREE_CURSOR + +// TDB_BTREE_DEBUG ===================== #ifndef NODEBUG typedef struct { SPgno pgno; @@ -1304,17 +1483,14 @@ typedef struct { SBtPageInfo btPageInfos[20]; void tdbBtPageInfo(SPage *pPage, int idx) { - u8 flags; SBtPageInfo *pBtPageInfo; pBtPageInfo = btPageInfos + idx; pBtPageInfo->pgno = TDB_PAGE_PGNO(pPage); - flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); - - pBtPageInfo->root = TDB_BTREE_PAGE_IS_ROOT(flags); - pBtPageInfo->leaf = TDB_BTREE_PAGE_IS_LEAF(flags); + pBtPageInfo->root = TDB_BTREE_PAGE_IS_ROOT(pPage); + pBtPageInfo->leaf = TDB_BTREE_PAGE_IS_LEAF(pPage); pBtPageInfo->rChild = 0; if (!pBtPageInfo->leaf) { @@ -1324,4 +1500,5 @@ void tdbBtPageInfo(SPage *pPage, int idx) { pBtPageInfo->nCells = TDB_PAGE_TOTAL_CELLS(pPage) - pPage->nOverflow; pBtPageInfo->nOvfl = pPage->nOverflow; } -#endif \ No newline at end of file +#endif +// TDB_BTREE_DEBUG \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 68adb7ccfcc851b40364430bf70ef9779a6c13e2..fe7b8c6d48e7f06b677aa048b2cc9aa249f09929 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,28 +76,17 @@ 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) { return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); } +int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen) { + return tdbBtreePGet(pDb->pBt, pKey, kLen, ppKey, pkLen, ppVal, vLen); +} + int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) { int ret; TDBC *pDbc = NULL; @@ -129,5 +120,11 @@ int tdbDbcClose(TDBC *pDbc) { tdbOsFree(pDbc); } + return 0; +} + +int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen) { + // TODO + ASSERT(0); return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 4439147e09344ee97ff1cf1e8de861a0ae8fe052..06d37df653cd5b41d2273472d50e35e6972f6df0 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 981dd63593c06f65c384ccd2e4d50ab7247e6cd3..d886cfd8898b7bdb65d254c195de1a788b7a0c39 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); } } @@ -122,7 +105,7 @@ static void tdbPCacheClearLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mute static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } -static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } +static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexUnlock(&(pCache->mutex)); } static bool tdbPCacheLocked(SPCache *pCache) { assert(0); @@ -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/page/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c similarity index 84% rename from source/libs/tdb/src/page/tdbPage.c rename to source/libs/tdb/src/db/tdbPage.c index 3301202a3383ef83b3426c7d4f27184095a05364..cc4ce20802ee8e678e71fc80f55e4df5f6e25538 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -242,6 +242,18 @@ void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { pToPage->nOverflow = pFromPage->nOverflow; } +int tdbPageCapacity(int pageSize, int amHdrSize) { + int szPageHdr; + + if (pageSize < 65536) { + szPageHdr = pageMethods.szPageHdr; + } else { + szPageHdr = pageLargeMethods.szPageHdr; + } + + return pageSize - szPageHdr - amHdrSize; +} + static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { SCell *pFreeCell; u8 *pOffset; @@ -503,4 +515,81 @@ SPageMethods pageMethods = { setPageCellOffset, // setCellOffset getPageFreeCellInfo, // getFreeCellInfo setPageFreeCellInfo // setFreeCellInfo +}; + +typedef struct __attribute__((__packed__)) { + u8 cellNum[3]; + u8 cellBody[3]; + u8 cellFree[3]; + u8 nFree[3]; +} SPageHdrL; + +typedef struct __attribute__((__packed__)) { + u8 szCell[3]; + u8 nxOffset[3]; +} SFreeCellL; + +// cellNum +static inline int getLPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); } +static inline void setLPageCellNum(SPage *pPage, int cellNum) { + TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum, cellNum); +} + +// cellBody +static inline int getLPageCellBody(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody); } +static inline void setLPageCellBody(SPage *pPage, int cellBody) { + TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody, cellBody); +} + +// cellFree +static inline int getLPageCellFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree); } +static inline void setLPageCellFree(SPage *pPage, int cellFree) { + TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree, cellFree); +} + +// nFree +static inline int getLPageNFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree); } +static inline void setLPageNFree(SPage *pPage, int nFree) { + TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree, nFree); +} + +// cell offset +static inline int getLPageCellOffset(SPage *pPage, int idx) { + ASSERT(idx >= 0 && idx < getPageCellNum(pPage)); + return TDB_GET_U24(pPage->pCellIdx + 3 * idx); +} + +static inline void setLPageCellOffset(SPage *pPage, int idx, int offset) { + TDB_PUT_U24(pPage->pCellIdx + 3 * idx, offset); +} + +// free cell info +static inline void getLPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) { + SFreeCellL *pFreeCell = (SFreeCellL *)pCell; + *szCell = TDB_GET_U24(pFreeCell->szCell); + *nxOffset = TDB_GET_U24(pFreeCell->nxOffset); +} + +static inline void setLPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { + SFreeCellL *pFreeCell = (SFreeCellL *)pCell; + TDB_PUT_U24(pFreeCell->szCell, szCell); + TDB_PUT_U24(pFreeCell->nxOffset, nxOffset); +} + +SPageMethods pageLargeMethods = { + 3, // szOffset + sizeof(SPageHdrL), // szPageHdr + sizeof(SFreeCellL), // szFreeCell + getLPageCellNum, // getCellNum + setLPageCellNum, // setCellNum + getLPageCellBody, // getCellBody + setLPageCellBody, // setCellBody + getLPageCellFree, // getCellFree + setLPageCellFree, // setCellFree + getLPageNFree, // getFreeBytes + setLPageNFree, // setFreeBytes + getLPageCellOffset, // getCellOffset + setLPageCellOffset, // setCellOffset + getLPageFreeCellInfo, // getFreeCellInfo + setLPageFreeCellInfo // setFreeCellInfo }; \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 748633da34354ba33e0cacd8f4dc7adbaa25b70c..2bc40a6aad11484d06f71db2402cd2d4f1ad8a02 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 fd4d5de60e8e1ed81cdde4dfda9065e864d47fac..03bcbb44a7ebcc6af3a16a3846900a3e526e08dd 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 e46e8bb78be7d890072dbb735d8c5d5434081cf2..2eba5f4f1a746e598473b41225e09aa7f4da83e8 100644 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ b/source/libs/tdb/src/inc/tdbBtree.h @@ -35,20 +35,19 @@ struct SBTC { int idx; int idxStack[BTREE_MAX_DEPTH + 1]; SPage *pgStack[BTREE_MAX_DEPTH + 1]; - void *pBuf; }; // 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); // SBTC int tdbBtcOpen(SBTC *pCur, SBTree *pBt); int tdbBtcMoveToFirst(SBTC *pBtc); int tdbBtcMoveToLast(SBTC *pBtc); -int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen); int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbBtcClose(SBTC *pBtc); diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index 4fbf65829daccd50c277e6e4fd7d556a47f3b179..e60371c734a7a0a4493cdf5a765a201e688d7393 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -29,11 +29,13 @@ int tdbDbClose(TDB *pDb); int tdbDbDrop(TDB *pDb); int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); +int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen); // TDBC int tdbDbcOpen(TDB *pDb, TDBC **ppDbc); int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbDbcClose(TDBC *pDbc); +int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index a651c3a12e98d0ccc24dd09dd115b71cf94680c9..e10c5d54e0f684969842765bd151774acef74ff5 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 361a460cef471eb42448ab6496ebcbba9eeef8bd..57e01f904cb8d45883585303d4ecf4f657719cbb 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 794d4c502a28bc46edb4ebc2507d8b1d2e32551c..ae389708f4f5cb3bd9dd1910f3a6568dc304f8ab 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 @@ -64,7 +66,7 @@ typedef TdThreadSpinlock tdb_spinlock_t; #define tdbSpinlockDestroy taosThreadSpinDestroy #define tdbSpinlockLock taosThreadSpinLock #define tdbSpinlockUnlock taosThreadSpinUnlock -#define tdbSpinlockTrylock pthread_spin_trylock +#define tdbSpinlockTrylock taosThreadSpinTrylock /* mutex lock */ typedef TdThreadMutex tdb_mutex_t; @@ -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 c7fa1556159ceeb98aa692ba27d8ea684b0aab9e..f71d34ab533ba82d7a6c158f548eb2702ce560f4 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 49aa9f439804eeaab634e824ba0794806060f005..77a1ee5f6ee4c0bdd341d6cd293efc7ffa33fa9e 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) @@ -111,6 +112,7 @@ void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl); int tdbPageDropCell(SPage *pPage, int idx); void tdbPageCopy(SPage *pFromPage, SPage *pToPage); +int tdbPageCapacity(int pageSize, int amHdrSize); static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { SCell *pCell; diff --git a/source/libs/tdb/src/inc/tdbPager.h b/source/libs/tdb/src/inc/tdbPager.h index f4cc822f273f5398199f0c2cf046cebdaeb23610..81b6074431d94e2ada3272a02359524d48cca97c 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 4300dc83245833377934e2ead18efd9eb4516809..0be2dad3c232e7fe5627672a28cd499bc53d1726 100644 --- a/source/libs/tdb/src/inc/tdbTxn.h +++ b/source/libs/tdb/src/inc/tdbTxn.h @@ -20,7 +20,7 @@ extern "C" { #endif -typedef struct STxn STXN; +typedef struct STxn TXN; struct STxn { u64 txnId; @@ -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 c06d9d18c9c61010b143a909afd54fbb2fe7173c..6abddb5b22c22a3ac7c3099aeaf767cc9d0f03a2 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/src/page/tdbPageL.c b/source/libs/tdb/src/page/tdbPageL.c deleted file mode 100644 index c5d4a6047fb73f34cdd4483e1162fe918b5c8999..0000000000000000000000000000000000000000 --- a/source/libs/tdb/src/page/tdbPageL.c +++ /dev/null @@ -1,93 +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 . - */ - -#include "tdbInt.h" - -typedef struct __attribute__((__packed__)) { - u8 cellNum[3]; - u8 cellBody[3]; - u8 cellFree[3]; - u8 nFree[3]; -} SPageHdrL; - -typedef struct __attribute__((__packed__)) { - u8 szCell[3]; - u8 nxOffset[3]; -} SFreeCellL; - -// cellNum -static inline int getPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); } -static inline void setPageCellNum(SPage *pPage, int cellNum) { - TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum, cellNum); -} - -// cellBody -static inline int getPageCellBody(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody); } -static inline void setPageCellBody(SPage *pPage, int cellBody) { - TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody, cellBody); -} - -// cellFree -static inline int getPageCellFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree); } -static inline void setPageCellFree(SPage *pPage, int cellFree) { - TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree, cellFree); -} - -// nFree -static inline int getPageNFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree); } -static inline void setPageNFree(SPage *pPage, int nFree) { - TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree, nFree); -} - -// cell offset -static inline int getPageCellOffset(SPage *pPage, int idx) { - ASSERT(idx >= 0 && idx < getPageCellNum(pPage)); - return TDB_GET_U24(pPage->pCellIdx + 3 * idx); -} - -static inline void setPageCellOffset(SPage *pPage, int idx, int offset) { - TDB_PUT_U24(pPage->pCellIdx + 3 * idx, offset); -} - -// free cell info -static inline void getPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) { - SFreeCellL *pFreeCell = (SFreeCellL *)pCell; - *szCell = TDB_GET_U24(pFreeCell->szCell); - *nxOffset = TDB_GET_U24(pFreeCell->nxOffset); -} - -static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { - SFreeCellL *pFreeCell = (SFreeCellL *)pCell; - TDB_PUT_U24(pFreeCell->szCell, szCell); - TDB_PUT_U24(pFreeCell->nxOffset, nxOffset); -} - -SPageMethods pageLargeMethods = { - 3, // szOffset - sizeof(SPageHdrL), // szPageHdr - sizeof(SFreeCellL), // szFreeCell - getPageCellNum, // getCellNum - setPageCellNum, // setCellNum - getPageCellBody, // getCellBody - setPageCellBody, // setCellBody - getPageCellFree, // getCellFree - setPageCellFree, // setCellFree - getPageNFree, // getFreeBytes - setPageNFree, // setFreeBytes - getPageCellOffset, // getCellOffset - setPageCellOffset, // setCellOffset - getPageFreeCellInfo, // getFreeCellInfo - setPageFreeCellInfo // setFreeCellInfo -}; \ No newline at end of file diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index f41e2bcbee7f147c23330cfe0931e017a759cd36..9e1277a53ddf8940957e78adbd0295b993684239 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; - - 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 i = 1; i <= nData;) { + tdbBegin(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 5296a1670363e300211ebf0291bd3021650ca287..2545eeab4bbff3e9974dac705b947201a0999b07 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 ed93708c0775793b768f8339d33fa82bc571cb31..1b73f968963573d57b2c1d0ab6cf7388d2d0e48c 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) { diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 81ee259ff1ae1bccd6de4151aa99433d86da7af4..3545aabdca9da2c1d8e530979692f8121bcae41c 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -17,19 +17,28 @@ #include #include "os.h" +#ifdef USE_TD_MEMORY + #define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S') #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; -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +// 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 @@ -70,6 +79,8 @@ int32_t taosBackTrace(void **buffer, int32_t size) { // return backtrace_symbols(buffer, *size); // } +#endif + void *taosMemoryMalloc(int32_t size) { #ifdef USE_TD_MEMORY void *tmp = malloc(size + sizeof(TdMemoryInfo)); @@ -125,10 +136,30 @@ void *taosMemoryRealloc(void *ptr, int32_t size) { #endif } -void taosMemoryFree(const void *ptr) { +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; +#ifdef USE_TD_MEMORY TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); if(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL) { pTdMemoryInfo->memorySize = 0; @@ -143,9 +174,9 @@ void taosMemoryFree(const void *ptr) { } int32_t taosMemorySize(void *ptr) { -#ifdef USE_TD_MEMORY if (ptr == NULL) return 0; - + +#ifdef USE_TD_MEMORY TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); diff --git a/source/os/src/osProc.c b/source/os/src/osProc.c new file mode 100644 index 0000000000000000000000000000000000000000..6b52fa30be2b7d1a5318388ce036d09b7b690f21 --- /dev/null +++ b/source/os/src/osProc.c @@ -0,0 +1,62 @@ +/* + * 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 ALLOW_FORBID_FUNC +#define _DEFAULT_SOURCE +#include "os.h" + +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 taosWaitProc(int32_t pid) { + int32_t status = 0; + 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); + + 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 new file mode 100644 index 0000000000000000000000000000000000000000..ba184c1f5d4ec79472919098aab8facc66ba07f8 --- /dev/null +++ b/source/os/src/osShm.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 ALLOW_FORBID_FUNC +#define _DEFAULT_SOURCE +#include "os.h" + +int32_t taosCreateShm(SShm* pShm, int32_t shmsize) { + pShm->id = -1; + + int32_t shmid = shmget(0X95279527, shmsize, IPC_CREAT | 0600); + if (shmid < 0) { + return -1; + } + + void* shmptr = shmat(shmid, NULL, 0); + if (shmptr == NULL) { + return -1; + } + + pShm->id = shmid; + pShm->size = shmsize; + pShm->ptr = shmptr; + return 0; +} + +void taosDropShm(SShm* pShm) { + if (pShm->id >= 0) { + if (pShm->ptr != NULL) { + shmdt(pShm->ptr); + } + shmctl(pShm->id, IPC_RMID, NULL); + } + pShm->id = -1; + pShm->size = 0; + pShm->ptr = NULL; +} + +int32_t taosAttachShm(SShm* pShm) { + errno = 0; + + void* ptr = shmat(pShm->id, NULL, 0); + if (errno == 0) { + pShm->ptr = ptr; + } + return errno; +} diff --git a/source/os/src/osSignal.c b/source/os/src/osSignal.c index 12721a17f55a3f716c4a65f41121280d6c56cbe3..d4e6cb3318f788e1173c1f25192c59d731e76f37 100644 --- a/source/os/src/osSignal.c +++ b/source/os/src/osSignal.c @@ -71,4 +71,6 @@ void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); } void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); } +void taosKillChildOnParentStopped() { prctl(PR_SET_PDEATHSIG, SIGKILL); } + #endif diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index b130689d4b5aa7bba55d341796cf6416594209d5..d79d7c3d580b53f3de9a1829afee9fe4f40c6892 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -758,7 +758,7 @@ void taosBlockSIGPIPE() { sigset_t signal_mask; sigemptyset(&signal_mask); sigaddset(&signal_mask, SIGPIPE); - int32_t rc = taosThreadSigmask(SIG_BLOCK, &signal_mask, NULL); + int32_t rc = taosThreadSigMask(SIG_BLOCK, &signal_mask, NULL); if (rc != 0) { // printf("failed to block SIGPIPE"); } @@ -876,7 +876,7 @@ void taosSetMaskSIGPIPE() { sigset_t signal_mask; sigemptyset(&signal_mask); sigaddset(&signal_mask, SIGPIPE); - int32_t rc = taosThreadSigmask(SIG_SETMASK, &signal_mask, NULL); + int32_t rc = taosThreadSigMask(SIG_SETMASK, &signal_mask, NULL); if (rc != 0) { // printf("failed to setmask SIGPIPE"); } diff --git a/source/os/src/osThread.c b/source/os/src/osThread.c index 716080274ba74315d6aef9a7bf40ee70738648aa..436614ad6a4fa7ff23187f0f2f2b67dd835f9499 100644 --- a/source/os/src/osThread.c +++ b/source/os/src/osThread.c @@ -14,132 +14,341 @@ */ #define ALLOW_FORBID_FUNC +#include #include "os.h" -// int32_t taosThreadSetnameNp(TdThread thread, const char *name) { -// return pthread_setname_np(thread,name); -// } +int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg) { + return pthread_create(tid, attr, start, arg); +} + +int32_t taosThreadAttrDestroy(TdThreadAttr * attr) { + return pthread_attr_destroy(attr); +} + +int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate) { + return pthread_attr_getdetachstate(attr, detachstate); +} + +int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched) { + return pthread_attr_getinheritsched(attr, inheritsched); +} + +int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param) { + return pthread_attr_getschedparam(attr, param); +} + +int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy) { + return pthread_attr_getschedpolicy(attr, policy); +} + +int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope) { + return pthread_attr_getscope(attr, contentionscope); +} + +int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize) { + return pthread_attr_getstacksize(attr, stacksize); +} + +int32_t taosThreadAttrInit(TdThreadAttr * attr) { + return pthread_attr_init(attr); +} + +int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate) { + return pthread_attr_setdetachstate(attr, detachstate); +} + +int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched) { + return pthread_attr_setinheritsched(attr, inheritsched); +} + +int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param) { + return pthread_attr_setschedparam(attr, param); +} + +int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy) { + return pthread_attr_setschedpolicy(attr, policy); +} + +int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope) { + return pthread_attr_setscope(attr, contentionscope); +} + +int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) { + return pthread_attr_setstacksize(attr, stacksize); +} + +int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier) { + return pthread_barrier_destroy(barrier); +} + +int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count) { + return pthread_barrier_init(barrier, attr, count); +} + +int32_t taosThreadBarrierWait(TdThreadBarrier * barrier) { + return pthread_barrier_wait(barrier); +} + +int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr) { + return pthread_barrierattr_destroy(attr); +} + +int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared) { + return pthread_barrierattr_getpshared(attr, pshared); +} + +int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr) { + return pthread_barrierattr_init(attr); +} + +int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared) { + return pthread_barrierattr_setpshared(attr, pshared); +} + +int32_t taosThreadCancel(TdThread thread) { + return pthread_cancel(thread); +} + +int32_t taosThreadCondDestroy(TdThreadCond * cond) { + return pthread_cond_destroy(cond); +} + +int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr) { + return pthread_cond_init(cond, attr); +} + +int32_t taosThreadCondSignal(TdThreadCond * cond) { + return pthread_cond_signal(cond); +} + +int32_t taosThreadCondBroadcast(TdThreadCond * cond) { + return pthread_cond_broadcast(cond); +} + +int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex) { + return pthread_cond_wait(cond, mutex); +} -int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared) { - return pthread_spin_init(lock, pshared); +int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime) { + return pthread_cond_timedwait(cond, mutex, abstime); } -int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) { - return pthread_mutex_init(mutex, attr); +int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr) { + return pthread_condattr_destroy(attr); } -int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) { - return pthread_spin_destroy(lock); +int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared) { + return pthread_condattr_getpshared(attr, pshared); +} + +int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr) { + return pthread_condattr_init(attr); +} + +int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared) { + return pthread_condattr_setpshared(attr, pshared); +} + +int32_t taosThreadDetach(TdThread thread) { + return pthread_detach(thread); +} + +int32_t taosThreadEqual(TdThread t1, TdThread t2) { + return pthread_equal(t1, t2); +} + +void taosThreadExit(void *valuePtr) { + return pthread_exit(valuePtr); +} + +int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) { + return pthread_getschedparam(thread, policy, param); +} + +void *taosThreadGetSpecific(TdThreadKey key) { + return pthread_getspecific(key); +} + +int32_t taosThreadJoin(TdThread thread, void **valuePtr) { + return pthread_join(thread, valuePtr); +} + +int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *)) { + return pthread_key_create(key, destructor); +} + +int32_t taosThreadKeyDelete(TdThreadKey key) { + return pthread_key_delete(key); +} + +int32_t taosThreadKill(TdThread thread, int32_t sig) { + return pthread_kill(thread, sig); +} + +int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) { + return pthread_mutex_consistent(mutex); } int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) { - return pthread_mutex_destroy(mutex); + return pthread_mutex_destroy(mutex); } -int32_t taosThreadSpinLock(TdThreadSpinlock *lock) { - return pthread_spin_lock(lock); +int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr) { + return pthread_mutex_init(mutex, attr); } -int32_t taosThreadMutexLock(TdThreadMutex *mutex) { - return pthread_mutex_lock(mutex); +int32_t taosThreadMutexLock(TdThreadMutex * mutex) { + return pthread_mutex_lock(mutex); } -int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) { - return pthread_spin_unlock(lock); +int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) { + return pthread_mutex_timedlock(mutex, abstime); } -int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { - return pthread_mutex_unlock(mutex); +int32_t taosThreadMutexTryLock(TdThreadMutex * mutex) { + return pthread_mutex_trylock(mutex); } -int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { - return pthread_rwlock_rdlock(rwlock); +int32_t taosThreadMutexUnlock(TdThreadMutex * mutex) { + return pthread_mutex_unlock(mutex); } -int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { - return pthread_rwlock_wrlock(rwlock); +int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr) { + return pthread_mutexattr_destroy(attr); } -int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { - return pthread_rwlock_unlock(rwlock); +int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared) { + return pthread_mutexattr_getpshared(attr, pshared); } -void taosThreadTestCancel(void) { - return pthread_testcancel(); +int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust) { + return pthread_mutexattr_getrobust(attr, robust); +} + +int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind) { + return pthread_mutexattr_gettype(attr, kind); } -int32_t taosThreadAttrInit(TdThreadAttr *attr) { - return pthread_attr_init(attr); +int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr) { + return pthread_mutexattr_init(attr); } -int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg) { - return pthread_create(tid, attr, start, arg); +int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared) { + return pthread_mutexattr_setpshared(attr, pshared); } -int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void)) { - return pthread_once(onceControl, initRoutine); +int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust) { + return pthread_mutexattr_setrobust(attr, robust); } -int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState) { - return pthread_attr_setdetachstate(attr, detachState); +int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind) { + return pthread_mutexattr_settype(attr, kind); } -int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { - return pthread_attr_destroy(attr); +int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)) { + return pthread_once(onceControl, initRoutine); } -int32_t taosThreadJoin(TdThread thread, void **pValue) { - return pthread_join(thread, pValue); +int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock) { + return pthread_rwlock_destroy(rwlock); } -int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) { - return pthread_rwlock_init(rwlock, attr); +int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr) { + return pthread_rwlock_init(rwlock, attr); } -int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { - return pthread_rwlock_destroy(rwlock); +int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) { + return pthread_rwlock_rdlock(rwlock); } -int32_t taosThreadCondSignal(TdThreadCond *cond) { - return pthread_cond_signal(cond); +int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) { + return pthread_rwlock_timedrdlock(rwlock, abstime); } -int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { - return pthread_cond_init(cond, attr); +int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime) { + return pthread_rwlock_timedwrlock(rwlock, abstime); } -int32_t taosThreadCondBroadcast(TdThreadCond *cond) { - return pthread_cond_broadcast(cond); +int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock) { + return pthread_rwlock_tryrdlock(rwlock); } -int32_t taosThreadCondDestroy(TdThreadCond *cond) { - return pthread_cond_destroy(cond); +int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock) { + return pthread_rwlock_trywrlock(rwlock); } -int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { - return pthread_cond_wait(cond, mutex); +int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock) { + return pthread_rwlock_unlock(rwlock); +} + +int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock) { + return pthread_rwlock_wrlock(rwlock); +} + +int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr) { + return pthread_rwlockattr_destroy(attr); +} + +int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared) { + return pthread_rwlockattr_getpshared(attr, pshared); +} + +int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr) { + return pthread_rwlockattr_init(attr); +} + +int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared) { + return pthread_rwlockattr_setpshared(attr, pshared); } TdThread taosThreadSelf(void) { - return pthread_self(); + return pthread_self(); } -// int32_t taosThreadGetW32ThreadIdNp(TdThread thread) { -// return pthread_getw32threadid_np(thread); -// } +int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { + return pthread_setcancelstate(state, oldstate); +} -int32_t taosThreadEqual(TdThread t1, TdThread t2) { - return pthread_equal(t1, t2); +int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { + return pthread_setcanceltype(type, oldtype); } -int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset) { - return pthread_sigmask(how, set, oset); +int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) { + return pthread_setschedparam(thread, policy, param); } -int32_t taosThreadCancel(TdThread thread) { - return pthread_cancel(thread); +int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { + return pthread_setspecific(key, value); +} + +int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) { + return pthread_spin_destroy(lock); +} + +int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) { + return pthread_spin_init(lock, pshared); +} + +int32_t taosThreadSpinLock(TdThreadSpinlock * lock) { + return pthread_spin_lock(lock); +} + +int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) { + return pthread_spin_trylock(lock); +} + +int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) { + return pthread_spin_unlock(lock); +} + +void taosThreadTestCancel(void) { + return pthread_testcancel(); +} + +int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset) { + return pthread_sigmask(how, set, oset); } -int32_t taosThreadKill(TdThread thread, int sig) { - return pthread_kill(thread, sig); +int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig) { + return sigwait(set, sig); } \ No newline at end of file diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index c98f6eb9be326317dd35dd678fed724ec30546ca..7f9a3ff5939e30384c47dff802fe23bb12066e74 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 96bb638b9555f0612032670b59e0f03a9444e2a8..ce9ef5b1c089a218b420b9ab8b6a67095812c9b6 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/terror.c b/source/util/src/terror.c index 005995c8e2aec90fde5db0d079f8c61a4f50ead0..90fa624a8d3bedc224c07912fd1e435217f07bfe 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -85,7 +85,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization TAOS_DEFINE_ERROR(TSDB_CODE_CFG_NOT_FOUND, "Config not found") TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CFG, "Invalid config option") TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_SHM_MEM, "Out of Share memory") - +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SHM_ID, "Invalid SHM ID") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, "Ref ID is removed") diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 0efcf517a9543730c01a86c19abced72eb3cf39a..93a843fee8ccbece4ac3e690e1905237b7a34485 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/tprocess.c b/source/util/src/tprocess.c index b2d4d1eddc7c8739a818ad8b43ae6e719edef387..1d41bd4a48e616cf16930ffb770b59abdec2785b 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -19,42 +19,40 @@ #include "tlog.h" #include "tqueue.h" -// todo -#include -#include - #define SHM_DEFAULT_SIZE (20 * 1024 * 1024) typedef void *(*ProcThreadFp)(void *param); typedef struct SProcQueue { - int32_t head; - int32_t tail; - int32_t total; - int32_t avail; - int32_t items; - char *pBuffer; - ProcMallocFp mallocHeadFp; - ProcFreeFp freeHeadFp; - ProcMallocFp mallocBodyFp; - ProcFreeFp freeBodyFp; - ProcConsumeFp consumeFp; - void *pParent; - tsem_t sem; - TdThreadMutex *mutex; - int32_t mutexShmid; - int32_t bufferShmid; - const char *name; + int32_t head; + int32_t tail; + int32_t total; + int32_t avail; + int32_t items; + char name[8]; + TdThreadMutex mutex; + tsem_t sem; + char pBuffer[]; } SProcQueue; typedef struct SProcObj { - TdThread childThread; - SProcQueue *pChildQueue; - TdThread parentThread; - SProcQueue *pParentQueue; - const char *name; - int32_t pid; - bool isChild; - bool stopFlag; + TdThread thread; + SProcQueue *pChildQueue; + SProcQueue *pParentQueue; + ProcConsumeFp childConsumeFp; + ProcMallocFp childMallocHeadFp; + ProcFreeFp childFreeHeadFp; + ProcMallocFp childMallocBodyFp; + ProcFreeFp childFreeBodyFp; + ProcConsumeFp parentConsumeFp; + ProcMallocFp parentMallocHeadFp; + ProcFreeFp parentFreeHeadFp; + ProcMallocFp parentMallocBodyFp; + ProcFreeFp parentFreeBodyFp; + void *pParent; + const char *name; + int32_t pid; + bool isChild; + bool stopFlag; } SProcObj; static inline int32_t CEIL8(int32_t v) { @@ -62,149 +60,95 @@ static inline int32_t CEIL8(int32_t v) { return c < 8 ? 8 : c; } -static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { - TdThreadMutex *pMutex = NULL; +static int32_t taosProcInitMutex(SProcQueue *pQueue) { TdThreadMutexAttr mattr = {0}; - int32_t shmid = -1; - int32_t code = -1; - if (pthread_mutexattr_init(&mattr) != 0) { + if (taosThreadMutexAttrInit(&mattr) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); uError("failed to init mutex while init attr since %s", terrstr()); - goto _OVER; + return -1; } - if (pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) { + if (taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) { + taosThreadMutexAttrDestroy(&mattr); terrno = TAOS_SYSTEM_ERROR(errno); uError("failed to init mutex while set shared since %s", terrstr()); - goto _OVER; - } - - shmid = shmget(IPC_PRIVATE, sizeof(TdThreadMutex), IPC_CREAT | 0600); - if (shmid <= 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to init mutex while shmget since %s", terrstr()); - goto _OVER; - } - - pMutex = (TdThreadMutex *)shmat(shmid, NULL, 0); - if (pMutex == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to init mutex while shmat since %s", terrstr()); - goto _OVER; + return -1; } - if (taosThreadMutexInit(pMutex, &mattr) != 0) { + if (taosThreadMutexInit(&pQueue->mutex, &mattr) != 0) { + taosThreadMutexDestroy(&pQueue->mutex); terrno = TAOS_SYSTEM_ERROR(errno); uError("failed to init mutex since %s", terrstr()); - goto _OVER; - } - - code = 0; - -_OVER: - if (code != 0) { - if (pMutex != NULL) { - taosThreadMutexDestroy(pMutex); - shmdt(pMutex); - } - if (shmid >= 0) { - shmctl(shmid, IPC_RMID, NULL); - } - } else { - *ppMutex = pMutex; - *pShmid = shmid; + return -1; } - pthread_mutexattr_destroy(&mattr); - return code; -} - -static void taosProcDestroyMutex(TdThreadMutex *pMutex, int32_t shmid) { - if (pMutex != NULL) { - taosThreadMutexDestroy(pMutex); - } - if (shmid >= 0) { - shmctl(shmid, IPC_RMID, NULL); - } + taosThreadMutexAttrDestroy(&mattr); + return 0; } -static int32_t taosProcInitBuffer(void **ppBuffer, int32_t size) { - int32_t shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600); - if (shmid <= 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to init buffer while shmget since %s", terrstr()); - return -1; - } - - void *shmptr = shmat(shmid, NULL, 0); - if (shmptr == NULL) { +static int32_t taosProcInitSem(SProcQueue *pQueue) { + if (tsem_init(&pQueue->sem, 1, 0) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to init buffer while shmat since %s", terrstr()); - shmctl(shmid, IPC_RMID, NULL); + uError("failed to init sem"); return -1; } - *ppBuffer = shmptr; - return shmid; + return 0; } -static void taosProcDestroyBuffer(void *pBuffer, int32_t shmid) { - if (shmid > 0) { - shmdt(pBuffer); - shmctl(shmid, IPC_RMID, NULL); +static SProcQueue *taosProcInitQueue(const char *name, bool isChild, char *ptr, int32_t size) { + int32_t bufSize = size - CEIL8(sizeof(SProcQueue)); + if (bufSize <= 1024) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; } -} -static SProcQueue *taosProcInitQueue(int32_t size) { - if (size <= 0) size = SHM_DEFAULT_SIZE; + SProcQueue *pQueue = (SProcQueue *)(ptr); - int32_t bufSize = CEIL8(size); - int32_t headSize = CEIL8(sizeof(SProcQueue)); + if (!isChild) { + if (taosProcInitMutex(pQueue) != 0) { + return NULL; + } - SProcQueue *pQueue = NULL; - int32_t shmId = taosProcInitBuffer((void **)&pQueue, bufSize + headSize); - if (shmId < 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - pQueue->bufferShmid = shmId; + if (taosProcInitSem(pQueue) != 0) { + return NULL; + } - if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { - taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); - return NULL; + tstrncpy(pQueue->name, name, sizeof(pQueue->name)); + pQueue->head = 0; + pQueue->tail = 0; + pQueue->total = bufSize; + pQueue->avail = bufSize; + pQueue->items = 0; } - if (tsem_init(&pQueue->sem, 1, 0) != 0) { - taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid); - taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + return pQueue; +} - if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { - tsem_destroy(&pQueue->sem); - taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid); - taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); - return NULL; +#if 0 +static void taosProcDestroyMutex(SProcQueue *pQueue) { + if (pQueue->mutex != NULL) { + taosThreadMutexDestroy(pQueue->mutex); + pQueue->mutex = NULL; } +} - pQueue->head = 0; - pQueue->tail = 0; - pQueue->total = bufSize; - pQueue->avail = bufSize; - pQueue->items = 0; - pQueue->pBuffer = (char *)pQueue + headSize; - return pQueue; +static void taosProcDestroySem(SProcQueue *pQueue) { + if (pQueue->sem != NULL) { + tsem_destroy(pQueue->sem); + pQueue->sem = NULL; + } } +#endif static void taosProcCleanupQueue(SProcQueue *pQueue) { +#if 0 if (pQueue != NULL) { - uDebug("proc:%s, queue:%p clean up", pQueue->name, pQueue); - tsem_destroy(&pQueue->sem); - taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid); - taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); + taosProcDestroyMutex(pQueue); + taosProcDestroySem(pQueue); } +#endif } static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, const char *pBody, @@ -213,9 +157,9 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t const int32_t bodyLen = CEIL8(rawBodyLen); const int32_t fullLen = headLen + bodyLen + 8; - taosThreadMutexLock(pQueue->mutex); + taosThreadMutexLock(&pQueue->mutex); if (fullLen > pQueue->avail) { - taosThreadMutexUnlock(pQueue->mutex); + taosThreadMutexUnlock(&pQueue->mutex); terrno = TSDB_CODE_OUT_OF_SHM_MEM; return -1; } @@ -264,7 +208,7 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t pQueue->avail -= fullLen; pQueue->items++; - taosThreadMutexUnlock(pQueue->mutex); + taosThreadMutexUnlock(&pQueue->mutex); tsem_post(&pQueue->sem); uTrace("proc:%s, push msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype, @@ -272,14 +216,14 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t return 0; } -static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, - int32_t *pBodyLen, ProcFuncType *pFuncType) { +static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, int32_t *pBodyLen, + ProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp, + ProcMallocFp mallocBodyFp, ProcFreeFp freeBodyFp) { tsem_wait(&pQueue->sem); - taosThreadMutexLock(pQueue->mutex); + taosThreadMutexLock(&pQueue->mutex); if (pQueue->total - pQueue->avail <= 0) { - taosThreadMutexUnlock(pQueue->mutex); - tsem_post(&pQueue->sem); + taosThreadMutexUnlock(&pQueue->mutex); terrno = TSDB_CODE_OUT_OF_SHM_MEM; return 0; } @@ -297,13 +241,13 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea bodyLen = *(int32_t *)(pQueue->pBuffer + 4); } - void *pHead = (*pQueue->mallocHeadFp)(headLen); - void *pBody = (*pQueue->mallocBodyFp)(bodyLen); + void *pHead = (*mallocHeadFp)(headLen); + void *pBody = (*mallocBodyFp)(bodyLen); if (pHead == NULL || pBody == NULL) { - taosThreadMutexUnlock(pQueue->mutex); + taosThreadMutexUnlock(&pQueue->mutex); tsem_post(&pQueue->sem); - (*pQueue->freeHeadFp)(pHead); - (*pQueue->freeBodyFp)(pBody); + (*freeHeadFp)(pHead); + (*freeBodyFp)(pBody); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -342,7 +286,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea pQueue->avail = pQueue->avail + headLen + bodyLen + 8; pQueue->items--; - taosThreadMutexUnlock(pQueue->mutex); + taosThreadMutexUnlock(&pQueue->mutex); *ppHead = pHead; *ppBody = pBody; @@ -362,65 +306,85 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { return NULL; } + int32_t cstart = 0; + int32_t csize = CEIL8(pCfg->shm.size / 2); + int32_t pstart = csize; + int32_t psize = CEIL8(pCfg->shm.size - pstart); + if (pstart + psize > pCfg->shm.size) { + psize -= 8; + } + pProc->name = pCfg->name; - pProc->pChildQueue = taosProcInitQueue(pCfg->childQueueSize); - pProc->pParentQueue = taosProcInitQueue(pCfg->parentQueueSize); + 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); taosMemoryFree(pProc); return NULL; } - pProc->pChildQueue->name = pCfg->name; - pProc->pChildQueue->pParent = pCfg->pParent; - pProc->pChildQueue->mallocHeadFp = pCfg->childMallocHeadFp; - pProc->pChildQueue->freeHeadFp = pCfg->childFreeHeadFp; - pProc->pChildQueue->mallocBodyFp = pCfg->childMallocBodyFp; - pProc->pChildQueue->freeBodyFp = pCfg->childFreeBodyFp; - pProc->pChildQueue->consumeFp = pCfg->childConsumeFp; - pProc->pParentQueue->name = pCfg->name; - pProc->pParentQueue->pParent = pCfg->pParent; - pProc->pParentQueue->mallocHeadFp = pCfg->parentdMallocHeadFp; - pProc->pParentQueue->freeHeadFp = pCfg->parentFreeHeadFp; - pProc->pParentQueue->mallocBodyFp = pCfg->parentMallocBodyFp; - pProc->pParentQueue->freeBodyFp = pCfg->parentFreeBodyFp; - pProc->pParentQueue->consumeFp = pCfg->parentConsumeFp; - - uDebug("proc:%s, is initialized, child queue:%p parent queue:%p", pProc->name, pProc->pChildQueue, pProc->pParentQueue); - - pProc->pid = fork(); - if (pProc->pid == 0) { - pProc->isChild = 1; - prctl(PR_SET_NAME, pProc->name, NULL, NULL, NULL); - } else { - pProc->isChild = 0; - uInfo("this is parent process, child pid:%d", pProc->pid); - } + pProc->name = pCfg->name; + pProc->pParent = pCfg->pParent; + pProc->childMallocHeadFp = pCfg->childMallocHeadFp; + pProc->childFreeHeadFp = pCfg->childFreeHeadFp; + pProc->childMallocBodyFp = pCfg->childMallocBodyFp; + pProc->childFreeBodyFp = pCfg->childFreeBodyFp; + pProc->childConsumeFp = pCfg->childConsumeFp; + pProc->parentMallocHeadFp = pCfg->parentMallocHeadFp; + pProc->parentFreeHeadFp = pCfg->parentFreeHeadFp; + pProc->parentMallocBodyFp = pCfg->parentMallocBodyFp; + pProc->parentFreeBodyFp = pCfg->parentFreeBodyFp; + pProc->parentConsumeFp = pCfg->parentConsumeFp; + pProc->isChild = pCfg->isChild; + + uDebug("proc:%s, is initialized, isChild:%d child queue:%p parent queue:%p", pProc->name, pProc->isChild, + pProc->pChildQueue, pProc->pParentQueue); return pProc; } -static void taosProcThreadLoop(SProcQueue *pQueue) { - ProcConsumeFp consumeFp = pQueue->consumeFp; - void *pParent = pQueue->pParent; +static void taosProcThreadLoop(SProcObj *pProc) { void *pHead, *pBody; int16_t headLen; ProcFuncType ftype; int32_t bodyLen; + SProcQueue *pQueue; + ProcConsumeFp consumeFp; + ProcMallocFp mallocHeadFp; + ProcFreeFp freeHeadFp; + ProcMallocFp mallocBodyFp; + ProcFreeFp freeBodyFp; - uDebug("proc:%s, start to get msg from queue:%p", pQueue->name, pQueue); + if (pProc->isChild) { + pQueue = pProc->pChildQueue; + consumeFp = pProc->childConsumeFp; + mallocHeadFp = pProc->childMallocHeadFp; + freeHeadFp = pProc->childFreeHeadFp; + mallocBodyFp = pProc->childMallocBodyFp; + freeBodyFp = pProc->childFreeBodyFp; + } else { + pQueue = pProc->pParentQueue; + consumeFp = pProc->parentConsumeFp; + mallocHeadFp = pProc->parentMallocHeadFp; + freeHeadFp = pProc->parentFreeHeadFp; + mallocBodyFp = pProc->parentMallocBodyFp; + freeBodyFp = pProc->parentFreeBodyFp; + } + + uDebug("proc:%s, start to get msg from queue:%p", pProc->name, pQueue); while (1) { - int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype); + int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype, mallocHeadFp, freeHeadFp, + mallocBodyFp, freeBodyFp); if (numOfMsgs == 0) { - uDebug("proc:%s, get no msg from queue:%p and exit the proc thread", pQueue->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", pQueue->name, pQueue, terrstr()); + uTrace("proc:%s, get no msg from queue:%p since %s", pProc->name, pQueue, terrstr()); taosMsleep(1); continue; } else { - (*consumeFp)(pParent, pHead, headLen, pBody, bodyLen, ftype); + (*consumeFp)(pProc->pParent, pHead, headLen, pBody, bodyLen, ftype); } } } @@ -430,40 +394,37 @@ int32_t taosProcRun(SProcObj *pProc) { taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); - if (pProc->isChild) { - if (taosThreadCreate(&pProc->childThread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc->pChildQueue) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to create thread since %s", terrstr()); - return -1; - } - uDebug("proc:%s, child start to consume queue:%p", pProc->name, pProc->pChildQueue); - } else { - if (taosThreadCreate(&pProc->parentThread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc->pParentQueue) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to create thread since %s", terrstr()); - return -1; - } - uDebug("proc:%s, parent start to consume queue:%p", pProc->name, pProc->pParentQueue); + if (taosThreadCreate(&pProc->thread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + uError("failed to create thread since %s", terrstr()); + return -1; } + uDebug("proc:%s, start to consume queue:%p, thread:%" PRId64, pProc->name, pProc->pChildQueue, pProc->thread); return 0; } -void taosProcStop(SProcObj *pProc) { - pProc->stopFlag = true; - // todo join -} - -bool taosProcIsChild(SProcObj *pProc) { return pProc->isChild; } +static void taosProcStop(SProcObj *pProc) { + if (!taosCheckPthreadValid(pProc->thread)) return; -int32_t taosProcChildId(SProcObj *pProc) { return pProc->pid; } + uDebug("proc:%s, start to join thread:%" PRId64, pProc->name, pProc->thread); + SProcQueue *pQueue; + if (pProc->isChild) { + pQueue = pProc->pChildQueue; + } else { + pQueue = pProc->pParentQueue; + } + tsem_post(&pQueue->sem); + taosThreadJoin(pProc->thread, NULL); +} 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); + uDebug("proc:%s, is cleaned up", pProc->name); taosMemoryFree(pProc); } } diff --git a/source/util/test/queueTest.cpp b/source/util/test/queueTest.cpp index 09c544df9f27f9f897d6376e5c08fbee9efe2057..0c4bcf84ad7ff937b0230aa39822af831ca2d72b 100644 --- a/source/util/test/queueTest.cpp +++ b/source/util/test/queueTest.cpp @@ -26,108 +26,3 @@ class UtilTestQueue : public ::testing::Test { static void SetUpTestSuite() {} static void TearDownTestSuite() {} }; - -#if 0 -TEST_F(UtilTestQueue, 01_fork) { - pid_t pid; - int shmid; - int* shmptr; - int* tmp; - - int err; - pthread_mutexattr_t mattr; - if ((err = pthread_mutexattr_init(&mattr)) < 0) { - printf("mutex addr init error:%s\n", strerror(err)); - exit(1); - } - - if ((err = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED)) < 0) { - printf("mutex addr get shared error:%s\n", strerror(err)); - exit(1); - } - - pthread_mutex_t* m; - int mid = shmget(IPC_PRIVATE, sizeof(pthread_mutex_t), 0600); - m = (pthread_mutex_t*)shmat(mid, NULL, 0); - - if ((err = pthread_mutex_init(m, &mattr)) < 0) { - printf("mutex mutex init error:%s\n", strerror(err)); - exit(1); - } - - if ((shmid = shmget(IPC_PRIVATE, 1000, IPC_CREAT | 0600)) < 0) { - perror("shmget error"); - exit(1); - } - - if ((shmptr = (int*)shmat(shmid, 0, 0)) == (void*)-1) { - perror("shmat error"); - exit(1); - } - - tmp = shmptr; - - int shmid2; - int** shmptr2; - if ((shmid2 = shmget(IPC_PRIVATE, 20, IPC_CREAT | 0600)) < 0) { - perror("shmget2 error"); - exit(1); - } - - if ((shmptr2 = (int**)shmat(shmid2, 0, 0)) == (void*)-1) { - perror("shmat2 error"); - exit(1); - } - - *shmptr2 = shmptr; - - if ((pid = fork()) < 0) { - perror("fork error"); - exit(1); - } else if (pid == 0) { - if ((err = taosThreadMutexLock(m)) < 0) { - printf("lock error:%s\n", strerror(err)); - exit(1); - } - for (int i = 0; i < 30; ++i) { - **shmptr2 = i; - (*shmptr2)++; - } - - if ((err = taosThreadMutexUnlock(m)) < 0) { - printf("unlock error:%s\n", strerror(err)); - exit(1); - } - exit(0); - - } else { - if ((err = taosThreadMutexLock(m)) < 0) { - printf("lock error:%s\n", strerror(err)); - exit(1); - } - for (int i = 10; i < 42; ++i) { - **shmptr2 = i; - (*shmptr2)++; - } - if ((err = taosThreadMutexUnlock(m)) < 0) { - printf("unlock error:%s\n", strerror(err)); - exit(1); - } - } - - wait(NULL); - - for (int i = 0; i < 70; ++i) { - printf("%d ", tmp[i]); - } - - printf("\n"); - - taosThreadAttrDestroy(&mattr); - //销毁mutex - pthread_mutex_destroy(m); - - exit(0); -} - -#endif \ No newline at end of file diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 2b654a379369c67cf906be0dde2f0cc4a309e1ea..9fe4ffa0d47735c032418796b6068f931bf08d95 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -50,7 +50,10 @@ class TDSql: def prepare(self): tdLog.info("prepare database:db") s = 'reset query cache' - self.cursor.execute(s) + try: + self.cursor.execute(s) + except: + tdLog.notice("'reset query cache' is not supported") s = 'drop database if exists db' self.cursor.execute(s) s = 'create database db' @@ -341,4 +344,4 @@ class TDSql: tdLog.info("dir: %s is created" %dir) pass -tdSql = TDSql() \ No newline at end of file +tdSql = TDSql() diff --git a/tests/script/general/stable/disk.sim b/tests/script/general/stable/disk.sim deleted file mode 100644 index 1faae78e898107af6d3a1140413ffe16b0680e26..0000000000000000000000000000000000000000 --- a/tests/script/general/stable/disk.sim +++ /dev/null @@ -1,199 +0,0 @@ -system sh/stop_dnodes.sh - - -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ======================== dnode1 start - -$dbPrefix = d_db -$tbPrefix = d_tb -$mtPrefix = d_mt -$tbNum = 10 -$rowNum = 20 -$totalNum = 200 - -print =============== step1 -$i = 0 -$db = $dbPrefix . $i -$mt = $mtPrefix . $i - -sql create database $db -sql use $db -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) - -$i = 0 -while $i < $tbNum - $tb = $tbPrefix . $i - sql create table $tb using $mt tags( $i ) - - $x = 0 - while $x < $rowNum - $val = $x * 60000 - $ms = 1519833600000 + $val - sql insert into $tb values ($ms , $x ) - $x = $x + 1 - endw - - $i = $i + 1 -endw - -sql show vgroups -print vgroups ==> $rows -if $rows != 3 then - return -1 -endi - -sql select count(*) from $mt -print select count(*) from $mt ===> $data00 -if $data00 != $totalNum then - return -1 -endi - -sleep 1000 -system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 3000 -system sh/exec.sh -n dnode1 -s start -sleep 6000 - -sql use $db -sql show vgroups -print vgroups ==> $rows -if $rows != 3 then - return -1 -endi - -print =============== step2 -$i = 1 -$tb = $tbPrefix . $i - -sql select count(*) from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -sql select count(tbcol) from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -print =============== step3 -sql select count(tbcol) from $tb where ts <= 1519833840000 -print ===> $data00 -if $data00 != 5 then - return -1 -endi - -print =============== step4 -sql select count(tbcol) as b from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -print =============== step5 -sql select count(tbcol) as b from $tb interval(1m) -print ===> $data01 -if $data01 != 1 then - return -1 -endi - -sql select count(tbcol) as b from $tb interval(1d) -print ===> $data01 -if $data01 != $rowNum then - return -1 -endi - -print =============== step6 -sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) -print ===> $data01 -if $data01 != 1 then - return -1 -endi -if $rows != 5 then - return -1 -endi - -print =============== step7 -sql select count(*) from $mt -print select count(*) from $mt ===> $data00 -if $data00 != $totalNum then - return -1 -endi - -sql select count(tbcol) from $mt -print ===> $data00 -if $data00 != $totalNum then - return -1 -endi - -print =============== step8 -sql select count(tbcol) as c from $mt where ts <= 1519833840000 -print ===> $data00 -if $data00 != 50 then - return -1 -endi - -sql select count(tbcol) as c from $mt where tgcol < 5 -print ===> $data00 -if $data00 != 100 then - return -1 -endi - -sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 -print ===> $data00 -if $data00 != 25 then - return -1 -endi - -print =============== step9 -sql select count(tbcol) as b from $mt interval(1m) -print select count(tbcol) as b from $mt interval(1m) ===> $data01 -if $data01 != 10 then - return -1 -endi - -sql select count(tbcol) as b from $mt interval(1d) -print ===> $data02 -if $data01 != 200 then - return -1 -endi - -print =============== step10 -print select count(tbcol) as b from $mt group by tgcol -sql select count(tbcol) as b from $mt group by tgcol -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -if $rows != $tbNum then - return -1 -endi - -print =============== step11 -sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol -print ===> $data01 -if $data01 != 1 then - return -1 -endi -if $rows != 50 then - return -1 -endi - -print =============== clear -sql drop database $db -sql show databases -if $rows != 0 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/stable/dnode3.sim b/tests/script/general/stable/dnode3.sim deleted file mode 100644 index 872cfb8d2e5022872e30eaabd7db67a4546a0204..0000000000000000000000000000000000000000 --- a/tests/script/general/stable/dnode3.sim +++ /dev/null @@ -1,212 +0,0 @@ -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/deploy.sh -n dnode4 -i 4 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode2 -c walLevel -v 1 -system sh/cfg.sh -n dnode3 -c walLevel -v 1 -system sh/cfg.sh -n dnode4 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/exec.sh -n dnode1 -s start - -sql connect - -sql create dnode $hostname2 -sql create dnode $hostname3 -sql create dnode $hostname4 -system sh/exec.sh -n dnode2 -s start -system sh/exec.sh -n dnode3 -s start -system sh/exec.sh -n dnode4 -s start -$x = 0 -createDnode: - $x = $x + 1 - sleep 1000 - if $x == 20 then - return -1 - endi -sql show dnodes; -if $data4_2 == offline then - goto createDnode -endi -if $data4_3 == offline then - goto createDnode -endi -if $data4_4 == offline then - goto createDnode -endi - -print ======================== dnode1 start - -$dbPrefix = r3v3_db -$tbPrefix = r3v3_tb -$mtPrefix = r3v3_mt -$tbNum = 10 -$rowNum = 20 -$totalNum = 200 - -print =============== step1 -$i = 0 -$db = $dbPrefix . $i -$mt = $mtPrefix . $i - -sql create database $db -sql use $db -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) - -$i = 0 -while $i < $tbNum - $tb = $tbPrefix . $i - sql create table $tb using $mt tags( $i ) - - $x = 0 - while $x < $rowNum - $val = $x * 60000 - $ms = 1519833600000 + $val - sql insert into $tb values ($ms , $x ) - $x = $x + 1 - endw - - $i = $i + 1 -endw - -sql show vgroups -print vgroups ==> $rows -if $rows != 3 then - return -1 -endi - -sleep 100 - -print =============== step2 -$i = 1 -$tb = $tbPrefix . $i - -sql select count(*) from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -sql select count(tbcol) from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -print =============== step3 -sql select count(tbcol) from $tb where ts <= 1519833840000 -print ===> $data00 -if $data00 != 5 then - return -1 -endi - -print =============== step4 -sql select count(tbcol) as b from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -print =============== step5 -sql select count(tbcol) as b from $tb interval(1m) -print ===> $data01 -if $data01 != 1 then - return -1 -endi - -sql select count(tbcol) as b from $tb interval(1d) -print ===> $data01 -if $data01 != $rowNum then - return -1 -endi - -print =============== step6 -sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) -print ===> $data01 -if $data01 != 1 then - return -1 -endi -if $rows != 5 then - return -1 -endi - -print =============== step7 -print select count(*) from $mt -sql select count(*) from $mt -print ===> $data00 -if $data00 != $totalNum then - return -1 -endi - -sql select count(tbcol) from $mt -print ===> $data00 -if $data00 != $totalNum then - return -1 -endi - -print =============== step8 -sql select count(tbcol) as c from $mt where ts <= 1519833840000 -print ===> $data00 -if $data00 != 50 then - return -1 -endi - -sql select count(tbcol) as c from $mt where tgcol < 5 -print ===> $data00 -if $data00 != 100 then - return -1 -endi - -sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 -print ===> $data00 -if $data00 != 25 then - return -1 -endi - -print =============== step9 -sql select count(tbcol) as b from $mt interval(1m) -print ===> $data01 -if $data01 != 10 then - return -1 -endi - -sql select count(tbcol) as b from $mt interval(1d) -print ===> $data01 -if $data01 != 200 then - return -1 -endi - -print =============== step10 -sql select count(tbcol) as b from $mt group by tgcol -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -if $rows != $tbNum then - return -1 -endi - -print =============== step11 -sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol -print ===> $data01 -if $data01 != 1 then - return -1 -endi -if $rows != 50 then - return -1 -endi - -print =============== clear -sql drop database $db -sql show databases -if $rows != 0 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/stable/values.sim b/tests/script/general/stable/values.sim deleted file mode 100644 index fb2c908da269872ddd85489d9d98510e1bb58749..0000000000000000000000000000000000000000 --- a/tests/script/general/stable/values.sim +++ /dev/null @@ -1,113 +0,0 @@ -system sh/stop_dnodes.sh - - -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ======================== dnode1 start - -sql create database vdb0 -sql create table vdb0.mt (ts timestamp, tbcol int) TAGS(tgcol int) - -sql create table vdb0.vtb00 using vdb0.mt tags( 0 ) -sql create table vdb0.vtb01 using vdb0.mt tags( 0 ) - -sql create database vdb1 -sql create table vdb1.mt (ts timestamp, tbcol int) TAGS(tgcol int) -sql_error create table vdb1.vtb10 using vdb0.mt tags( 1 ) -sql_error create table vdb1.vtb11 using vdb0.mt tags( 1 ) -sql create table vdb1.vtb10 using vdb1.mt tags( 1 ) -sql create table vdb1.vtb11 using vdb1.mt tags( 1 ) - -sql create database vdb2 -sql create table vdb2.mt (ts timestamp, tbcol int) TAGS(tgcol int) -sql_error create table vdb2.vtb20 using vdb0.mt tags( 2 ) -sql_error create table vdb2.vtb21 using vdb0.mt tags( 2 ) -sql create table vdb2.vtb20 using vdb2.mt tags( 2 ) -sql create table vdb2.vtb21 using vdb2.mt tags( 2 ) - -sql create database vdb3 -sql create table vdb3.mt (ts timestamp, tbcol int) TAGS(tgcol int) -sql_error create table vdb3.vtb20 using vdb0.mt tags( 2 ) -sql_error create table vdb3.vtb21 using vdb0.mt tags( 2 ) -sql create table vdb3.vtb30 using vdb3.mt tags( 3 ) -sql create table vdb3.vtb31 using vdb3.mt tags( 3 ) - -print =============== step2 -sql insert into vdb0.vtb00 values (1519833600000 , 10) (1519833600001, 20) (1519833600002, 30) -sql insert into vdb0.vtb01 values (1519833600000 , 10) (1519833600001, 20) (1519833600002, 30) -sql insert into vdb1.vtb10 values (1519833600000 , 11) (1519833600001, 21) (1519833600002, 31) -sql insert into vdb1.vtb11 values (1519833600000 , 11) (1519833600001, 21) (1519833600002, 31) -sql insert into vdb2.vtb20 values (1519833600000 , 12) (1519833600001, 22) (1519833600002, 32) -sql insert into vdb2.vtb21 values (1519833600000 , 12) (1519833600001, 22) (1519833600002, 32) -sql insert into vdb3.vtb30 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33) -sql insert into vdb3.vtb31 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33) -sql select * from vdb0.mt - -if $rows != 6 then - return -1 -endi - -print =============== step3 -sql insert into vdb0.vtb00 values (1519833600003 , 40) (1519833600005, 50) (1519833600004, 60) -sql insert into vdb0.vtb01 values (1519833600003 , 40) (1519833600005, 50) (1519833600004, 60) -sql insert into vdb1.vtb10 values (1519833600003 , 41) (1519833600005, 51) (1519833600004, 61) -sql insert into vdb1.vtb11 values (1519833600003 , 41) (1519833600005, 51) (1519833600004, 61) -sql insert into vdb2.vtb20 values (1519833600003 , 42) (1519833600005, 52) (1519833600004, 62) -sql insert into vdb2.vtb21 values (1519833600003 , 42) (1519833600005, 52) (1519833600004, 62) -sql insert into vdb3.vtb30 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63) -sql insert into vdb3.vtb31 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63) -sql select * from vdb0.mt - -if $rows != 12 then - return -1 -endi - -print =============== step4 -sql insert into vdb0.vtb00 values(1519833600006, 60) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 60) (1519833600007, 70) -sql insert into vdb1.vtb10 values(1519833600006, 61) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 61) (1519833600007, 71) -sql insert into vdb2.vtb20 values(1519833600006, 62) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 62) (1519833600007, 72) -sql insert into vdb3.vtb30 values(1519833600006, 63) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 63) (1519833600007, 73) -sql select * from vdb0.mt - -if $rows != 16 then - return -1 -endi - -print =============== step5 -sql insert into vdb0.vtb00 values(1519833600008, 80) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 80) (1519833600007, 70) -sql insert into vdb1.vtb10 values(1519833600008, 81) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 81) (1519833600007, 71) -sql insert into vdb2.vtb20 values(1519833600008, 82) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 82) (1519833600007, 72) -sql insert into vdb3.vtb30 values(1519833600008, 83) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 83) (1519833600007, 73) -sql select * from vdb0.mt - -if $rows != 17 then - return -1 -endi - -print =============== step6 -sql insert into vdb0.vtb00 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb10 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb20 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb30 values(1519833600009, 90) (1519833600010, 100) -sql insert into vdb0.vtb01 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb11 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb21 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb31 values(1519833600009, 90) (1519833600010, 100) - -sql select * from vdb0.mt - -if $rows != 21 then - return -1 -endi - -print =============== step7 -sql insert into vdb0.vtb00 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb10 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb20 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb30 values(1519833600012, 120) (1519833600011, 110) -sql insert into vdb0.vtb01 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb11 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb21 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb31 values(1519833600012, 120) (1519833600011, 110) - -sql select * from vdb0.mt - -if $rows != 25 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/stable/vnode3.sim b/tests/script/general/stable/vnode3.sim deleted file mode 100644 index 61948b506302f803aee2f73eb5e528e14f1174db..0000000000000000000000000000000000000000 --- a/tests/script/general/stable/vnode3.sim +++ /dev/null @@ -1,179 +0,0 @@ -system sh/stop_dnodes.sh - -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ======================== dnode1 start - -$dbPrefix = v3_db -$tbPrefix = v3_tb -$mtPrefix = v3_mt -$tbNum = 10 -$rowNum = 20 -$totalNum = 200 - -print =============== step1 -$i = 0 -$db = $dbPrefix . $i -$mt = $mtPrefix . $i - -sql create database $db -sql use $db -sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) - -$i = 0 -while $i < $tbNum - $tb = $tbPrefix . $i - sql create table $tb using $mt tags( $i ) - - $x = 0 - while $x < $rowNum - $val = $x * 60000 - $ms = 1519833600000 + $val - sql insert into $tb values ($ms , $x ) - $x = $x + 1 - endw - - $i = $i + 1 -endw - -sql show vgroups -print vgroups ==> $rows -if $rows != 3 then - return -1 -endi - - -print =============== step2 -$i = 1 -$tb = $tbPrefix . $i - -sql select count(*) from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -sql select count(tbcol) from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -print =============== step3 -sql select count(tbcol) from $tb where ts <= 1519833840000 -print ===> $data00 -if $data00 != 5 then - return -1 -endi - -print =============== step4 -sql select count(tbcol) as b from $tb -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -print =============== step5 -sql select count(tbcol) as b from $tb interval(1m) -print ===> $data01 -if $data01 != 1 then - return -1 -endi - -sql select count(tbcol) as b from $tb interval(1d) -print ===> $data01 -if $data01 != $rowNum then - return -1 -endi - -print =============== step6 -sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) -print ===> $data01 -if $data01 != 1 then - return -1 -endi -if $rows != 5 then - return -1 -endi - -print =============== step7 -sql select count(*) from $mt -print ===> $data00 -if $data00 != $totalNum then - return -1 -endi - -sql select count(tbcol) from $mt -print ===> $data00 -if $data00 != $totalNum then - return -1 -endi - -print =============== step8 -sql select count(tbcol) as c from $mt where ts <= 1519833840000 -print ===> $data00 -if $data00 != 50 then - return -1 -endi - -sql select count(tbcol) as c from $mt where tgcol < 5 -print ===> $data00 -if $data00 != 100 then - return -1 -endi - -sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 -print ===> $data00 -if $data00 != 25 then - return -1 -endi - -print =============== step9 -sql select count(tbcol) as b from $mt interval(1m) -print ===> $data01 -if $data01 != 10 then - return -1 -endi - -sql select count(tbcol) as b from $mt interval(1d) -print ===> $data01 -if $data01 != 200 then - return -1 -endi - -print =============== step10 -sql select count(tbcol) as b from $mt group by tgcol -print ===> $data00 -if $data00 != $rowNum then - return -1 -endi - -if $rows != $tbNum then - return -1 -endi - -print =============== step11 -sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol -print ===> $data01 -if $data01 != 1 then - return -1 -endi -if $rows != 50 then - return -1 -endi - -print =============== clear -sql drop database $db -sql show databases -if $rows != 0 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2cad51812822ef6fc1ddabbd755cbf4713674b1f..5c503c39bb82cafb07b955f9574aae4f3a46ad48 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -2,9 +2,10 @@ #======================b1-start=============== # ---- user -./test.sh -f tsim/user/basic1.sim +./test.sh -f tsim/user/basic1.sim # ---- db +./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,21 +23,33 @@ ./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 +./test.sh -f tsim/show/basic.sim # ---- table -./test.sh -f tsim/table/basic1.sim +./test.sh -f tsim/table/basic1.sim # ---- 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 +./test.sh -f tsim/stable/dnode3.sim +./test.sh -f tsim/stable/metrics.sim +./test.sh -f tsim/stable/refcount.sim +# ./test.sh -f tsim/stable/show.sim +./test.sh -f tsim/stable/values.sim +./test.sh -f tsim/stable/vnode3.sim #======================b1-end=============== diff --git a/tests/script/runAllSimCases.sh b/tests/script/runAllSimCases.sh new file mode 100755 index 0000000000000000000000000000000000000000..e1eea1cc385cd123c4a0e4683574c1e2a65be942 --- /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 ea1ad65a5bd1eb24c2db06264dcbaa8fa3fb2abc..1bbfccf98946c9f16cc06e285255f92eeff504bf 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -124,7 +124,7 @@ echo "firstEp ${HOSTNAME}:7100" >> $TAOS_CFG echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG echo "fqdn ${HOSTNAME}" >> $TAOS_CFG echo "serverPort ${NODE}" >> $TAOS_CFG -echo "supportVnodes 128" >> $TAOS_CFG +echo "supportVnodes 128" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG echo "debugFlag 0" >> $TAOS_CFG @@ -133,20 +133,17 @@ echo "dDebugFlag 143" >> $TAOS_CFG echo "vDebugFlag 143" >> $TAOS_CFG echo "tsdbDebugFlag 143" >> $TAOS_CFG echo "cDebugFlag 143" >> $TAOS_CFG -echo "jnidebugFlag 143" >> $TAOS_CFG -echo "qdebugFlag 143" >> $TAOS_CFG +echo "jniDebugFlag 143" >> $TAOS_CFG +echo "qDebugFlag 143" >> $TAOS_CFG echo "rpcDebugFlag 143" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG -echo "udebugFlag 143" >> $TAOS_CFG -echo "sdebugFlag 143" >> $TAOS_CFG -echo "wdebugFlag 143" >> $TAOS_CFG -echo "slaveQuery 0" >> $TAOS_CFG -echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG -echo "defaultPass taosdata" >> $TAOS_CFG +echo "uDebugFlag 143" >> $TAOS_CFG +echo "sDebugFlag 143" >> $TAOS_CFG +echo "wDebugFlag 143" >> $TAOS_CFG echo "numOfLogLines 20000000" >> $TAOS_CFG echo "statusInterval 1" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG -echo "fsync 0" >> $TAOS_CFG echo "telemetryReporting 0" >> $TAOS_CFG +echo "multiProcess 0" >> $TAOS_CFG echo " " >> $TAOS_CFG diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 8d7dba2de2a456a21e051ffa04acecf17157af25..1a9a6a2c5220184b99a6fe864372f585fd5c56bc 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -74,7 +74,7 @@ BUILD_DIR=$TAOS_DIR/$BIN_DIR SIM_DIR=$TAOS_DIR/sim NODE_DIR=$SIM_DIR/$NODE_NAME -EXE_DIR=$BUILD_DIR/source/dnode/mgmt/main +EXE_DIR=$BUILD_DIR/source/dnode/mgmt CFG_DIR=$NODE_DIR/cfg LOG_DIR=$NODE_DIR/log DATA_DIR=$NODE_DIR/data diff --git a/tests/script/sh/massiveTable/compileVersion.sh b/tests/script/sh/massiveTable/compileVersion.sh index 13b2baae32c6b559861a3fc3b11fcaf539ac88f8..68c049cad706435fba1d574451211e7bbf257d20 100755 --- a/tests/script/sh/massiveTable/compileVersion.sh +++ b/tests/script/sh/massiveTable/compileVersion.sh @@ -68,7 +68,7 @@ gitPullBranchInfo $TDengineBrVer compileTDengineVersion taos_dir=${projectDir}/debug/tools/shell -taosd_dir=${projectDir}/debug/source/dnode/mgmt/main +taosd_dir=${projectDir}/debug/source/dnode/mgmt exec_process_dir=${projectDir}/debug/tests/test/c rm -f /usr/bin/taos diff --git a/tests/script/tsim/db/alter_option.sim b/tests/script/tsim/db/alter_option.sim new file mode 100644 index 0000000000000000000000000000000000000000..f79bf88ad23ab676210c24c680e62e63c2ba928e --- /dev/null +++ b/tests/script/tsim/db/alter_option.sim @@ -0,0 +1,353 @@ +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 +#database_option: { +# BLOCKS value [3~1000, default: 6] +# | CACHELAST value [0, 1, 2, 3] +# | FSYNC value [0 ~ 180000 ms] +# | KEEP value [days, 365000] +# | QUORUM value [1 | 2] +# | REPLICA value [1 | 3] +# | WAL value [1 | 2] + +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 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 +print ====> dataX_db +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 != 6 then # vgroups + return -1 +endi +if $data3_db != 0 then # ntables + return -1 +endi +if $data4_db != 3 then # replica + return -1 +endi +if $data5_db != 1 then # quorum + return -1 +endi +if $data6_db != 345600 then # days + return -1 +endi +if $data7_db != 1440000,1440000,1440000 then # keep + return -1 +endi +if $data8_db != 3 then # cache + return -1 +endi +if $data9_db != 7 then # blocks + return -1 +endi +if $data10_db != 10 then # minrows + return -1 +endi +if $data11_db != 8000 then # maxrows + return -1 +endi +if $data12_db != 2 then # wal + return -1 +endi +if $data13_db != 1000 then # fsync + return -1 +endi +if $data14_db != 0 then # comp + return -1 +endi +if $data15_db != 3 then # cachelast + return -1 +endi +if $data16_db != ns then # precision + return -1 +endi + +print ============== not support modify options: name, create_time, vgroups, ntables +sql_error alter database db name dba +sql_error alter database db create_time "2022-03-03 15:08:13.329" +sql_error alter database db vgroups -1 +sql_error alter database db vgroups 0 +sql_error alter database db vgroups 2 +sql_error alter database db vgroups 20 +sql_error alter database db ntables -1 +sql_error alter database db ntables 0 +sql_error alter database db ntables 1 +sql_error alter database db ntables 10 + +#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 +sql_error alter database db replica 0 +#sql alter database db replica 1 +#sql show databases +#print replica: $data4_db +#if $data4_db != 1 then +# return -1 +#endi +#sql alter database db replica 3 +#sql show databases +#print replica: $data4_db +#if $data4_db != 3 then +# return -1 +#endi + +print ============== modify quorum +sql alter database db quorum 2 +sql show databases +print quorum $data5_db +if $data5_db != 2 then + return -1 +endi +sql alter database db quorum 1 +sql show databases +print quorum $data5_db +if $data5_db != 1 then + return -1 +endi + +sql_error alter database db quorum -1 +sql_error alter database db quorum 0 +sql_error alter database db quorum 3 +sql_error alter database db quorum 4 +sql_error alter database db quorum 5 + +#print ============== modify days +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 + +print ============== modify keep +sql alter database db keep 2000 +sql show databases +print keep $data7_db +if $data7_db != 2000,2000,2000 then + return -1 +endi + +#sql alter database db keep 1000,2000 +#sql show databases +#print keep $data7_db +#if $data7_db != 500,500,500 then +# return -1 +#endi + +#sql alter database db keep 40,50 +#sql alter database db keep 30,31 +#sql alter database db keep 20 +#sql_error alter database db keep 10.0 +#sql_error alter database db keep 9 +#sql_error alter database db keep 1 +sql_error alter database db keep 0 +sql_error alter database db keep -1 +#sql_error alter database db keep 365001 + +print ============== modify cache +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 + +print ============== modify blocks +sql alter database db blocks 3 +sql show databases +print blocks $data9_db +if $data9_db != 3 then + return -1 +endi +sql alter database db blocks 11 +sql show databases +print blocks $data9_db +if $data9_db != 11 then + return -1 +endi + +sql alter database db blocks 40 +sql alter database db blocks 30 +sql alter database db blocks 20 +sql alter database db blocks 10 +sql_error alter database db blocks 2 +sql_error alter database db blocks 1 +sql_error alter database db blocks 0 +sql_error alter database db blocks -1 +sql_error alter database db blocks 10001 + +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_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 +sql show databases +print wal $data12_db +if $data12_db != 1 then + return -1 +endi +sql alter database db wal 2 +sql show databases +print wal $data12_db +if $data12_db != 2 then + return -1 +endi + +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 + +print ============== modify fsync +sql alter database db fsync 2000 +sql show databases +print fsync $data13_db +if $data13_db != 2000 then + return -1 +endi +sql alter database db fsync 500 +sql show databases +print fsync $data13_db +if $data13_db != 500 then + return -1 +endi +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_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 +sql_error alter database db comp -1 + +print ============== modify cachelast [0, 1, 2, 3] +sql alter database db cachelast 2 +sql show databases +print cachelast $data15_db +if $data15_db != 2 then + return -1 +endi +sql alter database db cachelast 1 +sql show databases +print cachelast $data15_db +if $data15_db != 1 then + return -1 +endi +sql alter database db cachelast 0 +sql show databases +print cachelast $data15_db +if $data15_db != 0 then + return -1 +endi +sql alter database db cachelast 2 +sql show databases +print cachelast $data15_db +if $data15_db != 2 then + return -1 +endi +sql alter database db cachelast 3 +sql show databases +print cachelast $data15_db +if $data15_db != 3 then + return -1 +endi + +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_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 7e57fe8f1b3458e70772d50c83a60ac4831855c6..a768a0da38c49cbd5f38a33e29fb3ffa43903bd8 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/parser/fourArithmetic-basic.sim b/tests/script/tsim/parser/fourArithmetic-basic.sim index 2ade01522e3f22aadd29277427fe69f050539f32..bb35df5a906721e05a465f5736e8b4e253b167a9 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 c0cbfa8aeb57eb99456c3a1049ce626c2cec3e0d..f073200a05e31148d6ba6e9d89c8902297270190 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 4c4ebc66701a10b7f0d13fb8b03b5e075a86679d..616ece99e0c759fe653e2951f7bd2d8b94e15e0f 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 $data02 != 10000 then return -1 -endi -if $data40 != 1 then +endi +if $data45 != 1 then return -1 -endi +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 +if $data45 != 1 then return -1 -endi +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 6dd0a9537e0de9452f5d13659eb4372faf871e40..384008c88746f815ca66f281ce60fd3c043bc2de 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 new file mode 100644 index 0000000000000000000000000000000000000000..9e6d378bd058edef961647a6e7122a6328d0f069 --- /dev/null +++ b/tests/script/tsim/query/scalarFunction.sim @@ -0,0 +1,484 @@ +#### abs, log, pow, sqrt, sin, cos, tan, asin, acos, atan, ceil, floor, round + +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 $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 +sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int) + +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 double) + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== insert data +$rowNum = 20 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + $c1 = 0 + while $x < $rowNum + $c2 = 0 - $c1 + $c3 = $c1 + 100 + + sql insert into $tb values ($tstart , $c1 , $c2 , $c3 ) + sql insert into ntb values ($tstart , $c1 , $c2 , $c3 ) + $tstart = $tstart + 1 + $c1 = $c1 + 5 + $x = $x + 1 + endw + + $i = $i + 1 + $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 +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, 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 +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, 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 + +print ====> cos +sql select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ct1 +print ====> select c1, cos(c1), c2, cos(c2), c3, cos(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, 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 0000000000000000000000000000000000000000..43923fc5722150db85e6163f2f24da022802fbba --- /dev/null +++ b/tests/script/tsim/query/session.sim @@ -0,0 +1,229 @@ +#### 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 $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)('2020-05-13 10:00:00.005', 2)('2020-05-13 10:00:00.011', 3) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:00:01.011', 4)('2020-05-13 10:00:01.611', 5)('2020-05-13 10:00:02.612', 6) +sql INSERT INTO dev_001 VALUES('2020-05-13 10:01:02.612', 7)('2020-05-13 10:02:02.612', 8)('2020-05-13 10:03:02.613', 9) +sql INSERT INTO dev_001 VALUES('2020-05-13 11:00:00.000', 10)('2020-05-13 12:00:00.000', 11)('2020-05-13 13:00:00.001', 12) +sql INSERT INTO dev_001 VALUES('2020-05-14 13:00:00.001', 13)('2020-05-15 14:00:00.000', 14)('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)('2020-05-13 10:00:00.005', 2)('2020-05-13 10:00:00.009', 3) +sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.0021', 4)('2020-05-13 10:00:00.031', 5)('2020-05-13 10:00:00.036', 6)('2020-05-13 10:00:00.51', 7) + + + +# session(ts,5a) +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 + +return + +# +# # session(ts,5a) main query +# tdSql.query("select count(*) from (select * from dev_001) session(ts,5a)") +# tdSql.checkRows(15) +# tdSql.checkData(0, 1, 2) +# +# +# # session(ts,1s) +# tdSql.query("select count(*) from dev_001 session(ts,1s)") +# tdSql.checkRows(12) +# tdSql.checkData(0, 1, 5) +# +# # session(ts,1s) main query +# tdSql.query("select count(*) from (select * from dev_001) session(ts,1s)") +# tdSql.checkRows(12) +# tdSql.checkData(0, 1, 5) +# +# tdSql.query("select count(*) from dev_001 session(ts,1000a)") +# tdSql.checkRows(12) +# tdSql.checkData(0, 1, 5) +# +# tdSql.query("select count(*) from (select * from dev_001) session(ts,1000a)") +# tdSql.checkRows(12) +# tdSql.checkData(0, 1, 5) +# +# # session(ts,1m) +# tdSql.query("select count(*) from dev_001 session(ts,1m)") +# tdSql.checkRows(9) +# tdSql.checkData(0, 1, 8) +# +# # session(ts,1m) +# tdSql.query("select count(*) from (select * from dev_001) session(ts,1m)") +# tdSql.checkRows(9) +# tdSql.checkData(0, 1, 8) +# +# # session(ts,1h) +# tdSql.query("select count(*) from dev_001 session(ts,1h)") +# tdSql.checkRows(6) +# tdSql.checkData(0, 1, 11) +# +# # session(ts,1h) +# tdSql.query("select count(*) from (select * from dev_001) session(ts,1h)") +# tdSql.checkRows(6) +# tdSql.checkData(0, 1, 11) +# +# # session(ts,1d) +# tdSql.query("select count(*) from dev_001 session(ts,1d)") +# tdSql.checkRows(4) +# tdSql.checkData(0, 1, 13) +# +# # session(ts,1d) +# tdSql.query("select count(*) from (select * from dev_001) session(ts,1d)") +# tdSql.checkRows(4) +# tdSql.checkData(0, 1, 13) +# +# # session(ts,1w) +# tdSql.query("select count(*) from dev_001 session(ts,1w)") +# tdSql.checkRows(2) +# tdSql.checkData(0, 1, 15) +# +# # session(ts,1w) +# tdSql.query("select count(*) from (select * from dev_001) session(ts,1w)") +# tdSql.checkRows(2) +# tdSql.checkData(0, 1, 15) +# +# # session with where +# tdSql.query("select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d)") +# +# tdSql.checkRows(2) +# tdSql.checkData(0, 1, 13) +# tdSql.checkData(0, 2, 1) +# tdSql.checkData(0, 3, 13) +# tdSql.checkData(0, 4, 7) +# tdSql.checkData(0, 5, 91) +# tdSql.checkData(0, 6, 1) +# tdSql.checkData(0, 7, 13) +# tdSql.checkData(0, 8, '{slop:1.000000, intercept:0.000000}') +# tdSql.checkData(0, 9, 12) +# tdSql.checkData(0, 10, 3.741657387) +# tdSql.checkData(0, 11, 1) +# tdSql.checkData(1, 11, 14) +# +# # session with where main +# +# tdSql.query("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)") +# +# tdSql.checkRows(2) +# tdSql.checkData(0, 1, 13) +# tdSql.checkData(0, 2, 1) +# tdSql.checkData(0, 3, 13) +# tdSql.checkData(0, 4, 7) +# tdSql.checkData(0, 5, 91) +# tdSql.checkData(0, 6, 1) +# tdSql.checkData(0, 7, 13) +# tdSql.checkData(0, 8, '{slop:1.000000, intercept:0.000000}') +# +# # tdsql err +# tdSql.error("select * from dev_001 session(ts,1w)") +# tdSql.error("select count(*) from st session(ts,1w)") +# tdSql.error("select count(*) from dev_001 group by tagtype session(ts,1w) ") +# tdSql.error("select count(*) from dev_001 session(ts,1n)") +# tdSql.error("select count(*) from dev_001 session(ts,1y)") +# tdSql.error("select count(*) from dev_001 session(ts,0s)") +# tdSql.error("select count(*) from dev_001 session(i,1y)") +# tdSql.error("select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0'") +# +# #test precision us +# tdSql.execute("create database test precision 'us'") +# tdSql.execute("use test") +# tdSql.execute("create table dev_001 (ts timestamp ,i timestamp ,j int)") +# tdSql.execute("insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)") +# +# # session(ts,1u) +# tdSql.query("select count(*) from dev_001 session(ts,1u)") +# tdSql.checkRows(2) +# tdSql.checkData(0, 1, 3) +# tdSql.error("select count(*) from dev_001 session(i,1s)") +# # test second timestamp fileds +# tdSql.execute("create table secondts(ts timestamp,t2 timestamp,i int)") +# tdSql.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/stable/disk.sim b/tests/script/tsim/stable/disk.sim new file mode 100644 index 0000000000000000000000000000000000000000..0e33c2066d32d9cab37b651cba961d712ec78959 --- /dev/null +++ b/tests/script/tsim/stable/disk.sim @@ -0,0 +1,206 @@ +system sh/stop_dnodes.sh + + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4 +system sh/exec.sh -n dnode1 -s start + +sleep 2000 +sql connect + +print ======================== dnode1 start + +$dbPrefix = d_db +$tbPrefix = d_tb +$mtPrefix = d_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print =============== step1 +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql create database $db +sql use $db +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using $mt tags( $i ) + + $x = 0 + while $x < $rowNum + $val = $x * 60000 + $ms = 1519833600000 + $val + sql insert into $tb values ($ms , $x ) + $x = $x + 1 + endw + + $i = $i + 1 +endw + +sql show vgroups +print vgroups ==> $rows +if $rows != 2 then + return -1 +endi + +sql select count(tbcol) from $mt +print select count(tbcol) from $mt ===> $data00 +if $data00 != $totalNum then + return -1 +endi + +sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 3000 +system sh/exec.sh -n dnode1 -s start +sleep 6000 + +sql use $db +sql show vgroups +print vgroups ==> $rows +if $rows != 2 then + return -1 +endi + +print =============== step2 +$i = 1 +$tb = $tbPrefix . $i + +sql select count(tbcol) from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +sql select count(tbcol) from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step3 +# TODO : where condition +# sql select count(tbcol) from $tb where ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 5 then +# return -1 +# endi + +print =============== step4 +sql select count(tbcol) as b from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step5 +sql select count(tbcol) as b from $tb interval(1m) +print ===> $data00 +if $data00 != 1 then + return -1 +endi + +sql select count(tbcol) as b from $tb interval(1d) +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step6 +# TODO +# sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) +# print ===> $data00 +# if $data00 != 1 then +# return -1 +# endi +# if $rows != 5 then +# return -1 +# endi + +print =============== step7 +# TODO +# sql select count(*) from $mt +# print select count(*) from $mt ===> $data00 +# if $data00 != $totalNum then +# return -1 +# endi + +sql select count(tbcol) from $mt +print ===> $data00 +if $data00 != $totalNum then + return -1 +endi + +print =============== step8 +# TODO +# sql select count(tbcol) as c from $mt where ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 50 then +# return -1 +# endi +# +# sql select count(tbcol) as c from $mt where tgcol < 5 +# print ===> $data00 +# if $data00 != 100 then +# return -1 +# endi +# +# sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 25 then +# return -1 +# endi + +print =============== step9 +# TODO : count from stable +# sql select count(tbcol) as b from $mt interval(1m) +# print select count(tbcol) as b from $mt interval(1m) ===> $data01 +# if $data01 != 10 then +# return -1 +# endi + +# sql select count(tbcol) as b from $mt interval(1d) +# print ===> $data02 +# if $data01 != 200 then +# return -1 +# endi + +print =============== step10 +# TODO +# print select count(tbcol) as b from $mt group by tgcol +# sql select count(tbcol) as b from $mt group by tgcol +# print ===> $data00 +# if $data00 != $rowNum then +# return -1 +# endi + +# if $rows != $tbNum then +# return -1 +# endi +# +print =============== step11 +# TODO : where condition +# sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol +# print ===> $data01 +# if $data01 != 1 then +# return -1 +# endi +# if $rows != 50 then +# return -1 +# endi + +print =============== clear +sql drop database $db +sql show databases +if $rows != 1 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/stable/dnode3.sim b/tests/script/tsim/stable/dnode3.sim new file mode 100644 index 0000000000000000000000000000000000000000..c2243b1ac8b078818a0b174744e24480ca26d089 --- /dev/null +++ b/tests/script/tsim/stable/dnode3.sim @@ -0,0 +1,213 @@ +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/deploy.sh -n dnode4 -i 4 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode2 -c walLevel -v 1 +system sh/cfg.sh -n dnode3 -c walLevel -v 1 +system sh/cfg.sh -n dnode4 -c walLevel -v 1 +# system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 +# system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 +# system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 +# system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +system sh/exec.sh -n dnode1 -s start + +sql connect + +sql create dnode $hostname PORT 7200 +sql create dnode $hostname PORT 7300 +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +$x = 0 +createDnode: + $x = $x + 1 + sleep 1000 + if $x == 20 then + return -1 + endi +sql show dnodes; +if $data4_2 == offline then + goto createDnode +endi +if $data4_3 == offline then + goto createDnode +endi +if $data4_4 == offline then + goto createDnode +endi + +print ======================== dnode1 start + +$dbPrefix = r3v3_db +$tbPrefix = r3v3_tb +$mtPrefix = r3v3_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print =============== step1 +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql create database $db +sql use $db +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using $mt tags( $i ) + + $x = 0 + while $x < $rowNum + $val = $x * 60000 + $ms = 1519833600000 + $val + sql insert into $tb values ($ms , $x ) + $x = $x + 1 + endw + + $i = $i + 1 +endw + +sql show vgroups +print vgroups ==> $rows +if $rows != 2 then + return -1 +endi + +sleep 100 + +print =============== step2 +$i = 1 +$tb = $tbPrefix . $i + +sql select count(*) from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +sql select count(tbcol) from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step3 +# TODO : where condition +# sql select count(tbcol) from $tb where ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 5 then +# return -1 +# endi + +print =============== step4 +sql select count(tbcol) as b from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step5 +sql select count(tbcol) as b from $tb interval(1m) +print ===> $data00 +if $data00 != 1 then + return -1 +endi + +sql select count(tbcol) as b from $tb interval(1d) +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step6 +# sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) +# print ===> $data00 +# if $data00 != 1 then +# return -1 +# endi +# if $rows != 5 then +# return -1 +# endi + +print =============== step7 +# print select count(*) from $mt +# sql select count(*) from $mt +# print ===> $data00 +# if $data00 != $totalNum then +# return -1 +# endi +# +# sql select count(tbcol) from $mt +# print ===> $data00 +# if $data00 != $totalNum then +# return -1 +# endi + +print =============== step8 +# sql select count(tbcol) as c from $mt where ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 50 then +# return -1 +# endi +# +# sql select count(tbcol) as c from $mt where tgcol < 5 +# print ===> $data00 +# if $data00 != 100 then +# return -1 +# endi +# +# sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 25 then +# return -1 +# endi + +print =============== step9 +# TODO : group by in stable +# sql select count(tbcol) as b from $mt interval(1m) +# print ===> $data00 +# if $data00 != 10 then +# return -1 +# endi +# +# sql select count(tbcol) as b from $mt interval(1d) +# print ===> $data00 +# if $data00 != 200 then +# return -1 +# endi + +print =============== step10 +# sql select count(tbcol) as b from $mt group by tgcol +# print ===> $data00 +# if $data00 != $rowNum then +# return -1 +# endi +# +# if $rows != $tbNum then +# return -1 +# endi + +print =============== step11 +# sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol +# print ===> $data00 +# if $data00 != 1 then +# return -1 +# endi +# if $rows != 50 then +# return -1 +# endi + +print =============== clear +sql drop database $db +sql show databases +if $rows != 1 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/stable/metrics.sim b/tests/script/tsim/stable/metrics.sim similarity index 62% rename from tests/script/general/stable/metrics.sim rename to tests/script/tsim/stable/metrics.sim index a3dca3f1a5a5f2234520e987ab356f6ed68f0afc..948af72d09771626eed3fe0189a656515c820aeb 100644 --- a/tests/script/general/stable/metrics.sim +++ b/tests/script/tsim/stable/metrics.sim @@ -24,14 +24,14 @@ sql use $db sql create table $mt (ts timestamp, speed int) TAGS(sp int) sql show stables -if $rows != 1 then +if $rows != 1 then return -1 endi print =============== step2 sql drop table $mt sql show stables -if $rows != 0 then +if $rows != 0 then return -1 endi @@ -39,97 +39,98 @@ print =============== step3 sql create table $mt (ts timestamp, speed int) TAGS(sp int) sql show stables -if $rows != 1 then +if $rows != 1 then return -1 endi -if $data00 != $mt then +if $data00 != $mt then return -1 endi -if $data04 != 0 then - return -1 -endi -sql select * from $mt -if $rows != 0 then +if $data04 != 1 then return -1 endi +# TODO : select * from stable +# sql select * from $mt +# if $rows != 0 then +# return -1 +# endi print =============== step4 $i = 0 $tb = $tbPrefix . $i sql create table $tb using $mt tags(1) -$i = 1 +$i = 1 $tb = $tbPrefix . $i sql create table $tb using $mt tags(2) -$i = 2 +$i = 2 $tb = $tbPrefix . $i sql create table $tb using $mt tags(3) sql show tables -if $rows != 3 then - return -1 -endi -if $data03 != $mt then +if $rows != 3 then return -1 endi +# if $data03 != $mt then +# return -1 +# endi sql show stables -if $rows != 1 then - return -1 -endi -if $data00 != $mt then +if $rows != 1 then return -1 endi -if $data04 != 3 then +if $data00 != $mt then return -1 endi +# if $data04 != 3 then +# return -1 +# endi print =============== step5 $i = 0 $tb = $tbPrefix . $i -sql insert into $tb values (now + 1m , 1 ) +sql insert into $tb values (now + 1m , 1 ) $i = 1 $tb = $tbPrefix . $i -sql insert into $tb values (now + 1m , 1 ) +sql insert into $tb values (now + 1m , 1 ) $i = 2 $tb = $tbPrefix . $i -sql insert into $tb values (now + 1m , 1 ) +sql insert into $tb values (now + 1m , 1 ) print sleep 8000 sleep 8000 print =============== step6 -sql select * from $mt -print select * from $mt ==> $rows $data00 -if $rows != 3 then - return -1 -endi +# sql select * from $mt +# print select * from $mt ==> $rows $data00 +# if $rows != 3 then +# return -1 +# endi print =============== step7 -sql select * from $mt where sp = 1 -print select * from $mt where sp = 1 ==> $rows $data00 -if $rows != 1 then - return -1 -endi +# sql select * from $mt where sp = 1 +# print select * from $mt where sp = 1 ==> $rows $data00 +# if $rows != 1 then +# return -1 +# endi print =============== step8 sql drop table $mt print =============== step9 -sql show tables -if $rows != 0 then - return -1 -endi +#sql show tables +#if $rows != 0 then +# return -1 +#endi sql show stables -if $rows != 0 then +if $rows != 0 then return -1 endi sql drop database $db sql show databases -if $rows != 0 then +if $rows != 1 then return -1 endi diff --git a/tests/script/general/stable/refcount.sim b/tests/script/tsim/stable/refcount.sim similarity index 77% rename from tests/script/general/stable/refcount.sim rename to tests/script/tsim/stable/refcount.sim index 6629dc1177c6021fce45f135f153475f6cb858a3..1f0048309087e4a048dd9271b4946646a5cf239d 100644 --- a/tests/script/general/stable/refcount.sim +++ b/tests/script/tsim/stable/refcount.sim @@ -16,11 +16,11 @@ sql create table d1.t2 (ts timestamp, i int); sql create table d1.t3 (ts timestamp, i int); sql insert into d1.t1 values(now, 1); sql insert into d1.t2 values(now, 1); -sql drop table d1.t1; +# sql drop table d1.t1; sql drop database d1; sql show databases; -if $rows != 0 then +if $rows != 1 then return -1 endi @@ -32,24 +32,24 @@ sql create table d2.t2 (ts timestamp, i int); sql create table d2.t3 (ts timestamp, i int); sql insert into d2.t1 values(now, 1); sql insert into d2.t2 values(now, 1); -sql drop table d2.t1; -sql drop table d2.t2; -sql drop table d2.t3; - -sql show d2.tables; -if $rows != 0 then - return -1 -endi +# sql drop table d2.t1; +# sql drop table d2.t2; +# sql drop table d2.t3; +# +# sql show d2.tables; +# if $rows != 0 then +# return -1 +# endi sql show d2.vgroups; -if $rows != 0 then +if $rows != 2 then return -1 endi sql drop database d2; sql show databases; -if $rows != 0 then +if $rows != 1 then return -1 endi @@ -61,24 +61,24 @@ sql create table d3.t1 using d3.st tags(1); sql create table d3.t2 using d3.st tags(1); sql create table d3.t3 using d3.st tags(1); sql insert into d3.t1 values(now, 1); -sql drop table d3.t1; -sql drop table d3.t2; -sql drop table d3.t3; - -sql show d3.tables; -if $rows != 0 then - return -1 -endi +# sql drop table d3.t1; +# sql drop table d3.t2; +# sql drop table d3.t3; +# +# sql show d3.tables; +# if $rows != 0 then +# return -1 +# endi sql show d3.vgroups; -if $rows != 0 then +if $rows != 2 then return -1 endi sql drop database d3; sql show databases; -if $rows != 0 then +if $rows != 1 then return -1 endi @@ -90,23 +90,23 @@ sql create table d4.t1 using d4.st tags(1); sql create table d4.t2 using d4.st tags(1); sql create table d4.t3 using d4.st tags(1); sql insert into d4.t1 values(now, 1); -sql drop table d4.t1; +# sql drop table d4.t1; sql drop table d4.st; - -sql show d4.tables; -if $rows != 0 then - return -1 -endi +# +# sql show d4.tables; +# if $rows != 0 then +# return -1 +# endi sql show d4.stables; -if $rows != 0 then +if $rows != 0 then return -1 endi sql drop database d4; sql show databases; -if $rows != 0 then +if $rows != 1 then return -1 endi @@ -118,12 +118,12 @@ sql create table d5.t1 using d5.st tags(1); sql create table d5.t2 using d5.st tags(1); sql create table d5.t3 using d5.st tags(1); sql insert into d5.t1 values(now, 1); -sql drop table d5.t1; +# sql drop table d5.t1; sql drop database d5; sql show databases; -if $rows != 0 then +if $rows != 1 then return -1 endi diff --git a/tests/script/general/stable/show.sim b/tests/script/tsim/stable/show.sim similarity index 63% rename from tests/script/general/stable/show.sim rename to tests/script/tsim/stable/show.sim index 5fe05b41eb8fb6f0080eeea35cc63506faf55e5c..8ebb765a7817061b3a706c11845cc7db6a60008d 100644 --- a/tests/script/general/stable/show.sim +++ b/tests/script/tsim/stable/show.sim @@ -10,20 +10,37 @@ sql connect print ======================== create stable sql create database d1 +sql use d1 $x = 0 while $x < 128 $tb = d1.s . $x sql create table $tb (ts timestamp, i int) tags (j int) $x = $x + 1 -endw +endw + +print ======================== describe stables +# TODO : create stable error +$m = 0 +while $m < 128 + $tb = s . $m + $filter = ' . $tb + $filter = $filter . ' + sql show stables like $filter + # print sql : show stables like $filter ==> $rows + if $rows != 1 then + return -1 + endi + $m = $m + 1 +endw + print ======================== show stables sql show d1.stables print num of stables is $rows -if $rows != 128 then +if $rows != 128 then return -1 endi @@ -34,15 +51,15 @@ while $x < 424 $tb = d1.t . $x sql create table $tb using d1.s0 tags( $x ) $x = $x + 1 -endw +endw print ======================== show stables sql show d1.tables print num of tables is $rows -if $rows != 424 then +if $rows != 424 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stable/values.sim b/tests/script/tsim/stable/values.sim new file mode 100644 index 0000000000000000000000000000000000000000..e5e3118e12634f41b0d124d3ba379b8f93df442f --- /dev/null +++ b/tests/script/tsim/stable/values.sim @@ -0,0 +1,121 @@ +system sh/stop_dnodes.sh + + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 +system sh/exec.sh -n dnode1 -s start + +sleep 2000 +sql connect + +print ======================== dnode1 start + +sql create database vdb0 +sql create table vdb0.mt (ts timestamp, tbcol int) TAGS(tgcol int) + +sql create table vdb0.vtb00 using vdb0.mt tags( 0 ) +sql create table vdb0.vtb01 using vdb0.mt tags( 0 ) + +sql create database vdb1 +sql create table vdb1.mt (ts timestamp, tbcol int) TAGS(tgcol int) +# sql_error create table vdb1.vtb10 using vdb0.mt tags( 1 ) +# sql_error create table vdb1.vtb11 using vdb0.mt tags( 1 ) +sql create table vdb1.vtb10 using vdb1.mt tags( 1 ) +sql create table vdb1.vtb11 using vdb1.mt tags( 1 ) + +sql create database vdb2 +sql create table vdb2.mt (ts timestamp, tbcol int) TAGS(tgcol int) +# sql_error create table vdb2.vtb20 using vdb0.mt tags( 2 ) +# sql_error create table vdb2.vtb21 using vdb0.mt tags( 2 ) +sql create table vdb2.vtb20 using vdb2.mt tags( 2 ) +sql create table vdb2.vtb21 using vdb2.mt tags( 2 ) + +sql create database vdb3 +sql create table vdb3.mt (ts timestamp, tbcol int) TAGS(tgcol int) +# sql_error create table vdb3.vtb20 using vdb0.mt tags( 2 ) +# sql_error create table vdb3.vtb21 using vdb0.mt tags( 2 ) +sql create table vdb3.vtb30 using vdb3.mt tags( 3 ) +sql create table vdb3.vtb31 using vdb3.mt tags( 3 ) + +print =============== step2 +sql insert into vdb0.vtb00 values (1519833600000 , 10) (1519833600001, 20) (1519833600002, 30) +sql insert into vdb0.vtb01 values (1519833600000 , 10) (1519833600001, 20) (1519833600002, 30) +sql insert into vdb1.vtb10 values (1519833600000 , 11) (1519833600001, 21) (1519833600002, 31) +sql insert into vdb1.vtb11 values (1519833600000 , 11) (1519833600001, 21) (1519833600002, 31) +sql insert into vdb2.vtb20 values (1519833600000 , 12) (1519833600001, 22) (1519833600002, 32) +sql insert into vdb2.vtb21 values (1519833600000 , 12) (1519833600001, 22) (1519833600002, 32) +sql insert into vdb3.vtb30 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33) +sql insert into vdb3.vtb31 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33) +# sql select * from vdb0.mt +sql select ts from vdb0.mt + +if $rows != 6 then + return -1 +endi + +print =============== step3 +sql insert into vdb0.vtb00 values (1519833600003 , 40) (1519833600005, 50) (1519833600004, 60) +sql insert into vdb0.vtb01 values (1519833600003 , 40) (1519833600005, 50) (1519833600004, 60) +sql insert into vdb1.vtb10 values (1519833600003 , 41) (1519833600005, 51) (1519833600004, 61) +sql insert into vdb1.vtb11 values (1519833600003 , 41) (1519833600005, 51) (1519833600004, 61) +sql insert into vdb2.vtb20 values (1519833600003 , 42) (1519833600005, 52) (1519833600004, 62) +sql insert into vdb2.vtb21 values (1519833600003 , 42) (1519833600005, 52) (1519833600004, 62) +sql insert into vdb3.vtb30 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63) +sql insert into vdb3.vtb31 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63) +# TODO : select * from stable +# sql select * from vdb0.mt +sql select ts from vdb0.mt + +if $rows != 12 then + return -1 +endi + +print =============== step4 +# TODO : insert into diffrent table +# sql insert into vdb0.vtb00 values(1519833600006, 60) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 60) (1519833600007, 70) +# sql insert into vdb1.vtb10 values(1519833600006, 61) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 61) (1519833600007, 71) +# sql insert into vdb2.vtb20 values(1519833600006, 62) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 62) (1519833600007, 72) +# sql insert into vdb3.vtb30 values(1519833600006, 63) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 63) (1519833600007, 73) +# # sql select * from vdb0.mt +# sql select ts from vdb0.mt +# +# if $rows != 16 then +# return -1 +# endi + +print =============== step5 +# sql insert into vdb0.vtb00 values(1519833600008, 80) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 80) (1519833600007, 70) +# sql insert into vdb1.vtb10 values(1519833600008, 81) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 81) (1519833600007, 71) +# sql insert into vdb2.vtb20 values(1519833600008, 82) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 82) (1519833600007, 72) +# sql insert into vdb3.vtb30 values(1519833600008, 83) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 83) (1519833600007, 73) +# # sql select * from vdb0.mt +# sql select ts from vdb0.mt +# +# if $rows != 17 then +# return -1 +# endi + +print =============== step6 +# sql insert into vdb0.vtb00 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb10 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb20 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb30 values(1519833600009, 90) (1519833600010, 100) +# sql insert into vdb0.vtb01 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb11 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb21 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb31 values(1519833600009, 90) (1519833600010, 100) +# +# # sql select * from vdb0.mt +# sql select ts from vdb0.mt +# +# if $rows != 21 then +# return -1 +# endi + +print =============== step7 +# sql insert into vdb0.vtb00 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb10 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb20 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb30 values(1519833600012, 120) (1519833600011, 110) +# sql insert into vdb0.vtb01 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb11 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb21 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb31 values(1519833600012, 120) (1519833600011, 110) +# +# # sql select * from vdb0.mt +# sql select ts from vdb0.mt +# +# if $rows != 25 then +# return -1 +# endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stable/vnode3.sim b/tests/script/tsim/stable/vnode3.sim new file mode 100644 index 0000000000000000000000000000000000000000..2d408b4191d43c31ab21eb724da6d197d96b0af8 --- /dev/null +++ b/tests/script/tsim/stable/vnode3.sim @@ -0,0 +1,181 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4 +system sh/exec.sh -n dnode1 -s start + +sleep 2000 +sql connect + +print ======================== dnode1 start + +$dbPrefix = v3_db +$tbPrefix = v3_tb +$mtPrefix = v3_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print =============== step1 +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql create database $db +sql use $db +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using $mt tags( $i ) + + $x = 0 + while $x < $rowNum + $val = $x * 60000 + $ms = 1519833600000 + $val + sql insert into $tb values ($ms , $x ) + $x = $x + 1 + endw + + $i = $i + 1 +endw + +sql show vgroups +print vgroups ==> $rows +if $rows != 2 then + return -1 +endi + + +print =============== step2 +$i = 1 +$tb = $tbPrefix . $i + +sql select count(*) from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +sql select count(tbcol) from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step3 +# TODO : where condition +# sql select count(tbcol) from $tb where ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 5 then +# return -1 +# endi + +print =============== step4 +sql select count(tbcol) as b from $tb +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step5 +sql select count(tbcol) as b from $tb interval(1m) +print ===> $data00 +if $data00 != 1 then + return -1 +endi + +sql select count(tbcol) as b from $tb interval(1d) +print ===> $data00 +if $data00 != $rowNum then + return -1 +endi + +print =============== step6 +# sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) +# print ===> $data00 +# if $data00 != 1 then +# return -1 +# endi +# if $rows != 5 then +# return -1 +#endi + +print =============== step7 +# TODO : count(*) err +# sql select count(*) from $mt +# print ===> $data00 +# if $data00 != $totalNum then +# return -1 +# endi +# +# sql select count(tbcol) from $mt +# print ===> $data00 +# if $data00 != $totalNum then +# return -1 +# endi + +print =============== step8 +# sql select count(tbcol) as c from $mt where ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 50 then +# return -1 +# endi + +# sql select count(tbcol) as c from $mt where tgcol < 5 +# print ===> $data00 +# if $data00 != 100 then +# return -1 +# endi + +# sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 +# print ===> $data00 +# if $data00 != 25 then +# return -1 +# endi + +print =============== step9 +# sql select count(tbcol) as b from $mt interval(1m) +# print ===> $data00 +# if $data00 != 10 then +# return -1 +# endi +# +# sql select count(tbcol) as b from $mt interval(1d) +# print ===> $data00 +# if $data00 != 200 then +# return -1 +# endi + +print =============== step10 +# sql select count(tbcol) as b from $mt group by tgcol +# print ===> $data00 +# if $data00 != $rowNum then +# return -1 +# endi +# +# if $rows != $tbNum then +# return -1 +# endi + +print =============== step11 +# sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol +# print ===> $data01 +# if $data01 != 1 then +# return -1 +# endi +# if $rows != 50 then +# return -1 +# endi + +print =============== clear +sql drop database $db +sql show databases +if $rows != 1 then + return -1 +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 bf184f8794afebcba6204cec98ab828b9d7148bd..4245529343ac17934f715bf886027bef94ae5970 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/basic1.sim b/tests/script/tsim/tmq/basic1.sim index fe6a7a0660474f693ebf7c235745b2d8ec3f53b6..cfcb1ac992799edac91e0f27b3db8cc303471d9a 100644 --- a/tests/script/tsim/tmq/basic1.sim +++ b/tests/script/tsim/tmq/basic1.sim @@ -66,15 +66,15 @@ print =============== will support: * from stb; function from stb/ctb 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), sina(c2) 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), sina(c2) 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), sina(c2) from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb sql show tables if $rows != 3 then @@ -147,6 +147,13 @@ endi # 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: 20, 0}@ then + return -1 +endi + 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 @@ -161,6 +168,13 @@ if $system_content != @{consume success: 10, 0}@ 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: 10, 0}@ then + return -1 +endi + 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 @@ -175,6 +189,13 @@ if $system_content != @{consume success: 20, 0}@ 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: 20, 0}@ then + return -1 +endi + print =============== create database , vgroup 4 $dbNamme = d1 sql create database $dbNamme vgroups 4 diff --git a/tests/script/tsim/tmq/multiTopic.sim b/tests/script/tsim/tmq/multiTopic.sim new file mode 100644 index 0000000000000000000000000000000000000000..cd977e5909aad30ded0f06b4d0f83090671bdded --- /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 0000000000000000000000000000000000000000..8e8d00977c4060eadaf389f54ccfb9f1dd6e6a6e --- /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/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 182d40c96a6a4ca21802842db5aacfd6e399c918..d339166d74dea334e03a79a93e524e725294d5be 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -387,11 +387,12 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog printf("subscribe err\n"); return; } + /*taosSsleep(3);*/ int32_t batchCnt = 0; int32_t skipLogNum = 0; int64_t startTime = taosGetTimestampUs(); while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1); + tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 3000); if (tmqmessage) { batchCnt++; skipLogNum += tmqGetSkipLogNum(tmqmessage); diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 4d3108500e818995c3b788f856df1fbdfefc1105..38264331c13a1d3c940ea343c2ff5dc11ed5c5a9 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, 1); + tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 3000); if (tmqMsg) { totalMsgs++; diff --git a/tools/taos-tools b/tools/taos-tools index f36b07f710d661dca88fdd70e73b5e3e16a960e0..33cdfe4f90a209f105c1b6091439798a9cde1e93 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit f36b07f710d661dca88fdd70e73b5e3e16a960e0 +Subproject commit 33cdfe4f90a209f105c1b6091439798a9cde1e93