diff --git a/.clang-format b/.clang-format index e58d518b3b..3ddd8b43f6 100644 --- a/.clang-format +++ b/.clang-format @@ -5,7 +5,6 @@ AccessModifierOffset: -1 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: true -AlignConsecutiveMacros: true AlignEscapedNewlinesLeft: true AlignOperands: true AlignTrailingComments: true diff --git a/2.0/src/query/inc/qExecutor.h b/2.0/src/query/inc/qExecutor.h index 970b826303..967101fb41 100644 --- a/2.0/src/query/inc/qExecutor.h +++ b/2.0/src/query/inc/qExecutor.h @@ -574,11 +574,11 @@ typedef struct SMultiwayMergeInfo { } SMultiwayMergeInfo; // todo support the disk-based sort -typedef struct SOrderOperatorInfo { +typedef struct SSortOperatorInfo { int32_t colIndex; int32_t order; SSDataBlock *pDataBlock; -} SOrderOperatorInfo; +} SSortOperatorInfo; void appendUpstream(SOperatorInfo* p, SOperatorInfo* pUpstream); @@ -609,7 +609,7 @@ SOperatorInfo* createFilterOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator int32_t numOfOutput, SColumnInfo* pCols, int32_t numOfFilter); SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pUpstream, int32_t numOfUpstream, SSchema* pSchema, int32_t numOfOutput); -SOperatorInfo* createOrderOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal); +SOperatorInfo* createSortOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal); SSDataBlock* doGlobalAggregate(void* param, bool* newgroup); SSDataBlock* doMultiwayMergeSort(void* param, bool* newgroup); diff --git a/2.0/src/query/src/qExecutor.c b/2.0/src/query/src/qExecutor.c index 490584c75a..1e879c3912 100644 --- a/2.0/src/query/src/qExecutor.c +++ b/2.0/src/query/src/qExecutor.c @@ -2301,7 +2301,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf } case OP_Order: { - pRuntimeEnv->proot = createOrderOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput, &pQueryAttr->order); + pRuntimeEnv->proot = createSortOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput, &pQueryAttr->order); break; } @@ -5516,7 +5516,7 @@ static SSDataBlock* doSort(void* param, bool* newgroup) { return NULL; } - SOrderOperatorInfo* pInfo = pOperator->info; + SSortOperatorInfo* pInfo = pOperator->info; SSDataBlock* pBlock = NULL; while(1) { @@ -5556,8 +5556,8 @@ static SSDataBlock* doSort(void* param, bool* newgroup) { return (pInfo->pDataBlock->info.rows > 0)? pInfo->pDataBlock:NULL; } -SOperatorInfo *createOrderOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal) { - SOrderOperatorInfo* pInfo = calloc(1, sizeof(SOrderOperatorInfo)); +SOperatorInfo *createSortOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal) { + SSortOperatorInfo* pInfo = calloc(1, sizeof(SSortOperatorInfo)); { SSDataBlock* pDataBlock = calloc(1, sizeof(SSDataBlock)); @@ -6611,7 +6611,7 @@ static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) { } static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { - SOrderOperatorInfo* pInfo = (SOrderOperatorInfo*) param; + SSortOperatorInfo* pInfo = (SSortOperatorInfo*) param; pInfo->pDataBlock = blockDataDestroy(pInfo->pDataBlock); } diff --git a/example/src/tmq.c b/example/src/tmq.c index 3b4b6afbaf..8757104ad9 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -80,8 +80,9 @@ int32_t create_topic() { } taos_free_result(pRes); - const char* sql = "select * from tu1"; - pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql)); + /*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"); if (taos_errno(pRes) != 0) { printf("failed to create topic test_stb_topic_1, reason:%s\n", taos_errstr(pRes)); return -1; diff --git a/example/src/tstream.c b/example/src/tstream.c index 8ffa932bd2..40d8ff9b0b 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, 0); + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 7010); 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, 0); + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 7010); if (pConn == NULL) { return -1; } diff --git a/include/client/consumer/consumer.h b/include/client/consumer/consumer.h deleted file mode 100644 index 8d1c9835e6..0000000000 --- a/include/client/consumer/consumer.h +++ /dev/null @@ -1,78 +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_CONSUMER_H_ -#define _TD_CONSUMER_H_ - -#include "tlist.h" -#include "tarray.h" -#include "hash.h" - -#ifdef __cplusplus -extern "C" { -#endif - - //consumer handle - struct tmq_consumer_t; - typedef struct tmq_consumer_t tmq_consumer_t; - - //consumer config - struct tmq_consumer_config_t; - typedef struct tmq_consumer_config_t tmq_consumer_config_t; - - //response err - struct tmq_resp_err_t; - typedef struct tmq_resp_err_t tmq_resp_err_t; - - struct tmq_message_t; - typedef struct tmq_message_t tmq_message_t; - - struct tmq_col_batch_t; - typedef struct tmq_col_batch_t tmq_col_batch_t; - - //get content of message - tmq_col_batch_t* tmq_get_msg_col_by_idx(tmq_message_t*, int32_t col_id); - tmq_col_batch_t* tmq_get_msg_col_by_name(tmq_message_t*, const char*); - - //consumer config - int32_t tmq_conf_set(tmq_consumer_config_t* , const char* config_key, const char* config_value, char* errstr, int32_t errstr_cap); - - //consumer initialization - //resouces are supposed to be free by users by calling tmq_consumer_destroy - tmq_consumer_t* tmq_consumer_new(tmq_consumer_config_t* , char* errstr, int32_t errstr_cap); - - //subscribe - tmq_resp_err_t tmq_subscribe(tmq_consumer_t*, const SList*); - tmq_resp_err_t tmq_unsubscribe(tmq_consumer_t*); - - //consume - //resouces are supposed to be free by users by calling tmq_message_destroy - tmq_message_t* tmq_consume_poll(tmq_consumer_t*, int64_t blocking_time); - - //destroy message and free memory - void tmq_message_destroy(tmq_message_t*); - - //close consumer - int32_t tmq_consumer_close(tmq_consumer_t*); - - //destroy consumer - void tmq_consumer_destroy(tmq_message_t*); - - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_CONSUMER_H_*/ diff --git a/include/client/taos.h b/include/client/taos.h index dc54b89d04..111cd8ad3b 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -26,9 +26,11 @@ extern "C" { typedef void TAOS; typedef void TAOS_STMT; typedef void TAOS_RES; -typedef void TAOS_STREAM; -typedef void TAOS_SUB; typedef void **TAOS_ROW; +#if 0 +typedef void TAOS_STREAM; +#endif +typedef void TAOS_SUB; // Data type definition #define TSDB_DATA_TYPE_NULL 0 // 1 bytes @@ -122,8 +124,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); @@ -149,6 +168,7 @@ DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen); @@ -165,10 +185,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(); @@ -179,15 +202,20 @@ DLL_EXPORT int taos_errno(TAOS_RES *tres); DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param); DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); +// Shuduo: temporary enable for app build +#if 1 typedef void (*__taos_sub_fn_t)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code); DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, __taos_sub_fn_t fp, void *param, int interval); DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub); DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress); +#endif +#if 0 DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *)); DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr); +#endif DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); @@ -215,8 +243,12 @@ DLL_EXPORT tmq_list_t *tmq_list_new(); DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *); DLL_EXPORT void tmq_list_destroy(tmq_list_t *); -DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen); -DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen); +// will be removed in 3.0 +DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen); + +// will replace last one +DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen); + DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); /* ------------------------TMQ CONSUMER INTERFACE------------------------ */ @@ -255,20 +287,26 @@ int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message); /* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */ -DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message); -DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message); -DLL_EXPORT void *tmq_get_topic_schema(tmq_t *tmq, const char *topic); -DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message); +DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message); +DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message); +DLL_EXPORT int32_t tmq_get_vgroup_id(tmq_message_t *message); +DLL_EXPORT int64_t tmq_get_request_offset(tmq_message_t *message); +DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message); +DLL_EXPORT TAOS_FIELD *tmq_get_fields(tmq_t *tmq, const char *topic); +DLL_EXPORT int32_t tmq_field_count(tmq_t *tmq, const char *topic); +DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message); /* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */ +#if 0 DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen); +#endif DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql); -/* -------------------------------- OTHER -------------------------------- */ +/* ------------------------------ TMQ END -------------------------------- */ +#if 1 // Shuduo: temporary enable for app build typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code); - -DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); +#endif #ifdef __cplusplus } diff --git a/include/common/tcommon.h b/include/common/tcommon.h index b7fb988cec..51eabb7d61 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -197,6 +197,11 @@ typedef struct SGroupbyExpr { bool groupbyTag; // group by tag or column } SGroupbyExpr; +enum { + FUNC_PARAM_TYPE_VALUE = 0, + FUNC_PARAM_TYPE_COLUMN, +}; + typedef struct SFunctParam { int32_t type; SColumn* pCol; diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 2d5fba7368..4bbe42bc50 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -29,8 +29,9 @@ typedef struct SCorEpSet { } SCorEpSet; typedef struct SBlockOrderInfo { + bool nullFirst; int32_t order; - int32_t colIndex; + int32_t slotId; SColumnInfoData* pColData; } SBlockOrderInfo; @@ -132,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; } @@ -174,17 +176,16 @@ 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, bool nullFirst); +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 blockDataEnsureColumnCapacity(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); + 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/tglobal.h b/include/common/tglobal.h index 90aac6edcd..089cb5bb94 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 3f532398f4..cd16bbf862 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -469,8 +469,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; @@ -801,7 +800,10 @@ typedef struct SVgroupInfo { uint32_t hashBegin; uint32_t hashEnd; SEpSet epSet; - int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + union { + int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + int32_t taskId; // used in stream + }; } SVgroupInfo; typedef struct { @@ -2185,23 +2187,6 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) { return buf; } -typedef struct { - int64_t uid; - int32_t numOfRows; - char* colData; -} SMqTbData; - -typedef struct { - char topicName[TSDB_TOPIC_FNAME_LEN]; - int64_t committedOffset; - int64_t reqOffset; - int64_t rspOffset; - int32_t skipLogNum; - int32_t bodyLen; - int32_t numOfTb; - SMqTbData* tbData; -} SMqTopicData; - typedef struct { int8_t mqMsgType; int32_t code; @@ -2229,8 +2214,11 @@ typedef struct { } SMqSubVgEp; typedef struct { - char topic[TSDB_TOPIC_FNAME_LEN]; - SArray* vgs; // SArray + char topic[TSDB_TOPIC_FNAME_LEN]; + int8_t isSchemaAdaptive; + SArray* vgs; // SArray + int32_t numOfFields; + TAOS_FIELD* fields; } SMqSubTopicEp; typedef struct { @@ -2251,32 +2239,6 @@ typedef struct { SArray* topics; // SArray } SMqCMGetSubEpRsp; -typedef struct { - int32_t curBlock; - int32_t curRow; - void** uData; -} SMqRowIter; - -struct tmq_message_t { - SMqPollRsp msg; - void* vg; - SMqRowIter iter; -}; - -#if 0 -struct tmq_message_t { - SMqRspHead head; - union { - SMqPollRsp consumeRsp; - SMqCMGetSubEpRsp getEpRsp; - }; - void* extra; - int32_t curBlock; - int32_t curRow; - void** uData; -}; -#endif - static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) { taosArrayDestroy(pSubTopicEp->vgs); } static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) { @@ -2301,17 +2263,21 @@ static FORCE_INLINE void tDeleteSMqCMGetSubEpRsp(SMqCMGetSubEpRsp* pRsp) { static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp) { int32_t tlen = 0; tlen += taosEncodeString(buf, pTopicEp->topic); + tlen += taosEncodeFixedI8(buf, pTopicEp->isSchemaAdaptive); int32_t sz = taosArrayGetSize(pTopicEp->vgs); tlen += taosEncodeFixedI32(buf, sz); for (int32_t i = 0; i < sz; i++) { SMqSubVgEp* pVgEp = (SMqSubVgEp*)taosArrayGet(pTopicEp->vgs, i); tlen += tEncodeSMqSubVgEp(buf, pVgEp); } + tlen += taosEncodeFixedI32(buf, pTopicEp->numOfFields); + // tlen += taosEncodeBinary(buf, pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD)); return tlen; } static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp) { buf = taosDecodeStringTo(buf, pTopicEp->topic); + buf = taosDecodeFixedI8(buf, &pTopicEp->isSchemaAdaptive); int32_t sz; buf = taosDecodeFixedI32(buf, &sz); pTopicEp->vgs = taosArrayInit(sz, sizeof(SMqSubVgEp)); @@ -2323,6 +2289,8 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE buf = tDecodeSMqSubVgEp(buf, &vgEp); taosArrayPush(pTopicEp->vgs, &vgEp); } + buf = taosDecodeFixedI32(buf, &pTopicEp->numOfFields); + // buf = taosDecodeBinary(buf, (void**)&pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD)); return buf; } diff --git a/include/common/tmsgcb.h b/include/common/tmsgcb.h index 1b3311b400..cb59599d9a 100644 --- a/include/common/tmsgcb.h +++ b/include/common/tmsgcb.h @@ -25,6 +25,7 @@ extern "C" { typedef struct SRpcMsg SRpcMsg; typedef struct SEpSet SEpSet; typedef struct SMgmtWrapper SMgmtWrapper; + typedef enum { QUERY_QUEUE, FETCH_QUEUE, @@ -38,24 +39,31 @@ typedef enum { typedef int32_t (*PutToQueueFp)(SMgmtWrapper* pWrapper, SRpcMsg* pReq); typedef int32_t (*GetQueueSizeFp)(SMgmtWrapper* pWrapper, int32_t vgId, EQueueType qtype); -typedef int32_t (*SendReqFp)(SMgmtWrapper* pWrapper, SEpSet* epSet, SRpcMsg* pReq); +typedef int32_t (*SendReqFp)(SMgmtWrapper* pWrapper, const SEpSet* epSet, SRpcMsg* pReq); typedef int32_t (*SendMnodeReqFp)(SMgmtWrapper* pWrapper, SRpcMsg* pReq); -typedef void (*SendRspFp)(SMgmtWrapper* pWrapper, SRpcMsg* pRsp); +typedef void (*SendRspFp)(SMgmtWrapper* pWrapper, const SRpcMsg* pRsp); +typedef void (*RegisterBrokenLinkArgFp)(SMgmtWrapper* pWrapper, SRpcMsg* pMsg); +typedef void (*ReleaseHandleFp)(SMgmtWrapper* pWrapper, void* handle, int8_t type); typedef struct { - SMgmtWrapper* pWrapper; - PutToQueueFp queueFps[QUEUE_MAX]; - GetQueueSizeFp qsizeFp; - SendReqFp sendReqFp; - SendMnodeReqFp sendMnodeReqFp; - SendRspFp sendRspFp; + SMgmtWrapper* pWrapper; + PutToQueueFp queueFps[QUEUE_MAX]; + GetQueueSizeFp qsizeFp; + SendReqFp sendReqFp; + SendMnodeReqFp sendMnodeReqFp; + SendRspFp sendRspFp; + RegisterBrokenLinkArgFp registerBrokenLinkArgFp; + ReleaseHandleFp releaseHandleFp; } SMsgCb; +void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb); int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq); int32_t tmsgGetQueueSize(const SMsgCb* pMsgCb, int32_t vgId, EQueueType qtype); -int32_t tmsgSendReq(const SMsgCb* pMsgCb, SEpSet* epSet, SRpcMsg* pReq); +int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq); int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq); -void tmsgSendRsp(const SMsgCb* pMsgCb, SRpcMsg* pRsp); +void tmsgSendRsp(const SRpcMsg* pRsp); +void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg); +void tmsgReleaseHandle(void* handle, int8_t type); #ifdef __cplusplus } diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 51dd645a30..73c15d508c 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -138,47 +138,59 @@ #define TK_INTERVAL 120 #define TK_TOPIC 121 #define TK_AS 122 -#define TK_NK_BOOL 123 -#define TK_NK_VARIABLE 124 -#define TK_BETWEEN 125 -#define TK_IS 126 -#define TK_NULL 127 -#define TK_NK_LT 128 -#define TK_NK_GT 129 -#define TK_NK_LE 130 -#define TK_NK_GE 131 -#define TK_NK_NE 132 -#define TK_MATCH 133 -#define TK_NMATCH 134 -#define TK_IN 135 -#define TK_JOIN 136 -#define TK_INNER 137 -#define TK_SELECT 138 -#define TK_DISTINCT 139 -#define TK_WHERE 140 -#define TK_PARTITION 141 -#define TK_BY 142 -#define TK_SESSION 143 -#define TK_STATE_WINDOW 144 -#define TK_SLIDING 145 -#define TK_FILL 146 -#define TK_VALUE 147 -#define TK_NONE 148 -#define TK_PREV 149 -#define TK_LINEAR 150 -#define TK_NEXT 151 -#define TK_GROUP 152 -#define TK_HAVING 153 -#define TK_ORDER 154 -#define TK_SLIMIT 155 -#define TK_SOFFSET 156 -#define TK_LIMIT 157 -#define TK_OFFSET 158 -#define TK_ASC 159 -#define TK_DESC 160 -#define TK_NULLS 161 -#define TK_FIRST 162 -#define TK_LAST 163 +#define TK_EXPLAIN 123 +#define TK_ANALYZE 124 +#define TK_VERBOSE 125 +#define TK_NK_BOOL 126 +#define TK_RATIO 127 +#define TK_NULL 128 +#define TK_NK_VARIABLE 129 +#define TK_NK_UNDERLINE 130 +#define TK_ROWTS 131 +#define TK_TBNAME 132 +#define TK_QSTARTTS 133 +#define TK_QENDTS 134 +#define TK_WSTARTTS 135 +#define TK_WENDTS 136 +#define TK_WDURATION 137 +#define TK_BETWEEN 138 +#define TK_IS 139 +#define TK_NK_LT 140 +#define TK_NK_GT 141 +#define TK_NK_LE 142 +#define TK_NK_GE 143 +#define TK_NK_NE 144 +#define TK_MATCH 145 +#define TK_NMATCH 146 +#define TK_IN 147 +#define TK_JOIN 148 +#define TK_INNER 149 +#define TK_SELECT 150 +#define TK_DISTINCT 151 +#define TK_WHERE 152 +#define TK_PARTITION 153 +#define TK_BY 154 +#define TK_SESSION 155 +#define TK_STATE_WINDOW 156 +#define TK_SLIDING 157 +#define TK_FILL 158 +#define TK_VALUE 159 +#define TK_NONE 160 +#define TK_PREV 161 +#define TK_LINEAR 162 +#define TK_NEXT 163 +#define TK_GROUP 164 +#define TK_HAVING 165 +#define TK_ORDER 166 +#define TK_SLIMIT 167 +#define TK_SOFFSET 168 +#define TK_LIMIT 169 +#define TK_OFFSET 170 +#define TK_ASC 171 +#define TK_DESC 172 +#define TK_NULLS 173 +#define TK_FIRST 174 +#define TK_LAST 175 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index 8d19ce23df..e4f4bdf8f9 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/executor/executor.h b/include/libs/executor/executor.h index 4ad7e2dfc2..d3cd828cf5 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -20,8 +20,8 @@ extern "C" { #endif -#include "tcommon.h" #include "query.h" +#include "tcommon.h" typedef void* qTaskInfo_t; typedef void* DataSinkHandle; @@ -36,7 +36,12 @@ 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 @@ -54,6 +59,16 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle); */ int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type); +/** + * Set multiple input data blocks for the stream scan. + * @param tinfo + * @param pBlocks + * @param numOfInputBlock + * @param type + * @return + */ +int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type); + /** * Update the table id list, add or remove. * @@ -74,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, @@ -86,16 +101,6 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, */ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds); -/** - * Retrieve the produced results information, if current query is not paused or completed, - * this function will be blocked to wait for the query execution completed or paused, - * in which case enough results have been produced already. - * - * @param tinfo - * @return - */ -int32_t qRetrieveQueryResultInfo(qTaskInfo_t tinfo, bool* buildRes, void* pRspContext); - /** * kill the ongoing query and free the query handle and corresponding resources automatically * @param tinfo qhandle @@ -158,50 +163,6 @@ int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t */ int32_t qUpdateQueriedTableIdList(qTaskInfo_t tinfo, int64_t uid, int32_t type); -//================================================================================================ -// query handle management -/** - * Query handle mgmt object - * @param vgId - * @return - */ -void* qOpenTaskMgmt(int32_t vgId); - -/** - * broadcast the close information and wait for all query stop. - * @param pExecutor - */ -void qTaskMgmtNotifyClosing(void* pExecutor); - -/** - * Re-open the query handle management module when opening the vnode again. - * @param pExecutor - */ -void qQueryMgmtReOpen(void* pExecutor); - -/** - * Close query mgmt and clean up resources. - * @param pExecutor - */ -void qCleanupTaskMgmt(void* pExecutor); - -/** - * Add the query into the query mgmt object - * @param pMgmt - * @param qId - * @param qInfo - * @return - */ -void** qRegisterTask(void* pMgmt, uint64_t qId, void* qInfo); - -/** - * acquire the query handle according to the key from query mgmt object. - * @param pMgmt - * @param key - * @return - */ -void** qAcquireTask(void* pMgmt, uint64_t key); - /** * release the query handle and decrease the reference count in cache * @param pMgmt @@ -211,14 +172,6 @@ void** qAcquireTask(void* pMgmt, uint64_t key); */ void** qReleaseTask(void* pMgmt, void* pQInfo, bool freeHandle); -/** - * De-register the query handle from the management module and free it immediately. - * @param pMgmt - * @param pQInfo - * @return - */ -void** qDeregisterQInfo(void* pMgmt, void* pQInfo); - void qProcessFetchRsp(void* parent, struct SRpcMsg* pMsg, struct SEpSet* pEpSet); #ifdef __cplusplus diff --git a/include/libs/function/function.h b/include/libs/function/function.h index e7895bd972..278d9d8b7c 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/function/functionMgt.h b/include/libs/function/functionMgt.h index d1db2010d4..7d46b543cb 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -96,7 +96,16 @@ typedef enum EFunctionType { FUNCTION_TYPE_SERVER_SERSION, FUNCTION_TYPE_SERVER_STATUS, FUNCTION_TYPE_CURRENT_USER, - FUNCTION_TYPE_USER + FUNCTION_TYPE_USER, + + // pseudo column function + FUNCTION_TYPE_ROWTS = 3500, + FUNCTION_TYPE_TBNAME, + FUNCTION_TYPE_QSTARTTS, + FUNCTION_TYPE_QENDTS, + FUNCTION_TYPE_WSTARTTS, + FUNCTION_TYPE_WENDTS, + FUNCTION_TYPE_WDURATION } EFunctionType; struct SqlFunctionCtx; @@ -118,6 +127,8 @@ bool fmIsStringFunc(int32_t funcId); bool fmIsDatetimeFunc(int32_t funcId); bool fmIsTimelineFunc(int32_t funcId); bool fmIsTimeorderFunc(int32_t funcId); +bool fmIsWindowPseudoColumnFunc(int32_t funcId); +bool fmIsWindowClauseFunc(int32_t funcId); int32_t fmFuncScanType(int32_t funcId); diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 9b8739a4f3..83c0bccaaf 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,7 @@ typedef enum ENodeType { QUERY_NODE_CREATE_TOPIC_STMT, QUERY_NODE_DROP_TOPIC_STMT, QUERY_NODE_ALTER_LOCAL_STMT, + QUERY_NODE_EXPLAIN_STMT, QUERY_NODE_SHOW_DATABASES_STMT, QUERY_NODE_SHOW_TABLES_STMT, QUERY_NODE_SHOW_STABLES_STMT, @@ -121,6 +123,7 @@ typedef enum ENodeType { QUERY_NODE_LOGIC_PLAN_EXCHANGE, QUERY_NODE_LOGIC_PLAN_WINDOW, QUERY_NODE_LOGIC_PLAN_SORT, + QUERY_NODE_LOGIC_PLAN_PARTITION, QUERY_NODE_LOGIC_SUBPLAN, QUERY_NODE_LOGIC_PLAN, diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 08792b6f8f..f41e049196 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 { @@ -66,7 +67,11 @@ typedef struct SAggLogicNode { typedef struct SProjectLogicNode { SLogicNode node; SNodeList* pProjections; - char stmtName[TSDB_TABLE_NAME_LEN]; + char stmtName[TSDB_TABLE_NAME_LEN]; + int64_t limit; + int64_t offset; + int64_t slimit; + int64_t soffset; } SProjectLogicNode; typedef struct SVnodeModifLogicNode { @@ -106,6 +111,11 @@ typedef struct SSortLogicNode { SNodeList* pSortKeys; } SSortLogicNode; +typedef struct SPartitionLogicNode { + SLogicNode node; + SNodeList* pPartitionKeys; +} SPartitionLogicNode; + typedef enum ESubplanType { SUBPLAN_TYPE_MERGE = 1, SUBPLAN_TYPE_PARTIAL, @@ -150,7 +160,8 @@ typedef struct SDataBlockDescNode { ENodeType type; int16_t dataBlockId; SNodeList* pSlots; - int32_t resultRowSize; + int32_t totalRowSize; + int32_t outputRowSize; int16_t precision; } SDataBlockDescNode; @@ -187,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; @@ -195,6 +206,10 @@ typedef STableScanPhysiNode STableSeqScanPhysiNode; typedef struct SProjectPhysiNode { SPhysiNode node; SNodeList* pProjections; + int64_t limit; + int64_t offset; + int64_t slimit; + int64_t soffset; } SProjectPhysiNode; typedef struct SJoinPhysiNode { @@ -238,6 +253,7 @@ typedef struct SIntervalPhysiNode { int64_t sliding; int8_t intervalUnit; int8_t slidingUnit; + uint8_t precision; SFillNode* pFill; } SIntervalPhysiNode; @@ -283,11 +299,23 @@ typedef struct SSubplan { SDataSinkNode* pDataSink; // data of the subplan flow into the datasink } SSubplan; +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 66f60bde98..23a63c1a0b 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 { @@ -180,8 +181,8 @@ typedef struct SOrderByExprNode { typedef struct SLimitNode { ENodeType type; // QUERY_NODE_LIMIT - uint64_t limit; - uint64_t offset; + int64_t limit; + int64_t offset; } SLimitNode; typedef struct SStateWindowNode { @@ -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); diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index c6d17ef65c..7bc0ee42e9 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -58,6 +58,14 @@ int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +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 } #endif diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 02fe591a09..eadc901389 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -30,6 +30,11 @@ enum { STREAM_TASK_STATUS__STOP, }; +enum { + STREAM_CREATED_BY__USER = 1, + STREAM_CREATED_BY__SMA, +}; + #if 0 // pipe -> fetch/pipe queue // merge -> merge queue diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 8125de7647..157e0cb721 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -49,11 +49,13 @@ typedef struct SRpcMsg { } SRpcMsg; typedef struct { - char user[TSDB_USER_LEN]; - SRpcMsg rpcMsg; - int32_t rspLen; - void * pRsp; - void * pNode; + char user[TSDB_USER_LEN]; + uint32_t clientIp; + uint16_t clientPort; + SRpcMsg rpcMsg; + int32_t rspLen; + void *pRsp; + void *pNode; } SNodeMsg; typedef struct SRpcInit { @@ -105,20 +107,20 @@ void rpcClose(void *); void * rpcMallocCont(int contLen); void rpcFreeCont(void *pCont); void * rpcReallocCont(void *ptr, int contLen); -void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid); -void rpcSendRequestWithCtx(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid, SRpcCtx *ctx); +// Because taosd supports multi-process mode +// These functions should not be used on the server side +// Please use tmsg functions, which are defined in tmsgcb.h +void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid); void rpcSendResponse(const SRpcMsg *pMsg); +void rpcRegisterBrokenLinkArg(SRpcMsg *msg); +void rpcReleaseHandle(void *handle, int8_t type); // just release client conn to rpc instance, no close sock + +// These functions will not be called in the child process void rpcSendRedirectRsp(void *pConn, const SEpSet *pEpSet); +void rpcSendRequestWithCtx(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid, SRpcCtx *ctx); int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo); void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); -int rpcReportProgress(void *pConn, char *pCont, int contLen); -void rpcCancelRequest(int64_t rid); -void rpcRegisterBrokenLinkArg(SRpcMsg *msg); -// just release client conn to rpc instance, no close sock -void rpcReleaseHandle(void *handle, int8_t type); // -void rpcRefHandle(void *handle, int8_t type); -void rpcUnrefHandle(void *handle, int8_t type); #ifdef __cplusplus } diff --git a/include/os/os.h b/include/os/os.h index e7ce7d09ea..0d0c308134 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" @@ -84,6 +86,7 @@ extern "C" { #include "osThread.h" #include "osSemaphore.h" #include "osSignal.h" +#include "osShm.h" #include "osSleep.h" #include "osSocket.h" #include "osString.h" diff --git a/source/libs/scalar/inc/sclfunc.h b/include/os/osShm.h similarity index 70% rename from source/libs/scalar/inc/sclfunc.h rename to include/os/osShm.h index 679411e004..82ee2339f2 100644 --- a/source/libs/scalar/inc/sclfunc.h +++ b/include/os/osShm.h @@ -12,21 +12,27 @@ * 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_OS_SHM_H_ +#define _TD_OS_SHM_H_ #ifdef __cplusplus extern "C" { #endif -#include "function.h" -#include "scalar.h" - - +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); +void taosDetachShm(SShm *pShm); #ifdef __cplusplus } #endif -#endif // TDENGINE_TSCALARFUNCTION_H +#endif /*_TD_OS_SHM_H_*/ diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 994ad7afc6..d49e83b012 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" { diff --git a/include/util/tdef.h b/include/util/tdef.h index 193be4a3e6..43981adea2 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -381,6 +381,14 @@ 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_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 diff --git a/include/util/tprocess.h b/include/util/tprocess.h index a0be38a3ad..51ce0243b7 100644 --- a/include/util/tprocess.h +++ b/include/util/tprocess.h @@ -22,11 +22,14 @@ extern "C" { #endif +typedef enum { PROC_REQ, PROC_RSP, PROC_REG, PROC_RELEASE } ProcFuncType; + typedef struct SProcQueue SProcQueue; typedef struct SProcObj SProcObj; typedef void *(*ProcMallocFp)(int32_t contLen); typedef void *(*ProcFreeFp)(void *pCont); -typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen); +typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, + ProcFuncType ftype); typedef struct { int32_t childQueueSize; @@ -52,9 +55,10 @@ int32_t taosProcRun(SProcObj *pProc); void taosProcStop(SProcObj *pProc); bool taosProcIsChild(SProcObj *pProc); int32_t taosProcChildId(SProcObj *pProc); - -int32_t taosProcPutToChildQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen); -int32_t taosProcPutToParentQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen); +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, + ProcFuncType ftype); #ifdef __cplusplus } diff --git a/source/client/consumer/consumer.c b/source/client/consumer/consumer.c deleted file mode 100644 index 4ba1f95144..0000000000 --- a/source/client/consumer/consumer.c +++ /dev/null @@ -1,16 +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 "consumer.h" diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 8e67703ce5..53cc77af1a 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -200,6 +200,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/clientMain.c b/source/client/src/clientMain.c index a84aebabc8..42d4b5b2e5 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -1,12 +1,27 @@ -#include "os.h" -#include "tref.h" -#include "trpc.h" +/* + * 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 "catalog.h" #include "clientInt.h" #include "clientLog.h" +#include "os.h" #include "query.h" -#include "tmsg.h" #include "tglobal.h" -#include "catalog.h" +#include "tmsg.h" +#include "tref.h" +#include "trpc.h" #include "version.h" #define TSC_VAR_NOT_RELEASE 1 @@ -24,7 +39,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { } } - int ret = taos_options_imp(option, (const char*)arg); + int ret = taos_options_imp(option, (const char *)arg); atomic_store_32(&lock, 0); return ret; } @@ -56,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) { @@ -69,13 +90,13 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha return taos_connect_internal(ip, user, pass, NULL, db, port); } -void taos_close(TAOS* taos) { +void taos_close(TAOS *taos) { if (taos == NULL) { return; } STscObj *pTscObj = (STscObj *)taos; - tscDebug("0x%"PRIx64" try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs); + tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs); /*taosRemoveRef(clientConnRefPool, pTscObj->id);*/ } @@ -85,48 +106,46 @@ int taos_errno(TAOS_RES *tres) { return terrno; } - return ((SRequestObj*) tres)->code; + return ((SRequestObj *)tres)->code; } const char *taos_errstr(TAOS_RES *res) { - SRequestObj *pRequest = (SRequestObj *) res; + SRequestObj *pRequest = (SRequestObj *)res; if (pRequest == NULL) { - return (const char*) tstrerror(terrno); + return (const char *)tstrerror(terrno); } if (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) { return pRequest->msgBuf; } else { - return (const char*)tstrerror(pRequest->code); + return (const char *)tstrerror(pRequest->code); } } void taos_free_result(TAOS_RES *res) { - SRequestObj* pRequest = (SRequestObj*) res; + SRequestObj *pRequest = (SRequestObj *)res; destroyRequest(pRequest); } -int taos_field_count(TAOS_RES *res) { +int taos_field_count(TAOS_RES *res) { if (res == NULL) { return 0; } - SRequestObj* pRequest = (SRequestObj*) res; - SReqResultInfo* pResInfo = &pRequest->body.resInfo; + SRequestObj *pRequest = (SRequestObj *)res; + SReqResultInfo *pResInfo = &pRequest->body.resInfo; return pResInfo->numOfCols; } -int taos_num_fields(TAOS_RES *res) { - return taos_field_count(res); -} +int taos_num_fields(TAOS_RES *res) { return taos_field_count(res); } TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { if (taos_num_fields(res) == 0) { return NULL; } - SReqResultInfo* pResInfo = &(((SRequestObj*) res)->body.resInfo); + SReqResultInfo *pResInfo = &(((SRequestObj *)res)->body.resInfo); return pResInfo->fields; } @@ -135,7 +154,7 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) { return NULL; } - return taos_query_l(taos, sql, (int32_t) strlen(sql)); + return taos_query_l(taos, sql, (int32_t)strlen(sql)); } TAOS_ROW taos_fetch_row(TAOS_RES *res) { @@ -143,18 +162,16 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } - SRequestObj *pRequest = (SRequestObj *) res; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || - pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || - taos_num_fields(res) == 0) { + SRequestObj *pRequest = (SRequestObj *)res; + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { return NULL; } return doFetchRow(pRequest, true); } -int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { +int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { int32_t len = 0; for (int i = 0; i < num_fields; ++i) { if (i > 0) { @@ -213,7 +230,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: { - int32_t charLen = varDataLen((char*)row[i] - VARSTR_HEADER_SIZE); + int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE); if (fields[i].type == TSDB_DATA_TYPE_BINARY) { assert(charLen <= fields[i].bytes && charLen >= 0); } else { @@ -238,31 +255,49 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) return len; } -int* taos_fetch_lengths(TAOS_RES *res) { +int *taos_fetch_lengths(TAOS_RES *res) { if (res == NULL) { return NULL; } - return ((SRequestObj*) res)->body.resInfo.length; + 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) { - case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL"; - case TSDB_DATA_TYPE_BOOL: return "TSDB_DATA_TYPE_BOOL"; - case TSDB_DATA_TYPE_TINYINT: return "TSDB_DATA_TYPE_TINYINT"; - case TSDB_DATA_TYPE_SMALLINT: return "TSDB_DATA_TYPE_SMALLINT"; - case TSDB_DATA_TYPE_INT: return "TSDB_DATA_TYPE_INT"; - case TSDB_DATA_TYPE_BIGINT: return "TSDB_DATA_TYPE_BIGINT"; - case TSDB_DATA_TYPE_FLOAT: return "TSDB_DATA_TYPE_FLOAT"; - case TSDB_DATA_TYPE_DOUBLE: return "TSDB_DATA_TYPE_DOUBLE"; - case TSDB_DATA_TYPE_VARCHAR: return "TSDB_DATA_TYPE_VARCHAR"; -// case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_VARCHAR"; - case TSDB_DATA_TYPE_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP"; - case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR"; - case TSDB_DATA_TYPE_JSON: return "TSDB_DATA_TYPE_JSON"; - default: return "UNKNOWN"; + case TSDB_DATA_TYPE_NULL: + return "TSDB_DATA_TYPE_NULL"; + case TSDB_DATA_TYPE_BOOL: + return "TSDB_DATA_TYPE_BOOL"; + case TSDB_DATA_TYPE_TINYINT: + return "TSDB_DATA_TYPE_TINYINT"; + case TSDB_DATA_TYPE_SMALLINT: + return "TSDB_DATA_TYPE_SMALLINT"; + case TSDB_DATA_TYPE_INT: + return "TSDB_DATA_TYPE_INT"; + case TSDB_DATA_TYPE_BIGINT: + return "TSDB_DATA_TYPE_BIGINT"; + case TSDB_DATA_TYPE_FLOAT: + return "TSDB_DATA_TYPE_FLOAT"; + case TSDB_DATA_TYPE_DOUBLE: + return "TSDB_DATA_TYPE_DOUBLE"; + case TSDB_DATA_TYPE_VARCHAR: + return "TSDB_DATA_TYPE_VARCHAR"; + // case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_VARCHAR"; + case TSDB_DATA_TYPE_TIMESTAMP: + return "TSDB_DATA_TYPE_TIMESTAMP"; + case TSDB_DATA_TYPE_NCHAR: + return "TSDB_DATA_TYPE_NCHAR"; + case TSDB_DATA_TYPE_JSON: + return "TSDB_DATA_TYPE_JSON"; + default: + return "UNKNOWN"; } } @@ -273,8 +308,8 @@ int taos_affected_rows(TAOS_RES *res) { return 0; } - SRequestObj* pRequest = (SRequestObj*) res; - SReqResultInfo* pResInfo = &pRequest->body.resInfo; + SRequestObj *pRequest = (SRequestObj *)res; + SReqResultInfo *pResInfo = &pRequest->body.resInfo; return pResInfo->numOfRows; } @@ -295,8 +330,8 @@ int taos_select_db(TAOS *taos, const char *db) { char sql[256] = {0}; snprintf(sql, tListLen(sql), "use %s", db); - TAOS_RES* pRequest = taos_query(taos, sql); - int32_t code = taos_errno(pRequest); + TAOS_RES *pRequest = taos_query(taos, sql); + int32_t code = taos_errno(pRequest); taos_free_result(pRequest); return code; @@ -307,53 +342,59 @@ void taos_stop_query(TAOS_RES *res) { return; } - SRequestObj* pRequest = (SRequestObj*) res; - int32_t numOfFields = taos_num_fields(pRequest); + SRequestObj *pRequest = (SRequestObj *)res; + int32_t numOfFields = taos_num_fields(pRequest); // It is not a query, no need to stop. if (numOfFields == 0) { return; } -// scheduleCancelJob(pRequest->body.pQueryJob); + // scheduleCancelJob(pRequest->body.pQueryJob); } bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { - SRequestObj* pRequestObj = res; - SReqResultInfo* pResultInfo = &pRequestObj->body.resInfo; + SRequestObj *pRequestObj = res; + SReqResultInfo *pResultInfo = &pRequestObj->body.resInfo; if (col >= pResultInfo->numOfCols || col < 0 || row >= pResultInfo->numOfRows || row < 0) { return true; } - SResultColumn* pCol = &pRequestObj->body.resInfo.pCol[col]; + SResultColumn *pCol = &pRequestObj->body.resInfo.pCol[col]; return colDataIsNull_f(pCol->nullbitmap, row); } -int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { +bool taos_is_update_query(TAOS_RES *res) { + // TODO + return true; +} + +int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { if (res == NULL) { return 0; } - SRequestObj *pRequest = (SRequestObj *) res; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || - pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || - taos_num_fields(res) == 0) { + SRequestObj *pRequest = (SRequestObj *)res; + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { return 0; } doFetchRow(pRequest, false); // TODO refactor - SReqResultInfo* pResultInfo = &pRequest->body.resInfo; + SReqResultInfo *pResultInfo = &pRequest->body.resInfo; pResultInfo->current = pResultInfo->numOfRows; *rows = pResultInfo->row; return pResultInfo->numOfRows; } -int taos_validate_sql(TAOS *taos, const char *sql) { - return true; +int taos_validate_sql(TAOS *taos, const char *sql) { return true; } + +void taos_reset_current_db(TAOS *taos) { + // TODO + return; } const char *taos_get_server_info(TAOS *taos) { @@ -361,7 +402,7 @@ const char *taos_get_server_info(TAOS *taos) { return NULL; } - STscObj* pTscObj = (STscObj*) taos; + STscObj *pTscObj = (STscObj *)taos; return pTscObj->ver; } @@ -387,52 +428,67 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { // TODO } -TAOS_STMT* taos_stmt_init(TAOS* taos) { - // TODO - return NULL; +int taos_load_table_info(TAOS *taos, const char *tableNameList) { + // TODO + return -1; } -int taos_stmt_close(TAOS_STMT* stmt) { - // TODO - return -1; +TAOS_STMT *taos_stmt_init(TAOS *taos) { + // TODO + return NULL; } -int taos_stmt_execute(TAOS_STMT* stmt) { - // TODO - return -1; +int taos_stmt_close(TAOS_STMT *stmt) { + // TODO + return -1; +} + +int taos_stmt_execute(TAOS_STMT *stmt) { + // TODO + return -1; } char *taos_stmt_errstr(TAOS_STMT *stmt) { - // TODO - return NULL; + // TODO + return NULL; } -int taos_stmt_affected_rows(TAOS_STMT* stmt) { +int taos_stmt_affected_rows(TAOS_STMT *stmt) { + // TODO + return -1; +} + +TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) { + // TODO + return NULL; +} + +int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind) { + // TODO + return -1; +} + +int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) { + // TODO + return -1; +} + +int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags) { + // TODO + return -1; +} + +int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) { + // TODO + return -1; +} + +int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) { // TODO return -1; } -TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) { - // TODO - return NULL; -} - -int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) { - // TODO - return -1; -} - -int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { - // TODO - return -1; -} - -int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) { - // TODO - return -1; -} - -int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { +int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) { // TODO return -1; } @@ -442,6 +498,11 @@ int taos_stmt_add_batch(TAOS_STMT* stmt) { return -1; } +TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) { + // TODO + return NULL; +} + int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) { // TODO return -1; diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 5d00cca76e..1fa267ae7e 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -26,6 +26,18 @@ #include "tqueue.h" #include "tref.h" +typedef struct { + int32_t curBlock; + int32_t curRow; + void** uData; +} SMqRowIter; + +struct tmq_message_t { + SMqPollRsp msg; + void* vg; + SMqRowIter iter; +}; + struct tmq_list_t { SArray container; }; @@ -99,13 +111,14 @@ typedef struct { typedef struct { // subscribe info - int32_t sqlLen; - char* sql; - char* topicName; - int64_t topicId; - int32_t nextVgIdx; - SArray* vgs; // SArray - SSchemaWrapper schema; + int32_t sqlLen; + char* sql; + char* topicName; + int64_t topicId; + SArray* vgs; // SArray + int8_t isSchemaAdaptive; + int32_t numOfFields; + TAOS_FIELD* fields; } SMqClientTopic; typedef struct { @@ -130,11 +143,11 @@ typedef struct { } SMqPollCbParam; typedef struct { - tmq_t* tmq; - /*SMqClientVg* pVg;*/ + tmq_t* tmq; int32_t async; tsem_t rspSem; tmq_resp_err_t rspErr; + /*SMqClientVg* pVg;*/ } SMqCommitCbParam; tmq_conf_t* tmq_conf_new() { @@ -228,6 +241,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) { @@ -471,7 +488,12 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) { tNameExtractFullName(&name, topicFname); tscDebug("subscribe topic: %s", topicFname); SMqClientTopic topic = { - .nextVgIdx = 0, .sql = NULL, .sqlLen = 0, .topicId = 0, .topicName = topicFname, .vgs = NULL}; + .sql = NULL, + .sqlLen = 0, + .topicId = 0, + .topicName = topicFname, + .vgs = NULL, + }; topic.vgs = taosArrayInit(0, sizeof(SMqClientVg)); taosArrayPush(tmq->clientTopics, &topic); taosArrayPush(req.topicNames, &topicFname); @@ -615,6 +637,7 @@ _return: return pRequest; } +#if 0 TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) { STscObj* pTscObj = (STscObj*)taos; SRequestObj* pRequest = NULL; @@ -700,6 +723,7 @@ _return: return pRequest; } +#endif static char* formatTimestamp(char* buf, int64_t val, int precision) { time_t tt; @@ -807,7 +831,7 @@ 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); + tscWarn("msg discard, code:%x", code); goto WRITE_QUEUE_FAIL; } @@ -815,12 +839,12 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { int32_t tmqEpoch = atomic_load_32(&tmq->epoch); if (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); } @@ -879,19 +903,54 @@ WRITE_QUEUE_FAIL: bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { /*printf("call update ep %d\n", 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); + 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; + if (pOffset != NULL) { + offset = *pOffset; + } SMqClientVg clientVg = { .pollCnt = 0, - .currentOffset = pVgEp->offset, + .currentOffset = offset, .vgId = pVgEp->vgId, .epSet = pVgEp->epSet, .vgStatus = TMQ_VG_STATUS__IDLE, @@ -902,6 +961,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; @@ -911,7 +971,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param; tmq_t* tmq = pParam->tmq; 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; } @@ -1282,6 +1342,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); diff --git a/source/client/test/tmqTest.cpp b/source/client/test/tmqTest.cpp index c34c10d871..d45050d7ff 100644 --- a/source/client/test/tmqTest.cpp +++ b/source/client/test/tmqTest.cpp @@ -35,7 +35,7 @@ int main(int argc, char** argv) { TEST(testCase, driverInit_Test) { // taosInitGlobalCfg(); -// taos_init(); + // taos_init(); } TEST(testCase, create_topic_ctb_Test) { @@ -55,8 +55,9 @@ TEST(testCase, create_topic_ctb_Test) { taos_free_result(pRes); - char* sql = "select * from tu"; - pRes = tmq_create_topic(pConn, "test_ctb_topic_1", sql, strlen(sql)); + // char* sql = "select * from tu"; + // pRes = tmq_create_topic(pConn, "test_ctb_topic_1", sql, strlen(sql)); + pRes = taos_query(pConn, "create test_ctb_topic_1 as select * from tu"); taos_free_result(pRes); taos_close(pConn); } @@ -69,7 +70,7 @@ TEST(testCase, create_topic_stb_Test) { if (taos_errno(pRes) != 0) { printf("error in use db, reason:%s\n", taos_errstr(pRes)); } - //taos_free_result(pRes); + // taos_free_result(pRes); TAOS_FIELD* pFields = taos_fetch_fields(pRes); ASSERT_TRUE(pFields == nullptr); @@ -79,8 +80,9 @@ TEST(testCase, create_topic_stb_Test) { taos_free_result(pRes); - char* sql = "select * from st1"; - pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql)); + // char* sql = "select * from st1"; + // pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql)); + pRes = taos_query(pConn, "create test_ctb_topic_1 as select * from st1"); taos_free_result(pRes); taos_close(pConn); } diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index d2a5f1ab74..7f25fd1e80 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; @@ -647,7 +630,6 @@ double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { typedef struct SSDataBlockSortHelper { SArray* orderInfo; // SArray SSDataBlock* pDataBlock; - bool nullFirst; } SSDataBlockSortHelper; int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) { @@ -672,11 +654,11 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) { } if (rightNull) { - return pHelper->nullFirst ? 1 : -1; + return pOrder->nullFirst ? 1 : -1; } if (leftNull) { - return pHelper->nullFirst ? -1 : 1; + return pOrder->nullFirst ? -1 : 1; } } @@ -907,7 +889,7 @@ static __compar_fn_t getComparFn(int32_t type, int32_t order) { } } -int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst) { +int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { ASSERT(pDataBlock != NULL && pOrderInfo != NULL); if (pDataBlock->info.rows <= 1) { return TSDB_CODE_SUCCESS; @@ -922,7 +904,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs for (int32_t i = 0; i < taosArrayGetSize(pOrderInfo); ++i) { SBlockOrderInfo* pInfo = taosArrayGet(pOrderInfo, i); - SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, pInfo->colIndex); + SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, pInfo->slotId); if (pColInfoData->hasNull) { sortColumnHasNull = true; } @@ -961,10 +943,10 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs int64_t p0 = taosGetTimestampUs(); - SSDataBlockSortHelper helper = {.nullFirst = nullFirst, .pDataBlock = pDataBlock, .orderInfo = pOrderInfo}; + SSDataBlockSortHelper helper = {.pDataBlock = pDataBlock, .orderInfo = pOrderInfo}; for (int32_t i = 0; i < taosArrayGetSize(helper.orderInfo); ++i) { struct SBlockOrderInfo* pInfo = taosArrayGet(helper.orderInfo, i); - pInfo->pColData = taosArrayGet(pDataBlock->pDataBlock, pInfo->colIndex); + pInfo->pColData = taosArrayGet(pDataBlock->pDataBlock, pInfo->slotId); } taosqsort(index, rows, sizeof(int32_t), &helper, dataBlockCompar); @@ -1012,7 +994,7 @@ SHelper* createTupleIndex_rv(int32_t numOfRows, SArray* pOrderInfo, SSDataBlock* for (int32_t i = 0; i < numOfCols; ++i) { SBlockOrderInfo* pInfo = taosArrayGet(pOrderInfo, i); - SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, pInfo->colIndex); + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, pInfo->slotId); pInfo->pColData = pColInfo; sortValLengthPerRow += pColInfo->info.bytes; } @@ -1106,7 +1088,7 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF // Allocate the additional buffer. int64_t p0 = taosGetTimestampUs(); - SSDataBlockSortHelper helper = {.nullFirst = nullFirst, .pDataBlock = pDataBlock, .orderInfo = pOrderInfo}; + SSDataBlockSortHelper helper = {.pDataBlock = pDataBlock, .orderInfo = pOrderInfo}; uint32_t rows = pDataBlock->info.rows; SHelper* index = createTupleIndex_rv(rows, helper.orderInfo, pDataBlock); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index efd790ade8..c79e153122 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/tmsgcb.c b/source/common/src/tmsgcb.c index 98ee1b679d..e90634a604 100644 --- a/source/common/src/tmsgcb.c +++ b/source/common/src/tmsgcb.c @@ -16,6 +16,10 @@ #define _DEFAULT_SOURCE #include "tmsgcb.h" +static SMsgCb tsDefaultMsgCb; + +void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb) { tsDefaultMsgCb = *pMsgCb; } + int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq) { return (*pMsgCb->queueFps[qtype])(pMsgCb->pWrapper, pReq); } @@ -24,7 +28,7 @@ int32_t tmsgGetQueueSize(const SMsgCb* pMsgCb, int32_t vgId, EQueueType qtype) { return (*pMsgCb->qsizeFp)(pMsgCb->pWrapper, vgId, qtype); } -int32_t tmsgSendReq(const SMsgCb* pMsgCb, SEpSet* epSet, SRpcMsg* pReq) { +int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq) { return (*pMsgCb->sendReqFp)(pMsgCb->pWrapper, epSet, pReq); } @@ -32,4 +36,12 @@ int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq) { return (*pMsgCb->sendMnodeReqFp)(pMsgCb->pWrapper, pReq); } -void tmsgSendRsp(const SMsgCb* pMsgCb, SRpcMsg* pRsp) { return (*pMsgCb->sendRspFp)(pMsgCb->pWrapper, pRsp); } +void tmsgSendRsp(const SRpcMsg* pRsp) { return (*tsDefaultMsgCb.sendRspFp)(tsDefaultMsgCb.pWrapper, pRsp); } + +void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg) { + (*pMsgCb->registerBrokenLinkArgFp)(pMsgCb->pWrapper, pMsg); +} + +void tmsgReleaseHandle(void* handle, int8_t type) { + (*tsDefaultMsgCb.releaseHandleFp)(tsDefaultMsgCb.pWrapper, handle, type); +} \ No newline at end of file diff --git a/source/common/test/commonTests.cpp b/source/common/test/commonTests.cpp index ccd800d3f4..d60261dfca 100644 --- a/source/common/test/commonTests.cpp +++ b/source/common/test/commonTests.cpp @@ -167,10 +167,10 @@ TEST(testCase, Datablock_test) { printf("the second row of binary:%s, length:%d\n", (char*)varDataVal(pData), varDataLen(pData)); SArray* pOrderInfo = taosArrayInit(3, sizeof(SBlockOrderInfo)); - SBlockOrderInfo order = {.order = TSDB_ORDER_ASC, .colIndex = 0}; + SBlockOrderInfo order = {.nullFirst = true, .order = TSDB_ORDER_ASC, .slotId = 0}; taosArrayPush(pOrderInfo, &order); - blockDataSort(b, pOrderInfo, true); + blockDataSort(b, pOrderInfo); blockDataDestroy(b); taosArrayDestroy(pOrderInfo); diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 35ea166983..81c434eb27 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 98% rename from source/dnode/mgmt/bnode/src/bmInt.c rename to source/dnode/mgmt/bm/src/bmInt.c index e2506ab383..4b87f4463c 100644 --- a/source/dnode/mgmt/bnode/src/bmInt.c +++ b/source/dnode/mgmt/bm/src/bmInt.c @@ -24,6 +24,7 @@ static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; + msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; pOption->msgCb = msgCb; } 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/dndFile.c b/source/dnode/mgmt/container/src/dndFile.c deleted file mode 100644 index ab04040b57..0000000000 --- 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 93% rename from source/dnode/mgmt/dnode/inc/dm.h rename to source/dnode/mgmt/dm/inc/dm.h index 6c18d7969c..3984e6dbd4 100644 --- a/source/dnode/mgmt/dnode/inc/dm.h +++ b/source/dnode/mgmt/dm/inc/dm.h @@ -29,7 +29,7 @@ void dmInitMsgHandles(SMgmtWrapper *pWrapper); void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); -void dmSendRedirectRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); +void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pMsg); #ifdef __cplusplus } 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 100% rename from source/dnode/mgmt/dnode/src/dmFile.c rename to source/dnode/mgmt/dm/src/dmFile.c diff --git a/source/dnode/mgmt/dnode/src/dmInt.c b/source/dnode/mgmt/dm/src/dmInt.c similarity index 98% rename from source/dnode/mgmt/dnode/src/dmInt.c rename to source/dnode/mgmt/dm/src/dmInt.c index 53049f7e78..b729888a72 100644 --- a/source/dnode/mgmt/dnode/src/dmInt.c +++ b/source/dnode/mgmt/dm/src/dmInt.c @@ -54,7 +54,7 @@ void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqd taosRUnLockLatch(&pMgmt->latch); } -void dmSendRedirectRsp(SDnodeMgmt *pMgmt, SRpcMsg *pReq) { +void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) { SDnode *pDnode = pMgmt->pDnode; SEpSet epSet = {0}; diff --git a/source/dnode/mgmt/dnode/src/dmMsg.c b/source/dnode/mgmt/dm/src/dmMsg.c similarity index 100% rename from source/dnode/mgmt/dnode/src/dmMsg.c rename to source/dnode/mgmt/dm/src/dmMsg.c 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 baa486b91f..0000000000 --- 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 0000000000..525b26d967 --- /dev/null +++ b/source/dnode/mgmt/main/exe/dndMain.c @@ -0,0 +1,217 @@ +/* + * 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("signal:%d is received", signum); + SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); + if (pDnode != NULL) { + dndHandleEvent(pDnode, DND_EVENT_STOP); + } +} + +static void dndHandleChild(int signum, void *info, void *ctx) { + dInfo("signal:%d is received", signum); + dndHandleEvent(global.pDnode, DND_EVENT_CHILD); +} + +static void dndSetSignalHandle() { + taosSetSignal(SIGTERM, dndStopDnode); + taosSetSignal(SIGHUP, dndStopDnode); + taosSetSignal(SIGINT, dndStopDnode); + taosSetSignal(SIGABRT, dndStopDnode); + taosSetSignal(SIGBREAK, dndStopDnode); + + if (!tsMultiProcess) { + // Set the single process signal + } else if (global.ntype == DNODE) { + // Set the parent process signal + // When the child process exits, the parent process receives a signal + taosSetSignal(SIGCHLD, dndHandleChild); + } else { + // Set child process signal + // When the parent process exits, the child process will receive the SIGKILL signal + prctl(PR_SET_PDEATHSIG, SIGKILL); + } +} + +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], "-k") == 0) { + global.generateGrant = true; + } else if (strcmp(argv[i], "-n") == 0) { + global.ntype = atoi(argv[++i]); + } 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 dndSetProcName(char **argv) { + if (global.ntype != DNODE) { + const char *name = dndNodeProcStr(global.ntype); + prctl(PR_SET_NAME, name); + strcpy(argv[0], name); + } +} + +static int32_t dndRunDnode() { + if (dndInit() != 0) { + dError("failed to initialize 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 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; + } + + dndSetProcName((char **)argv); + return dndRunDnode(); +} diff --git a/source/dnode/mgmt/container/inc/dnd.h b/source/dnode/mgmt/main/inc/dnd.h similarity index 84% rename from source/dnode/mgmt/container/inc/dnd.h rename to source/dnode/mgmt/main/inc/dnd.h index 7c06e08dff..b416ee4f7a 100644 --- a/source/dnode/mgmt/container/inc/dnd.h +++ b/source/dnode/mgmt/main/inc/dnd.h @@ -33,6 +33,7 @@ #include "tthread.h" #include "ttime.h" #include "tworker.h" +#include "tmsgcb.h" #include "dnode.h" #include "monitor.h" @@ -95,10 +96,11 @@ typedef struct SMgmtWrapper { bool required; EProcType procType; 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 + int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode SMgmtFp fp; } SMgmtWrapper; @@ -118,27 +120,32 @@ 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 runtimeFile; 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); +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 dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); -int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, SEpSet *pEpSet, SRpcMsg *pMsg); -void dndSendRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp); +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); diff --git a/source/dnode/mgmt/container/inc/dndInt.h b/source/dnode/mgmt/main/inc/dndInt.h similarity index 88% rename from source/dnode/mgmt/container/inc/dndInt.h rename to source/dnode/mgmt/main/inc/dndInt.h index 8ea496b2fb..56782f872b 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 @@ -56,6 +55,12 @@ 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 +int32_t dndOpenRuntimeFile(SDnode *pDnode); +int32_t dndWriteRuntimeFile(SDnode *pDnode); +void dndCloseRuntimeFile(SDnode *pDnode); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/main/inc/dndMain.h b/source/dnode/mgmt/main/inc/dndMain.h deleted file mode 100644 index 1958d628a0..0000000000 --- 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/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c similarity index 84% rename from source/dnode/mgmt/container/src/dndExec.c rename to source/dnode/mgmt/main/src/dndExec.c index 8ffa53f034..c41d4f28e4 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -77,6 +77,8 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { 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); @@ -116,11 +118,11 @@ static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) { } } -static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t msgLen, void *pCont, int32_t contLen) { +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 process queue, type:%s handle:%p app:%p", pMsg, TMSG_INFO(pRpc->msgType), - pRpc->handle, pRpc->ahandle); + 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); @@ -138,13 +140,27 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t } } -static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, int32_t msgLen, void *pCont, int32_t contLen) { - pRpc->pCont = pCont; - dTrace("msg:%p, get from parent process queue, type:%s handle:%p app:%p", pRpc, TMSG_INFO(pRpc->msgType), - pRpc->handle, pRpc->ahandle); +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); - dndSendRsp(pWrapper, pRpc); - taosMemoryFree(pRpc); + 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) { @@ -155,6 +171,9 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { 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()); @@ -202,15 +221,23 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { dndClearNodesExecpt(pDnode, n); dInfo("node:%s, will be initialized in child process", pWrapper->name); - dndOpenNode(pWrapper); + 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; + if (taosProcRun(pProc) != 0) { + dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); + return -1; + } } } @@ -232,7 +259,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { } int32_t dndRun(SDnode *pDnode) { - if (tsMultiProcess == 0) { + if (!tsMultiProcess) { if (dndRunInSingleProcess(pDnode) != 0) { dError("failed to run dnode in single process mode since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/main/src/dndFile.c b/source/dnode/mgmt/main/src/dndFile.c new file mode 100644 index 0000000000..51d4ff3902 --- /dev/null +++ b/source/dnode/mgmt/main/src/dndFile.c @@ -0,0 +1,264 @@ +/* + * 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; +} + +int32_t dndOpenRuntimeFile(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.running", 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; + } + + if (taosLockFile(pFile) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to lock file:%s since %s", file, terrstr()); + 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) { + for (ENodeType ntype = DNODE; ntype < NODE_MAX; ++ntype) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->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 since %s", pWrapper->shm.id, terrstr()); + goto _OVER; + } + dDebug("shmid:%d, is attached, size:%d", pWrapper->shm.id, pWrapper->shm.size); + } + + dDebug("successed to open %s", file); + code = 0; + +_OVER: + if (root != NULL) cJSON_Delete(root); + if (code != 0) { + if (pFile != NULL) taosCloseFile(&pFile); + } else { + pDnode->runtimeFile = pFile; + } + + return code; +} + +int32_t dndWriteRuntimeFile(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.running.bak", pDnode->dataDir, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%s.running", 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[pDnode->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; + } + + dDebug("successed to write %s", realfile); + code = 0; + +_OVER: + if (pFile != NULL) { + taosCloseFile(&pFile); + } + + return code; +} + +void dndCloseRuntimeFile(SDnode *pDnode) { + if (pDnode->runtimeFile) { + taosUnLockFile(pDnode->runtimeFile); + taosCloseFile(&pDnode->runtimeFile); + pDnode->runtimeFile = NULL; + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/container/src/dndInt.c b/source/dnode/mgmt/main/src/dndInt.c similarity index 68% rename from source/dnode/mgmt/container/src/dndInt.c rename to source/dnode/mgmt/main/src/dndInt.c index 33d6bb0ee3..7dde3561fb 100644 --- a/source/dnode/mgmt/container/src/dndInt.c +++ b/source/dnode/mgmt/main/src/dndInt.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,29 +38,27 @@ int32_t dndInit() { monCfg.comp = tsMonitorComp; if (monInit(&monCfg) != 0) { dError("failed to init monitor since %s", terrstr()); - dndCleanup(); return -1; } - dInfo("dnode env is initialized"); + dDebug("dnode env is initialized"); return 0; } 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"); + dDebug("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/dndMain.c b/source/dnode/mgmt/main/src/dndMain.c deleted file mode 100644 index 3aff3446da..0000000000 --- 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 96% rename from source/dnode/mgmt/container/src/dndMsg.c rename to source/dnode/mgmt/main/src/dndMsg.c index 5da1d73034..3aafa5a5e3 100644 --- a/source/dnode/mgmt/container/src/dndMsg.c +++ b/source/dnode/mgmt/main/src/dndMsg.c @@ -42,6 +42,8 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { } memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); + pMsg->clientIp = connInfo.clientIp; + pMsg->clientPort = connInfo.clientPort; memcpy(&pMsg->rpcMsg, pRpc, sizeof(SRpcMsg)); return 0; } @@ -66,7 +68,7 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { } else if (pWrapper->procType == PROC_PARENT) { dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); - code = taosProcPutToChildQueue(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen); + code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, PROC_REQ); } else { dTrace("msg:%p, should not processed in child process, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); diff --git a/source/dnode/mgmt/container/src/dndObj.c b/source/dnode/mgmt/main/src/dndObj.c similarity index 91% rename from source/dnode/mgmt/container/src/dndObj.c rename to source/dnode/mgmt/main/src/dndObj.c index b9ea8df808..99dc782a9b 100644 --- a/source/dnode/mgmt/container/src/dndObj.c +++ b/source/dnode/mgmt/main/src/dndObj.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 || @@ -36,16 +37,12 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { 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; - } + dndCloseRuntimeFile(pDnode); taosMemoryFreeClear(pDnode->localEp); taosMemoryFreeClear(pDnode->localFqdn); taosMemoryFreeClear(pDnode->firstEp); @@ -67,13 +64,21 @@ 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) { + dmGetMgmtFp(&pDnode->wrappers[DNODE]); + mmGetMgmtFp(&pDnode->wrappers[MNODE]); + vmGetMgmtFp(&pDnode->wrappers[VNODES]); + qmGetMgmtFp(&pDnode->wrappers[QNODE]); + smGetMgmtFp(&pDnode->wrappers[SNODE]); + bmGetMgmtFp(&pDnode->wrappers[BNODE]); + + if (dndOpenRuntimeFile(pDnode) != 0) { + dError("failed to open runtime file since %s", terrstr()); goto _OVER; } @@ -87,13 +92,6 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { goto _OVER; } - dmGetMgmtFp(&pDnode->wrappers[DNODE]); - mmGetMgmtFp(&pDnode->wrappers[MNODE]); - vmGetMgmtFp(&pDnode->wrappers[VNODES]); - qmGetMgmtFp(&pDnode->wrappers[QNODE]); - smGetMgmtFp(&pDnode->wrappers[SNODE]); - bmGetMgmtFp(&pDnode->wrappers[BNODE]); - if (dndInitMsgHandle(pDnode) != 0) { goto _OVER; } @@ -116,7 +114,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { _OVER: if (code != 0 && pDnode) { - dndClearMemory(pDnode); + dndClearVars(pDnode); pDnode = NULL; dError("failed to create dnode object since %s", terrstr()); } else { @@ -145,7 +143,7 @@ void dndClose(SDnode *pDnode) { dndCloseNode(pWrapper); } - dndClearMemory(pDnode); + dndClearVars(pDnode); dInfo("dnode object is closed, data:%p", pDnode); } diff --git a/source/dnode/mgmt/main/src/dndStr.c b/source/dnode/mgmt/main/src/dndStr.c new file mode 100644 index 0000000000..00d8b0d6e0 --- /dev/null +++ b/source/dnode/mgmt/main/src/dndStr.c @@ -0,0 +1,64 @@ +/* + * 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"; + } +} diff --git a/source/dnode/mgmt/container/src/dndTransport.c b/source/dnode/mgmt/main/src/dndTransport.c similarity index 85% rename from source/dnode/mgmt/container/src/dndTransport.c rename to source/dnode/mgmt/main/src/dndTransport.c index b7d0cf26c0..07ea0309a8 100644 --- a/source/dnode/mgmt/container/src/dndTransport.c +++ b/source/dnode/mgmt/main/src/dndTransport.c @@ -309,7 +309,7 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { return 0; } -static int32_t dndSendRpcReq(STransMgmt *pMgmt, SEpSet *pEpSet, SRpcMsg *pReq) { +static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *pReq) { if (pMgmt->clientRpc == NULL) { terrno = TSDB_CODE_DND_OFFLINE; return -1; @@ -319,9 +319,8 @@ static int32_t dndSendRpcReq(STransMgmt *pMgmt, SEpSet *pEpSet, SRpcMsg *pReq) { return 0; } -int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, SEpSet *pEpSet, SRpcMsg *pReq) { - if (pWrapper->procType == PROC_CHILD) { - } else { +int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { + if (pWrapper->procType != PROC_CHILD) { SDnode *pDnode = pWrapper->pDnode; if (dndGetStatus(pDnode) != DND_STAT_RUNNING) { terrno = TSDB_CODE_DND_OFFLINE; @@ -329,26 +328,27 @@ int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, SEpSet *pEpSet, SRpcMsg *pReq) return -1; } return dndSendRpcReq(&pDnode->trans, pEpSet, pReq); + } else { + while (taosProcPutToParentQ(pWrapper->pProc, pReq, sizeof(SRpcMsg), pReq->pCont, pReq->contLen, PROC_REQ) != 0) { + taosMsleep(1); + } } } int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pReq) { - if (pWrapper->procType == PROC_CHILD) { - } else { - SDnode *pDnode = pWrapper->pDnode; - STransMgmt *pTrans = &pDnode->trans; - SEpSet epSet = {0}; + SDnode *pDnode = pWrapper->pDnode; + STransMgmt *pTrans = &pDnode->trans; + SEpSet epSet = {0}; - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, DNODE); - if (pWrapper != NULL) { - dmGetMnodeEpSet(pWrapper->pMgmt, &epSet); - dndReleaseWrapper(pWrapper); - } - return dndSendRpcReq(pTrans, &epSet, pReq); + SMgmtWrapper *pWrapper2 = dndAcquireWrapper(pDnode, DNODE); + if (pWrapper2 != NULL) { + dmGetMnodeEpSet(pWrapper2->pMgmt, &epSet); + dndReleaseWrapper(pWrapper2); } + return dndSendRpcReq(pTrans, &epSet, pReq); } -static void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) { +void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { if (pRsp->code == TSDB_CODE_APP_NOT_READY) { SMgmtWrapper *pDnodeWrapper = dndAcquireWrapper(pWrapper->pDnode, DNODE); if (pDnodeWrapper != NULL) { @@ -362,16 +362,45 @@ static void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) { } } -void dndSendRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) { - if (pWrapper->procType == PROC_CHILD) { - int32_t code = -1; - do { - code = taosProcPutToParentQueue(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen); - if (code != 0) { - taosMsleep(10); - } - } while (code != 0); - } else { +void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { + if (pWrapper->procType != PROC_CHILD) { dndSendRpcRsp(pWrapper, pRsp); + } else { + while (taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP) != 0) { + taosMsleep(1); + } } } + +void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { + if (pWrapper->procType != PROC_CHILD) { + rpcRegisterBrokenLinkArg(pMsg); + } else { + while (taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REG) != 0) { + taosMsleep(1); + } + } +} + +static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { + if (pWrapper->procType != PROC_CHILD) { + rpcReleaseHandle(handle, type); + } else { + SRpcMsg msg = {.handle = handle, .code = type}; + while (taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE) != 0) { + taosMsleep(1); + } + } +} + +SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) { + SMsgCb msgCb = { + .pWrapper = pWrapper, + .registerBrokenLinkArgFp = dndRegisterBrokenLinkArg, + .releaseHandleFp = dndReleaseHandle, + .sendMnodeReqFp = dndSendReqToMnode, + .sendReqFp = dndSendReqToDnode, + .sendRspFp = dndSendRsp, + }; + return msgCb; +} \ No newline at end of file diff --git a/source/dnode/mgmt/main/src/dndUtil.c b/source/dnode/mgmt/main/src/dndUtil.c deleted file mode 100644 index e07ef68c77..0000000000 --- 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 99% rename from source/dnode/mgmt/mnode/src/mmInt.c rename to source/dnode/mgmt/mm/src/mmInt.c index f5a3252fa2..3d15c9b9ae 100644 --- a/source/dnode/mgmt/mnode/src/mmInt.c +++ b/source/dnode/mgmt/mm/src/mmInt.c @@ -52,6 +52,7 @@ static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; + msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; pOption->msgCb = msgCb; } 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 98% rename from source/dnode/mgmt/qnode/src/qmInt.c rename to source/dnode/mgmt/qm/src/qmInt.c index c8cb7258c3..11c80a2904 100644 --- a/source/dnode/mgmt/qnode/src/qmInt.c +++ b/source/dnode/mgmt/qm/src/qmInt.c @@ -27,6 +27,7 @@ static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; + msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; pOption->msgCb = msgCb; } 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 98% rename from source/dnode/mgmt/snode/src/smInt.c rename to source/dnode/mgmt/sm/src/smInt.c index 351f7d656e..a639fc76bb 100644 --- a/source/dnode/mgmt/snode/src/smInt.c +++ b/source/dnode/mgmt/sm/src/smInt.c @@ -24,6 +24,7 @@ static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; + msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; pOption->msgCb = msgCb; } 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/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 464e789e46..b52c6253dc 100644 --- a/source/dnode/mgmt/vnode/src/vmInt.c +++ b/source/dnode/mgmt/vm/src/vmInt.c @@ -137,6 +137,7 @@ static void *vmOpenVnodeFunc(void *param) { msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; + msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; SVnodeCfg cfg = {.msgCb = msgCb, .pTfs = pMgmt->pTfs, .vgId = pCfg->vgId, .dbId = pCfg->dbUid}; SVnode *pImpl = vnodeOpen(pCfg->path, &cfg); if (pImpl == NULL) { @@ -284,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 68% rename from source/dnode/mgmt/vnode/src/vmMsg.c rename to source/dnode/mgmt/vm/src/vmMsg.c index 8090319582..f00bb89354 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vm/src/vmMsg.c @@ -91,6 +91,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; + msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; vnodeCfg.msgCb = msgCb; vnodeCfg.pTfs = pMgmt->pTfs; @@ -244,44 +245,45 @@ int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { void vmInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, vmProcessMergeMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, VND_VGID); 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 193807317f..9d62624756 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)); @@ -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 caf5172596..6976d83abd 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -731,10 +731,10 @@ typedef struct { int32_t vgNum; SRWLatch lock; int8_t status; - int8_t sourceType; - int8_t sinkType; // int32_t sqlLen; - int32_t sinkVgId; // 0 for automatic + int8_t createdBy; // STREAM_CREATED_BY__USER or SMA + int32_t fixedSinkVgId; // 0 for shuffle + int64_t smaId; // 0 for unused char* sql; char* logicalPlan; char* physicalPlan; diff --git a/source/dnode/mnode/impl/inc/mndScheduler.h b/source/dnode/mnode/impl/inc/mndScheduler.h index 416061bf34..42951beca2 100644 --- a/source/dnode/mnode/impl/inc/mndScheduler.h +++ b/source/dnode/mnode/impl/inc/mndScheduler.h @@ -27,7 +27,7 @@ void mndCleanupScheduler(SMnode* pMnode); int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub); -int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId); +int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h index e7cdd34a7e..b5d22cb7a5 100644 --- a/source/dnode/mnode/impl/inc/mndStream.h +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -31,7 +31,7 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream); SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw); -int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId); +int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 1b3564924a..6374b4cad2 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -26,8 +26,11 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { if (tEncodeI64(pEncoder, pObj->dbUid) < 0) return -1; if (tEncodeI32(pEncoder, pObj->version) < 0) return -1; if (tEncodeI8(pEncoder, pObj->status) < 0) return -1; + if (tEncodeI8(pEncoder, pObj->createdBy) < 0) return -1; + if (tEncodeI32(pEncoder, pObj->fixedSinkVgId) < 0) return -1; + if (tEncodeI64(pEncoder, pObj->smaId) < 0) return -1; if (tEncodeCStr(pEncoder, pObj->sql) < 0) return -1; - if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1; + /*if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1;*/ if (tEncodeCStr(pEncoder, pObj->physicalPlan) < 0) return -1; // TODO encode tasks if (pObj->tasks) { @@ -69,8 +72,11 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { if (tDecodeI64(pDecoder, &pObj->dbUid) < 0) return -1; if (tDecodeI32(pDecoder, &pObj->version) < 0) return -1; if (tDecodeI8(pDecoder, &pObj->status) < 0) return -1; + if (tDecodeI8(pDecoder, &pObj->createdBy) < 0) return -1; + if (tDecodeI32(pDecoder, &pObj->fixedSinkVgId) < 0) return -1; + if (tDecodeI64(pDecoder, &pObj->smaId) < 0) return -1; if (tDecodeCStrAlloc(pDecoder, &pObj->sql) < 0) return -1; - if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1; + /*if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;*/ if (tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan) < 0) return -1; pObj->tasks = NULL; int32_t sz; diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index c9b69bc161..ce08dfaaa3 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -20,138 +20,178 @@ #define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE) //!!!! Note: only APPEND columns in below tables, NO insert !!!! -static const SInfosTableSchema dnodesSchema[] = {{.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "max_vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - }; -static const SInfosTableSchema mnodesSchema[] = {{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - }; -static const SInfosTableSchema modulesSchema[] = {{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "module", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, - }; -static const SInfosTableSchema qnodesSchema[] = {{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - }; -static const SInfosTableSchema userDBSchema[] = {{.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.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 = "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}, - {.name = "minrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "maxrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "wallevel", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "fsync", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "precision", .bytes = 3 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, -// {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update - }; -static const SInfosTableSchema userFuncSchema[] = {{.name = "name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "ntables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "precision", .bytes = 2, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, - }; -static const SInfosTableSchema userIdxSchema[] = {{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_database", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "column_name", .bytes = 64, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_BINARY}, - }; -static const SInfosTableSchema userStbsSchema[] = {{.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.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}, - }; -static const SInfosTableSchema userStreamsSchema[] = {{.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_BINARY}, - }; +static const SInfosTableSchema dnodesSchema[] = { + {.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "max_vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, +}; +static const SInfosTableSchema mnodesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; +static const SInfosTableSchema modulesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "module", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, +}; +static const SInfosTableSchema qnodesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; +static const SInfosTableSchema userDBSchema[] = { + {.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.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 = "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}, + {.name = "minrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "maxrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "wallevel", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "fsync", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "precision", .bytes = 3 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + // {.name = "update", .bytes = 1, .type = + // TSDB_DATA_TYPE_TINYINT}, // disable update +}; +static const SInfosTableSchema userFuncSchema[] = { + {.name = "name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "ntables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "precision", .bytes = 2, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, +}; +static const SInfosTableSchema userIdxSchema[] = { + {.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "index_database", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "index_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "column_name", .bytes = 64, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_BINARY}, +}; +static const SInfosTableSchema userStbsSchema[] = { + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.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}, +}; +static const SInfosTableSchema userStreamsSchema[] = { + {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_BINARY}, +}; static const SInfosTableSchema userTblsSchema[] = { - {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "table_comment", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - }; -static const SInfosTableSchema userTblDistSchema[] = {{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "distributed_histogram", .bytes = 500, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "min_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "max_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "avg_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "stddev_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "rows", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "storage_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "compression_ratio", .bytes = 8, .type = TSDB_DATA_TYPE_DOUBLE}, - {.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - }; -static const SInfosTableSchema userUsersSchema[] = {{.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - }; -static const SInfosTableSchema vgroupsSchema[] = {{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "onlines", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v1_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v1_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "v2_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v2_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "v3_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v3_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "compacting", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "nfiles", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - }; + {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "table_comment", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; +static const SInfosTableSchema userTblDistSchema[] = { + {.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "distributed_histogram", .bytes = 500, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "min_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "max_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "avg_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "stddev_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "rows", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "storage_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "compression_ratio", .bytes = 8, .type = TSDB_DATA_TYPE_DOUBLE}, + {.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; +static const SInfosTableSchema userUsersSchema[] = { + {.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, +}; +static const SInfosTableSchema vgroupsSchema[] = { + {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "onlines", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v1_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v1_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "v2_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v2_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "v3_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v3_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "compacting", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "nfiles", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; -static const SInfosTableMeta infosMeta[] = {{TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema)}, - {TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)}, - {TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)}, - {TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)}, - {TSDB_INS_TABLE_USER_DATABASES, userDBSchema, tListLen(userDBSchema)}, - {TSDB_INS_TABLE_USER_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema)}, - {TSDB_INS_TABLE_USER_INDEXES, userIdxSchema, tListLen(userIdxSchema)}, - {TSDB_INS_TABLE_USER_STABLES, userStbsSchema, tListLen(userStbsSchema)}, - {TSDB_INS_TABLE_USER_STREAMS, userStreamsSchema, tListLen(userStreamsSchema)}, - {TSDB_INS_TABLE_USER_TABLES, userTblsSchema, tListLen(userTblsSchema)}, - {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, - {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, - {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, - }; +// TODO put into perf schema +static const SInfosTableSchema topicSchema[] = { + {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "row_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; -//connection/application/ +static const SInfosTableSchema consumerSchema[] = { + {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "status", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + // ep + // up time + // topics +}; + +static const SInfosTableSchema subscribeSchema[] = { + {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, +}; + +static const SInfosTableMeta infosMeta[] = { + {TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema)}, + {TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)}, + {TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)}, + {TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)}, + {TSDB_INS_TABLE_USER_DATABASES, userDBSchema, tListLen(userDBSchema)}, + {TSDB_INS_TABLE_USER_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema)}, + {TSDB_INS_TABLE_USER_INDEXES, userIdxSchema, tListLen(userIdxSchema)}, + {TSDB_INS_TABLE_USER_STABLES, userStbsSchema, tListLen(userStbsSchema)}, + {TSDB_INS_TABLE_USER_STREAMS, userStreamsSchema, tListLen(userStreamsSchema)}, + {TSDB_INS_TABLE_USER_TABLES, userTblsSchema, tListLen(userTblsSchema)}, + {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, + {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, + {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, +}; + +// connection/application/ int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, SSchema **pDst) { SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema)); if (NULL == schema) { @@ -161,7 +201,7 @@ int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, S for (int32_t i = 0; i < colNum; ++i) { strcpy(schema[i].name, pSrc[i].name); - + schema[i].type = pSrc[i].type; schema[i].colId = i + 1; schema[i].bytes = pSrc[i].bytes; @@ -182,11 +222,11 @@ int32_t mndInsInitMeta(SHashObj *hash) { for (int32_t i = 0; i < tListLen(infosMeta); ++i) { strcpy(meta.tbName, infosMeta[i].name); meta.numOfColumns = infosMeta[i].colNum; - + if (mndInitInfosTableSchema(infosMeta[i].schema, infosMeta[i].colNum, &meta.pSchemas)) { return -1; } - + if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -210,7 +250,7 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char * } *pRsp = *meta; - + pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema)); if (pRsp->pSchemas == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -237,13 +277,13 @@ void mndCleanupInfos(SMnode *pMnode) { if (NULL == pMnode->infosMeta) { return; } - + void *pIter = taosHashIterate(pMnode->infosMeta, NULL); while (pIter) { STableMetaRsp *meta = (STableMetaRsp *)pIter; taosMemoryFreeClear(meta->pSchemas); - + pIter = taosHashIterate(pMnode->infosMeta, pIter); } @@ -251,5 +291,3 @@ void mndCleanupInfos(SMnode *pMnode) { pMnode->infosMeta = NULL; } - - diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index bf378a4d43..6c38d8626c 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -44,7 +44,8 @@ typedef struct { SQueryDesc *pQueries; } SConnObj; -static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime); +static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid, + const char *app, int64_t startTime); static void mndFreeConn(SConnObj *pConn); static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId); static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn); @@ -94,7 +95,8 @@ void mndCleanupProfile(SMnode *pMnode) { } } -static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime) { +static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid, + const char *app, int64_t startTime) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; int32_t connId = atomic_add_fetch_32(&pMgmt->connId, 1); @@ -104,8 +106,8 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, SConnObj connObj = {.id = connId, .appStartTimeMs = startTime, .pid = pid, - .ip = pInfo->clientIp, - .port = pInfo->clientPort, + .ip = ip, + .port = port, .killed = 0, .loginTimeMs = taosGetTimestampMs(), .lastAccessTimeMs = 0, @@ -114,17 +116,17 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, .pQueries = NULL}; connObj.lastAccessTimeMs = connObj.loginTimeMs; - tstrncpy(connObj.user, pInfo->user, TSDB_USER_LEN); + tstrncpy(connObj.user, user, TSDB_USER_LEN); tstrncpy(connObj.app, app, TSDB_APP_NAME_LEN); int32_t keepTime = tsShellActivityTimer * 3; SConnObj *pConn = taosCachePut(pMgmt->cache, &connId, sizeof(int32_t), &connObj, sizeof(connObj), keepTime * 1000); if (pConn == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("conn:%d, failed to put into cache since %s, user:%s", connId, pInfo->user, terrstr()); + mError("conn:%d, failed to put into cache since %s, user:%s", connId, user, terrstr()); return NULL; } else { - mTrace("conn:%d, is created, data:%p user:%s", pConn->id, pConn, pInfo->user); + mTrace("conn:%d, is created, data:%p user:%s", pConn->id, pConn, user); return pConn; } } @@ -184,20 +186,14 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { SConnObj *pConn = NULL; int32_t code = -1; SConnectReq connReq = {0}; + char ip[30] = {0}; if (tDeserializeSConnectReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &connReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; goto CONN_OVER; } - SRpcConnInfo info = {0}; - if (rpcGetConnInfo(pReq->rpcMsg.handle, &info) != 0) { - mError("user:%s, failed to login while get connection info since %s", pReq->user, terrstr()); - goto CONN_OVER; - } - - char ip[30]; - taosIp2String(info.clientIp, ip); + taosIp2String(pReq->clientIp, ip); pUser = mndAcquireUser(pMnode, pReq->user); if (pUser == NULL) { @@ -216,7 +212,8 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { } } - pConn = mndCreateConn(pMnode, &info, connReq.pid, connReq.app, connReq.startTime); + pConn = + mndCreateConn(pMnode, pReq->user, pReq->clientIp, pReq->clientPort, connReq.pid, connReq.app, connReq.startTime); if (pConn == NULL) { mError("user:%s, failed to login from %s while create connection since %s", pReq->user, ip, terrstr()); goto CONN_OVER; @@ -241,7 +238,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { pReq->rspLen = contLen; pReq->pRsp = pRsp; - mDebug("user:%s, login from %s, conn:%d, app:%s", info.user, ip, pConn->id, connReq.app); + mDebug("user:%s, login from %s, conn:%d, app:%s", pReq->user, ip, pConn->id, connReq.app); code = 0; diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index e93a0d9b17..40b4f60bd4 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -14,15 +14,15 @@ */ #include "mndQuery.h" -#include "mndMnode.h" #include "executor.h" +#include "mndMnode.h" #include "qworker.h" int32_t mndProcessQueryMsg(SNodeMsg *pReq) { - mTrace("message in query queue is processing"); - SMnode *pMnode = pReq->pNode; + SMnode *pMnode = pReq->pNode; SReadHandle handle = {0}; + mTrace("msg:%p, in query queue is processing", pReq); switch (pReq->rpcMsg.msgType) { case TDMT_VND_QUERY: return qWorkerProcessQueryMsg(&handle, pMnode->pQuery, &pReq->rpcMsg); @@ -35,9 +35,9 @@ int32_t mndProcessQueryMsg(SNodeMsg *pReq) { } int32_t mndProcessFetchMsg(SNodeMsg *pReq) { - mTrace("message in fetch queue is processing"); SMnode *pMnode = pReq->pNode; - + mTrace("msg:%p, in fetch queue is processing", pReq); + switch (pReq->rpcMsg.msgType) { case TDMT_VND_FETCH: return qWorkerProcessFetchMsg(pMnode, pMnode->pQuery, &pReq->rpcMsg); @@ -52,9 +52,9 @@ int32_t mndProcessFetchMsg(SNodeMsg *pReq) { } int32_t mndInitQuery(SMnode *pMnode) { - int32_t code = qWorkerInit(NODE_TYPE_MNODE, MND_VGID, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb); - if (code) { - return code; + if (qWorkerInit(NODE_TYPE_MNODE, MND_VGID, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb) != 0) { + mError("failed to init qworker in mnode since %s", terrstr()); + return -1; } mndSetMsgHandle(pMnode, TDMT_VND_QUERY, mndProcessQueryMsg); @@ -67,4 +67,3 @@ int32_t mndInitQuery(SMnode *pMnode) { } void mndCleanupQuery(SMnode *pMnode) { qWorkerDestroy((void **)&pMnode->pQuery); } - diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 305912a72a..4562d9e5d3 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -119,7 +119,92 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) { return pVgroup; } -int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId) { +int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { + SSdb* pSdb = pMnode->pSdb; + void* pIter = NULL; + SArray* tasks = taosArrayGetP(pStream->tasks, 0); + + ASSERT(taosArrayGetSize(pStream->tasks) == 1); + + while (1) { + SVgObj* pVgroup; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup); + if (pIter == NULL) break; + if (pVgroup->dbUid != pStream->dbUid) { + sdbRelease(pSdb, pVgroup); + continue; + } + SStreamTask* pTask = tNewSStreamTask(pStream->uid); + if (pTask == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + taosArrayPush(tasks, &pTask); + + pTask->nodeId = pVgroup->vgId; + pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup); + + // source + pTask->sourceType = TASK_SOURCE__MERGE; + + // exec + pTask->execType = TASK_EXEC__NONE; + + // sink + if (pStream->createdBy == STREAM_CREATED_BY__SMA) { + pTask->sinkType = TASK_SINK__SMA; + pTask->smaSink.smaId = pStream->smaId; + } else { + pTask->sinkType = TASK_SINK__TABLE; + } + + // dispatch + pTask->dispatchType = TASK_DISPATCH__NONE; + + mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId); + } + return 0; +} + +int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { + ASSERT(pStream->fixedSinkVgId != 0); + SArray* tasks = taosArrayGetP(pStream->tasks, 0); + SStreamTask* pTask = tNewSStreamTask(pStream->uid); + if (pTask == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + taosArrayPush(tasks, &pTask); + + pTask->nodeId = pStream->fixedSinkVgId; + SVgObj* pVgroup = mndAcquireVgroup(pMnode, pStream->fixedSinkVgId); + if (pVgroup == NULL) { + return -1; + } + pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup); + // source + pTask->sourceType = TASK_SOURCE__MERGE; + + // exec + pTask->execType = TASK_EXEC__NONE; + + // sink + if (pStream->createdBy == STREAM_CREATED_BY__SMA) { + pTask->sinkType = TASK_SINK__SMA; + pTask->smaSink.smaId = pStream->smaId; + } else { + pTask->sinkType = TASK_SINK__TABLE; + } + // + // dispatch + pTask->dispatchType = TASK_DISPATCH__NONE; + + mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId); + + return 0; +} + +int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SSdb* pSdb = pMnode->pSdb; SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan); if (pPlan == NULL) { @@ -132,6 +217,19 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i ASSERT(totLevel <= 2); pStream->tasks = taosArrayInit(totLevel, sizeof(void*)); + bool hasExtraSink = false; + if (totLevel == 2) { + SArray* taskOneLevel = taosArrayInit(0, sizeof(void*)); + taosArrayPush(pStream->tasks, &taskOneLevel); + // add extra sink + hasExtraSink = true; + if (pStream->fixedSinkVgId == 0) { + mndAddShuffledSinkToStream(pMnode, pTrans, pStream); + } else { + mndAddFixedSinkToStream(pMnode, pTrans, pStream); + } + } + for (int32_t level = 0; level < totLevel; level++) { SArray* taskOneLevel = taosArrayInit(0, sizeof(void*)); SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, level); @@ -164,9 +262,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i // only for inplace pTask->sinkType = TASK_SINK__SHOW; pTask->showSink.reserved = 0; - if (smaId != -1) { - pTask->sinkType = TASK_SINK__SMA; - pTask->smaSink.smaId = smaId; + if (!hasExtraSink) { +#if 1 + if (pStream->createdBy == STREAM_CREATED_BY__SMA) { + pTask->sinkType = TASK_SINK__SMA; + pTask->smaSink.smaId = pStream->smaId; + } else { + pTask->sinkType = TASK_SINK__TABLE; + } +#endif } } else { pTask->sinkType = TASK_SINK__NONE; @@ -175,17 +279,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i // dispatch part if (level == 0) { pTask->dispatchType = TASK_DISPATCH__NONE; - // if inplace sink, no dispatcher - // if fixed ep, add fixed ep dispatcher - // if shuffle, add shuffle dispatcher } else { // add fixed ep dispatcher int32_t lastLevel = level - 1; ASSERT(lastLevel == 0); + if (hasExtraSink) lastLevel++; SArray* pArray = taosArrayGetP(pStream->tasks, lastLevel); // one merge only ASSERT(taosArrayGetSize(pArray) == 1); - SStreamTask* lastLevelTask = taosArrayGetP(pArray, lastLevel); + SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0); pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC; pTask->dispatchType = TASK_DISPATCH__FIXED; @@ -222,18 +324,55 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i /*pTask->sinkType = TASK_SINK__NONE;*/ // dispatch part - pTask->dispatchType = TASK_DISPATCH__NONE; -#if 0 - pTask->dispatchType = TASK_DISPATCH__SHUFFLE; - pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; - SDbObj* pDb = mndAcquireDb(pMnode, pStream->db); - ASSERT(pDb); - if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) { - sdbRelease(pSdb, pDb); - qDestroyQueryPlan(pPlan); - return -1; + ASSERT(hasExtraSink); + /*pTask->dispatchType = TASK_DISPATCH__NONE;*/ +#if 1 + + if (hasExtraSink) { + // add dispatcher + if (pStream->fixedSinkVgId == 0) { + pTask->dispatchType = TASK_DISPATCH__SHUFFLE; + + pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; + SDbObj* pDb = mndAcquireDb(pMnode, pStream->db); + ASSERT(pDb); + if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) { + sdbRelease(pSdb, pDb); + qDestroyQueryPlan(pPlan); + return -1; + } + sdbRelease(pSdb, pDb); + + // put taskId to useDbRsp + // TODO: optimize + SArray* pVgs = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; + int32_t sz = taosArrayGetSize(pVgs); + SArray* sinkLv = taosArrayGetP(pStream->tasks, 0); + int32_t sinkLvSize = taosArrayGetSize(sinkLv); + for (int32_t i = 0; i < sz; i++) { + SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i); + for (int32_t j = 0; j < sinkLvSize; j++) { + SStreamTask* pLastLevelTask = taosArrayGetP(sinkLv, j); + /*printf("vgid %d node id %d\n", pVgInfo->vgId, pTask->nodeId);*/ + if (pLastLevelTask->nodeId == pVgInfo->vgId) { + pVgInfo->taskId = pLastLevelTask->taskId; + /*printf("taskid %d set to %d\n", pVgInfo->taskId, pTask->taskId);*/ + break; + } + } + } + } else { + pTask->dispatchType = TASK_DISPATCH__FIXED; + pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; + SArray* pArray = taosArrayGetP(pStream->tasks, 0); + // one sink only + ASSERT(taosArrayGetSize(pArray) == 1); + SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0); + pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId; + pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId; + pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet; + } } - sdbRelease(pSdb, pDb); #endif // exec part diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 5c62cfa0f2..94114a96bf 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -415,6 +415,10 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre streamObj.dbUid = pDb->uid; streamObj.version = 1; streamObj.sql = pCreate->sql; + streamObj.createdBy = STREAM_CREATED_BY__SMA; + // TODO + streamObj.fixedSinkVgId = 0; + streamObj.smaId = smaObj.uid; /*streamObj.physicalPlan = "";*/ streamObj.logicalPlan = "not implemented"; @@ -428,7 +432,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; - if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, smaObj.uid) != 0) goto _OVER; + if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index bbb2f64282..376a41b0cd 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -246,7 +246,7 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) { return code; } -int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId) { +int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) { SNode *pAst = NULL; if (nodesStringToNode(ast, &pAst) < 0) { @@ -271,7 +271,7 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast return -1; } - if (mndScheduleStream(pMnode, pTrans, pStream, smaId) < 0) { + if (mndScheduleStream(pMnode, pTrans, pStream) < 0) { mError("stream:%ld, schedule stream since %s", pStream->uid, terrstr()); return -1; } @@ -300,6 +300,10 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe streamObj.dbUid = pDb->uid; streamObj.version = 1; streamObj.sql = pCreate->sql; + streamObj.createdBy = STREAM_CREATED_BY__USER; + // TODO + streamObj.fixedSinkVgId = 0; + streamObj.smaId = 0; /*streamObj.physicalPlan = "";*/ streamObj.logicalPlan = "not implemented"; @@ -310,7 +314,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe } mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name); - if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, -1) != 0) { + if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) { mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); return -1; diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 08a88a19ec..806415ccd9 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -62,8 +62,6 @@ static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqT static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp); -static int32_t mndInitUnassignedVg(SMnode *pMnode, const SMqTopicObj *pTopic, SMqSubscribeObj *pSub); - int32_t mndInitSubscribe(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_SUBSCRIBE, .keyType = SDB_KEY_BINARY, @@ -98,14 +96,6 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj return NULL; } -#if 0 - if (mndInitUnassignedVg(pMnode, pTopic, pSub) < 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - tDeleteSMqSubscribeObj(pSub); - taosMemoryFree(pSub); - return NULL; - } -#endif // TODO: disable alter subscribed table return pSub; } @@ -210,45 +200,6 @@ static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMq return 0; } -#if 0 -static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg) { - SMnode *pMnode = pMsg->pNode; - uint8_t *str = pMsg->rpcMsg.pCont; - SMqCMResetOffsetReq req; - - SCoder decoder; - tCoderInit(&decoder, TD_LITTLE_ENDIAN, str, pMsg->rpcMsg.contLen, TD_DECODER); - tDecodeSMqCMResetOffsetReq(&decoder, &req); - - SHashObj *pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); - if (pHash == NULL) { - return -1; - } - - for (int32_t i = 0; i < req.num; i++) { - SMqOffset *pOffset = &req.offsets[i]; - SMqVgOffsets *pVgOffset = taosHashGet(pHash, &pOffset->vgId, sizeof(int32_t)); - if (pVgOffset == NULL) { - pVgOffset = taosMemoryMalloc(sizeof(SMqVgOffsets)); - if (pVgOffset == NULL) { - return -1; - } - pVgOffset->offsets = taosArrayInit(0, sizeof(void *)); - taosArrayPush(pVgOffset->offsets, &pOffset); - } - taosHashPut(pHash, &pOffset->vgId, sizeof(int32_t), &pVgOffset, sizeof(void *)); - } - - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("mq-reset-offset: failed since %s", terrstr()); - return -1; - } - - return 0; -} -#endif - static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) { SMnode *pMnode = pMsg->pNode; SMqCMGetSubEpReq *pReq = (SMqCMGetSubEpReq *)pMsg->rpcMsg.pCont; @@ -574,251 +525,6 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { return 0; } -#if 0 - for (int32_t j = 0; j < consumerNum; j++) { - bool changed = false; - bool unfished = false; - - bool canUseLeft = imbalanceSolved < imbalanceVg; - bool mustUseLeft = canUseLeft && (imbalanceVg - imbalanceSolved >= consumerNum - j); - ASSERT(imbalanceVg - imbalanceSolved <= consumerNum - j); - - int32_t maxVg = vgEachConsumer + canUseLeft; - int32_t minVg = vgEachConsumer + mustUseLeft; - - SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, j); - int32_t vgThisConsumerBeforeRb = taosArrayGetSize(pSubConsumer->vgInfo); - int32_t vgThisConsumerAfterRb; - if (vgThisConsumerBeforeRb > maxVg) { - vgThisConsumerAfterRb = maxVg; - imbalanceSolved++; - changed = true; - } else if (vgThisConsumerBeforeRb < minVg) { - vgThisConsumerAfterRb = minVg; - if (mustUseLeft) imbalanceSolved++; - changed = true; - } else { - vgThisConsumerAfterRb = vgThisConsumerBeforeRb; - } - - if (vgThisConsumerBeforeRb > vgThisConsumerAfterRb) { - while (taosArrayGetSize(pSubConsumer->vgInfo) > vgThisConsumerAfterRb) { - // put into unassigned - SMqConsumerEp *pConsumerEp = taosArrayPop(pSubConsumer->vgInfo); - ASSERT(pConsumerEp != NULL); - ASSERT(pConsumerEp->consumerId == pSubConsumer->consumerId); - taosArrayPush(unassignedVgStash, pConsumerEp); - } - - } else if (vgThisConsumerBeforeRb < vgThisConsumerAfterRb) { - // assign from unassigned - while (taosArrayGetSize(pSubConsumer->vgInfo) < vgThisConsumerAfterRb) { - // if no unassgined, save j - if (taosArrayGetSize(unassignedVgStash) == 0) { - taosArrayPush(unassignedConsumerIdx, &j); - unfished = true; - break; - } - // assign vg to consumer - SMqConsumerEp *pConsumerEp = taosArrayPop(unassignedVgStash); - ASSERT(pConsumerEp != NULL); - pConsumerEp->oldConsumerId = pConsumerEp->consumerId; - pConsumerEp->consumerId = pSubConsumer->consumerId; - taosArrayPush(pSubConsumer->vgInfo, pConsumerEp); - // build msg and persist into trans - } - } - - if (changed && !unfished) { - SMqConsumerObj *pRebConsumer = mndAcquireConsumer(pMnode, pSubConsumer->consumerId); - pRebConsumer->epoch++; - if (vgThisConsumerAfterRb != 0) { - atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__ACTIVE); - } else { - atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__IDLE); - } - SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer); - sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY); - mndTransAppendRedolog(pTrans, pConsumerRaw); - mndReleaseConsumer(pMnode, pRebConsumer); - // TODO: save history - } - } - - for (int32_t j = 0; j < taosArrayGetSize(unassignedConsumerIdx); j++) { - bool canUseLeft = imbalanceSolved < imbalanceVg; - int32_t consumerIdx = *(int32_t *)taosArrayGet(unassignedConsumerIdx, j); - SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, consumerIdx); - if (canUseLeft) imbalanceSolved++; - // must use - int32_t vgThisConsumerAfterRb = taosArrayGetSize(pSubConsumer->vgInfo) + canUseLeft; - while (taosArrayGetSize(pSubConsumer->vgInfo) < vgEachConsumer + canUseLeft) { - // assign vg to consumer - SMqConsumerEp *pConsumerEp = taosArrayPop(unassignedVgStash); - ASSERT(pConsumerEp != NULL); - pConsumerEp->oldConsumerId = pConsumerEp->consumerId; - pConsumerEp->consumerId = pSubConsumer->consumerId; - taosArrayPush(pSubConsumer->vgInfo, pConsumerEp); - // build msg and persist into trans - } - SMqConsumerObj *pRebConsumer = mndAcquireConsumer(pMnode, pSubConsumer->consumerId); - pRebConsumer->epoch++; - atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__ACTIVE); - SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer); - sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY); - mndTransAppendRedolog(pTrans, pConsumerRaw); - mndReleaseConsumer(pMnode, pRebConsumer); - // TODO: save history - } -#endif - -#if 0 - //update consumer status for the subscribption - for (int32_t i = 0; i < taosArrayGetSize(pSub->assigned); i++) { - SMqConsumerEp *pCEp = taosArrayGet(pSub->assigned, i); - int64_t consumerId = pCEp->consumerId; - if (pCEp->status != -1) { - int32_t consumerHbStatus = atomic_fetch_add_32(&pCEp->consumerHbStatus, 1); - if (consumerHbStatus < MND_SUBSCRIBE_REBALANCE_CNT) { - continue; - } - // put consumer into lostConsumer - SMqConsumerEp* lostConsumer = taosArrayPush(pSub->lostConsumer, pCEp); - lostConsumer->qmsg = NULL; - // put vg into unassigned - taosArrayPush(pSub->unassignedVg, pCEp); - // remove from assigned - // TODO: swap with last one, reduce size and reset i - taosArrayRemove(pSub->assigned, i); - // remove from available consumer - for (int32_t j = 0; j < taosArrayGetSize(pSub->availConsumer); j++) { - if (*(int64_t *)taosArrayGet(pSub->availConsumer, i) == pCEp->consumerId) { - taosArrayRemove(pSub->availConsumer, j); - break; - } - // TODO: acquire consumer, set status to unavail - } -#if 0 - SMqConsumerObj* pConsumer = mndAcquireConsumer(pMnode, consumerId); - pConsumer->epoch++; - printf("current epoch %ld size %ld", pConsumer->epoch, pConsumer->topics->size); - SSdbRaw* pRaw = mndConsumerActionEncode(pConsumer); - sdbSetRawStatus(pRaw, SDB_STATUS_READY); - sdbWriteNotFree(pMnode->pSdb, pRaw); - mndReleaseConsumer(pMnode, pConsumer); -#endif - } - } - // no available consumer, skip rebalance - if (taosArrayGetSize(pSub->availConsumer) == 0) { - continue; - } - taosArrayGet(pSub->availConsumer, 0); - // rebalance condition1 : have unassigned vg - // assign vg to a consumer, trying to find the least assigned one - if ((sz = taosArrayGetSize(pSub->unassignedVg)) > 0) { - char *topic = NULL; - char *cgroup = NULL; - mndSplitSubscribeKey(pSub->key, &topic, &cgroup); - - SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - for (int32_t i = 0; i < sz; i++) { - int64_t consumerId = *(int64_t *)taosArrayGet(pSub->availConsumer, pSub->nextConsumerIdx); - pSub->nextConsumerIdx = (pSub->nextConsumerIdx + 1) % taosArrayGetSize(pSub->availConsumer); - - SMqConsumerEp *pCEp = taosArrayPop(pSub->unassignedVg); - pCEp->oldConsumerId = pCEp->consumerId; - pCEp->consumerId = consumerId; - taosArrayPush(pSub->assigned, pCEp); - - SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, consumerId); - pConsumer->epoch++; - SSdbRaw* pConsumerRaw = mndConsumerActionEncode(pConsumer); - sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY); - sdbWrite(pMnode->pSdb, pConsumerRaw); - mndReleaseConsumer(pMnode, pConsumer); - - void* msg; - int32_t msgLen; - mndBuildRebalanceMsg(&msg, &msgLen, pTopic, pCEp, cgroup, topic); - - // persist msg - STransAction action = {0}; - action.epSet = pCEp->epSet; - action.pCont = msg; - action.contLen = sizeof(SMsgHead) + msgLen; - action.msgType = TDMT_VND_MQ_SET_CONN; - mndTransAppendRedoAction(pTrans, &action); - - // persist data - SSdbRaw *pRaw = mndSubActionEncode(pSub); - sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mndTransAppendRedolog(pTrans, pRaw); - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - } - mndReleaseTopic(pMnode, pTopic); - mndTransDrop(pTrans); - taosMemoryFreeClear(topic); - taosMemoryFreeClear(cgroup); - } - // rebalance condition2 : imbalance assignment - } - return 0; -} -#endif - -#if 0 -static int32_t mndInitUnassignedVg(SMnode *pMnode, const SMqTopicObj *pTopic, SMqSubscribeObj *pSub) { - SSdb *pSdb = pMnode->pSdb; - SVgObj *pVgroup = NULL; - SQueryPlan *pPlan = qStringToQueryPlan(pTopic->physicalPlan); - SArray *pArray = NULL; - SNodeListNode *inner = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0); - SSubplan *plan = (SSubplan*)nodesListGetNode(inner->pNodeList, 0); - SArray *unassignedVg = pSub->unassignedVg; - - void *pIter = NULL; - while (1) { - pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); - if (pIter == NULL) break; - if (pVgroup->dbUid != pTopic->dbUid) { - sdbRelease(pSdb, pVgroup); - continue; - } - - pSub->vgNum++; - plan->execNode.nodeId = pVgroup->vgId; - plan->execNode.epset = mndGetVgroupEpset(pMnode, pVgroup); - - if (schedulerConvertDagToTaskList(pPlan, &pArray) < 0) { - terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC; - mError("unsupport topic: %s, sql: %s", pTopic->name, pTopic->sql); - return -1; - } - - SMqConsumerEp consumerEp = {0}; - consumerEp.status = 0; - consumerEp.consumerId = -1; - STaskInfo *pTaskInfo = taosArrayGet(pArray, 0); - consumerEp.epSet = pTaskInfo->addr.epset; - consumerEp.vgId = pTaskInfo->addr.nodeId; - - ASSERT(consumerEp.vgId == pVgroup->vgId); - consumerEp.qmsg = strdup(pTaskInfo->msg->msg); - taosArrayPush(unassignedVg, &consumerEp); - // TODO: free taskInfo - taosArrayDestroy(pArray); - } - - /*qDestroyQueryDag(pDag);*/ - return 0; -} -#endif - static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqTopicObj *pTopic, const char *cgroup, const SMqConsumerEp *pConsumerEp) { ASSERT(pConsumerEp->oldConsumerId == -1); @@ -1140,7 +846,7 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) { } } - if (oldSub) taosArrayDestroyEx(oldSub, (void (*)(void*))taosMemoryFree); + if (oldSub) taosArrayDestroyEx(oldSub, (void (*)(void *))taosMemoryFree); // persist consumerObj SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pConsumer); diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index fa2ba4bfc0..13ccc912d6 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); @@ -65,9 +65,11 @@ void mndCleanupTopic(SMnode *pMnode) {} SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { terrno = TSDB_CODE_OUT_OF_MEMORY; - int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1; - int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1; - int32_t size = sizeof(SMqTopicObj) + logicalPlanLen + physicalPlanLen + pTopic->sqlLen + MND_TOPIC_RESERVE_SIZE; + int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1; + int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1; + int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema); + int32_t size = + sizeof(SMqTopicObj) + logicalPlanLen + physicalPlanLen + pTopic->sqlLen + swLen + MND_TOPIC_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size); if (pRaw == NULL) goto TOPIC_ENCODE_OVER; @@ -86,8 +88,7 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER); SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER); - int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema); - void *swBuf = taosMemoryMalloc(swLen); + void *swBuf = taosMemoryMalloc(swLen); if (swBuf == NULL) { goto TOPIC_ENCODE_OVER; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 3314211437..4e54d56c09 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -54,7 +54,7 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans); static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans); static void mndTransExecute(SMnode *pMnode, STrans *pTrans); -static void mndTransSendRpcRsp(STrans *pTrans); +static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans); static int32_t mndProcessTransReq(SNodeMsg *pReq); static int32_t mndProcessKillTransReq(SNodeMsg *pReq); @@ -737,7 +737,7 @@ static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { return 0; } -static void mndTransSendRpcRsp(STrans *pTrans) { +static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) { bool sendRsp = false; if (pTrans->stage == TRN_STAGE_FINISHED) { @@ -771,7 +771,7 @@ static void mndTransSendRpcRsp(STrans *pTrans) { .ahandle = pTrans->rpcAHandle, .pCont = rpcCont, .contLen = pTrans->rpcRspLen}; - rpcSendResponse(&rspMsg); + tmsgSendRsp(&rspMsg); pTrans->rpcHandle = NULL; pTrans->rpcRsp = NULL; pTrans->rpcRspLen = 0; @@ -898,7 +898,7 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr pAction->msgReceived = 0; pAction->errCode = 0; } else { - mDebug("trans:%d, action:%d not send since %s", pTrans->id, action, terrstr()); + mError("trans:%d, action:%d not send since %s", pTrans->id, action, terrstr()); return -1; } } @@ -938,7 +938,7 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA return errCode; } } else { - mDebug("trans:%d, %d of %d actions executed, code:0x%04x", pTrans->id, numOfReceived, numOfActions, errCode & 0XFFFF); + mDebug("trans:%d, %d of %d actions executing", pTrans->id, numOfReceived, numOfActions); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } } @@ -1158,7 +1158,7 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { } } - mndTransSendRpcRsp(pTrans); + mndTransSendRpcRsp(pMnode, pTrans); } static int32_t mndProcessTransReq(SNodeMsg *pReq) { diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index bdc8a71b04..56a8698d77 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/vnode.h b/source/dnode/vnode/inc/vnode.h index dd4b8d84ca..c1c000295a 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/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 5ec5b1d58f..e5d1f952a8 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -197,9 +197,9 @@ int tqCommit(STQ*); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); 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/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index f4b450b4a8..ee928ef039 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -15,131 +15,637 @@ #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 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; + ret = tdbDbOpen("stb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pStbIdx)); + if (ret < 0) { + // TODO + ASSERT(0); + 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; - -_err: - return -1; } 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; + metaEncodeSchema(&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; + 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)); + metaDecodeSchema(pBuf, pSchemaWrapper); + + 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; + SSchema *pSchema; + STSchema *pTSchema; + STbCfg *pTbCfg; + + pTbCfg = metaGetTbInfoByUid(pMeta, uid); + if (pTbCfg->type == META_CHILD_TABLE) { + quid = pTbCfg->ctbCfg.suid; + } else { + quid = uid; + } + + pSW = metaGetTableSchema(pMeta, quid, sver, true); + if (pSW == NULL) { + return NULL; + } + + tdInitTSchemaBuilder(&sb, 0); + for (int i = 0; i < pSW->nCols; i++) { + pSchema = pSW->pSchema + i; + tdAddColToSchema(&sb, pSchema->type, pSchema->colId, pSchema->bytes); + } + 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) { - // TODO - return NULL; + 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) { - // TODO + 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; -} \ No newline at end of file +} + +STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { + // TODO + ASSERT(0); + return NULL; +} + +int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) { + // TODO + ASSERT(0); + return 0; +} + +int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { + // TODO + ASSERT(0); + return 0; +} + +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 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/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index efc7ac80e9..06a2350aab 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -275,7 +275,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { pMsg->pCont = NULL; pMsg->contLen = 0; pMsg->code = -1; - rpcSendResponse(pMsg); + tmsgSendRsp(pMsg); return 0; } @@ -340,7 +340,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { pMsg->pCont = buf; pMsg->contLen = tlen; pMsg->code = 0; - rpcSendResponse(pMsg); + tmsgSendRsp(pMsg); return 0; } } else { @@ -367,7 +367,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { pMsg->pCont = buf; pMsg->contLen = tlen; pMsg->code = 0; - rpcSendResponse(pMsg); + tmsgSendRsp(pMsg); /*}*/ return 0; @@ -489,7 +489,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) { @@ -497,22 +497,24 @@ 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); - int32_t taskId = req.taskId; + int32_t taskId = req.taskId; + ASSERT(taskId); + 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 8c161e4c8b..9c0b0802ab 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -114,10 +114,9 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper; int32_t numOfRows = pHandle->pBlock->numOfRows; - int32_t numOfCols = pHandle->pSchema->numOfCols; + /*int32_t numOfCols = pHandle->pSchema->numOfCols;*/ int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList); - // TODO: stable case if (colNumNeed > pSchemaWrapper->nCols) { colNumNeed = pSchemaWrapper->nCols; } @@ -138,56 +137,24 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { colNeed++; } else { SColumnInfoData colInfo = {0}; - int sz = numOfRows * pColSchema->bytes; + /*int sz = numOfRows * pColSchema->bytes;*/ colInfo.info.bytes = pColSchema->bytes; colInfo.info.colId = pColSchema->colId; colInfo.info.type = pColSchema->type; - colInfo.pData = taosMemoryCalloc(1, sz); - if (colInfo.pData == NULL) { - // TODO free - taosArrayDestroy(pArray); + if (blockDataEnsureColumnCapacity(&colInfo, numOfRows) < 0) { + taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); return NULL; } - - blockDataEnsureColumnCapacity(&colInfo, numOfRows); taosArrayPush(pArray, &colInfo); colMeta++; colNeed++; } } - int j = 0; - for (int32_t i = 0; i < colNumNeed; i++) { - col_id_t colId = *(col_id_t*)taosArrayGet(pHandle->pColIdList, i); - while (j < pSchemaWrapper->nCols && pSchemaWrapper->pSchema[j].colId < colId) { - j++; - } - if (j >= pSchemaWrapper->nCols) { - continue; - } - SSchema* pColSchema = &pSchemaWrapper->pSchema[j]; - SColumnInfoData colInfo = {0}; - int sz = numOfRows * pColSchema->bytes; - colInfo.info.bytes = pColSchema->bytes; - colInfo.info.colId = colId; - colInfo.info.type = pColSchema->type; - - colInfo.pData = taosMemoryCalloc(1, sz); - if (colInfo.pData == NULL) { - // TODO free - taosArrayDestroy(pArray); - return NULL; - } - - blockDataEnsureColumnCapacity(&colInfo, numOfRows); - taosArrayPush(pArray, &colInfo); - } - STSRowIter iter = {0}; tdSTSRowIterInit(&iter, pTschema); STSRow* row; - // int32_t kvIdx = 0; int32_t curRow = 0; tInitSubmitBlkIter(pHandle->pBlock, &pHandle->blkIter); while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) { @@ -200,25 +167,11 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { break; } - memcpy(POINTER_SHIFT(pColData->pData, curRow * pColData->info.bytes), sVal.val, pColData->info.bytes); - } -#if 0 - for (int32_t i = 0; i < colNumNeed; i++) { - SColumnInfoData* pColData = taosArrayGet(pArray, i); - STColumn* pCol = schemaColAt(pTschema, i); - // TODO - if(pCol->colId != pColData->info.colId) { - continue; + if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) { + taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); + return NULL; } - // void* val = tdGetMemRowDataOfColEx(row, pCol->colId, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset, &kvIdx); - SCellVal sVal = {0}; - if (!tdSTSRowIterNext(&iter, pCol->colId, pCol->type, &sVal)) { - // TODO: reach end - break; - } - memcpy(POINTER_SHIFT(pColData->pData, curRow * pCol->bytes), sVal.val, pCol->bytes); } -#endif curRow++; } return pArray; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 74d7558e0d..598647f797 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); @@ -69,9 +69,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { return tqProcessPollReq(pVnode->pTq, pMsg); case TDMT_VND_TASK_PIPE_EXEC: case TDMT_VND_TASK_MERGE_EXEC: - return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen); + return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, pInfo->workerId); case TDMT_VND_STREAM_TRIGGER: - return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen); + return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, pInfo->workerId); case TDMT_VND_QUERY_HEARTBEAT: return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); default: @@ -205,8 +205,7 @@ _exit: rpcMsg.contLen = rspLen; rpcMsg.code = code; - rpcSendResponse(&rpcMsg); - + tmsgSendRsp(&rpcMsg); return TSDB_CODE_SUCCESS; } @@ -276,8 +275,7 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { .code = 0, }; - rpcSendResponse(&rpcMsg); - + tmsgSendRsp(&rpcMsg); taosArrayDestroyEx(pArray, freeItemHelper); return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index cd47d1a942..d6f9f0da0b 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -186,17 +186,18 @@ 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, diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index fe48cc21e4..1d7023930d 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -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; @@ -330,11 +319,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_fn_t getNextFn; - __optr_fn_t cleanupFn; - __optr_close_fn_t closeFn; __optr_open_fn_t _openFn; // DO NOT invoke this function directly - __optr_encode_fn_t encodeResultRow; // + __optr_fn_t getNextFn; + __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_encode_fn_t encodeResultRow; __optr_decode_fn_t decodeResultRow; } SOperatorInfo; @@ -363,18 +353,18 @@ 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; + EX_SOURCE_STATUS status; } SSourceDataInfo; typedef struct SLoadRemoteDataInfo { @@ -383,12 +373,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; @@ -430,9 +414,10 @@ typedef struct STagScanInfo { } STagScanInfo; typedef struct SStreamBlockScanInfo { + SArray* pBlockLists; // multiple SSDatablock. SSDataBlock* pRes; // result SSDataBlock int32_t blockType; // current block type - bool blockValid; // Is current data has returned? + int32_t validBlockIndex; // Is current data has returned? SColumnInfo* pCols; // the output column info uint64_t numOfRows; // total scanned rows uint64_t numOfExec; // execution times @@ -483,16 +468,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 { @@ -572,11 +559,13 @@ typedef struct SGroupbyOperatorInfo { typedef struct SSessionAggOperatorInfo { SOptrBasicInfo binfo; SAggSupporter aggSup; + SGroupResInfo groupResInfo; STimeWindow curWindow; // current time window TSKEY prevTs; // previous timestamp int32_t numOfRows; // number of rows int32_t start; // start row index bool reptScan; // next round scan + int64_t gap; // session window gap } SSessionAggOperatorInfo; typedef struct SStateWindowOperatorInfo { @@ -593,8 +582,7 @@ typedef struct SSortedMergeOperatorInfo { SOptrBasicInfo binfo; bool hasVarCol; - SArray *orderInfo; // SArray - bool nullFirst; + SArray* pSortInfo; int32_t numOfSources; SSortHandle *pSortHandle; @@ -613,12 +601,10 @@ typedef struct SSortedMergeOperatorInfo { SAggSupporter aggSup; } SSortedMergeOperatorInfo; -typedef struct SOrderOperatorInfo { +typedef struct SSortOperatorInfo { uint32_t sortBufSize; // max buffer size for in-memory sort SSDataBlock *pDataBlock; - bool hasVarCol; // has variable length column, such as binary/varchar/nchar - SArray *orderInfo; - bool nullFirst; + SArray* pSortInfo; SSortHandle *pSortHandle; int32_t bufPageSize; int32_t numOfRowsInRes; @@ -629,7 +615,7 @@ typedef struct SOrderOperatorInfo { uint64_t totalSize; // total load bytes from remote uint64_t totalRows; // total number of rows uint64_t totalElapsed; // total elapsed time -} SOrderOperatorInfo; +} SSortOperatorInfo; typedef struct SDistinctDataInfo { int32_t index; @@ -655,15 +641,15 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* 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* createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SArray* pOrderVal, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pOrderVal, SArray* pGroupInfo, 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, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo); SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock, @@ -695,12 +681,6 @@ SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorI 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); @@ -734,7 +714,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/inc/tsort.h b/source/libs/executor/inc/tsort.h index ef7af2b4e3..8971ee33d3 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -63,7 +63,7 @@ typedef int32_t (*_sort_merge_compar_fn_t)(const void* p1, const void* p2, void* * @param type * @return */ -SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, bool nullFirst, int32_t type, int32_t pageSize, int32_t numOfPages, SSchema* pSchema, int32_t numOfCols, const char* idstr); +SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr); /** * diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index f0cffafca2..2c6468a13f 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -19,8 +19,6 @@ #include "executil.h" #include "executorimpl.h" -//#include "queryLog.h" -#include "tbuffer.h" #include "tcompression.h" #include "tlosertree.h" diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 26422fa618..15203d91ca 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -16,9 +16,10 @@ #include "executor.h" #include "executorimpl.h" #include "planner.h" +#include "tdatablock.h" #include "vnode.h" -static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t type, char* id) { +static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) { ASSERT(pOperator != NULL); if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { if (pOperator->numOfDownstream == 0) { @@ -31,7 +32,7 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t t return TSDB_CODE_QRY_APP_ERROR; } pOperator->status = OP_NOT_OPENED; - return doSetStreamBlock(pOperator->pDownstream[0], input, type, id); + return doSetStreamBlock(pOperator->pDownstream[0], input, numOfBlocks, type, id); } else { SStreamBlockScanInfo* pInfo = pOperator->info; @@ -48,15 +49,16 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t t return TSDB_CODE_QRY_APP_ERROR; } } else { - ASSERT(!pInfo->blockValid); + for (int32_t i = 0; i < numOfBlocks; ++i) { + SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i]; - SSDataBlock* pDataBlock = input; - pInfo->pRes->info = pDataBlock->info; - taosArrayClear(pInfo->pRes->pDataBlock); - taosArrayAddAll(pInfo->pRes->pDataBlock, pDataBlock->pDataBlock); + SSDataBlock* p = createOneDataBlock(pDataBlock); + p->info = pDataBlock->info; - // set current block valid. - pInfo->blockValid = true; + taosArrayClear(p->pDataBlock); + taosArrayAddAll(p->pDataBlock, pDataBlock->pDataBlock); + taosArrayPush(pInfo->pBlockLists, &p); + } } return TSDB_CODE_SUCCESS; @@ -64,17 +66,21 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t t } int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type) { + return qSetMultiStreamInput(tinfo, input, 1, type); +} + +int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) { if (tinfo == NULL) { return TSDB_CODE_QRY_APP_ERROR; } - if (input == NULL) { + if (pBlocks == NULL || numOfBlocks == 0) { return TSDB_CODE_SUCCESS; } SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void*)input, type, GET_TASKID(pTaskInfo)); + int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void**)pBlocks, numOfBlocks, type, GET_TASKID(pTaskInfo)); if (code != TSDB_CODE_SUCCESS) { qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo)); } else { @@ -107,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 cc9921ce73..6d78fa835a 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 f38888440c..2df18f135c 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -43,32 +43,34 @@ #define IS_MAIN_SCAN(runtime) ((runtime)->scanFlag == MAIN_SCAN) #define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN) #define IS_REPEAT_SCAN(runtime) ((runtime)->scanFlag == REPEAT_SCAN) -#define SET_MAIN_SCAN_FLAG(runtime) ((runtime)->scanFlag = MAIN_SCAN) +#define SET_MAIN_SCAN_FLAG(runtime) ((runtime)->scanFlag = MAIN_SCAN) #define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = REVERSE_SCAN) #define TSWINDOW_IS_EQUAL(t1, t2) (((t1).skey == (t2).skey) && ((t1).ekey == (t2).ekey)) -#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) +#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) -#define SDATA_BLOCK_INITIALIZER (SDataBlockInfo) {{0}, 0} +#define SDATA_BLOCK_INITIALIZER \ + (SDataBlockInfo) { {0}, 0 } #define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP) -#define MULTI_KEY_DELIM "-" +#define MULTI_KEY_DELIM "-" enum { - TS_JOIN_TS_EQUAL = 0, - TS_JOIN_TS_NOT_EQUALS = 1, + TS_JOIN_TS_EQUAL = 0, + TS_JOIN_TS_NOT_EQUALS = 1, TS_JOIN_TAG_NOT_EQUALS = 2, }; typedef enum SResultTsInterpType { RESULT_ROW_START_INTERP = 1, - RESULT_ROW_END_INTERP = 2, + RESULT_ROW_END_INTERP = 2, } SResultTsInterpType; typedef struct SColMatchInfo { int32_t colId; int32_t targetSlotId; + bool output; } SColMatchInfo; #if 0 @@ -109,47 +111,51 @@ static UNUSED_FUNC void* u_realloc(void* p, size_t __size) { #define GET_NUM_OF_TABLEGROUP(q) taosArrayGetSize((q)->tableqinfoGroupInfo.pGroupList) #define QUERY_IS_INTERVAL_QUERY(_q) ((_q)->interval.interval > 0) -#define TSKEY_MAX_ADD(a,b) \ -do { \ - if (a < 0) { a = a + b; break;} \ - if (sizeof(a) == sizeof(int32_t)) { \ - if((b) > 0 && ((b) >= INT32_MAX - (a))){\ - a = INT32_MAX; \ - } else { \ - a = a + b; \ - } \ - } else { \ - if((b) > 0 && ((b) >= INT64_MAX - (a))){\ - a = INT64_MAX; \ - } else { \ - a = a + b; \ - } \ - } \ -} while(0) +#define TSKEY_MAX_ADD(a, b) \ + do { \ + if (a < 0) { \ + a = a + b; \ + break; \ + } \ + if (sizeof(a) == sizeof(int32_t)) { \ + if ((b) > 0 && ((b) >= INT32_MAX - (a))) { \ + a = INT32_MAX; \ + } else { \ + a = a + b; \ + } \ + } else { \ + if ((b) > 0 && ((b) >= INT64_MAX - (a))) { \ + a = INT64_MAX; \ + } else { \ + a = a + b; \ + } \ + } \ + } while (0) -#define TSKEY_MIN_SUB(a,b) \ -do { \ - if (a >= 0) { a = a + b; break;} \ - if (sizeof(a) == sizeof(int32_t)){ \ - if((b) < 0 && ((b) <= INT32_MIN - (a))){\ - a = INT32_MIN; \ - } else { \ - a = a + b; \ - } \ - } else { \ - if((b) < 0 && ((b) <= INT64_MIN-(a))) {\ - a = INT64_MIN; \ - } else { \ - a = a + b; \ - } \ - } \ -} while (0) +#define TSKEY_MIN_SUB(a, b) \ + do { \ + if (a >= 0) { \ + a = a + b; \ + break; \ + } \ + if (sizeof(a) == sizeof(int32_t)) { \ + if ((b) < 0 && ((b) <= INT32_MIN - (a))) { \ + a = INT32_MIN; \ + } else { \ + a = a + b; \ + } \ + } else { \ + if ((b) < 0 && ((b) <= INT64_MIN - (a))) { \ + a = INT64_MIN; \ + } else { \ + a = a + b; \ + } \ + } \ + } while (0) -int32_t getMaximumIdleDurationSec() { - return tsShellActivityTimer * 2; -} +int32_t getMaximumIdleDurationSec() { return tsShellActivityTimer * 2; } -static int32_t getExprFunctionId(SExprInfo *pExprInfo) { +static int32_t getExprFunctionId(SExprInfo* pExprInfo) { assert(pExprInfo != NULL && pExprInfo->pExpr != NULL && pExprInfo->pExpr->nodeType == TEXPR_UNARYEXPR_NODE); return 0; } @@ -163,7 +169,7 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o } int64_t key = tw->skey, interval = pInterval->interval; - //convert key to second + // convert key to second key = convertTimePrecision(key, precision, TSDB_TIME_PRECISION_MILLI) / 1000; if (pInterval->intervalUnit == 'y') { @@ -171,7 +177,7 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o } struct tm tm; - time_t t = (time_t)key; + time_t t = (time_t)key; taosLocalTime(&t, &tm); int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor); @@ -191,20 +197,21 @@ static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type 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); +void setResultRowOutputBufInitCtx(STaskRuntimeEnv* pRuntimeEnv, SResultRow* pResult, SqlFunctionCtx* pCtx, + int32_t numOfOutput, int32_t* rowCellInfoOffset); +static bool functionNeedToExecute(SqlFunctionCtx* pCtx); -static void setBlockStatisInfo(SqlFunctionCtx *pCtx, SSDataBlock* pSDataBlock, SColumn* pColumn); +static void setBlockStatisInfo(SqlFunctionCtx* pCtx, SSDataBlock* pSDataBlock, SColumn* pColumn); -static void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo); -static bool hasMainOutput(STaskAttr *pQueryAttr); +static void destroyTableQueryInfoImpl(STableQueryInfo* pTableQueryInfo); +static bool hasMainOutput(STaskAttr* pQueryAttr); static SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int32_t* numOfFilterCols); -static int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, STableQueryInfo *pTableQueryInfo); -static void releaseQueryBuf(size_t numOfTables); -static int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order); -//static STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win); +static int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, STableQueryInfo* pTableQueryInfo); +static void releaseQueryBuf(size_t numOfTables); +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); @@ -234,59 +241,65 @@ static void doSetOperatorCompleted(SOperatorInfo* pOperator) { setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); } } - #define OPTR_IS_OPENED(_optr) (((_optr)->status & OP_OPENED) == OP_OPENED) #define OPTR_SET_OPENED(_optr) ((_optr)->status |= OP_OPENED) -static int32_t operatorDummyOpenFn(SOperatorInfo *pOperator) { +static int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) { OPTR_SET_OPENED(pOperator); return TSDB_CODE_SUCCESS; } static void operatorDummyCloseFn(void* param, int32_t numOfCols) {} -static int32_t doCopyToSDataBlock(SDiskbasedBuf *pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); +static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, + SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); -static int32_t getGroupbyColumnIndex(SGroupbyExpr *pGroupbyExpr, SSDataBlock* pDataBlock); -static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo *binfo, int32_t numOfCols, char *pData, int16_t type, int16_t bytes, int32_t groupId, - SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup); -static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size); -static void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow *win); +static int32_t getGroupbyColumnIndex(SGroupbyExpr* pGroupbyExpr, SSDataBlock* pDataBlock); +static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, + int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, + SAggSupporter* pAggSup); +static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size); +static void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, + int64_t keyLast, STimeWindow* win); 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); +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); SArray* getOrderCheckColumns(STaskAttr* pQuery); typedef struct SRowCompSupporter { - STaskRuntimeEnv *pRuntimeEnv; - int16_t dataOffset; - __compar_fn_t comFunc; + STaskRuntimeEnv* pRuntimeEnv; + int16_t dataOffset; + __compar_fn_t comFunc; } SRowCompSupporter; -static int compareRowData(const void *a, const void *b, const void *userData) { - const SResultRow *pRow1 = (const SResultRow *)a; - const SResultRow *pRow2 = (const SResultRow *)b; +static int compareRowData(const void* a, const void* b, const void* userData) { + const SResultRow* pRow1 = (const SResultRow*)a; + const SResultRow* pRow2 = (const SResultRow*)b; - SRowCompSupporter *supporter = (SRowCompSupporter *)userData; - STaskRuntimeEnv* pRuntimeEnv = supporter->pRuntimeEnv; + SRowCompSupporter* supporter = (SRowCompSupporter*)userData; + STaskRuntimeEnv* pRuntimeEnv = supporter->pRuntimeEnv; - SFilePage *page1 = getBufPage(pRuntimeEnv->pResultBuf, pRow1->pageId); - SFilePage *page2 = getBufPage(pRuntimeEnv->pResultBuf, pRow2->pageId); + SFilePage* page1 = getBufPage(pRuntimeEnv->pResultBuf, pRow1->pageId); + SFilePage* page2 = getBufPage(pRuntimeEnv->pResultBuf, pRow2->pageId); int16_t offset = supporter->dataOffset; - char *in1 = getPosInResultPage(pRuntimeEnv->pQueryAttr, page1, pRow1->offset, offset); - char *in2 = getPosInResultPage(pRuntimeEnv->pQueryAttr, page2, pRow2->offset, offset); + char* in1 = getPosInResultPage(pRuntimeEnv->pQueryAttr, page1, pRow1->offset, offset); + char* in2 = getPosInResultPage(pRuntimeEnv->pQueryAttr, page2, pRow2->offset, offset); return (in1 != NULL && in2 != NULL) ? supporter->comFunc(in1, in2) : 0; } -static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, STaskRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock) { - SArray *columnOrderList = getOrderCheckColumns(pRuntimeEnv->pQueryAttr); - size_t size = taosArrayGetSize(columnOrderList); +static void sortGroupResByOrderList(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRuntimeEnv, + SSDataBlock* pDataBlock) { + SArray* columnOrderList = getOrderCheckColumns(pRuntimeEnv->pQueryAttr); + size_t size = taosArrayGetSize(columnOrderList); taosArrayDestroy(columnOrderList); if (size <= 0) { @@ -298,11 +311,11 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, STaskRuntimeEn return; } - bool found = false; + bool found = false; int16_t dataOffset = 0; for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { - SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j); + SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pDataBlock->pDataBlock, j); if (orderId == j) { found = true; break; @@ -321,27 +334,7 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, STaskRuntimeEn taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); } -//setup the output buffer for each operator -SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numOfRows) { - const static int32_t minSize = 8; - - SSDataBlock *res = taosMemoryCalloc(1, sizeof(SSDataBlock)); - res->info.numOfCols = numOfOutput; - res->pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData)); - for (int32_t i = 0; i < numOfOutput; ++i) { - SColumnInfoData idata = {{0}}; - idata.info.type = pExpr[i].base.resSchema.type; - idata.info.bytes = pExpr[i].base.resSchema.bytes; - idata.info.colId = pExpr[i].base.resSchema.colId; - - int32_t size = TMAX(idata.info.bytes * numOfRows, minSize); - idata.pData = taosMemoryCalloc(1, size); // at least to hold a pointer on x64 platform - taosArrayPush(res->pDataBlock, &idata); - } - - return res; -} - +// setup the output buffer for each operator SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { int32_t numOfCols = LIST_LENGTH(pNode->pSlots); @@ -350,14 +343,18 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); pBlock->info.blockId = pNode->dataBlockId; - pBlock->info.rowSize = pNode->resultRowSize; + pBlock->info.rowSize = pNode->totalRowSize; // todo ?? - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData idata = {{0}}; - SSlotDescNode* pDescNode = nodesListGetNode(pNode->pSlots, i); - idata.info.type = pDescNode->dataType.type; - idata.info.bytes = pDescNode->dataType.bytes; - idata.info.scale = pDescNode->dataType.scale; + SSlotDescNode* pDescNode = nodesListGetNode(pNode->pSlots, i); + if (!pDescNode->output) { + continue; + } + + idata.info.type = pDescNode->dataType.type; + idata.info.bytes = pDescNode->dataType.bytes; + idata.info.scale = pDescNode->dataType.scale; idata.info.slotId = pDescNode->slotId; idata.info.precision = pDescNode->dataType.precision; @@ -367,27 +364,27 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { return pBlock; } -static bool isSelectivityWithTagsQuery(SqlFunctionCtx *pCtx, int32_t numOfOutput) { +static bool isSelectivityWithTagsQuery(SqlFunctionCtx* pCtx, int32_t numOfOutput) { return true; -// bool hasTags = false; -// int32_t numOfSelectivity = 0; -// -// for (int32_t i = 0; i < numOfOutput; ++i) { -// int32_t functId = pCtx[i].functionId; -// if (functId == FUNCTION_TAG_DUMMY || functId == FUNCTION_TS_DUMMY) { -// hasTags = true; -// continue; -// } -// -// if ((aAggs[functId].status & FUNCSTATE_SELECTIVITY) != 0) { -// numOfSelectivity++; -// } -// } -// -// return (numOfSelectivity > 0 && hasTags); + // bool hasTags = false; + // int32_t numOfSelectivity = 0; + // + // for (int32_t i = 0; i < numOfOutput; ++i) { + // int32_t functId = pCtx[i].functionId; + // if (functId == FUNCTION_TAG_DUMMY || functId == FUNCTION_TS_DUMMY) { + // hasTags = true; + // continue; + // } + // + // if ((aAggs[functId].status & FUNCSTATE_SELECTIVITY) != 0) { + // numOfSelectivity++; + // } + // } + // + // return (numOfSelectivity > 0 && hasTags); } -static bool isProjQuery(STaskAttr *pQueryAttr) { +static bool isProjQuery(STaskAttr* pQueryAttr) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functId = getExprFunctionId(&pQueryAttr->pExpr1[i]); if (functId != FUNCTION_PRJ && functId != FUNCTION_TAGPRJ) { @@ -398,8 +395,9 @@ static bool isProjQuery(STaskAttr *pQueryAttr) { return true; } -static bool hasNull(SColumn* pColumn, SColumnDataAgg *pStatis) { - if (TSDB_COL_IS_TAG(pColumn->flag) || TSDB_COL_IS_UD_COL(pColumn->flag) || pColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { +static bool hasNull(SColumn* pColumn, SColumnDataAgg* pStatis) { + if (TSDB_COL_IS_TAG(pColumn->flag) || TSDB_COL_IS_UD_COL(pColumn->flag) || + pColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { return false; } @@ -428,13 +426,13 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) newCapacity += 4; } - char *t = taosMemoryRealloc(pResultRowInfo->pResult, (size_t)(newCapacity * POINTER_BYTES)); + 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; + pResultRowInfo->pResult = (SResultRow**)t; int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity; memset(&pResultRowInfo->pResult[pResultRowInfo->capacity], 0, POINTER_BYTES * inc); @@ -443,13 +441,13 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) pResultRowInfo->capacity = (int32_t)newCapacity; } -static bool chkResultRowFromKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, char *pData, - int16_t bytes, bool masterscan, uint64_t uid) { +static bool chkResultRowFromKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, char* pData, + int16_t bytes, bool masterscan, uint64_t uid) { bool existed = false; SET_RES_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, uid); - SResultRow **p1 = - (SResultRow **)taosHashGet(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); + SResultRow** p1 = + (SResultRow**)taosHashGet(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); // in case of repeat scan/reverse scan, no new time window added. if (QUERY_IS_INTERVAL_QUERY(pRuntimeEnv->pQueryAttr)) { @@ -465,7 +463,8 @@ static bool chkResultRowFromKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pR 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 = taosHashGet(pRuntimeEnv->pResultRowListSet, pRuntimeEnv->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes)); + int64_t* index = + taosHashGet(pRuntimeEnv->pResultRowListSet, pRuntimeEnv->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes)); if (index != NULL) { existed = true; } else { @@ -480,19 +479,18 @@ static bool chkResultRowFromKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pR return p1 != NULL; } - static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, int64_t tid, char* pData, int16_t bytes, bool masterscan, uint64_t tableGroupId) { bool existed = false; SET_RES_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, tableGroupId); - SResultRow **p1 = - (SResultRow **)taosHashGet(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); + SResultRow** p1 = + (SResultRow**)taosHashGet(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); // in case of repeat scan/reverse scan, no new time window added. if (QUERY_IS_INTERVAL_QUERY(pRuntimeEnv->pQueryAttr)) { if (!masterscan) { // the *p1 may be NULL in case of sliding+offset exists. - return (p1 != NULL)? *p1:NULL; + return (p1 != NULL) ? *p1 : NULL; } if (p1 != NULL) { @@ -504,9 +502,10 @@ static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultR 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)); + 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; @@ -521,9 +520,9 @@ static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultR } if (!existed) { -// prepareResultListBuffer(pResultRowInfo, pRuntimeEnv); + // prepareResultListBuffer(pResultRowInfo, pRuntimeEnv); - SResultRow *pResult = NULL; + SResultRow* pResult = NULL; if (p1 == NULL) { pResult = getNewResultRow(pRuntimeEnv->pool); int32_t ret = initResultRow(pResult); @@ -532,7 +531,8 @@ static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultR } // add a new result set for a new group - taosHashPut(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pResult, POINTER_BYTES); + taosHashPut(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pResult, + POINTER_BYTES); SResultRowCell cell = {.groupId = tableGroupId, .pRow = pResult}; taosArrayPush(pRuntimeEnv->pResultRowArrayList, &cell); } else { @@ -544,7 +544,8 @@ static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultR int64_t index = pResultRowInfo->curPos; SET_RES_EXT_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, tid, pResultRowInfo); - taosHashPut(pRuntimeEnv->pResultRowListSet, pRuntimeEnv->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes), &index, POINTER_BYTES); + taosHashPut(pRuntimeEnv->pResultRowListSet, pRuntimeEnv->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes), &index, + POINTER_BYTES); } // too many time window in query @@ -556,7 +557,7 @@ static SResultRow* doSetResultOutBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultR } SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize) { - SFilePage *pData = NULL; + SFilePage* pData = NULL; // in the first scan, new space needed for results int32_t pageId = -1; @@ -595,18 +596,18 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, return pResultRow; } -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) { +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; SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, tableGroupId); - SResultRow **p1 = - (SResultRow **)taosHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); + SResultRow** p1 = (SResultRow**)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; + return (p1 != NULL) ? *p1 : NULL; } if (p1 != NULL) { @@ -620,7 +621,7 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR 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; + pResultRowInfo->curPos = (int32_t)*index; existed = true; } else { existed = false; @@ -637,7 +638,7 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR if (!existed) { prepareResultListBuffer(pResultRowInfo, pTaskInfo->env); - SResultRow *pResult = NULL; + SResultRow* pResult = NULL; if (p1 == NULL) { pResult = getNewResultRow_rv(pResultBuf, tableGroupId, pSup->resultRowSize); int32_t ret = initResultRow(pResult); @@ -654,7 +655,8 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR } pResultRowInfo->curPos = pResultRowInfo->size; - pResultRowInfo->pPosition[pResultRowInfo->size] = (SResultRowPosition) {.pageId = pResult->pageId, .offset = pResult->offset}; + pResultRowInfo->pPosition[pResultRowInfo->size] = + (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; pResultRowInfo->pResult[pResultRowInfo->size++] = pResult; int64_t index = pResultRowInfo->curPos; @@ -670,7 +672,8 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR return pResultRowInfo->pResult[pResultRowInfo->curPos]; } -static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, TSKEY ts, STimeWindow* w, TSKEY ekey, bool ascQuery) { +static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, TSKEY ts, STimeWindow* w, TSKEY ekey, + bool ascQuery) { if (ascQuery) { getAlignQueryTimeWindow(pInterval, precision, ts, ts, ekey, w); } else { @@ -678,7 +681,7 @@ static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, T getAlignQueryTimeWindow(pInterval, precision, ts, ekey, ts, w); int64_t key = w->skey; - while(key < ts) { // moving towards end + while (key < ts) { // moving towards end key = taosTimeAdd(key, pInterval->sliding, pInterval->slidingUnit, precision); if (key >= ts) { break; @@ -690,10 +693,11 @@ 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, int32_t precision, STimeWindow* win) { +static STimeWindow getActiveTimeWindow(SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, + int32_t precision, STimeWindow* win) { STimeWindow w = {0}; - if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value + if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value getInitialStartTimeWindow(pInterval, precision, ts, &w, win->ekey, true); w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; } else { @@ -724,14 +728,16 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t } // get the correct time window according to the handled timestamp -static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t ts, STaskAttr *pQueryAttr) { +static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo* pResultRowInfo, int64_t ts, STaskAttr* pQueryAttr) { STimeWindow w = {0}; - if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value -// getInitialStartTimeWindow(pQueryAttr, ts, &w); + if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value + // getInitialStartTimeWindow(pQueryAttr, ts, &w); if (pQueryAttr->interval.intervalUnit == 'n' || pQueryAttr->interval.intervalUnit == 'y') { - w.ekey = taosTimeAdd(w.skey, pQueryAttr->interval.interval, pQueryAttr->interval.intervalUnit, pQueryAttr->precision) - 1; + w.ekey = + taosTimeAdd(w.skey, pQueryAttr->interval.interval, pQueryAttr->interval.intervalUnit, pQueryAttr->precision) - + 1; } else { w.ekey = w.skey + pQueryAttr->interval.interval - 1; } @@ -751,12 +757,12 @@ static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo * pResultRowInfo, i } // a new buffer page for each table. Needs to opt this design -static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedBuf *pResultBuf, int32_t tid, uint32_t size) { +static int32_t addNewWindowResultBuf(SResultRow* pWindowRes, SDiskbasedBuf* pResultBuf, int32_t tid, uint32_t size) { if (pWindowRes->pageId != -1) { return 0; } - SFilePage *pData = NULL; + SFilePage* pData = NULL; // in the first scan, new space needed for results int32_t pageId = -1; @@ -797,20 +803,21 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedBuf *pRes return 0; } -static bool chkWindowOutputBufByKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, STimeWindow *win, - bool masterscan, SResultRow **pResult, int64_t groupId, SqlFunctionCtx* pCtx, - int32_t numOfOutput, int32_t* rowCellInfoOffset) { +static bool chkWindowOutputBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, STimeWindow* win, + bool masterscan, SResultRow** pResult, int64_t groupId, SqlFunctionCtx* pCtx, + int32_t numOfOutput, int32_t* rowCellInfoOffset) { assert(win->skey <= win->ekey); - return chkResultRowFromKey(pRuntimeEnv, pResultRowInfo, (char *)&win->skey, TSDB_KEYSIZE, masterscan, groupId); + return chkResultRowFromKey(pRuntimeEnv, pResultRowInfo, (char*)&win->skey, TSDB_KEYSIZE, masterscan, groupId); } -static int32_t setResultOutputBufByKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, int64_t tid, STimeWindow *win, - bool masterscan, SResultRow **pResult, int64_t tableGroupId, SqlFunctionCtx* pCtx, - int32_t numOfOutput, int32_t* rowCellInfoOffset) { +static int32_t setResultOutputBufByKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, int64_t tid, + STimeWindow* win, bool masterscan, SResultRow** pResult, int64_t tableGroupId, + SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset) { assert(win->skey <= win->ekey); - SDiskbasedBuf *pResultBuf = pRuntimeEnv->pResultBuf; + SDiskbasedBuf* pResultBuf = pRuntimeEnv->pResultBuf; - SResultRow *pResultRow = doSetResultOutBufByKey(pRuntimeEnv, pResultRowInfo, tid, (char *)&win->skey, TSDB_KEYSIZE, masterscan, tableGroupId); + SResultRow* pResultRow = doSetResultOutBufByKey(pRuntimeEnv, pResultRowInfo, tid, (char*)&win->skey, TSDB_KEYSIZE, + masterscan, tableGroupId); if (pResultRow == NULL) { *pResult = NULL; return TSDB_CODE_SUCCESS; @@ -818,7 +825,8 @@ static int32_t setResultOutputBufByKey(STaskRuntimeEnv *pRuntimeEnv, SResultRowI // not assign result buffer yet, add new result buffer if (pResultRow->pageId == -1) { - int32_t ret = addNewWindowResultBuf(pResultRow, pResultBuf, (int32_t) tableGroupId, pRuntimeEnv->pQueryAttr->intermediateResultRowSize); + int32_t ret = addNewWindowResultBuf(pResultRow, pResultBuf, (int32_t)tableGroupId, + pRuntimeEnv->pQueryAttr->intermediateResultRowSize); if (ret != TSDB_CODE_SUCCESS) { return -1; } @@ -832,14 +840,16 @@ 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(SDiskbasedBuf* pBuf, 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, - int32_t numOfOutput, int32_t* rowCellInfoOffset, SAggSupporter *pAggSup, SExecTaskInfo* pTaskInfo) { +static int32_t setResultOutputBufByKey_rv(SResultRowInfo* pResultRowInfo, int64_t id, STimeWindow* win, bool masterscan, + SResultRow** pResult, int64_t tableGroupId, SqlFunctionCtx* pCtx, + int32_t numOfOutput, int32_t* rowCellInfoOffset, SAggSupporter* pAggSup, + SExecTaskInfo* pTaskInfo) { assert(win->skey <= win->ekey); - SResultRow *pResultRow = doSetResultOutBufByKey_rv(pAggSup->pResultBuf, pResultRowInfo, id, (char *)&win->skey, TSDB_KEYSIZE, masterscan, tableGroupId, - pTaskInfo, true, pAggSup); + SResultRow* pResultRow = doSetResultOutBufByKey_rv(pAggSup->pResultBuf, pResultRowInfo, id, (char*)&win->skey, + TSDB_KEYSIZE, masterscan, tableGroupId, pTaskInfo, true, pAggSup); if (pResultRow == NULL) { *pResult = NULL; @@ -853,13 +863,12 @@ static int32_t setResultOutputBufByKey_rv(SResultRowInfo *pResultRowInfo, int64_ return TSDB_CODE_SUCCESS; } - static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) { assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP)); if (type == RESULT_ROW_START_INTERP) { pResult->startInterp = true; } else { - pResult->endInterp = true; + pResult->endInterp = true; } } @@ -868,16 +877,16 @@ static bool resultRowInterpolated(SResultRow* pResult, SResultTsInterpType type) if (type == RESULT_ROW_START_INTERP) { return pResult->startInterp == true; } else { - return pResult->endInterp == true; + return pResult->endInterp == true; } } -static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, int16_t pos, - int16_t order, int64_t *pData) { +static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, + int16_t pos, int16_t order, int64_t* pData) { int32_t forwardStep = 0; if (order == TSDB_ORDER_ASC) { - int32_t end = searchFn((char*) &pData[pos], numOfRows - pos, ekey, order); + int32_t end = searchFn((char*)&pData[pos], numOfRows - pos, ekey, order); if (end >= 0) { forwardStep = end; @@ -886,7 +895,7 @@ static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_se } } } else { - int32_t end = searchFn((char *)pData, pos + 1, ekey, order); + int32_t end = searchFn((char*)pData, pos + 1, ekey, order); if (end >= 0) { forwardStep = pos - end; @@ -900,19 +909,21 @@ 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; int32_t i = 0; for (i = pResultRowInfo->size - 1; i >= 0; --i) { - SResultRow *pResult = pResultRowInfo->pResult[i]; + SResultRow* pResult = pResultRowInfo->pResult[i]; if (pResult->closed) { break; } // new closed result rows if (timeWindowInterpo) { - if (pResult->endInterp && ((pResult->win.skey <= lastKey && ascQuery) || (pResult->win.skey >= lastKey && !ascQuery))) { - if (i > 0) { // the first time window, the startInterp is false. + if (pResult->endInterp && + ((pResult->win.skey <= lastKey && ascQuery) || (pResult->win.skey >= lastKey && !ascQuery))) { + if (i > 0) { // the first time window, the startInterp is false. assert(pResult->startInterp); } @@ -932,16 +943,15 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey, // all result rows are closed, set the last one to be the skey if (skey == TSKEY_INITIAL_VAL) { if (pResultRowInfo->size == 0) { -// assert(pResultRowInfo->current == NULL); + // assert(pResultRowInfo->current == NULL); assert(pResultRowInfo->curPos == -1); pResultRowInfo->curPos = -1; } else { pResultRowInfo->curPos = pResultRowInfo->size - 1; } } else { - for (i = pResultRowInfo->size - 1; i >= 0; --i) { - SResultRow *pResult = pResultRowInfo->pResult[i]; + SResultRow* pResult = pResultRowInfo->pResult[i]; if (pResult->closed) { break; } @@ -955,7 +965,8 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey, } } -static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, const STimeWindow* pWin, TSKEY lastKey, bool ascQuery, bool interp) { +static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, const STimeWindow* pWin, TSKEY lastKey, + bool ascQuery, bool interp) { if ((lastKey > pWin->ekey && ascQuery) || (lastKey < pWin->ekey && (!ascQuery))) { closeAllResultRows(pResultRowInfo); pResultRowInfo->curPos = pResultRowInfo->size - 1; @@ -965,12 +976,13 @@ static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, const } } -static int32_t getNumOfRowsInTimeWindow(SDataBlockInfo *pDataBlockInfo, TSKEY *pPrimaryColumn, - int32_t startPos, TSKEY ekey, __block_search_fn_t searchFn, STableQueryInfo* item, int32_t order) { +static int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, + TSKEY ekey, __block_search_fn_t searchFn, STableQueryInfo* item, + int32_t order) { assert(startPos >= 0 && startPos < pDataBlockInfo->rows); - int32_t num = -1; - int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); + int32_t num = -1; + int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); if (order == TSDB_ORDER_ASC) { if (ekey < pDataBlockInfo->window.ekey && pPrimaryColumn) { @@ -1002,15 +1014,42 @@ 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); + + blockDataEnsureColumnCapacity(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 + updateTimeWindowInfo(pTimeWindowData, pWin); + for (int32_t k = 0; k < numOfOutput; ++k) { pCtx[k].startTs = pWin->skey; // keep it temporarialy - bool hasAgg = pCtx[k].input.colDataAggIsSet; + bool hasAgg = pCtx[k].input.colDataAggIsSet; int32_t startOffset = pCtx[k].input.startRowIndex; - int32_t numOfRows = pCtx[k].input.numOfRows; + int32_t numOfRows = pCtx[k].input.numOfRows; int32_t pos = (order == TSDB_ORDER_ASC) ? offset : offset - (forwardStep - 1); pCtx[k].input.startRowIndex = pos; @@ -1026,6 +1065,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]); } @@ -1040,9 +1094,9 @@ static void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, int32_t of static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, SDataBlockInfo* pDataBlockInfo, TSKEY* primaryKeys, int32_t prevPosition, STableIntervalOperatorInfo* pInfo) { int32_t order = pInfo->order; - bool ascQuery = (order == TSDB_ORDER_ASC); + 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 @@ -1051,7 +1105,7 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, return -1; } - TSKEY startKey = ascQuery? pNext->skey:pNext->ekey; + TSKEY startKey = ascQuery ? pNext->skey : pNext->ekey; int32_t startPos = 0; // tumbling time window query, a special case of sliding time window query @@ -1064,14 +1118,14 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, } else if (startKey >= pDataBlockInfo->window.ekey && !ascQuery) { startPos = pDataBlockInfo->rows - 1; } else { - startPos = binarySearchForKey((char *)primaryKeys, pDataBlockInfo->rows, startKey, order); + startPos = binarySearchForKey((char*)primaryKeys, pDataBlockInfo->rows, startKey, order); } } /* interp query with fill should not skip time window */ -// if (pQueryAttr->pointInterpQuery && pQueryAttr->fillType != TSDB_FILL_NONE) { -// return startPos; -// } + // if (pQueryAttr->pointInterpQuery && pQueryAttr->fillType != TSDB_FILL_NONE) { + // return startPos; + // } /* * This time window does not cover any data, try next time window, @@ -1090,7 +1144,7 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, pNext->skey = taosTimeTruncate(next, pInterval, precision); pNext->ekey = taosTimeAdd(pNext->skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; } else { - pNext->ekey += ((next - pNext->ekey + pInterval->sliding - 1)/pInterval->sliding) * pInterval->sliding; + pNext->ekey += ((next - pNext->ekey + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; pNext->skey = pNext->ekey - pInterval->interval + 1; } } else if ((!ascQuery) && primaryKeys[startPos] < pNext->skey) { @@ -1108,7 +1162,7 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, return startPos; } -static FORCE_INLINE TSKEY reviseWindowEkey(STaskAttr *pQueryAttr, STimeWindow *pWindow) { +static FORCE_INLINE TSKEY reviseWindowEkey(STaskAttr* pQueryAttr, STimeWindow* pWindow) { TSKEY ekey = -1; if (QUERY_IS_ASC_QUERY(pQueryAttr)) { ekey = pWindow->ekey; @@ -1143,7 +1197,7 @@ static void saveDataBlockLastRow(char** pRow, SArray* pDataBlock, int32_t rowInd } for (int32_t k = 0; k < numOfCols; ++k) { - SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, k); + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, k); memcpy(pRow[k], ((char*)pColInfo->pData) + (pColInfo->info.bytes * rowIndex), pColInfo->info.bytes); } } @@ -1151,9 +1205,9 @@ static void saveDataBlockLastRow(char** pRow, SArray* pDataBlock, int32_t rowInd static TSKEY getStartTsKey(STimeWindow* win, const TSKEY* tsCols, int32_t rows, bool ascQuery) { TSKEY ts = TSKEY_INITIAL_VAL; if (tsCols == NULL) { - ts = ascQuery? win->skey : win->ekey; + ts = ascQuery ? win->skey : win->ekey; } else { - int32_t offset = ascQuery? 0:rows-1; + int32_t offset = ascQuery ? 0 : rows - 1; ts = tsCols[offset]; } @@ -1162,13 +1216,14 @@ static TSKEY getStartTsKey(STimeWindow* win, const TSKEY* tsCols, int32_t rows, static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order); -static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order) { +static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, + int32_t order) { for (int32_t i = 0; i < pOperator->numOfOutput; ++i) { pCtx[i].order = order; - pCtx[i].size = pBlock->info.rows; + pCtx[i].size = pBlock->info.rows; pCtx[i].currentStage = (uint8_t)pOperator->pRuntimeEnv->scanFlag; - setBlockStatisInfo(&pCtx[i], pBlock, NULL/*&pOperator->pExpr[i].base.colInfo*/); + setBlockStatisInfo(&pCtx[i], pBlock, NULL /*&pOperator->pExpr[i].base.colInfo*/); } } @@ -1183,11 +1238,22 @@ void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlo static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order) { for (int32_t i = 0; i < pOperator->numOfOutput; ++i) { pCtx[i].order = order; - pCtx[i].size = pBlock->info.rows; + pCtx[i].size = pBlock->info.rows; pCtx[i].currentStage = MAIN_SCAN; + SExprInfo expr = pOperator->pExpr[i]; + for (int32_t j = 0; j < expr.base.numOfParams; ++j) { + SFunctParam *pFuncParam = &expr.base.pParam[j]; + if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) { + int32_t slotId = pFuncParam->pCol->slotId; + pCtx[i].input.pData[j] = taosArrayGet(pBlock->pDataBlock, slotId); + pCtx[i].input.totalRows = pBlock->info.rows; + pCtx[i].input.numOfRows = pBlock->info.rows; + pCtx[i].input.startRowIndex = 0; + ASSERT(pCtx[i].input.pData[j] != NULL); + } + } // setBlockStatisInfo(&pCtx[i], pBlock, pOperator->pExpr[i].base.pColumns); - int32_t slotId = pOperator->pExpr[i].base.pParam[0].pCol->slotId; // uint32_t flag = pOperator->pExpr[i].base.pParam[0].pCol->flag; // if (TSDB_COL_IS_NORMAL_COL(flag) /*|| (pCtx[i].functionId == FUNCTION_BLKINFO) || @@ -1205,12 +1271,11 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, // } // in case of the block distribution query, the inputBytes is not a constant value. - pCtx[i].input.pData[0] = taosArrayGet(pBlock->pDataBlock, slotId); - pCtx[i].input.totalRows = pBlock->info.rows; - pCtx[i].input.numOfRows = pBlock->info.rows; - pCtx[i].input.startRowIndex = 0; + //pCtx[i].input.pData[0] = taosArrayGet(pBlock->pDataBlock, slotId); + //pCtx[i].input.totalRows = pBlock->info.rows; + //pCtx[i].input.numOfRows = pBlock->info.rows; + //pCtx[i].input.startRowIndex = 0; - ASSERT(pCtx[i].input.pData[0] != NULL); // uint32_t status = aAggs[pCtx[i].functionId].status; // if ((status & (FUNCSTATE_SELECTIVITY | FUNCSTATE_NEED_TS)) != 0) { @@ -1240,15 +1305,16 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunctionCtx* pCtx) { for (int32_t k = 0; k < pOperator->numOfOutput; ++k) { if (functionNeedToExecute(&pCtx[k])) { - pCtx[k].startTs = startTs;// this can be set during create the struct + pCtx[k].startTs = startTs; // this can be set during create the struct pCtx[k].fpSet.process(&pCtx[k]); } } } -static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx *pCtx, int32_t numOfOutput) { +static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, + int32_t numOfOutput) { for (int32_t k = 0; k < numOfOutput; ++k) { - if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query + if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k); colDataAssign(pColInfoData, pCtx[k].input.pData[0], pCtx[k].input.numOfRows); @@ -1267,15 +1333,17 @@ static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSData } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_FUNCTION) { ASSERT(!fmIsAggFunc(pCtx->functionId)); - SScalarParam p = {.numOfRows = pSrcBlock->info.rows}; - int32_t slotId = pExpr[k].base.pParam[0].pCol->slotId; - p.columnData = taosArrayGet(pSrcBlock->pDataBlock, slotId); + SArray* pBlockList = taosArrayInit(4, POINTER_BYTES); + taosArrayPush(pBlockList, &pSrcBlock); SScalarParam dest = {0}; dest.columnData = taosArrayGet(pResult->pDataBlock, k); - pCtx[k].sfp.process(&p, 1, &dest); + scalarCalculate((SNode *)pExpr[k].pExpr->_function.pFunctNode, pBlockList, &dest); pResult->info.rows = dest.numOfRows; + + taosArrayDestroy(pBlockList); + } else { ASSERT(0); } @@ -1284,8 +1352,8 @@ static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSData void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, SArray* pDataBlock, TSKEY prevTs, int32_t prevRowIndex, TSKEY curTs, int32_t curRowIndex, TSKEY windowKey, int32_t type) { - STaskRuntimeEnv *pRuntimeEnv = pOperator->pRuntimeEnv; - SExprInfo* pExpr = pOperator->pExpr; + STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + SExprInfo* pExpr = pOperator->pExpr; SqlFunctionCtx* pCtx = pInfo->pCtx; @@ -1296,20 +1364,20 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, continue; } - SColIndex * pColIndex = NULL/*&pExpr[k].base.colInfo*/; + SColIndex* pColIndex = NULL /*&pExpr[k].base.colInfo*/; int16_t index = pColIndex->colIndex; - SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, index); + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, index); -// assert(pColInfo->info.colId == pColIndex->info.colId && curTs != windowKey); + // assert(pColInfo->info.colId == pColIndex->info.colId && curTs != windowKey); double v1 = 0, v2 = 0, v = 0; if (prevRowIndex == -1) { - GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pRuntimeEnv->prevRow[index]); + GET_TYPED_DATA(v1, double, pColInfo->info.type, (char*)pRuntimeEnv->prevRow[index]); } else { - GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes); + GET_TYPED_DATA(v1, double, pColInfo->info.type, (char*)pColInfo->pData + prevRowIndex * pColInfo->info.bytes); } - GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes); + GET_TYPED_DATA(v2, double, pColInfo->info.type, (char*)pColInfo->pData + curRowIndex * pColInfo->info.bytes); if (functionId == FUNCTION_INTERP) { if (type == RESULT_ROW_START_INTERP) { @@ -1321,18 +1389,18 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { if (prevRowIndex == -1) { - pCtx[k].start.ptr = (char *)pRuntimeEnv->prevRow[index]; + pCtx[k].start.ptr = (char*)pRuntimeEnv->prevRow[index]; } else { - pCtx[k].start.ptr = (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes; + pCtx[k].start.ptr = (char*)pColInfo->pData + prevRowIndex * pColInfo->info.bytes; } - pCtx[k].end.ptr = (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes; + pCtx[k].end.ptr = (char*)pColInfo->pData + curRowIndex * pColInfo->info.bytes; } } } else if (functionId == FUNCTION_TWA) { - SPoint point1 = (SPoint){.key = prevTs, .val = &v1}; - SPoint point2 = (SPoint){.key = curTs, .val = &v2}; - SPoint point = (SPoint){.key = windowKey, .val = &v }; + SPoint point1 = (SPoint){.key = prevTs, .val = &v1}; + SPoint point2 = (SPoint){.key = curTs, .val = &v2}; + SPoint point = (SPoint){.key = windowKey, .val = &v}; taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE); @@ -1348,18 +1416,19 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, } static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SqlFunctionCtx* pCtx, int32_t pos, - int32_t numOfRows, SArray* pDataBlock, const TSKEY* tsCols, STimeWindow* win) { + int32_t numOfRows, SArray* pDataBlock, const TSKEY* tsCols, + STimeWindow* win) { STaskRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); - TSKEY curTs = tsCols[pos]; - TSKEY lastTs = *(TSKEY *) pRuntimeEnv->prevRow[0]; + TSKEY curTs = tsCols[pos]; + TSKEY lastTs = *(TSKEY*)pRuntimeEnv->prevRow[0]; // lastTs == INT64_MIN and pos == 0 means this is the first time window, interpolation is not needed. // start exactly from this point, no need to do interpolation - TSKEY key = ascQuery? win->skey:win->ekey; + TSKEY key = ascQuery ? win->skey : win->ekey; if (key == curTs) { setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfOutput, RESULT_ROW_START_INTERP); return true; @@ -1371,22 +1440,23 @@ static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SqlF } int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); - TSKEY prevTs = ((pos == 0 && ascQuery) || (pos == (numOfRows - 1) && !ascQuery))? lastTs:tsCols[pos - step]; + TSKEY prevTs = ((pos == 0 && ascQuery) || (pos == (numOfRows - 1) && !ascQuery)) ? lastTs : tsCols[pos - step]; - doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pDataBlock, prevTs, pos - step, curTs, pos, - key, RESULT_ROW_START_INTERP); + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pDataBlock, prevTs, pos - step, curTs, pos, key, + RESULT_ROW_START_INTERP); return true; } -static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SqlFunctionCtx* pCtx, - int32_t endRowIndex, SArray* pDataBlock, const TSKEY* tsCols, TSKEY blockEkey, STimeWindow* win) { - STaskRuntimeEnv *pRuntimeEnv = pOperatorInfo->pRuntimeEnv; - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t numOfOutput = pOperatorInfo->numOfOutput; +static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SqlFunctionCtx* pCtx, int32_t endRowIndex, + SArray* pDataBlock, const TSKEY* tsCols, TSKEY blockEkey, + STimeWindow* win) { + STaskRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + int32_t numOfOutput = pOperatorInfo->numOfOutput; - TSKEY actualEndKey = tsCols[endRowIndex]; + TSKEY actualEndKey = tsCols[endRowIndex]; - TSKEY key = QUERY_IS_ASC_QUERY(pQueryAttr)? win->ekey:win->skey; + TSKEY key = QUERY_IS_ASC_QUERY(pQueryAttr) ? win->ekey : win->skey; // not ended in current data block, do not invoke interpolation if ((key > blockEkey && QUERY_IS_ASC_QUERY(pQueryAttr)) || (key < blockEkey && !QUERY_IS_ASC_QUERY(pQueryAttr))) { @@ -1406,12 +1476,13 @@ static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SqlFun TSKEY nextKey = tsCols[nextRowIndex]; doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pDataBlock, actualEndKey, endRowIndex, nextKey, - nextRowIndex, key, RESULT_ROW_END_INTERP); + nextRowIndex, key, RESULT_ROW_END_INTERP); return true; } static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBlock* pBlock, SqlFunctionCtx* pCtx, - SResultRow* pResult, STimeWindow* win, int32_t startPos, int32_t forwardStep, int32_t order, bool timeWindowInterpo) { + SResultRow* pResult, STimeWindow* win, int32_t startPos, int32_t forwardStep, + int32_t order, bool timeWindowInterpo) { if (!timeWindowInterpo) { return; } @@ -1419,19 +1490,19 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc assert(pBlock != NULL); int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); - if (pBlock->pDataBlock == NULL){ -// tscError("pBlock->pDataBlock == NULL"); + if (pBlock->pDataBlock == NULL) { + // tscError("pBlock->pDataBlock == NULL"); return; } - SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0); + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0); - TSKEY *tsCols = (TSKEY *)(pColInfo->pData); - bool done = resultRowInterpolated(pResult, RESULT_ROW_START_INTERP); - if (!done) { // it is not interpolated, now start to generated the interpolated value + TSKEY* tsCols = (TSKEY*)(pColInfo->pData); + bool done = resultRowInterpolated(pResult, RESULT_ROW_START_INTERP); + if (!done) { // it is not interpolated, now start to generated the interpolated value int32_t startRowIndex = startPos; - bool interp = setTimeWindowInterpolationStartTs(pOperatorInfo, pCtx, startRowIndex, pBlock->info.rows, pBlock->pDataBlock, - tsCols, win); + bool interp = setTimeWindowInterpolationStartTs(pOperatorInfo, pCtx, startRowIndex, pBlock->info.rows, + pBlock->pDataBlock, tsCols, win); if (interp) { setResultRowInterpo(pResult, RESULT_ROW_START_INTERP); } @@ -1440,17 +1511,18 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc } // point interpolation does not require the end key time window interpolation. -// if (pointInterpQuery) { -// return; -// } + // if (pointInterpQuery) { + // return; + // } // interpolation query does not generate the time window end interpolation done = resultRowInterpolated(pResult, RESULT_ROW_END_INTERP); if (!done) { int32_t endRowIndex = startPos + (forwardStep - 1) * step; - TSKEY endKey = (order == TSDB_ORDER_ASC)? pBlock->info.window.ekey:pBlock->info.window.skey; - bool interp = setTimeWindowInterpolationEndTs(pOperatorInfo, pCtx, endRowIndex, pBlock->pDataBlock, tsCols, endKey, win); + TSKEY endKey = (order == TSDB_ORDER_ASC) ? pBlock->info.window.ekey : pBlock->info.window.skey; + bool interp = + setTimeWindowInterpolationEndTs(pOperatorInfo, pCtx, endRowIndex, pBlock->pDataBlock, tsCols, endKey, win); if (interp) { setResultRowInterpo(pResult, RESULT_ROW_END_INTERP); } @@ -1459,37 +1531,49 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc } } -static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, int32_t tableGroupId) { - STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*) pOperatorInfo->info; +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; + 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; TSKEY* tsCols = NULL; 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); + tsCols = (int64_t*)pColDataInfo->pData; + 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); - bool masterScan = true; + STimeWindow win = getActiveTimeWindow(pResultRowInfo, ts, &pInfo->interval, pInfo->interval.precision, &pInfo->win); + bool masterScan = true; SResultRow* pResult = NULL; - int32_t ret = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, tableGroupId, pInfo->binfo.pCtx, - numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); + int32_t ret = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, + tableGroupId, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, + &pInfo->aggSup, pTaskInfo); if (ret != TSDB_CODE_SUCCESS || pResult == NULL) { 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 = @@ -1505,35 +1589,37 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul continue; } - STimeWindow w = pRes->win; - ret = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &w, masterScan, &pResult, - tableGroupId, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); - if (ret != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - 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); + STimeWindow w = pRes->win; + ret = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &w, masterScan, &pResult, tableGroupId, + pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, + pTaskInfo); + if (ret != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } + 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, &pInfo->timeWindowData, startPos, 0, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); + } + // restore current time window - ret = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, tableGroupId, pInfo->binfo.pCtx, - numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); + ret = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, tableGroupId, + pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, + pTaskInfo); if (ret != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } } // 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); + doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, forwardStep, + pInfo->order, false); + doApplyFunctions(pInfo->binfo.pCtx, &win, &pInfo->timeWindowData, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); STimeWindow nextWin = win; while (1) { @@ -1544,55 +1630,65 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul } // null data, failed to allocate more memory buffer - int32_t code = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &nextWin, masterScan, &pResult, tableGroupId, - pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); + int32_t code = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &nextWin, masterScan, &pResult, + tableGroupId, pInfo->binfo.pCtx, numOfOutput, + pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); if (code != TSDB_CODE_SUCCESS || pResult == NULL) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - ekey = nextWin.ekey;//reviseWindowEkey(pQueryAttr, &nextWin); - forwardStep = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); + 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); // 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); + doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardStep, + pInfo->order, false); + 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); } -// updateResultRowInfoActiveIndex(pResultRowInfo, &pInfo->win, pRuntimeEnv->current->lastKey, true, false); + return pUpdated; + // updateResultRowInfoActiveIndex(pResultRowInfo, &pInfo->win, pRuntimeEnv->current->lastKey, true, false); } -static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, int32_t tableGroupId) { - STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*) pOperatorInfo->info; +static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, + int32_t tableGroupId) { + STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*)pOperatorInfo->info; STaskRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; - int32_t numOfOutput = pOperatorInfo->numOfOutput; + int32_t numOfOutput = pOperatorInfo->numOfOutput; STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); - bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); + bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); TSKEY* tsCols = NULL; if (pSDataBlock->pDataBlock != NULL) { SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, 0); - tsCols = (int64_t*) pColDataInfo->pData; + tsCols = (int64_t*)pColDataInfo->pData; 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 = ascQuery ? 0 : (pSDataBlock->info.rows - 1); + TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols, pSDataBlock->info.rows, ascQuery); STimeWindow win = getCurrentActiveTimeWindow(pResultRowInfo, ts, pQueryAttr); - bool masterScan = IS_MAIN_SCAN(pRuntimeEnv); + bool masterScan = IS_MAIN_SCAN(pRuntimeEnv); SResultRow* pResult = NULL; - int32_t forwardStep = 0; - int32_t ret = 0; + int32_t forwardStep = 0; + int32_t ret = 0; STimeWindow preWin = win; while (1) { @@ -1603,20 +1699,24 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - TSKEY ekey = reviseWindowEkey(pQueryAttr, &win); -// forwardStep = getNumOfRowsInTimeWindow(pRuntimeEnv, &pSDataBlock->info, tsCols, startPos, ekey, binarySearchForKey, true); + TSKEY ekey = reviseWindowEkey(pQueryAttr, &win); + // forwardStep = getNumOfRowsInTimeWindow(pRuntimeEnv, &pSDataBlock->info, tsCols, startPos, ekey, + // binarySearchForKey, true); // window start(end) key interpolation -// doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, forwardStep); -// doApplyFunctions(pRuntimeEnv, pInfo->binfo.pCtx, ascQuery ? &win : &preWin, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); + // doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, + // forwardStep); doApplyFunctions(pRuntimeEnv, pInfo->binfo.pCtx, ascQuery ? &win : &preWin, startPos, + // forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); preWin = win; int32_t prevEndPos = (forwardStep - 1) * step + startPos; -// startPos = getNextQualifiedWindow(pQueryAttr, &win, &pSDataBlock->info, tsCols, binarySearchForKey, prevEndPos); + // startPos = getNextQualifiedWindow(pQueryAttr, &win, &pSDataBlock->info, tsCols, binarySearchForKey, + // prevEndPos); if (startPos < 0) { if ((ascQuery && win.skey <= pQueryAttr->window.ekey) || ((!ascQuery) && win.ekey >= pQueryAttr->window.ekey)) { - int32_t code = setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, tableGroupId, - pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset); + int32_t code = + setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, + tableGroupId, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset); if (code != TSDB_CODE_SUCCESS || pResult == NULL) { longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -1624,8 +1724,9 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe startPos = pSDataBlock->info.rows - 1; // window start(end) key interpolation -// doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, forwardStep); -// doApplyFunctions(pRuntimeEnv, pInfo->binfo.pCtx, ascQuery ? &win : &preWin, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); + // doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &win, startPos, + // forwardStep); doApplyFunctions(pRuntimeEnv, pInfo->binfo.pCtx, ascQuery ? &win : &preWin, startPos, + // forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); } break; @@ -1634,14 +1735,15 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe } if (pQueryAttr->timeWindowInterpo) { - int32_t rowIndex = ascQuery? (pSDataBlock->info.rows-1):0; -// saveDataBlockLastRow(pRuntimeEnv, &pSDataBlock->info, pSDataBlock->pDataBlock, rowIndex); + int32_t rowIndex = ascQuery ? (pSDataBlock->info.rows - 1) : 0; + // saveDataBlockLastRow(pRuntimeEnv, &pSDataBlock->info, pSDataBlock->pDataBlock, rowIndex); } -// updateResultRowInfoActiveIndex(pResultRowInfo, pQueryAttr, pRuntimeEnv->current->lastKey); + // updateResultRowInfoActiveIndex(pResultRowInfo, pQueryAttr, pRuntimeEnv->current->lastKey); } -static bool groupKeyCompare(SGroupbyOperatorInfo* pInfo, SSDataBlock* pBlock, int32_t rowIndex, int32_t numOfGroupCols) { +static bool groupKeyCompare(SGroupbyOperatorInfo* pInfo, SSDataBlock* pBlock, int32_t rowIndex, + int32_t numOfGroupCols) { SColumnDataAgg* pColAgg = NULL; for (int32_t i = 0; i < numOfGroupCols; ++i) { SColumn* pCol = taosArrayGet(pInfo->pGroupCols, i); @@ -1709,9 +1811,9 @@ static int32_t generatedHashKey(void* pKey, int32_t* length, SArray* pGroupColVa ASSERT(pKey != NULL); size_t numOfGroupCols = taosArrayGetSize(pGroupColVals); - char* isNull = (char*) pKey; - char* pStart = (char*) pKey + sizeof(int8_t) * numOfGroupCols; - for(int32_t i = 0; i < numOfGroupCols; ++i) { + char* isNull = (char*)pKey; + char* pStart = (char*)pKey + sizeof(int8_t) * numOfGroupCols; + for (int32_t i = 0; i < numOfGroupCols; ++i) { SGroupKeys* pkey = taosArrayGet(pGroupColVals, i); if (pkey->isNull) { isNull[i] = 1; @@ -1729,13 +1831,13 @@ static int32_t generatedHashKey(void* pKey, int32_t* length, SArray* pGroupColVa } } - *length = (pStart - (char*) pKey); + *length = (pStart - (char*)pKey); return 0; } // assign the group keys or user input constant values if required static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t totalRows, int32_t rowIndex) { - for(int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t i = 0; i < numOfOutput; ++i) { if (pCtx[i].functionId == -1) { SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[i]); @@ -1753,18 +1855,18 @@ static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t } } -static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; - SGroupbyOperatorInfo *pInfo = pOperator->info; +static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SGroupbyOperatorInfo* pInfo = pOperator->info; SqlFunctionCtx* pCtx = pInfo->binfo.pCtx; - int32_t numOfGroupCols = taosArrayGetSize(pInfo->pGroupCols); -// if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE) { - //qError("QInfo:0x%"PRIx64" group by not supported on double/float columns, abort", GET_TASKID(pRuntimeEnv)); -// return; -// } + int32_t numOfGroupCols = taosArrayGetSize(pInfo->pGroupCols); + // if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE) { + // qError("QInfo:0x%"PRIx64" group by not supported on double/float columns, abort", GET_TASKID(pRuntimeEnv)); + // return; + // } - int32_t len = 0; + int32_t len = 0; STimeWindow w = TSWINDOW_INITIALIZER; int32_t num = 0; @@ -1783,15 +1885,16 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { continue; } - /*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 = */ 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); 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); @@ -1800,38 +1903,41 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { } if (num > 0) { - /*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 = */ 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); if (ret != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } 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); } } -static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; - STableQueryInfo* item = pRuntimeEnv->current; +// todo handle multiple tables cases. +static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperatorInfo* pInfo, SSDataBlock* pBlock) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; // primary timestamp column - SColumnInfoData* pColInfoData = taosArrayGet(pSDataBlock->pDataBlock, 0); + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); - bool masterScan = IS_MAIN_SCAN(pRuntimeEnv); - SOptrBasicInfo* pBInfo = &pInfo->binfo; + bool masterScan = true; + STimeWindow window = {0}; + int32_t numOfOutput = pOperator->numOfOutput; + int64_t gid = pBlock->info.groupId; - int64_t gap = pOperator->pRuntimeEnv->pQueryAttr->sw.gap; + int64_t gap = pInfo->gap; pInfo->numOfRows = 0; - if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { + if (/*IS_REPEAT_SCAN(pRuntimeEnv) && */ !pInfo->reptScan) { pInfo->reptScan = true; pInfo->prevTs = INT64_MIN; } TSKEY* tsList = (TSKEY*)pColInfoData->pData; - for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { + for (int32_t j = 0; j < pBlock->info.rows; ++j) { if (pInfo->prevTs == INT64_MIN) { pInfo->curWindow.skey = tsList[j]; pInfo->curWindow.ekey = tsList[j]; @@ -1848,17 +1954,16 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator } } else { // start a new session window SResultRow* pResult = NULL; - pInfo->curWindow.ekey = pInfo->curWindow.skey; - int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.uid, &pInfo->curWindow, masterScan, - &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, - pBInfo->rowCellInfoOffset); + int32_t ret = setResultOutputBufByKey_rv(&pInfo->binfo.resultRowInfo, pBlock->info.uid, &window, masterScan, + &pResult, gid, pInfo->binfo.pCtx, numOfOutput, + pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code - longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); + longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } -// doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, -// pSDataBlock->info.rows, pOperator->numOfOutput); + // pInfo->numOfRows data belong to the current session window + doApplyFunctions(pInfo->binfo.pCtx, &window, NULL, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); pInfo->curWindow.skey = tsList[j]; pInfo->curWindow.ekey = tsList[j]; @@ -1871,15 +1976,14 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator SResultRow* pResult = NULL; pInfo->curWindow.ekey = pInfo->curWindow.skey; - int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.uid, &pInfo->curWindow, masterScan, - &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, - pBInfo->rowCellInfoOffset); + int32_t ret = setResultOutputBufByKey_rv(&pInfo->binfo.resultRowInfo, pBlock->info.uid, &window, masterScan, &pResult, + gid, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, + &pInfo->aggSup, pTaskInfo); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code - longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); + longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } -// doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, -// pSDataBlock->info.rows, pOperator->numOfOutput); + 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) { @@ -1899,14 +2003,15 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { } } -static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo *binfo, int32_t numOfCols, char *pData, int16_t type, int16_t bytes, int32_t groupId, - SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup) { - SResultRowInfo *pResultRowInfo = &binfo->resultRowInfo; - SqlFunctionCtx *pCtx = binfo->pCtx; +static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, + int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, + SAggSupporter* pAggSup) { + SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo; + SqlFunctionCtx* pCtx = binfo->pCtx; - SResultRow *pResultRow = doSetResultOutBufByKey_rv(pBuf, pResultRowInfo, groupId, (char *)pData, bytes, true, groupId, - pTaskInfo, true, pAggSup); - assert (pResultRow != NULL); + SResultRow* pResultRow = doSetResultOutBufByKey_rv(pBuf, pResultRowInfo, groupId, (char*)pData, bytes, true, groupId, + pTaskInfo, true, pAggSup); + assert(pResultRow != NULL); setResultRowKey(pResultRow, pData, type); @@ -1914,7 +2019,7 @@ static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo *binfo, int32_t numOfCo return TSDB_CODE_SUCCESS; } -static int32_t getGroupbyColumnIndex(SGroupbyExpr *pGroupbyExpr, SSDataBlock* pDataBlock) { +static int32_t getGroupbyColumnIndex(SGroupbyExpr* pGroupbyExpr, SSDataBlock* pDataBlock) { size_t num = taosArrayGetSize(pGroupbyExpr->columnInfo); for (int32_t k = 0; k < num; ++k) { SColIndex* pColIndex = taosArrayGet(pGroupbyExpr->columnInfo, k); @@ -1936,8 +2041,8 @@ static int32_t getGroupbyColumnIndex(SGroupbyExpr *pGroupbyExpr, SSDataBlock* pD return -1; } -static bool functionNeedToExecute(SqlFunctionCtx *pCtx) { - struct SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); +static bool functionNeedToExecute(SqlFunctionCtx* pCtx) { + struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); // in case of timestamp column, always generated results. int32_t functionId = pCtx->functionId; @@ -1945,40 +2050,36 @@ 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; } if (functionId == FUNCTION_FIRST_DST || functionId == FUNCTION_FIRST) { -// return QUERY_IS_ASC_QUERY(pQueryAttr); + // return QUERY_IS_ASC_QUERY(pQueryAttr); } // denote the order type if ((functionId == FUNCTION_LAST_DST || functionId == FUNCTION_LAST)) { -// return pCtx->param[0].i == pQueryAttr->order.order; + // return pCtx->param[0].i == pQueryAttr->order.order; } // in the reverse table scan, only the following functions need to be executed -// if (IS_REVERSE_SCAN(pRuntimeEnv) || -// (pRuntimeEnv->scanFlag == REPEAT_SCAN && functionId != FUNCTION_STDDEV && functionId != FUNCTION_PERCT)) { -// return false; -// } + // if (IS_REVERSE_SCAN(pRuntimeEnv) || + // (pRuntimeEnv->scanFlag == REPEAT_SCAN && functionId != FUNCTION_STDDEV && functionId != FUNCTION_PERCT)) { + // return false; + // } return true; } -void setBlockStatisInfo(SqlFunctionCtx *pCtx, SSDataBlock* pSDataBlock, SColumn* pColumn) { - SColumnDataAgg *pAgg = NULL; +void setBlockStatisInfo(SqlFunctionCtx* pCtx, SSDataBlock* pSDataBlock, SColumn* pColumn) { + SColumnDataAgg* pAgg = NULL; if (pSDataBlock->pBlockAgg != NULL && TSDB_COL_IS_NORMAL_COL(pColumn->flag)) { pAgg = &pSDataBlock->pBlockAgg[pCtx->columnIndex]; pCtx->agg = *pAgg; - pCtx->isAggSet = true; + pCtx->isAggSet = true; assert(pCtx->agg.numOfNull <= pSDataBlock->info.rows); } else { pCtx->isAggSet = false; @@ -1988,14 +2089,14 @@ void setBlockStatisInfo(SqlFunctionCtx *pCtx, SSDataBlock* pSDataBlock, SColumn* // set the statistics data for primary time stamp column if (pCtx->functionId == FUNCTION_SPREAD && pColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { - pCtx->isAggSet = true; + pCtx->isAggSet = true; pCtx->agg.min = pSDataBlock->info.window.skey; pCtx->agg.max = pSDataBlock->info.window.ekey; } } // set the output buffer for the selectivity + tag query -static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) { +static int32_t setCtxTagColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutput) { if (!isSelectivityWithTagsQuery(pCtx, numOfOutput)) { return TSDB_CODE_SUCCESS; } @@ -2015,7 +2116,7 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) { if (functionId == FUNCTION_TAG_DUMMY || functionId == FUNCTION_TS_DUMMY) { tagLen += pCtx[i].resDataInfo.bytes; pTagCtx[num++] = &pCtx[i]; - } else if (1/*(aAggs[functionId].status & FUNCSTATE_SELECTIVITY) != 0*/) { + } else if (1 /*(aAggs[functionId].status & FUNCSTATE_SELECTIVITY) != 0*/) { p = &pCtx[i]; } else if (functionId == FUNCTION_TS || functionId == FUNCTION_TAG) { // tag function may be the group by tag column @@ -2037,7 +2138,7 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) { } static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) { - SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); + SqlFunctionCtx* pFuncCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); if (pFuncCtx == NULL) { return NULL; } @@ -2051,7 +2152,7 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num for (int32_t i = 0; i < numOfOutput; ++i) { SExprInfo* pExpr = &pExprInfo[i]; - SExprBasicInfo *pFunct = &pExpr->base; + SExprBasicInfo* pFunct = &pExpr->base; SqlFunctionCtx* pCtx = &pFuncCtx[i]; pCtx->functionId = -1; @@ -2064,24 +2165,25 @@ 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) { - } pCtx->input.numOfInputCols = pFunct->numOfParams; pCtx->input.pData = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); pCtx->input.pColumnDataAgg = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); - pCtx->ptsOutputBuf = NULL; - pCtx->resDataInfo.bytes = pFunct->resSchema.bytes; - pCtx->resDataInfo.type = pFunct->resSchema.type; - pCtx->order = TSDB_ORDER_ASC; - pCtx->start.key = INT64_MIN; - pCtx->end.key = INT64_MIN; + pCtx->ptsOutputBuf = NULL; + pCtx->resDataInfo.bytes = pFunct->resSchema.bytes; + pCtx->resDataInfo.type = pFunct->resSchema.type; + pCtx->order = TSDB_ORDER_ASC; + pCtx->start.key = INT64_MIN; + pCtx->end.key = INT64_MIN; #if 0 for (int32_t j = 0; j < pCtx->numOfParams; ++j) { // int16_t type = pFunct->param[j].nType; @@ -2131,8 +2233,9 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num #endif } - for(int32_t i = 1; i < numOfOutput; ++i) { - (*rowCellInfoOffset)[i] = (int32_t)((*rowCellInfoOffset)[i - 1] + sizeof(SResultRowEntryInfo) + pFuncCtx[i - 1].resDataInfo.interBufSize); + for (int32_t i = 1; i < numOfOutput; ++i) { + (*rowCellInfoOffset)[i] = + (int32_t)((*rowCellInfoOffset)[i - 1] + sizeof(SResultRowEntryInfo) + pFuncCtx[i - 1].resDataInfo.interBufSize); } setCtxTagColumnInfo(pFuncCtx, numOfOutput); @@ -2157,52 +2260,56 @@ static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) { return NULL; } -static int32_t setupQueryRuntimeEnv(STaskRuntimeEnv *pRuntimeEnv, int32_t numOfTables, SArray* pOperator, void* merger) { - //qDebug("QInfo:0x%"PRIx64" setup runtime env", GET_TASKID(pRuntimeEnv)); - STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; +static int32_t setupQueryRuntimeEnv(STaskRuntimeEnv* pRuntimeEnv, int32_t numOfTables, SArray* pOperator, + void* merger) { + // qDebug("QInfo:0x%"PRIx64" setup runtime env", GET_TASKID(pRuntimeEnv)); + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; pRuntimeEnv->prevGroupId = INT32_MIN; pRuntimeEnv->pQueryAttr = pQueryAttr; - pRuntimeEnv->pResultRowHashTable = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - pRuntimeEnv->pResultRowListSet = taosHashInit(numOfTables * 10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - pRuntimeEnv->keyBuf = taosMemoryMalloc(pQueryAttr->maxTableColumnWidth + sizeof(int64_t) + POINTER_BYTES); -// pRuntimeEnv->pool = initResultRowPool(getResultRowSize(pRuntimeEnv)); + pRuntimeEnv->pResultRowHashTable = + taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + pRuntimeEnv->pResultRowListSet = + taosHashInit(numOfTables * 10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + pRuntimeEnv->keyBuf = taosMemoryMalloc(pQueryAttr->maxTableColumnWidth + sizeof(int64_t) + POINTER_BYTES); + // pRuntimeEnv->pool = initResultRowPool(getResultRowSize(pRuntimeEnv)); pRuntimeEnv->pResultRowArrayList = taosArrayInit(numOfTables, sizeof(SResultRowCell)); pRuntimeEnv->prevRow = taosMemoryMalloc(POINTER_BYTES * pQueryAttr->numOfCols + pQueryAttr->srcRowSize); - pRuntimeEnv->tagVal = taosMemoryMalloc(pQueryAttr->tagLen); + pRuntimeEnv->tagVal = taosMemoryMalloc(pQueryAttr->tagLen); // NOTE: pTableCheckInfo need to update the query time range and the lastKey info - pRuntimeEnv->pTableRetrieveTsMap = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + pRuntimeEnv->pTableRetrieveTsMap = + taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); - //pRuntimeEnv->scalarSup = createScalarFuncSupport(pQueryAttr->numOfOutput); + // pRuntimeEnv->scalarSup = createScalarFuncSupport(pQueryAttr->numOfOutput); if (pRuntimeEnv->scalarSup == NULL || pRuntimeEnv->pResultRowHashTable == NULL || pRuntimeEnv->keyBuf == NULL || - pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL) { + pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL) { goto _clean; } if (pQueryAttr->numOfCols) { - char* start = POINTER_BYTES * pQueryAttr->numOfCols + (char*) pRuntimeEnv->prevRow; + char* start = POINTER_BYTES * pQueryAttr->numOfCols + (char*)pRuntimeEnv->prevRow; pRuntimeEnv->prevRow[0] = start; - for(int32_t i = 1; i < pQueryAttr->numOfCols; ++i) { - pRuntimeEnv->prevRow[i] = pRuntimeEnv->prevRow[i - 1] + pQueryAttr->tableCols[i-1].bytes; + for (int32_t i = 1; i < pQueryAttr->numOfCols; ++i) { + pRuntimeEnv->prevRow[i] = pRuntimeEnv->prevRow[i - 1] + pQueryAttr->tableCols[i - 1].bytes; } if (pQueryAttr->tableCols[0].type == TSDB_DATA_TYPE_TIMESTAMP) { - *(int64_t*) pRuntimeEnv->prevRow[0] = INT64_MIN; + *(int64_t*)pRuntimeEnv->prevRow[0] = INT64_MIN; } } - //qDebug("QInfo:0x%"PRIx64" init runtime environment completed", GET_TASKID(pRuntimeEnv)); + // qDebug("QInfo:0x%"PRIx64" init runtime environment completed", GET_TASKID(pRuntimeEnv)); // group by normal column, sliding window query, interval query are handled by interval query processor // interval (down sampling operation) return TSDB_CODE_SUCCESS; _clean: - //destroyScalarFuncSupport(pRuntimeEnv->scalarSup, pRuntimeEnv->pQueryAttr->numOfOutput); + // destroyScalarFuncSupport(pRuntimeEnv->scalarSup, pRuntimeEnv->pQueryAttr->numOfOutput); taosMemoryFreeClear(pRuntimeEnv->pResultRowHashTable); taosMemoryFreeClear(pRuntimeEnv->keyBuf); taosMemoryFreeClear(pRuntimeEnv->prevRow); @@ -2214,70 +2321,71 @@ _clean: static void doFreeQueryHandle(STaskRuntimeEnv* pRuntimeEnv) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; -// tsdbCleanupReadHandle(pRuntimeEnv->pTsdbReadHandle); + // tsdbCleanupReadHandle(pRuntimeEnv->pTsdbReadHandle); pRuntimeEnv->pTsdbReadHandle = NULL; -// SMemRef* pMemRef = &pQueryAttr->memRef; -// assert(pMemRef->ref == 0 && pMemRef->snapshot.imem == NULL && pMemRef->snapshot.mem == NULL); + // SMemRef* pMemRef = &pQueryAttr->memRef; + // assert(pMemRef->ref == 0 && pMemRef->snapshot.imem == NULL && pMemRef->snapshot.mem == NULL); } -static void destroyTsComp(STaskRuntimeEnv *pRuntimeEnv, STaskAttr *pQueryAttr) { - if (pQueryAttr->tsCompQuery && pRuntimeEnv->outputBuf && pRuntimeEnv->outputBuf->pDataBlock && taosArrayGetSize(pRuntimeEnv->outputBuf->pDataBlock) > 0) { +static void destroyTsComp(STaskRuntimeEnv* pRuntimeEnv, STaskAttr* pQueryAttr) { + if (pQueryAttr->tsCompQuery && pRuntimeEnv->outputBuf && pRuntimeEnv->outputBuf->pDataBlock && + taosArrayGetSize(pRuntimeEnv->outputBuf->pDataBlock) > 0) { SColumnInfoData* pColInfoData = taosArrayGet(pRuntimeEnv->outputBuf->pDataBlock, 0); if (pColInfoData) { - TdFilePtr pFile = *(TdFilePtr *)pColInfoData->pData; // TODO refactor + TdFilePtr pFile = *(TdFilePtr*)pColInfoData->pData; // TODO refactor if (pFile != NULL) { taosCloseFile(&pFile); - *(TdFilePtr *)pColInfoData->pData = NULL; + *(TdFilePtr*)pColInfoData->pData = NULL; } } } } -bool isTaskKilled(SExecTaskInfo *pTaskInfo) { +bool isTaskKilled(SExecTaskInfo* pTaskInfo) { // query has been executed more than tsShellActivityTimer, and the retrieve has not arrived // abort current query execution. - if (pTaskInfo->owner != 0 && ((taosGetTimestampSec() - pTaskInfo->cost.start/1000) > 10*getMaximumIdleDurationSec()) + if (pTaskInfo->owner != 0 && + ((taosGetTimestampSec() - pTaskInfo->cost.start / 1000) > 10 * getMaximumIdleDurationSec()) /*(!needBuildResAfterQueryComplete(pTaskInfo))*/) { - assert(pTaskInfo->cost.start != 0); -// qDebug("QInfo:%" PRIu64 " retrieve not arrive beyond %d ms, abort current query execution, start:%" PRId64 -// ", current:%d", pQInfo->qId, 1, pQInfo->startExecTs, taosGetTimestampSec()); -// return true; + // qDebug("QInfo:%" PRIu64 " retrieve not arrive beyond %d ms, abort current query execution, start:%" PRId64 + // ", current:%d", pQInfo->qId, 1, pQInfo->startExecTs, taosGetTimestampSec()); + // return true; } return false; } -void setTaskKilled(SExecTaskInfo *pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED;} +void setTaskKilled(SExecTaskInfo* pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED; } -//static bool isFixedOutputQuery(STaskAttr* pQueryAttr) { -// if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) { -// return false; -// } +// static bool isFixedOutputQuery(STaskAttr* pQueryAttr) { +// if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) { +// return false; +// } // -// // Note:top/bottom query is fixed output query -// if (pQueryAttr->topBotQuery || pQueryAttr->groupbyColumn || pQueryAttr->tsCompQuery) { -// return true; -// } +// // Note:top/bottom query is fixed output query +// if (pQueryAttr->topBotQuery || pQueryAttr->groupbyColumn || pQueryAttr->tsCompQuery) { +// return true; +// } // -// for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { -// SExprBasicInfo *pExpr = &pQueryAttr->pExpr1[i].base; +// for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { +// SExprBasicInfo *pExpr = &pQueryAttr->pExpr1[i].base; // -// if (pExpr->functionId == FUNCTION_TS || pExpr->functionId == FUNCTION_TS_DUMMY) { -// continue; -// } +// if (pExpr->functionId == FUNCTION_TS || pExpr->functionId == FUNCTION_TS_DUMMY) { +// continue; +// } // -// if (!IS_MULTIOUTPUT(aAggs[pExpr->functionId].status)) { -// return true; -// } -// } +// if (!IS_MULTIOUTPUT(aAggs[pExpr->functionId].status)) { +// return true; +// } +// } // -// return false; -//} +// return false; +// } // todo refactor with isLastRowQuery -//bool isPointInterpoQuery(STaskAttr *pQueryAttr) { +// bool isPointInterpoQuery(STaskAttr *pQueryAttr) { // for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { // int32_t functionId = pQueryAttr->pExpr1[i].base.functionId; // if (functionId == FUNCTION_INTERP) { @@ -2288,7 +2396,7 @@ void setTaskKilled(SExecTaskInfo *pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_Q // return false; //} -static bool isFirstLastRowQuery(STaskAttr *pQueryAttr) { +static bool isFirstLastRowQuery(STaskAttr* pQueryAttr) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functionID = getExprFunctionId(&pQueryAttr->pExpr1[i]); if (functionID == FUNCTION_LAST_ROW) { @@ -2299,7 +2407,7 @@ static bool isFirstLastRowQuery(STaskAttr *pQueryAttr) { return false; } -static bool isCachedLastQuery(STaskAttr *pQueryAttr) { +static bool isCachedLastQuery(STaskAttr* pQueryAttr) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]); if (functionId == FUNCTION_LAST || functionId == FUNCTION_LAST_DST) { @@ -2329,8 +2437,9 @@ static bool isCachedLastQuery(STaskAttr *pQueryAttr) { } ///////////////////////////////////////////////////////////////////////////////////////////// -//todo refactor : return window -void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow *win) { +// todo refactor : return window +void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, + STimeWindow* win) { ASSERT(key >= keyFirst && key <= keyLast); win->skey = taosTimeTruncate(key, pInterval, precision); @@ -2349,11 +2458,11 @@ void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t ke /* * todo add more parameters to check soon.. */ -bool colIdCheck(STaskAttr *pQueryAttr, uint64_t qId) { +bool colIdCheck(STaskAttr* pQueryAttr, uint64_t qId) { // load data column information is incorrect for (int32_t i = 0; i < pQueryAttr->numOfCols - 1; ++i) { if (pQueryAttr->tableCols[i].colId == pQueryAttr->tableCols[i + 1].colId) { - //qError("QInfo:0x%"PRIx64" invalid data load column for query", qId); + // qError("QInfo:0x%"PRIx64" invalid data load column for query", qId); return false; } } @@ -2363,7 +2472,7 @@ bool colIdCheck(STaskAttr *pQueryAttr, uint64_t qId) { // todo ignore the avg/sum/min/max/count/stddev/top/bottom functions, of which // the scan order is not matter -static bool onlyOneQueryType(STaskAttr *pQueryAttr, int32_t functId, int32_t functIdDst) { +static bool onlyOneQueryType(STaskAttr* pQueryAttr, int32_t functId, int32_t functIdDst) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]); @@ -2380,13 +2489,19 @@ static bool onlyOneQueryType(STaskAttr *pQueryAttr, int32_t functId, int32_t fun return true; } -static bool onlyFirstQuery(STaskAttr *pQueryAttr) { return onlyOneQueryType(pQueryAttr, FUNCTION_FIRST, FUNCTION_FIRST_DST); } +static bool onlyFirstQuery(STaskAttr* pQueryAttr) { + return onlyOneQueryType(pQueryAttr, FUNCTION_FIRST, FUNCTION_FIRST_DST); +} -static bool onlyLastQuery(STaskAttr *pQueryAttr) { return onlyOneQueryType(pQueryAttr, FUNCTION_LAST, FUNCTION_LAST_DST); } +static bool onlyLastQuery(STaskAttr* pQueryAttr) { + return onlyOneQueryType(pQueryAttr, FUNCTION_LAST, FUNCTION_LAST_DST); +} -static bool notContainSessionOrStateWindow(STaskAttr *pQueryAttr) { return !(pQueryAttr->sw.gap > 0 || pQueryAttr->stateWindow); } +static bool notContainSessionOrStateWindow(STaskAttr* pQueryAttr) { + return !(pQueryAttr->sw.gap > 0 || pQueryAttr->stateWindow); +} -static int32_t updateBlockLoadStatus(STaskAttr *pQuery, int32_t status) { +static int32_t updateBlockLoadStatus(STaskAttr* pQuery, int32_t status) { bool hasFirstLastFunc = false; bool hasOtherFunc = false; @@ -2410,7 +2525,7 @@ static int32_t updateBlockLoadStatus(STaskAttr *pQuery, int32_t status) { } if (hasFirstLastFunc && status == BLK_DATA_NO_NEEDED) { - if(!hasOtherFunc) { + if (!hasOtherFunc) { return BLK_DATA_DISCARD; } else { return BLK_DATA_ALL_NEEDED; @@ -2424,67 +2539,70 @@ static void doUpdateLastKey(STaskAttr* pQueryAttr) { STimeWindow* win = &pQueryAttr->window; size_t num = taosArrayGetSize(pQueryAttr->tableGroupInfo.pGroupList); - for(int32_t i = 0; i < num; ++i) { + for (int32_t i = 0; i < num; ++i) { SArray* p1 = taosArrayGetP(pQueryAttr->tableGroupInfo.pGroupList, i); size_t len = taosArrayGetSize(p1); - for(int32_t j = 0; j < len; ++j) { -// STableKeyInfo* pInfo = taosArrayGet(p1, j); -// -// // update the new lastkey if it is equalled to the value of the old skey -// if (pInfo->lastKey == win->ekey) { -// pInfo->lastKey = win->skey; -// } + for (int32_t j = 0; j < len; ++j) { + // STableKeyInfo* pInfo = taosArrayGet(p1, j); + // + // // update the new lastkey if it is equalled to the value of the old skey + // if (pInfo->lastKey == win->ekey) { + // pInfo->lastKey = win->skey; + // } } } } -//static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableReq* pQueryMsg, bool stableQuery) { -// STaskAttr* pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; +// static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableReq* pQueryMsg, bool stableQuery) { +// STaskAttr* pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; // -// // in case of point-interpolation query, use asc order scan -// char msg[] = "QInfo:0x%"PRIx64" scan order changed for %s query, old:%d, new:%d, qrange exchanged, old qrange:%" PRId64 -// "-%" PRId64 ", new qrange:%" PRId64 "-%" PRId64; +// // in case of point-interpolation query, use asc order scan +// char msg[] = "QInfo:0x%"PRIx64" scan order changed for %s query, old:%d, new:%d, qrange exchanged, old qrange:%" +// PRId64 +// "-%" PRId64 ", new qrange:%" PRId64 "-%" PRId64; // -// // todo handle the case the the order irrelevant query type mixed up with order critical query type -// // descending order query for last_row query -// if (isFirstLastRowQuery(pQueryAttr)) { -// //qDebug("QInfo:0x%"PRIx64" scan order changed for last_row query, old:%d, new:%d", pQInfo->qId, pQueryAttr->order.order, TSDB_ORDER_ASC); +// // todo handle the case the the order irrelevant query type mixed up with order critical query type +// // descending order query for last_row query +// if (isFirstLastRowQuery(pQueryAttr)) { +// //qDebug("QInfo:0x%"PRIx64" scan order changed for last_row query, old:%d, new:%d", pQInfo->qId, +// pQueryAttr->order.order, TSDB_ORDER_ASC); // -// pQueryAttr->order.order = TSDB_ORDER_ASC; -// if (pQueryAttr->window.skey > pQueryAttr->window.ekey) { -// TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); -// } +// pQueryAttr->order.order = TSDB_ORDER_ASC; +// if (pQueryAttr->window.skey > pQueryAttr->window.ekey) { +// TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); +// } // -// pQueryAttr->needReverseScan = false; -// return; -// } +// pQueryAttr->needReverseScan = false; +// return; +// } // -// if (pQueryAttr->groupbyColumn && pQueryAttr->order.order == TSDB_ORDER_DESC) { -// pQueryAttr->order.order = TSDB_ORDER_ASC; -// if (pQueryAttr->window.skey > pQueryAttr->window.ekey) { -// TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); -// } +// if (pQueryAttr->groupbyColumn && pQueryAttr->order.order == TSDB_ORDER_DESC) { +// pQueryAttr->order.order = TSDB_ORDER_ASC; +// if (pQueryAttr->window.skey > pQueryAttr->window.ekey) { +// TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); +// } // -// pQueryAttr->needReverseScan = false; -// doUpdateLastKey(pQueryAttr); -// return; -// } +// pQueryAttr->needReverseScan = false; +// doUpdateLastKey(pQueryAttr); +// return; +// } // -// if (pQueryAttr->pointInterpQuery && pQueryAttr->interval.interval == 0) { -// if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { -// //qDebug(msg, pQInfo->qId, "interp", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); -// TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); -// } +// if (pQueryAttr->pointInterpQuery && pQueryAttr->interval.interval == 0) { +// if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { +// //qDebug(msg, pQInfo->qId, "interp", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, +// pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); TSWAP(pQueryAttr->window.skey, +// pQueryAttr->window.ekey, TSKEY); +// } // -// pQueryAttr->order.order = TSDB_ORDER_ASC; -// return; -// } +// pQueryAttr->order.order = TSDB_ORDER_ASC; +// return; +// } // -// if (pQueryAttr->interval.interval == 0) { -// if (onlyFirstQuery(pQueryAttr)) { -// if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { -// //qDebug(msg, pQInfo->qId, "only-first", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, +// if (pQueryAttr->interval.interval == 0) { +// if (onlyFirstQuery(pQueryAttr)) { +// if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { +// //qDebug(msg, pQInfo->qId, "only-first", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, //// pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); // // TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); @@ -2511,7 +2629,8 @@ static void doUpdateLastKey(STaskAttr* pQueryAttr) { // if (onlyFirstQuery(pQueryAttr)) { // if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { // //qDebug(msg, pQInfo->qId, "only-first stable", pQueryAttr->order.order, TSDB_ORDER_ASC, -//// pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); +//// pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, +/// pQueryAttr->window.skey); // // TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); // doUpdateLastKey(pQueryAttr); @@ -2522,7 +2641,8 @@ static void doUpdateLastKey(STaskAttr* pQueryAttr) { // } else if (onlyLastQuery(pQueryAttr)) { // if (QUERY_IS_ASC_QUERY(pQueryAttr)) { // //qDebug(msg, pQInfo->qId, "only-last stable", pQueryAttr->order.order, TSDB_ORDER_DESC, -//// pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); +//// pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, +/// pQueryAttr->window.skey); // // TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); // doUpdateLastKey(pQueryAttr); @@ -2537,29 +2657,31 @@ static void doUpdateLastKey(STaskAttr* pQueryAttr) { static void getIntermediateBufInfo(STaskRuntimeEnv* pRuntimeEnv, int32_t* ps, int32_t* rowsize) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t MIN_ROWS_PER_PAGE = 4; + int32_t MIN_ROWS_PER_PAGE = 4; - *rowsize = (int32_t)(pQueryAttr->resultRowSize * getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); + *rowsize = (int32_t)(pQueryAttr->resultRowSize * + getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); int32_t overhead = sizeof(SFilePage); // one page contains at least two rows *ps = DEFAULT_INTERN_BUF_PAGE_SIZE; - while(((*rowsize) * MIN_ROWS_PER_PAGE) > (*ps) - overhead) { + while (((*rowsize) * MIN_ROWS_PER_PAGE) > (*ps) - overhead) { *ps = ((*ps) << 1u); } } #define IS_PREFILTER_TYPE(_t) ((_t) != TSDB_DATA_TYPE_BINARY && (_t) != TSDB_DATA_TYPE_NCHAR) -//static FORCE_INLINE bool doFilterByBlockStatistics(STaskRuntimeEnv* pRuntimeEnv, SDataStatis *pDataStatis, SqlFunctionCtx *pCtx, int32_t numOfRows) { -// STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; +// static FORCE_INLINE bool doFilterByBlockStatistics(STaskRuntimeEnv* pRuntimeEnv, SDataStatis *pDataStatis, +// SqlFunctionCtx *pCtx, int32_t numOfRows) { +// STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; // -// if (pDataStatis == NULL || pQueryAttr->pFilters == NULL) { -// return true; -// } +// if (pDataStatis == NULL || pQueryAttr->pFilters == NULL) { +// return true; +// } // -// return filterRangeExecute(pQueryAttr->pFilters, pDataStatis, pQueryAttr->numOfCols, numOfRows); -//} +// return filterRangeExecute(pQueryAttr->pFilters, pDataStatis, pQueryAttr->numOfCols, numOfRows); +// } static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockInfo) { STimeWindow w = {0}; @@ -2568,15 +2690,15 @@ static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockI TSKEY ek = TMAX(pQueryAttr->window.skey, pQueryAttr->window.ekey); if (QUERY_IS_ASC_QUERY(pQueryAttr)) { -// getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.skey, sk, ek, &w); + // getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.skey, sk, ek, &w); assert(w.ekey >= pBlockInfo->window.skey); if (w.ekey < pBlockInfo->window.ekey) { return true; } - while(1) { -// getNextTimeWindow(pQueryAttr, &w); + while (1) { + // getNextTimeWindow(pQueryAttr, &w); if (w.skey > pBlockInfo->window.ekey) { break; } @@ -2587,15 +2709,15 @@ static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockI } } } else { -// getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.ekey, sk, ek, &w); + // getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.ekey, sk, ek, &w); assert(w.skey <= pBlockInfo->window.ekey); if (w.skey > pBlockInfo->window.skey) { return true; } - while(1) { -// getNextTimeWindow(pQueryAttr, &w); + while (1) { + // getNextTimeWindow(pQueryAttr, &w); if (w.ekey < pBlockInfo->window.skey) { break; } @@ -2610,11 +2732,12 @@ static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockI return false; } -static int32_t doTSJoinFilter(STaskRuntimeEnv *pRuntimeEnv, TSKEY key, bool ascQuery) { +static int32_t doTSJoinFilter(STaskRuntimeEnv* pRuntimeEnv, TSKEY key, bool ascQuery) { STSElem elem = tsBufGetElem(pRuntimeEnv->pTsBuf); #if defined(_DEBUG_VIEW) - printf("elem in comp ts file:%" PRId64 ", key:%" PRId64 ", tag:%"PRIu64", query order:%d, ts order:%d, traverse:%d, index:%d\n", + printf("elem in comp ts file:%" PRId64 ", key:%" PRId64 ", tag:%" PRIu64 + ", query order:%d, ts order:%d, traverse:%d, index:%d\n", elem.ts, key, elem.tag.i, pQueryAttr->order.order, pRuntimeEnv->pTsBuf->tsOrder, pRuntimeEnv->pTsBuf->cur.order, pRuntimeEnv->pTsBuf->cur.tsIndex); #endif @@ -2648,23 +2771,23 @@ bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilter qualified = false; for (int32_t j = 0; j < pFilterInfo[k].numOfFilters; ++j) { SColumnFilterElem* pFilterElem = NULL; -// SColumnFilterElem* pFilterElem = &pFilterInfo[k].pFilters[j]; + // SColumnFilterElem* pFilterElem = &pFilterInfo[k].pFilters[j]; bool isnull = isNull(pElem, pFilterInfo[k].info.type); if (isnull) { -// if (pFilterElem->fp == isNullOperator) { -// qualified = true; -// break; -// } else { -// continue; -// } + // if (pFilterElem->fp == isNullOperator) { + // qualified = true; + // break; + // } else { + // continue; + // } } else { -// if (pFilterElem->fp == notNullOperator) { -// qualified = true; -// break; -// } else if (pFilterElem->fp == isNullOperator) { -// continue; -// } + // if (pFilterElem->fp == notNullOperator) { + // qualified = true; + // break; + // } else if (pFilterElem->fp == isNullOperator) { + // continue; + // } } if (pFilterElem->fp(pFilterElem, pElem, pElem, pFilterInfo[k].info.type)) { @@ -2740,7 +2863,7 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo SSDataBlock* pBlock, bool ascQuery) { int32_t numOfRows = pBlock->info.rows; - int8_t *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); + int8_t* p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); bool all = true; #if 0 if (pRuntimeEnv->pTsBuf != NULL) { @@ -2780,58 +2903,59 @@ void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo } void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock, bool ascQuery) { - int32_t numOfRows = pBlock->info.rows; + int32_t numOfRows = pBlock->info.rows; - int8_t *p = NULL; - bool all = true; + int8_t* p = NULL; + bool all = true; - if (pRuntimeEnv->pTsBuf != NULL) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); - p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); - - TSKEY* k = (TSKEY*) pColInfoData->pData; - for (int32_t i = 0; i < numOfRows; ++i) { - int32_t offset = ascQuery? i:(numOfRows - i - 1); - int32_t ret = doTSJoinFilter(pRuntimeEnv, k[offset], ascQuery); - if (ret == TS_JOIN_TAG_NOT_EQUALS) { - break; - } else if (ret == TS_JOIN_TS_NOT_EQUALS) { - all = false; - continue; - } else { - assert(ret == TS_JOIN_TS_EQUAL); - p[offset] = true; - } + if (pRuntimeEnv->pTsBuf != NULL) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); + p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); - if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) { - break; - } - } + TSKEY* k = (TSKEY*)pColInfoData->pData; + for (int32_t i = 0; i < numOfRows; ++i) { + int32_t offset = ascQuery ? i : (numOfRows - i - 1); + int32_t ret = doTSJoinFilter(pRuntimeEnv, k[offset], ascQuery); + if (ret == TS_JOIN_TAG_NOT_EQUALS) { + break; + } else if (ret == TS_JOIN_TS_NOT_EQUALS) { + all = false; + continue; + } else { + assert(ret == TS_JOIN_TS_EQUAL); + p[offset] = true; + } - // save the cursor status -// pRuntimeEnv->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf); - } else { -// all = filterExecute(pRuntimeEnv->pQueryAttr->pFilters, numOfRows, &p, pBlock->pBlockAgg, pRuntimeEnv->pQueryAttr->numOfCols); - } + if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) { + break; + } + } - if (!all) { - if (p) { - doCompactSDataBlock(pBlock, numOfRows, p); - } else { - pBlock->info.rows = 0; - pBlock->pBlockAgg = NULL; // clean the block statistics info - } - } + // save the cursor status + // pRuntimeEnv->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf); + } else { + // all = filterExecute(pRuntimeEnv->pQueryAttr->pFilters, numOfRows, &p, pBlock->pBlockAgg, + // pRuntimeEnv->pQueryAttr->numOfCols); + } - taosMemoryFreeClear(p); + if (!all) { + if (p) { + doCompactSDataBlock(pBlock, numOfRows, p); + } else { + pBlock->info.rows = 0; + pBlock->pBlockAgg = NULL; // clean the block statistics info + } + } + + taosMemoryFreeClear(p); } static SColumnInfo* doGetTagColumnInfoById(SColumnInfo* pTagColList, int32_t numOfTags, int16_t colId); -static void doSetTagValueInParam(void* pTable, int32_t tagColId, SVariant *tag, int16_t type, int16_t bytes); +static void doSetTagValueInParam(void* pTable, int32_t tagColId, SVariant* tag, int16_t type, int16_t bytes); static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock) { SqlFunctionCtx* pCtx = pTableScanInfo->pCtx; - uint32_t status = BLK_DATA_NO_NEEDED; + uint32_t status = BLK_DATA_NO_NEEDED; int32_t numOfOutput = pTableScanInfo->numOfOutput; for (int32_t i = 0; i < numOfOutput; ++i) { @@ -2843,10 +2967,10 @@ static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSData status |= BLK_DATA_ALL_NEEDED; return status; } else { -// status |= aAggs[functionId].dataReqFunc(&pTableScanInfo->pCtx[i], &pBlock->info.window, colId); -// if ((status & BLK_DATA_ALL_NEEDED) == BLK_DATA_ALL_NEEDED) { -// return status; -// } + // status |= aAggs[functionId].dataReqFunc(&pTableScanInfo->pCtx[i], &pBlock->info.window, colId); + // if ((status & BLK_DATA_ALL_NEEDED) == BLK_DATA_ALL_NEEDED) { + // return status; + // } } } @@ -2867,7 +2991,7 @@ void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFi } } -int32_t loadDataBlock(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { +int32_t loadDataBlock(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { STaskCostInfo* pCost = &pTaskInfo->cost; pCost->totalBlocks += 1; @@ -2883,26 +3007,30 @@ int32_t loadDataBlock(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableScanInfo, return terrno; } - int32_t numOfCols = pBlock->info.numOfCols; - for(int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* p = taosArrayGet(pCols, i); - SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i); - ASSERT(pColMatchInfo->colId == p->info.colId); - - taosArraySet(pBlock->pDataBlock, pColMatchInfo->targetSlotId, p); + int32_t numOfCols = pBlock->info.numOfCols; + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* p = taosArrayGet(pCols, i); + SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i); + if (!pColMatchInfo->output) { + continue; } - return TSDB_CODE_SUCCESS; + ASSERT(pColMatchInfo->colId == p->info.colId); + taosArraySet(pBlock->pDataBlock, pColMatchInfo->targetSlotId, p); + } + + return TSDB_CODE_SUCCESS; } -int32_t loadDataBlockOnDemand(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { +int32_t loadDataBlockOnDemand(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, + uint32_t* status) { *status = BLK_DATA_NO_NEEDED; pBlock->pDataBlock = NULL; - pBlock->pBlockAgg = NULL; + pBlock->pBlockAgg = NULL; -// int64_t groupId = pRuntimeEnv->current->groupIndex; -// bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); + // int64_t groupId = pRuntimeEnv->current->groupIndex; + // bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); STaskCostInfo* pCost = &pTaskInfo->cost; @@ -3058,7 +3186,7 @@ int32_t loadDataBlockOnDemand(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableSc return TSDB_CODE_SUCCESS; } -int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) { +int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { int32_t midPos = -1; int32_t numOfRows; @@ -3068,7 +3196,7 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) { assert(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC); - TSKEY * keyList = (TSKEY *)pValue; + TSKEY* keyList = (TSKEY*)pValue; int32_t firstPos = 0; int32_t lastPos = num - 1; @@ -3125,16 +3253,16 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) { * set tag value in SqlFunctionCtx * e.g.,tag information into input buffer */ -static void doSetTagValueInParam(void* pTable, int32_t tagColId, SVariant *tag, int16_t type, int16_t bytes) { +static void doSetTagValueInParam(void* pTable, int32_t tagColId, SVariant* tag, int16_t type, int16_t bytes) { taosVariantDestroy(tag); char* val = NULL; -// if (tagColId == TSDB_TBNAME_COLUMN_INDEX) { -// val = tsdbGetTableName(pTable); -// assert(val != NULL); -// } else { -// val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); -// } + // if (tagColId == TSDB_TBNAME_COLUMN_INDEX) { + // val = tsdbGetTableName(pTable); + // assert(val != NULL); + // } else { + // val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); + // } if (val == NULL || isNull(val, type)) { tag->nType = TSDB_DATA_TYPE_NULL; @@ -3143,9 +3271,9 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, SVariant *tag, if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { int32_t maxLen = bytes - VARSTR_HEADER_SIZE; - int32_t len = (varDataLen(val) > maxLen)? maxLen:varDataLen(val); + int32_t len = (varDataLen(val) > maxLen) ? maxLen : varDataLen(val); taosVariantCreateFromBinary(tag, varDataVal(val), len, type); - //taosVariantCreateFromBinary(tag, varDataVal(val), varDataLen(val), type); + // taosVariantCreateFromBinary(tag, varDataVal(val), varDataLen(val), type); } else { taosVariantCreateFromBinary(tag, val, bytes, type); } @@ -3154,7 +3282,7 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, SVariant *tag, static SColumnInfo* doGetTagColumnInfoById(SColumnInfo* pTagColList, int32_t numOfTags, int16_t colId) { assert(pTagColList != NULL && numOfTags > 0); - for(int32_t i = 0; i < numOfTags; ++i) { + for (int32_t i = 0; i < numOfTags; ++i) { if (pTagColList[i].colId == colId) { return &pTagColList[i]; } @@ -3163,19 +3291,19 @@ static SColumnInfo* doGetTagColumnInfoById(SColumnInfo* pTagColList, int32_t num return NULL; } -void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SqlFunctionCtx* pCtx, int32_t numOfOutput) { +void setTagValue(SOperatorInfo* pOperatorInfo, void* pTable, SqlFunctionCtx* pCtx, int32_t numOfOutput) { STaskRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; - SExprInfo *pExpr = pOperatorInfo->pExpr; - STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; + SExprInfo* pExpr = pOperatorInfo->pExpr; + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; SExprInfo* pExprInfo = &pExpr[0]; - int32_t functionId = getExprFunctionId(pExprInfo); + int32_t functionId = getExprFunctionId(pExprInfo); if (pQueryAttr->numOfOutput == 1 && functionId == FUNCTION_TS_COMP && pQueryAttr->stableQuery) { assert(pExprInfo->base.numOfParams == 1); -// int16_t tagColId = (int16_t)pExprInfo->base.param[0].i; + // int16_t tagColId = (int16_t)pExprInfo->base.param[0].i; int16_t tagColId = -1; SColumnInfo* pColInfo = doGetTagColumnInfoById(pQueryAttr->tagColList, pQueryAttr->numOfTags, tagColId); @@ -3195,23 +3323,23 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SqlFunctionCtx* pCt } // todo use tag column index to optimize performance - doSetTagValueInParam(pTable, pLocalExprInfo->base.pParam[0].pCol->colId, &pCtx[idx].tag, pLocalExprInfo->base.resSchema.type, - pLocalExprInfo->base.resSchema.bytes); + doSetTagValueInParam(pTable, pLocalExprInfo->base.pParam[0].pCol->colId, &pCtx[idx].tag, + pLocalExprInfo->base.resSchema.type, pLocalExprInfo->base.resSchema.bytes); - if (IS_NUMERIC_TYPE(pLocalExprInfo->base.resSchema.type) - || pLocalExprInfo->base.resSchema.type == TSDB_DATA_TYPE_BOOL - || pLocalExprInfo->base.resSchema.type == TSDB_DATA_TYPE_TIMESTAMP) { + if (IS_NUMERIC_TYPE(pLocalExprInfo->base.resSchema.type) || + pLocalExprInfo->base.resSchema.type == TSDB_DATA_TYPE_BOOL || + pLocalExprInfo->base.resSchema.type == TSDB_DATA_TYPE_TIMESTAMP) { memcpy(pRuntimeEnv->tagVal + offset, &pCtx[idx].tag.i, pLocalExprInfo->base.resSchema.bytes); } else { if (pCtx[idx].tag.pz != NULL) { memcpy(pRuntimeEnv->tagVal + offset, pCtx[idx].tag.pz, pCtx[idx].tag.nLen); - } + } } offset += pLocalExprInfo->base.resSchema.bytes; } - //todo : use index to avoid iterator all possible output columns + // todo : use index to avoid iterator all possible output columns if (pQueryAttr->stableQuery && pQueryAttr->stabledev && (pRuntimeEnv->prevResult != NULL)) { setParamForStableStddev(pRuntimeEnv, pCtx, numOfOutput, pExprInfo); } @@ -3231,12 +3359,12 @@ void copyToSDataBlock(SSDataBlock* pBlock, int32_t* offset, SGroupResInfo* pGrou // all results in current group have been returned to client, try next group if ((pGroupResInfo->pRows == NULL) || taosArrayGetSize(pGroupResInfo->pRows) == 0) { assert(pGroupResInfo->index == 0); -// if ((code = mergeIntoGroupResult(&pGroupResInfo, pRuntimeEnv, offset)) != TSDB_CODE_SUCCESS) { - return; -// } + // if ((code = mergeIntoGroupResult(&pGroupResInfo, pRuntimeEnv, offset)) != TSDB_CODE_SUCCESS) { + return; + // } } -// doCopyToSDataBlock(pResBuf, pGroupResInfo, TSDB_ORDER_ASC, pBlock, ); + // doCopyToSDataBlock(pResBuf, pGroupResInfo, TSDB_ORDER_ASC, pBlock, ); // current data are all dumped to result buffer, clear it if (!hasRemainDataInCurrentGroup(pGroupResInfo)) { @@ -3247,22 +3375,22 @@ void copyToSDataBlock(SSDataBlock* pBlock, int32_t* offset, SGroupResInfo* pGrou } // enough results in data buffer, return -// if (pBlock->info.rows >= threshold) { -// break; -// } + // if (pBlock->info.rows >= threshold) { + // break; + // } } } -static void updateTableQueryInfoForReverseScan(STableQueryInfo *pTableQueryInfo) { +static void updateTableQueryInfoForReverseScan(STableQueryInfo* pTableQueryInfo) { if (pTableQueryInfo == NULL) { return; } -// TSWAP(pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey, TSKEY); -// pTableQueryInfo->lastKey = pTableQueryInfo->win.skey; + // TSWAP(pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey, TSKEY); + // pTableQueryInfo->lastKey = pTableQueryInfo->win.skey; -// SWITCH_ORDER(pTableQueryInfo->cur.order); -// pTableQueryInfo->cur.vgroupIndex = -1; + // SWITCH_ORDER(pTableQueryInfo->cur.order); + // pTableQueryInfo->cur.vgroupIndex = -1; // set the index to be the end slot of result rows array SResultRowInfo* pResultRowInfo = &pTableQueryInfo->resInfo; @@ -3294,7 +3422,6 @@ static void setupQueryRangeForReverseScan(STableScanInfo* pTableScanInfo) { } } #endif - } void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { @@ -3304,7 +3431,7 @@ void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { } // TODO fix this bug. -int32_t initResultRow(SResultRow *pResultRow) { +int32_t initResultRow(SResultRow* pResultRow) { pResultRow->pEntryInfo = (struct SResultRowEntryInfo*)((char*)pResultRow + sizeof(SResultRow)); return TSDB_CODE_SUCCESS; } @@ -3319,39 +3446,40 @@ int32_t initResultRow(SResultRow *pResultRow) { */ // TODO refactor: some function move away void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t stage, SExecTaskInfo* pTaskInfo) { - SqlFunctionCtx* pCtx = pInfo->pCtx; - SSDataBlock* pDataBlock = pInfo->pRes; - int32_t* rowCellInfoOffset = pInfo->rowCellInfoOffset; + SqlFunctionCtx* pCtx = pInfo->pCtx; + SSDataBlock* pDataBlock = pInfo->pRes; + int32_t* rowCellInfoOffset = pInfo->rowCellInfoOffset; SResultRowInfo* pResultRowInfo = &pInfo->resultRowInfo; - int64_t tid = 0; - int64_t groupId = 0; - SResultRow* pRow = doSetResultOutBufByKey_rv(pSup->pResultBuf, pResultRowInfo, tid, (char *)&tid, sizeof(tid), true, groupId, pTaskInfo, false, pSup); + int64_t tid = 0; + int64_t groupId = 0; + SResultRow* pRow = doSetResultOutBufByKey_rv(pSup->pResultBuf, pResultRowInfo, tid, (char*)&tid, sizeof(tid), true, + groupId, pTaskInfo, false, pSup); for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { struct SResultRowEntryInfo* pEntry = getResultCell(pRow, i, rowCellInfoOffset); cleanupResultRowEntry(pEntry); - pCtx[i].resultInfo = pEntry; + pCtx[i].resultInfo = pEntry; pCtx[i].currentStage = stage; // set the timestamp output buffer for top/bottom/diff query -// int32_t fid = pCtx[i].functionId; -// if (fid == FUNCTION_TOP || fid == FUNCTION_BOTTOM || fid == FUNCTION_DIFF || fid == FUNCTION_DERIVATIVE) { -// if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput; -// } + // int32_t fid = pCtx[i].functionId; + // if (fid == FUNCTION_TOP || fid == FUNCTION_BOTTOM || fid == FUNCTION_DIFF || fid == FUNCTION_DERIVATIVE) { + // if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput; + // } } initCtxOutputBuffer(pCtx, pDataBlock->info.numOfCols); } -void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOfInputRows) { +void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity, int32_t numOfInputRows) { SSDataBlock* pDataBlock = pBInfo->pRes; - int32_t newSize = pDataBlock->info.rows + numOfInputRows + 5; // extra output buffer + int32_t newSize = pDataBlock->info.rows + numOfInputRows + 5; // extra output buffer if ((*bufCapacity) < newSize) { - for(int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { - SColumnInfoData *pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); + for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); char* p = taosMemoryRealloc(pColInfo->pData, newSize * pColInfo->info.bytes); if (p != NULL) { @@ -3366,16 +3494,16 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf } } - for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { - SColumnInfoData *pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); pBInfo->pCtx[i].pOutput = pColInfo->pData + pColInfo->info.bytes * pDataBlock->info.rows; // set the correct pointer after the memory buffer reallocated. int32_t functionId = pBInfo->pCtx[i].functionId; - if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF || functionId == FUNCTION_DERIVATIVE) { - if (i > 0) pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i-1].pOutput; + if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF || + functionId == FUNCTION_DERIVATIVE) { + if (i > 0) pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i - 1].pOutput; } } } @@ -3383,16 +3511,16 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput) { bool needCopyTs = false; int32_t tsNum = 0; - char *src = NULL; + char* src = NULL; for (int32_t i = 0; i < numOfOutput; i++) { int32_t functionId = pCtx[i].functionId; if (functionId == FUNCTION_DIFF || functionId == FUNCTION_DERIVATIVE) { needCopyTs = true; - if (i > 0 && pCtx[i-1].functionId == FUNCTION_TS_DUMMY) { - SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i - 1); // find ts data + if (i > 0 && pCtx[i - 1].functionId == FUNCTION_TS_DUMMY) { + SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i - 1); // find ts data src = pColRes->pData; } - } else if(functionId == FUNCTION_TS_DUMMY) { + } else if (functionId == FUNCTION_TS_DUMMY) { tsNum++; } } @@ -3403,18 +3531,18 @@ void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput) for (int32_t i = 0; i < numOfOutput; i++) { int32_t functionId = pCtx[i].functionId; - if(functionId == FUNCTION_TS_DUMMY) { + if (functionId == FUNCTION_TS_DUMMY) { SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i); memcpy(pColRes->pData, src, pColRes->info.bytes * pRes->info.rows); } } } -void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity) { +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); + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock->pDataBlock, i); int32_t functionId = pBInfo->pCtx[i].functionId; if (functionId < 0) { @@ -3434,7 +3562,7 @@ void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size) { } } -void setTaskStatus(SExecTaskInfo *pTaskInfo, int8_t status) { +void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status) { if (status == TASK_NOT_COMPLETED) { pTaskInfo->status = status; } else { @@ -3444,24 +3572,24 @@ void setTaskStatus(SExecTaskInfo *pTaskInfo, int8_t status) { } } -static void setupEnvForReverseScan(STableScanInfo *pTableScanInfo, SqlFunctionCtx* pCtx, int32_t numOfOutput) { -// if (pRuntimeEnv->pTsBuf) { -// SWITCH_ORDER(pRuntimeEnv->pTsBuf->cur.order); -// bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf); -// assert(ret); -// } +static void setupEnvForReverseScan(STableScanInfo* pTableScanInfo, SqlFunctionCtx* pCtx, int32_t numOfOutput) { + // if (pRuntimeEnv->pTsBuf) { + // SWITCH_ORDER(pRuntimeEnv->pTsBuf->cur.order); + // bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf); + // assert(ret); + // } // reverse order time range SET_REVERSE_SCAN_FLAG(pTableScanInfo); -// setTaskStatus(pTableScanInfo, QUERY_NOT_COMPLETED); + // setTaskStatus(pTableScanInfo, QUERY_NOT_COMPLETED); switchCtxOrder(pCtx, numOfOutput); SWITCH_ORDER(pTableScanInfo->order); setupQueryRangeForReverseScan(pTableScanInfo); - pTableScanInfo->times = 1; - pTableScanInfo->current = 0; + pTableScanInfo->times = 1; + pTableScanInfo->current = 0; pTableScanInfo->reverseTimes = 0; } @@ -3475,11 +3603,12 @@ void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput) { } } -void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf *pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset) { +void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, + SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset) { for (int32_t i = 0; i < pResultRowInfo->size; ++i) { SResultRowPosition* pPos = &pResultRowInfo->pPosition[i]; - SFilePage* bufPage = getBufPage(pBuf, pPos->pageId); + SFilePage* bufPage = getBufPage(pBuf, pPos->pageId); SResultRow* pRow = (SResultRow*)((char*)bufPage + pPos->offset); if (!isResultRowClosed(pResultRowInfo, i)) { continue; @@ -3493,7 +3622,7 @@ void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SD continue; } - if (pCtx[j].fpSet.process) { // TODO set the dummy function. + if (pCtx[j].fpSet.process) { // TODO set the dummy function. pCtx[j].fpSet.finalize(&pCtx[j]); } @@ -3507,11 +3636,47 @@ void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SD * 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); + // buf->numOfRows = (uint16_t)getNumOfResult(pCtx, numOfOutput); } } -static bool hasMainOutput(STaskAttr *pQueryAttr) { +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); + + struct SResultRowEntryInfo* pResInfo = pCtx[j].resultInfo; + if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) { + continue; + } + + if (pCtx[j].fpSet.process) { // TODO set the dummy function. + 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); + } +} + +static bool hasMainOutput(STaskAttr* pQueryAttr) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]); @@ -3523,19 +3688,19 @@ static bool hasMainOutput(STaskAttr *pQueryAttr) { return false; } -STableQueryInfo *createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow win) { - STableQueryInfo *pTableQueryInfo = buf; +STableQueryInfo* createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow win) { + STableQueryInfo* pTableQueryInfo = buf; pTableQueryInfo->lastKey = win.skey; // set more initial size of interval/groupby query -// if (/*QUERY_IS_INTERVAL_QUERY(pQueryAttr) || */groupbyColumn) { - int32_t initialSize = 128; - int32_t code = initResultRowInfo(&pTableQueryInfo->resInfo, initialSize); - if (code != TSDB_CODE_SUCCESS) { - return NULL; - } -// } else { // in other aggregate query, do not initialize the windowResInfo -// } + // if (/*QUERY_IS_INTERVAL_QUERY(pQueryAttr) || */groupbyColumn) { + int32_t initialSize = 128; + int32_t code = initResultRowInfo(&pTableQueryInfo->resInfo, initialSize); + if (code != TSDB_CODE_SUCCESS) { + return NULL; + } + // } else { // in other aggregate query, do not initialize the windowResInfo + // } return pTableQueryInfo; } @@ -3543,7 +3708,7 @@ STableQueryInfo *createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow STableQueryInfo* createTmpTableQueryInfo(STimeWindow win) { STableQueryInfo* pTableQueryInfo = taosMemoryCalloc(1, sizeof(STableQueryInfo)); -// pTableQueryInfo->win = win; + // pTableQueryInfo->win = win; pTableQueryInfo->lastKey = win.skey; // set more initial size of interval/groupby query @@ -3557,17 +3722,17 @@ STableQueryInfo* createTmpTableQueryInfo(STimeWindow win) { return pTableQueryInfo; } -void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo) { +void destroyTableQueryInfoImpl(STableQueryInfo* pTableQueryInfo) { if (pTableQueryInfo == NULL) { return; } -// taosVariantDestroy(&pTableQueryInfo->tag); + // taosVariantDestroy(&pTableQueryInfo->tag); cleanupResultRowInfo(&pTableQueryInfo->resInfo); } -void setResultRowOutputBufInitCtx(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SqlFunctionCtx* pCtx, - int32_t numOfOutput, int32_t* rowCellInfoOffset) { +void setResultRowOutputBufInitCtx(STaskRuntimeEnv* pRuntimeEnv, 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 SFilePage* bufPage = getBufPage(pRuntimeEnv->pResultBuf, pResult->pageId); @@ -3590,17 +3755,17 @@ void setResultRowOutputBufInitCtx(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pRes } if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) { - if(i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput; + if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i - 1].pOutput; } -// if (!pResInfo->initialized) { -// aAggs[functionId].init(&pCtx[i], pResInfo); -// } + // if (!pResInfo->initialized) { + // aAggs[functionId].init(&pCtx[i], pResInfo); + // } } } -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(SDiskbasedBuf* pBuf, 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); @@ -3608,13 +3773,18 @@ void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf * pBuf, SResultRow *pResult, 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; + } + + // int32_t functionId = pCtx[i].functionId; + // if (functionId < 0) { + // continue; + // } + // if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) { + // if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i - 1].pOutput; + // } if (!pResInfo->initialized && pCtx[i].functionId != -1) { pCtx[i].fpSet.init(&pCtx[i], pResInfo); @@ -3622,25 +3792,28 @@ void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf * pBuf, SResultRow *pResult, } } -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; SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo; SqlFunctionCtx* pCtx = pAggInfo->binfo.pCtx; - int32_t* rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset; + int32_t* rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset; SResultRow* pResultRow = - doSetResultOutBufByKey_rv(pAggInfo->pResultBuf, pResultRowInfo, tid, (char*)&tableGroupId, sizeof(tableGroupId), true, uid, pTaskInfo, false, &pAggInfo->aggSup); - assert (pResultRow != NULL); + doSetResultOutBufByKey_rv(pAggInfo->pResultBuf, pResultRowInfo, tid, (char*)&tableGroupId, sizeof(tableGroupId), + true, uid, pTaskInfo, false, &pAggInfo->aggSup); + assert(pResultRow != NULL); /* * not assign result buffer yet, add new result buffer * 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; } @@ -3649,7 +3822,8 @@ void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, i setResultRowOutputBufInitCtx_rv(pAggInfo->pResultBuf, pResultRow, pCtx, numOfOutput, rowCellInfoOffset); } -void setExecutionContext(int32_t numOfOutput, int32_t tableGroupId, TSKEY nextKey, SExecTaskInfo* pTaskInfo, STableQueryInfo *pTableQueryInfo, SAggOperatorInfo* pAggInfo) { +void setExecutionContext(int32_t numOfOutput, int32_t tableGroupId, TSKEY nextKey, SExecTaskInfo* pTaskInfo, + STableQueryInfo* pTableQueryInfo, SAggOperatorInfo* pAggInfo) { // lastKey needs to be updated pTableQueryInfo->lastKey = nextKey; if (pAggInfo->groupId != INT32_MIN && pAggInfo->groupId == tableGroupId) { @@ -3662,10 +3836,10 @@ 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) { +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); + SFilePage* page = getBufPage(pRuntimeEnv->pResultBuf, pResult->pageId); int16_t offset = 0; for (int32_t i = 0; i < numOfCols; ++i) { @@ -3673,8 +3847,9 @@ void setResultOutputBuf(STaskRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SqlFu 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; + if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF || + functionId == FUNCTION_DERIVATIVE) { + if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i - 1].pOutput; } /* @@ -3689,28 +3864,30 @@ void setCtxTagForJoin(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, SExprI STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; SExprBasicInfo* pExpr = &pExprInfo->base; -// if (pQueryAttr->stableQuery && (pRuntimeEnv->pTsBuf != NULL) && -// (pExpr->functionId == FUNCTION_TS || pExpr->functionId == FUNCTION_PRJ) && -// (pExpr->colInfo.colIndex == PRIMARYKEY_TIMESTAMP_COL_ID)) { -// assert(pExpr->numOfParams == 1); -// -// int16_t tagColId = (int16_t)pExprInfo->base.param[0].i; -// SColumnInfo* pColInfo = doGetTagColumnInfoById(pQueryAttr->tagColList, pQueryAttr->numOfTags, tagColId); -// -// doSetTagValueInParam(pTable, tagColId, &pCtx->tag, pColInfo->type, pColInfo->bytes); -// -// int16_t tagType = pCtx[0].tag.nType; -// if (tagType == TSDB_DATA_TYPE_BINARY || tagType == TSDB_DATA_TYPE_NCHAR) { -// //qDebug("QInfo:0x%"PRIx64" set tag value for join comparison, colId:%" PRId64 ", val:%s", GET_TASKID(pRuntimeEnv), -//// pExprInfo->base.param[0].i, pCtx[0].tag.pz); -// } else { -// //qDebug("QInfo:0x%"PRIx64" set tag value for join comparison, colId:%" PRId64 ", val:%" PRId64, GET_TASKID(pRuntimeEnv), -//// pExprInfo->base.param[0].i, pCtx[0].tag.i); -// } -// } + // if (pQueryAttr->stableQuery && (pRuntimeEnv->pTsBuf != NULL) && + // (pExpr->functionId == FUNCTION_TS || pExpr->functionId == FUNCTION_PRJ) && + // (pExpr->colInfo.colIndex == PRIMARYKEY_TIMESTAMP_COL_ID)) { + // assert(pExpr->numOfParams == 1); + // + // int16_t tagColId = (int16_t)pExprInfo->base.param[0].i; + // SColumnInfo* pColInfo = doGetTagColumnInfoById(pQueryAttr->tagColList, pQueryAttr->numOfTags, tagColId); + // + // doSetTagValueInParam(pTable, tagColId, &pCtx->tag, pColInfo->type, pColInfo->bytes); + // + // int16_t tagType = pCtx[0].tag.nType; + // if (tagType == TSDB_DATA_TYPE_BINARY || tagType == TSDB_DATA_TYPE_NCHAR) { + // //qDebug("QInfo:0x%"PRIx64" set tag value for join comparison, colId:%" PRId64 ", val:%s", + // GET_TASKID(pRuntimeEnv), + //// pExprInfo->base.param[0].i, pCtx[0].tag.pz); + // } else { + // //qDebug("QInfo:0x%"PRIx64" set tag value for join comparison, colId:%" PRId64 ", val:%" PRId64, + // GET_TASKID(pRuntimeEnv), + //// pExprInfo->base.param[0].i, pCtx[0].tag.i); + // } + // } } -int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, STableQueryInfo *pTableQueryInfo) { +int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, STableQueryInfo* pTableQueryInfo) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; assert(pRuntimeEnv->pTsBuf != NULL); @@ -3753,7 +3930,8 @@ int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, S } // TODO refactor: this funciton should be merged with setparamForStableStddevColumnData function. -void setParamForStableStddev(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, SExprInfo* pExprInfo) { +void setParamForStableStddev(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, + SExprInfo* pExprInfo) { #if 0 STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; @@ -3788,7 +3966,8 @@ void setParamForStableStddev(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, #endif } -void setParamForStableStddevByColData(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, SExprInfo* pExpr, char* val, int16_t bytes) { +void setParamForStableStddevByColData(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, + SExprInfo* pExpr, char* val, int16_t bytes) { STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; #if 0 int32_t numOfExprs = pQueryAttr->numOfOutput; @@ -3823,22 +4002,22 @@ void setParamForStableStddevByColData(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionC /* * There are two cases to handle: * - * 1. Query range is not set yet (queryRangeSet = 0). we need to set the query range info, including pQueryAttr->lastKey, - * pQueryAttr->window.skey, and pQueryAttr->eKey. + * 1. Query range is not set yet (queryRangeSet = 0). we need to set the query range info, including + * pQueryAttr->lastKey, pQueryAttr->window.skey, and pQueryAttr->eKey. * 2. Query range is set and query is in progress. There may be another result with the same query ranges to be * merged during merge stage. In this case, we need the pTableQueryInfo->lastResRows to decide if there * is a previous result generated or not. */ -void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) { - STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; - STableQueryInfo *pTableQueryInfo = pRuntimeEnv->current; - SResultRowInfo *pResultRowInfo = &pTableQueryInfo->resInfo; +void setIntervalQueryRange(STaskRuntimeEnv* pRuntimeEnv, TSKEY key) { + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; + SResultRowInfo* pResultRowInfo = &pTableQueryInfo->resInfo; if (pResultRowInfo->curPos != -1) { return; } -// pTableQueryInfo->win.skey = key; + // pTableQueryInfo->win.skey = key; STimeWindow win = {.skey = key, .ekey = pQueryAttr->window.ekey}; /** @@ -3851,17 +4030,17 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) { TSKEY sk = TMIN(win.skey, win.ekey); TSKEY ek = TMAX(win.skey, win.ekey); -// getAlignQueryTimeWindow(pQueryAttr, win.skey, sk, ek, &w); + // getAlignQueryTimeWindow(pQueryAttr, win.skey, sk, ek, &w); -// if (pResultRowInfo->prevSKey == TSKEY_INITIAL_VAL) { -// if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { -// assert(win.ekey == pQueryAttr->window.ekey); -// } -// -// pResultRowInfo->prevSKey = w.skey; -// } + // if (pResultRowInfo->prevSKey == TSKEY_INITIAL_VAL) { + // if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { + // assert(win.ekey == pQueryAttr->window.ekey); + // } + // + // pResultRowInfo->prevSKey = w.skey; + // } -// pTableQueryInfo->lastKey = pTableQueryInfo->win.skey; + // pTableQueryInfo->lastKey = pTableQueryInfo->win.skey; } /** @@ -3873,14 +4052,15 @@ void setIntervalQueryRange(STaskRuntimeEnv *pRuntimeEnv, TSKEY key) { * @param pQInfo * @param result */ -static int32_t doCopyToSDataBlock(SDiskbasedBuf *pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset) { +static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, + SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset) { int32_t numOfRows = getNumOfTotalRes(pGroupResInfo); - int32_t numOfResult = pBlock->info.rows; // there are already exists result rows + int32_t numOfResult = pBlock->info.rows; // there are already exists result rows int32_t start = 0; int32_t step = -1; - //qDebug("QInfo:0x%"PRIx64" start to copy data from windowResInfo to output buf", GET_TASKID(pRuntimeEnv)); + // qDebug("QInfo:0x%"PRIx64" start to copy data from windowResInfo to output buf", GET_TASKID(pRuntimeEnv)); assert(orderType == TSDB_ORDER_ASC || orderType == TSDB_ORDER_DESC); if (orderType == TSDB_ORDER_ASC) { @@ -3895,7 +4075,7 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf *pBuf, SGroupResInfo* pGroupResI for (int32_t i = start; (i < numOfRows) && (i >= 0); i += step) { SResultRowPosition* pPos = taosArrayGet(pGroupResInfo->pRows, i); - SFilePage *page = getBufPage(pBuf, pPos->pageId); + SFilePage* page = getBufPage(pBuf, pPos->pageId); SResultRow* pRow = (SResultRow*)((char*)page + pPos->offset); if (pRow->numOfRows == 0) { @@ -3905,14 +4085,14 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf *pBuf, SGroupResInfo* pGroupResI // TODO copy multiple rows? int32_t numOfRowsToCopy = pRow->numOfRows; - if (numOfResult + numOfRowsToCopy >= rowCapacity) { + if (numOfResult + numOfRowsToCopy >= rowCapacity) { break; } pGroupResInfo->index += 1; for (int32_t j = 0; j < pBlock->info.numOfCols; ++j) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, j); + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, j); SResultRowEntryInfo* pEntryInfo = getResultCell(pRow, j, rowCellOffset); char* in = GET_ROWCELL_INTERBUF(pEntryInfo); @@ -3928,12 +4108,13 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf *pBuf, SGroupResInfo* pGroupResI } } - //qDebug("QInfo:0x%"PRIx64" copy data to query buf completed", GET_TASKID(pRuntimeEnv)); + // qDebug("QInfo:0x%"PRIx64" copy data to query buf completed", GET_TASKID(pRuntimeEnv)); pBlock->info.rows = numOfResult; return 0; } -static void toSDatablock(SGroupResInfo *pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset) { +static void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, + int32_t* rowCellOffset) { assert(pGroupResInfo->currentGroup <= pGroupResInfo->totalGroup); blockDataCleanup(pBlock); @@ -3941,22 +4122,22 @@ 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 blockDataUpdateTsWindow(pBlock); } -static void updateNumOfRowsInResultRows(SqlFunctionCtx* pCtx, int32_t numOfOutput, - SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset) { +static void updateNumOfRowsInResultRows(SqlFunctionCtx* pCtx, int32_t numOfOutput, SResultRowInfo* pResultRowInfo, + int32_t* rowCellInfoOffset) { // update the number of result for each, only update the number of rows for the corresponding window result. -// if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) { -// return; -// } + // if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) { + // return; + // } for (int32_t i = 0; i < pResultRowInfo->size; ++i) { - SResultRow *pResult = pResultRowInfo->pResult[i]; + SResultRow* pResult = pResultRowInfo->pResult[i]; for (int32_t j = 0; j < numOfOutput; ++j) { int32_t functionId = pCtx[j].functionId; @@ -3970,17 +4151,17 @@ static void updateNumOfRowsInResultRows(SqlFunctionCtx* pCtx, int32_t numOfOutpu } } -static int32_t compressQueryColData(SColumnInfoData *pColRes, int32_t numOfRows, char *data, int8_t compressed) { +static int32_t compressQueryColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, int8_t compressed) { int32_t colSize = pColRes->info.bytes * numOfRows; return (*(tDataTypes[pColRes->info.type].compFunc))(pColRes->pData, colSize, numOfRows, data, - colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0); + colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0); } -int32_t doFillTimeIntervalGapsInResults(struct SFillInfo* pFillInfo, SSDataBlock *pOutput, int32_t capacity, void** p) { -// for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) { -// SColumnInfoData* pColInfoData = taosArrayGet(pOutput->pDataBlock, i); -// p[i] = pColInfoData->pData + (pColInfoData->info.bytes * pOutput->info.rows); -// } +int32_t doFillTimeIntervalGapsInResults(struct SFillInfo* pFillInfo, SSDataBlock* pOutput, int32_t capacity, void** p) { + // for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) { + // SColumnInfoData* pColInfoData = taosArrayGet(pOutput->pDataBlock, i); + // p[i] = pColInfoData->pData + (pColInfoData->info.bytes * pOutput->info.rows); + // } int32_t numOfRows = (int32_t)taosFillResultDataBlock(pFillInfo, p, capacity - pOutput->info.rows); pOutput->info.rows += numOfRows; @@ -3991,19 +4172,19 @@ int32_t doFillTimeIntervalGapsInResults(struct SFillInfo* pFillInfo, SSDataBlock void publishOperatorProfEvent(SOperatorInfo* operatorInfo, EQueryProfEventType eventType) { SQueryProfEvent event = {0}; - event.eventType = eventType; - event.eventTime = taosGetTimestampUs(); + event.eventType = eventType; + event.eventTime = taosGetTimestampUs(); event.operatorType = operatorInfo->operatorType; if (operatorInfo->pRuntimeEnv) { -// SQInfo* pQInfo = operatorInfo->pRuntimeEnv->qinfo; -// if (pQInfo->summary.queryProfEvents) { -// taosArrayPush(pQInfo->summary.queryProfEvents, &event); -// } + // SQInfo* pQInfo = operatorInfo->pRuntimeEnv->qinfo; + // if (pQInfo->summary.queryProfEvents) { + // taosArrayPush(pQInfo->summary.queryProfEvents, &event); + // } } } -void publishQueryAbortEvent(SExecTaskInfo * pTaskInfo, int32_t code) { +void publishQueryAbortEvent(SExecTaskInfo* pTaskInfo, int32_t code) { SQueryProfEvent event; event.eventType = QUERY_PROF_QUERY_ABORT; event.eventTime = taosGetTimestampUs(); @@ -4014,7 +4195,7 @@ void publishQueryAbortEvent(SExecTaskInfo * pTaskInfo, int32_t code) { } } -typedef struct { +typedef struct { uint8_t operatorType; int64_t beginTime; int64_t endTime; @@ -4022,7 +4203,8 @@ typedef struct { int64_t descendantsTime; } SOperatorStackItem; -static void doOperatorExecProfOnce(SOperatorStackItem* item, SQueryProfEvent* event, SArray* opStack, SHashObj* profResults) { +static void doOperatorExecProfOnce(SOperatorStackItem* item, SQueryProfEvent* event, SArray* opStack, + SHashObj* profResults) { item->endTime = event->eventTime; item->selfTime = (item->endTime - item->beginTime) - (item->descendantsTime); @@ -4031,7 +4213,7 @@ static void doOperatorExecProfOnce(SOperatorStackItem* item, SQueryProfEvent* ev ancestor->descendantsTime += item->selfTime; } - uint8_t operatorType = item->operatorType; + uint8_t operatorType = item->operatorType; SOperatorProfResult* result = taosHashGet(profResults, &operatorType, sizeof(operatorType)); if (result != NULL) { result->sumRunTimes++; @@ -4041,19 +4223,18 @@ static void doOperatorExecProfOnce(SOperatorStackItem* item, SQueryProfEvent* ev opResult.operatorType = operatorType; opResult.sumSelfTime = item->selfTime; opResult.sumRunTimes = 1; - taosHashPut(profResults, &(operatorType), sizeof(operatorType), - &opResult, sizeof(opResult)); + taosHashPut(profResults, &(operatorType), sizeof(operatorType), &opResult, sizeof(opResult)); } } void calculateOperatorProfResults(SQInfo* pQInfo) { if (pQInfo->summary.queryProfEvents == NULL) { - //qDebug("QInfo:0x%"PRIx64" query prof events array is null", pQInfo->qId); + // qDebug("QInfo:0x%"PRIx64" query prof events array is null", pQInfo->qId); return; } if (pQInfo->summary.operatorProfResults == NULL) { - //qDebug("QInfo:0x%"PRIx64" operator prof results hash is null", pQInfo->qId); + // qDebug("QInfo:0x%"PRIx64" operator prof results hash is null", pQInfo->qId); return; } @@ -4062,7 +4243,7 @@ void calculateOperatorProfResults(SQInfo* pQInfo) { return; } - size_t size = taosArrayGetSize(pQInfo->summary.queryProfEvents); + size_t size = taosArrayGetSize(pQInfo->summary.queryProfEvents); SHashObj* profResults = pQInfo->summary.operatorProfResults; for (int i = 0; i < size; ++i) { @@ -4088,280 +4269,287 @@ void calculateOperatorProfResults(SQInfo* pQInfo) { taosArrayDestroy(opStack); } -void queryCostStatis(SExecTaskInfo *pTaskInfo) { - STaskCostInfo *pSummary = &pTaskInfo->cost; +void queryCostStatis(SExecTaskInfo* pTaskInfo) { + STaskCostInfo* pSummary = &pTaskInfo->cost; -// uint64_t hashSize = taosHashGetMemSize(pQInfo->runtimeEnv.pResultRowHashTable); -// hashSize += taosHashGetMemSize(pRuntimeEnv->tableqinfoGroupInfo.map); -// pSummary->hashSize = hashSize; + // uint64_t hashSize = taosHashGetMemSize(pQInfo->runtimeEnv.pResultRowHashTable); + // hashSize += taosHashGetMemSize(pRuntimeEnv->tableqinfoGroupInfo.map); + // pSummary->hashSize = hashSize; // add the merge time pSummary->elapsedTime += pSummary->firstStageMergeTime; -// SResultRowPool* p = pTaskInfo->pool; -// if (p != NULL) { -// pSummary->winInfoSize = getResultRowPoolMemSize(p); -// pSummary->numOfTimeWindows = getNumOfAllocatedResultRows(p); -// } else { -// pSummary->winInfoSize = 0; -// pSummary->numOfTimeWindows = 0; -// } -// -// calculateOperatorProfResults(pQInfo); + // SResultRowPool* p = pTaskInfo->pool; + // if (p != NULL) { + // pSummary->winInfoSize = getResultRowPoolMemSize(p); + // pSummary->numOfTimeWindows = getNumOfAllocatedResultRows(p); + // } else { + // pSummary->winInfoSize = 0; + // pSummary->numOfTimeWindows = 0; + // } + // + // calculateOperatorProfResults(pQInfo); - qDebug("%s :cost summary: elapsed time:%"PRId64" us, first merge:%"PRId64" us, total blocks:%d, " - "load block statis:%d, load data block:%d, total rows:%"PRId64 ", check rows:%"PRId64, - GET_TASKID(pTaskInfo), pSummary->elapsedTime, pSummary->firstStageMergeTime, pSummary->totalBlocks, pSummary->loadBlockStatis, - pSummary->loadBlocks, pSummary->totalRows, pSummary->totalCheckedRows); -// - //qDebug("QInfo:0x%"PRIx64" :cost summary: winResPool size:%.2f Kb, numOfWin:%"PRId64", tableInfoSize:%.2f Kb, hashTable:%.2f Kb", pQInfo->qId, pSummary->winInfoSize/1024.0, -// pSummary->numOfTimeWindows, pSummary->tableInfoSize/1024.0, pSummary->hashSize/1024.0); + qDebug("%s :cost summary: elapsed time:%" PRId64 " us, first merge:%" PRId64 + " us, total blocks:%d, " + "load block statis:%d, load data block:%d, total rows:%" PRId64 ", check rows:%" PRId64, + GET_TASKID(pTaskInfo), pSummary->elapsedTime, pSummary->firstStageMergeTime, pSummary->totalBlocks, + pSummary->loadBlockStatis, pSummary->loadBlocks, pSummary->totalRows, pSummary->totalCheckedRows); + // + // qDebug("QInfo:0x%"PRIx64" :cost summary: winResPool size:%.2f Kb, numOfWin:%"PRId64", tableInfoSize:%.2f Kb, + // hashTable:%.2f Kb", pQInfo->qId, pSummary->winInfoSize/1024.0, + // pSummary->numOfTimeWindows, pSummary->tableInfoSize/1024.0, pSummary->hashSize/1024.0); if (pSummary->operatorProfResults) { SOperatorProfResult* opRes = taosHashIterate(pSummary->operatorProfResults, NULL); while (opRes != NULL) { - //qDebug("QInfo:0x%" PRIx64 " :cost summary: operator : %d, exec times: %" PRId64 ", self time: %" PRId64, -// pQInfo->qId, opRes->operatorType, opRes->sumRunTimes, opRes->sumSelfTime); + // qDebug("QInfo:0x%" PRIx64 " :cost summary: operator : %d, exec times: %" PRId64 ", self time: %" PRId64, + // pQInfo->qId, opRes->operatorType, opRes->sumRunTimes, opRes->sumSelfTime); opRes = taosHashIterate(pSummary->operatorProfResults, opRes); } } } -//static void updateOffsetVal(STaskRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) { -// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; -// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; +// static void updateOffsetVal(STaskRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) { +// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; +// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; // -// int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); +// int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); // -// if (pQueryAttr->limit.offset == pBlockInfo->rows) { // current block will ignore completed -// pTableQueryInfo->lastKey = QUERY_IS_ASC_QUERY(pQueryAttr) ? pBlockInfo->window.ekey + step : pBlockInfo->window.skey + step; -// pQueryAttr->limit.offset = 0; -// return; -// } +// if (pQueryAttr->limit.offset == pBlockInfo->rows) { // current block will ignore completed +// pTableQueryInfo->lastKey = QUERY_IS_ASC_QUERY(pQueryAttr) ? pBlockInfo->window.ekey + step : +// pBlockInfo->window.skey + step; pQueryAttr->limit.offset = 0; return; +// } // -// if (QUERY_IS_ASC_QUERY(pQueryAttr)) { -// pQueryAttr->pos = (int32_t)pQueryAttr->limit.offset; -// } else { -// pQueryAttr->pos = pBlockInfo->rows - (int32_t)pQueryAttr->limit.offset - 1; -// } +// if (QUERY_IS_ASC_QUERY(pQueryAttr)) { +// pQueryAttr->pos = (int32_t)pQueryAttr->limit.offset; +// } else { +// pQueryAttr->pos = pBlockInfo->rows - (int32_t)pQueryAttr->limit.offset - 1; +// } // -// assert(pQueryAttr->pos >= 0 && pQueryAttr->pos <= pBlockInfo->rows - 1); +// assert(pQueryAttr->pos >= 0 && pQueryAttr->pos <= pBlockInfo->rows - 1); // -// SArray * pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pTsdbReadHandle, NULL); -// SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock, 0); +// SArray * pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pTsdbReadHandle, NULL); +// SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock, 0); // -// // update the pQueryAttr->limit.offset value, and pQueryAttr->pos value -// TSKEY *keys = (TSKEY *) pColInfoData->pData; +// // update the pQueryAttr->limit.offset value, and pQueryAttr->pos value +// TSKEY *keys = (TSKEY *) pColInfoData->pData; // -// // update the offset value -// pTableQueryInfo->lastKey = keys[pQueryAttr->pos]; -// pQueryAttr->limit.offset = 0; +// // update the offset value +// pTableQueryInfo->lastKey = keys[pQueryAttr->pos]; +// pQueryAttr->limit.offset = 0; // -// int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, NULL, binarySearchForKey, pDataBlock); +// int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, NULL, binarySearchForKey, pDataBlock); // -// //qDebug("QInfo:0x%"PRIx64" check data block, brange:%" PRId64 "-%" PRId64 ", numBlocksOfStep:%d, numOfRes:%d, lastKey:%"PRId64, GET_TASKID(pRuntimeEnv), -// pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows, numOfRes, pQuery->current->lastKey); -//} +// //qDebug("QInfo:0x%"PRIx64" check data block, brange:%" PRId64 "-%" PRId64 ", numBlocksOfStep:%d, numOfRes:%d, +// lastKey:%"PRId64, GET_TASKID(pRuntimeEnv), +// pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows, numOfRes, pQuery->current->lastKey); +// } -//void skipBlocks(STaskRuntimeEnv *pRuntimeEnv) { -// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; +// void skipBlocks(STaskRuntimeEnv *pRuntimeEnv) { +// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; // -// if (pQueryAttr->limit.offset <= 0 || pQueryAttr->numOfFilterCols > 0) { -// return; -// } +// if (pQueryAttr->limit.offset <= 0 || pQueryAttr->numOfFilterCols > 0) { +// return; +// } // -// pQueryAttr->pos = 0; -// int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); +// pQueryAttr->pos = 0; +// int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); // -// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; -// TsdbQueryHandleT pTsdbReadHandle = pRuntimeEnv->pTsdbReadHandle; +// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; +// TsdbQueryHandleT pTsdbReadHandle = pRuntimeEnv->pTsdbReadHandle; // -// SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER; -// while (tsdbNextDataBlock(pTsdbReadHandle)) { -// if (isTaskKilled(pRuntimeEnv->qinfo)) { -// longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); -// } +// SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER; +// while (tsdbNextDataBlock(pTsdbReadHandle)) { +// if (isTaskKilled(pRuntimeEnv->qinfo)) { +// longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); +// } // -// tsdbRetrieveDataBlockInfo(pTsdbReadHandle, &blockInfo); +// tsdbRetrieveDataBlockInfo(pTsdbReadHandle, &blockInfo); // -// if (pQueryAttr->limit.offset > blockInfo.rows) { -// pQueryAttr->limit.offset -= blockInfo.rows; -// pTableQueryInfo->lastKey = (QUERY_IS_ASC_QUERY(pQueryAttr)) ? blockInfo.window.ekey : blockInfo.window.skey; -// pTableQueryInfo->lastKey += step; +// if (pQueryAttr->limit.offset > blockInfo.rows) { +// pQueryAttr->limit.offset -= blockInfo.rows; +// pTableQueryInfo->lastKey = (QUERY_IS_ASC_QUERY(pQueryAttr)) ? blockInfo.window.ekey : blockInfo.window.skey; +// pTableQueryInfo->lastKey += step; // -// //qDebug("QInfo:0x%"PRIx64" skip rows:%d, offset:%" PRId64, GET_TASKID(pRuntimeEnv), blockInfo.rows, -// pQuery->limit.offset); -// } else { // find the appropriated start position in current block -// updateOffsetVal(pRuntimeEnv, &blockInfo); -// break; -// } -// } +// //qDebug("QInfo:0x%"PRIx64" skip rows:%d, offset:%" PRId64, GET_TASKID(pRuntimeEnv), blockInfo.rows, +// pQuery->limit.offset); +// } else { // find the appropriated start position in current block +// updateOffsetVal(pRuntimeEnv, &blockInfo); +// break; +// } +// } // -// if (terrno != TSDB_CODE_SUCCESS) { -// longjmp(pRuntimeEnv->env, terrno); -// } -//} +// if (terrno != TSDB_CODE_SUCCESS) { +// longjmp(pRuntimeEnv->env, terrno); +// } +// } -//static TSKEY doSkipIntervalProcess(STaskRuntimeEnv* pRuntimeEnv, STimeWindow* win, SDataBlockInfo* pBlockInfo, STableQueryInfo* pTableQueryInfo) { -// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; -// SResultRowInfo *pWindowResInfo = &pRuntimeEnv->resultRowInfo; +// static TSKEY doSkipIntervalProcess(STaskRuntimeEnv* pRuntimeEnv, STimeWindow* win, SDataBlockInfo* pBlockInfo, +// STableQueryInfo* pTableQueryInfo) { +// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; +// SResultRowInfo *pWindowResInfo = &pRuntimeEnv->resultRowInfo; // -// assert(pQueryAttr->limit.offset == 0); -// STimeWindow tw = *win; -// getNextTimeWindow(pQueryAttr, &tw); +// assert(pQueryAttr->limit.offset == 0); +// STimeWindow tw = *win; +// getNextTimeWindow(pQueryAttr, &tw); // -// if ((tw.skey <= pBlockInfo->window.ekey && QUERY_IS_ASC_QUERY(pQueryAttr)) || -// (tw.ekey >= pBlockInfo->window.skey && !QUERY_IS_ASC_QUERY(pQueryAttr))) { +// if ((tw.skey <= pBlockInfo->window.ekey && QUERY_IS_ASC_QUERY(pQueryAttr)) || +// (tw.ekey >= pBlockInfo->window.skey && !QUERY_IS_ASC_QUERY(pQueryAttr))) { // -// // load the data block and check data remaining in current data block -// // TODO optimize performance -// SArray * pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pTsdbReadHandle, NULL); -// SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock, 0); +// // load the data block and check data remaining in current data block +// // TODO optimize performance +// SArray * pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pTsdbReadHandle, NULL); +// SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock, 0); // -// tw = *win; -// int32_t startPos = -// getNextQualifiedWindow(pQueryAttr, &tw, pBlockInfo, pColInfoData->pData, binarySearchForKey, -1); -// assert(startPos >= 0); +// tw = *win; +// int32_t startPos = +// getNextQualifiedWindow(pQueryAttr, &tw, pBlockInfo, pColInfoData->pData, binarySearchForKey, -1); +// assert(startPos >= 0); // -// // set the abort info -// pQueryAttr->pos = startPos; +// // set the abort info +// pQueryAttr->pos = startPos; // -// // reset the query start timestamp -// pTableQueryInfo->win.skey = ((TSKEY *)pColInfoData->pData)[startPos]; -// pQueryAttr->window.skey = pTableQueryInfo->win.skey; -// TSKEY key = pTableQueryInfo->win.skey; +// // reset the query start timestamp +// pTableQueryInfo->win.skey = ((TSKEY *)pColInfoData->pData)[startPos]; +// pQueryAttr->window.skey = pTableQueryInfo->win.skey; +// TSKEY key = pTableQueryInfo->win.skey; // -// pWindowResInfo->prevSKey = tw.skey; -// int32_t index = pRuntimeEnv->resultRowInfo.curIndex; +// pWindowResInfo->prevSKey = tw.skey; +// int32_t index = pRuntimeEnv->resultRowInfo.curIndex; // -// int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, NULL, binarySearchForKey, pDataBlock); -// pRuntimeEnv->resultRowInfo.curIndex = index; // restore the window index +// int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, NULL, binarySearchForKey, pDataBlock); +// pRuntimeEnv->resultRowInfo.curIndex = index; // restore the window index // -// //qDebug("QInfo:0x%"PRIx64" check data block, brange:%" PRId64 "-%" PRId64 ", numOfRows:%d, numOfRes:%d, lastKey:%" PRId64, -// GET_TASKID(pRuntimeEnv), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows, numOfRes, -// pQueryAttr->current->lastKey); +// //qDebug("QInfo:0x%"PRIx64" check data block, brange:%" PRId64 "-%" PRId64 ", numOfRows:%d, numOfRes:%d, +// lastKey:%" PRId64, +// GET_TASKID(pRuntimeEnv), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows, numOfRes, +// pQueryAttr->current->lastKey); // -// return key; -// } else { // do nothing -// pQueryAttr->window.skey = tw.skey; -// pWindowResInfo->prevSKey = tw.skey; -// pTableQueryInfo->lastKey = tw.skey; +// return key; +// } else { // do nothing +// pQueryAttr->window.skey = tw.skey; +// pWindowResInfo->prevSKey = tw.skey; +// pTableQueryInfo->lastKey = tw.skey; // -// return tw.skey; -// } +// return tw.skey; +// } // -// return true; -//} +// return true; +// } -//static bool skipTimeInterval(STaskRuntimeEnv *pRuntimeEnv, TSKEY* start) { -// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; -// if (QUERY_IS_ASC_QUERY(pQueryAttr)) { -// assert(*start <= pRuntimeEnv->current->lastKey); -// } else { -// assert(*start >= pRuntimeEnv->current->lastKey); -// } +// static bool skipTimeInterval(STaskRuntimeEnv *pRuntimeEnv, TSKEY* start) { +// STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; +// if (QUERY_IS_ASC_QUERY(pQueryAttr)) { +// assert(*start <= pRuntimeEnv->current->lastKey); +// } else { +// assert(*start >= pRuntimeEnv->current->lastKey); +// } // -// // if queried with value filter, do NOT forward query start position -// if (pQueryAttr->limit.offset <= 0 || pQueryAttr->numOfFilterCols > 0 || pRuntimeEnv->pTsBuf != NULL || pRuntimeEnv->pFillInfo != NULL) { -// return true; -// } +// // if queried with value filter, do NOT forward query start position +// if (pQueryAttr->limit.offset <= 0 || pQueryAttr->numOfFilterCols > 0 || pRuntimeEnv->pTsBuf != NULL || +// pRuntimeEnv->pFillInfo != NULL) { +// return true; +// } // -// /* -// * 1. for interval without interpolation query we forward pQueryAttr->interval.interval at a time for -// * pQueryAttr->limit.offset times. Since hole exists, pQueryAttr->interval.interval*pQueryAttr->limit.offset value is -// * not valid. otherwise, we only forward pQueryAttr->limit.offset number of points -// */ -// assert(pRuntimeEnv->resultRowInfo.prevSKey == TSKEY_INITIAL_VAL); +// /* +// * 1. for interval without interpolation query we forward pQueryAttr->interval.interval at a time for +// * pQueryAttr->limit.offset times. Since hole exists, pQueryAttr->interval.interval*pQueryAttr->limit.offset +// value is +// * not valid. otherwise, we only forward pQueryAttr->limit.offset number of points +// */ +// assert(pRuntimeEnv->resultRowInfo.prevSKey == TSKEY_INITIAL_VAL); // -// STimeWindow w = TSWINDOW_INITIALIZER; -// bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); +// STimeWindow w = TSWINDOW_INITIALIZER; +// bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); // -// SResultRowInfo *pWindowResInfo = &pRuntimeEnv->resultRowInfo; -// STableQueryInfo *pTableQueryInfo = pRuntimeEnv->current; +// SResultRowInfo *pWindowResInfo = &pRuntimeEnv->resultRowInfo; +// STableQueryInfo *pTableQueryInfo = pRuntimeEnv->current; // -// SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER; -// while (tsdbNextDataBlock(pRuntimeEnv->pTsdbReadHandle)) { -// tsdbRetrieveDataBlockInfo(pRuntimeEnv->pTsdbReadHandle, &blockInfo); +// SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER; +// while (tsdbNextDataBlock(pRuntimeEnv->pTsdbReadHandle)) { +// tsdbRetrieveDataBlockInfo(pRuntimeEnv->pTsdbReadHandle, &blockInfo); // -// if (QUERY_IS_ASC_QUERY(pQueryAttr)) { -// if (pWindowResInfo->prevSKey == TSKEY_INITIAL_VAL) { -// getAlignQueryTimeWindow(pQueryAttr, blockInfo.window.skey, blockInfo.window.skey, pQueryAttr->window.ekey, &w); -// pWindowResInfo->prevSKey = w.skey; -// } -// } else { -// getAlignQueryTimeWindow(pQueryAttr, blockInfo.window.ekey, pQueryAttr->window.ekey, blockInfo.window.ekey, &w); -// pWindowResInfo->prevSKey = w.skey; -// } +// if (QUERY_IS_ASC_QUERY(pQueryAttr)) { +// if (pWindowResInfo->prevSKey == TSKEY_INITIAL_VAL) { +// getAlignQueryTimeWindow(pQueryAttr, blockInfo.window.skey, blockInfo.window.skey, pQueryAttr->window.ekey, +// &w); pWindowResInfo->prevSKey = w.skey; +// } +// } else { +// getAlignQueryTimeWindow(pQueryAttr, blockInfo.window.ekey, pQueryAttr->window.ekey, blockInfo.window.ekey, &w); +// pWindowResInfo->prevSKey = w.skey; +// } // -// // the first time window -// STimeWindow win = getActiveTimeWindow(pWindowResInfo, pWindowResInfo->prevSKey, pQueryAttr); +// // the first time window +// STimeWindow win = getActiveTimeWindow(pWindowResInfo, pWindowResInfo->prevSKey, pQueryAttr); // -// while (pQueryAttr->limit.offset > 0) { -// STimeWindow tw = win; +// while (pQueryAttr->limit.offset > 0) { +// STimeWindow tw = win; // -// if ((win.ekey <= blockInfo.window.ekey && ascQuery) || (win.ekey >= blockInfo.window.skey && !ascQuery)) { -// pQueryAttr->limit.offset -= 1; -// pWindowResInfo->prevSKey = win.skey; +// if ((win.ekey <= blockInfo.window.ekey && ascQuery) || (win.ekey >= blockInfo.window.skey && !ascQuery)) { +// pQueryAttr->limit.offset -= 1; +// pWindowResInfo->prevSKey = win.skey; // -// // current time window is aligned with blockInfo.window.ekey -// // restart it from next data block by set prevSKey to be TSKEY_INITIAL_VAL; -// if ((win.ekey == blockInfo.window.ekey && ascQuery) || (win.ekey == blockInfo.window.skey && !ascQuery)) { -// pWindowResInfo->prevSKey = TSKEY_INITIAL_VAL; -// } -// } +// // current time window is aligned with blockInfo.window.ekey +// // restart it from next data block by set prevSKey to be TSKEY_INITIAL_VAL; +// if ((win.ekey == blockInfo.window.ekey && ascQuery) || (win.ekey == blockInfo.window.skey && !ascQuery)) { +// pWindowResInfo->prevSKey = TSKEY_INITIAL_VAL; +// } +// } // -// if (pQueryAttr->limit.offset == 0) { -// *start = doSkipIntervalProcess(pRuntimeEnv, &win, &blockInfo, pTableQueryInfo); -// return true; -// } +// if (pQueryAttr->limit.offset == 0) { +// *start = doSkipIntervalProcess(pRuntimeEnv, &win, &blockInfo, pTableQueryInfo); +// return true; +// } // -// // current window does not ended in current data block, try next data block -// getNextTimeWindow(pQueryAttr, &tw); +// // current window does not ended in current data block, try next data block +// getNextTimeWindow(pQueryAttr, &tw); // -// /* -// * If the next time window still starts from current data block, -// * load the primary timestamp column first, and then find the start position for the next queried time window. -// * Note that only the primary timestamp column is required. -// * TODO: Optimize for this cases. All data blocks are not needed to be loaded, only if the first actually required -// * time window resides in current data block. -// */ -// if ((tw.skey <= blockInfo.window.ekey && ascQuery) || (tw.ekey >= blockInfo.window.skey && !ascQuery)) { +// /* +// * If the next time window still starts from current data block, +// * load the primary timestamp column first, and then find the start position for the next queried time window. +// * Note that only the primary timestamp column is required. +// * TODO: Optimize for this cases. All data blocks are not needed to be loaded, only if the first actually +// required +// * time window resides in current data block. +// */ +// if ((tw.skey <= blockInfo.window.ekey && ascQuery) || (tw.ekey >= blockInfo.window.skey && !ascQuery)) { // -// SArray *pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pTsdbReadHandle, NULL); -// SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock, 0); +// SArray *pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pTsdbReadHandle, NULL); +// SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock, 0); // -// if ((win.ekey > blockInfo.window.ekey && ascQuery) || (win.ekey < blockInfo.window.skey && !ascQuery)) { -// pQueryAttr->limit.offset -= 1; -// } +// if ((win.ekey > blockInfo.window.ekey && ascQuery) || (win.ekey < blockInfo.window.skey && !ascQuery)) { +// pQueryAttr->limit.offset -= 1; +// } // -// if (pQueryAttr->limit.offset == 0) { -// *start = doSkipIntervalProcess(pRuntimeEnv, &win, &blockInfo, pTableQueryInfo); -// return true; -// } else { -// tw = win; -// int32_t startPos = -// getNextQualifiedWindow(pQueryAttr, &tw, &blockInfo, pColInfoData->pData, binarySearchForKey, -1); -// assert(startPos >= 0); +// if (pQueryAttr->limit.offset == 0) { +// *start = doSkipIntervalProcess(pRuntimeEnv, &win, &blockInfo, pTableQueryInfo); +// return true; +// } else { +// tw = win; +// int32_t startPos = +// getNextQualifiedWindow(pQueryAttr, &tw, &blockInfo, pColInfoData->pData, binarySearchForKey, -1); +// assert(startPos >= 0); // -// // set the abort info -// pQueryAttr->pos = startPos; -// pTableQueryInfo->lastKey = ((TSKEY *)pColInfoData->pData)[startPos]; -// pWindowResInfo->prevSKey = tw.skey; -// win = tw; -// } -// } else { -// break; // offset is not 0, and next time window begins or ends in the next block. -// } -// } -// } +// // set the abort info +// pQueryAttr->pos = startPos; +// pTableQueryInfo->lastKey = ((TSKEY *)pColInfoData->pData)[startPos]; +// pWindowResInfo->prevSKey = tw.skey; +// win = tw; +// } +// } else { +// break; // offset is not 0, and next time window begins or ends in the next block. +// } +// } +// } // -// // check for error -// if (terrno != TSDB_CODE_SUCCESS) { -// longjmp(pRuntimeEnv->env, terrno); -// } +// // check for error +// if (terrno != TSDB_CODE_SUCCESS) { +// longjmp(pRuntimeEnv->env, terrno); +// } // -// return true; -//} +// return true; +// } int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num) { if (p->pDownstream == NULL) { @@ -4381,7 +4569,7 @@ int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t static void doDestroyTableQueryInfo(STableGroupInfo* pTableqinfoGroupInfo); static int32_t setupQueryHandle(void* tsdb, STaskRuntimeEnv* pRuntimeEnv, int64_t qId, bool isSTableQuery) { - STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; #if 0 // TODO set the tags scan handle if (onlyQueryTags(pQueryAttr)) { @@ -4439,10 +4627,10 @@ static int32_t setupQueryHandle(void* tsdb, STaskRuntimeEnv* pRuntimeEnv, int64_ } int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr, int32_t tbScanner, SArray* pOperator, - void* param) { - STaskRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; + void* param) { + STaskRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; - STaskAttr *pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; + STaskAttr* pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; pQueryAttr->tsdb = tsdb; if (tsdb != NULL) { @@ -4454,7 +4642,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr pQueryAttr->interBufSize = getOutputInterResultBufSize(pQueryAttr); - pRuntimeEnv->groupResInfo.totalGroup = (int32_t) (pQueryAttr->stableQuery? GET_NUM_OF_TABLEGROUP(pRuntimeEnv):0); + pRuntimeEnv->groupResInfo.totalGroup = (int32_t)(pQueryAttr->stableQuery ? GET_NUM_OF_TABLEGROUP(pRuntimeEnv) : 0); pRuntimeEnv->enableGroupData = false; pRuntimeEnv->pQueryAttr = pQueryAttr; @@ -4475,7 +4663,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr int32_t ps = 4096; getIntermediateBufInfo(pRuntimeEnv, &ps, &pQueryAttr->intermediateResultRowSize); - int32_t TENMB = 1024*1024*10; + int32_t TENMB = 1024 * 1024 * 10; int32_t code = createDiskbasedBuf(&pRuntimeEnv->pResultBuf, ps, TENMB, "", "/tmp"); if (code != TSDB_CODE_SUCCESS) { return code; @@ -4486,22 +4674,22 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr 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); + // 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); + // qDebug("QInfo:0x%"PRIx64" failed to allocate operator prof results hash", pQInfo->qId); } - code = setupQueryRuntimeEnv(pRuntimeEnv, (int32_t) pQueryAttr->tableGroupInfo.numOfTables, pOperator, param); + code = setupQueryRuntimeEnv(pRuntimeEnv, (int32_t)pQueryAttr->tableGroupInfo.numOfTables, pOperator, param); if (code != TSDB_CODE_SUCCESS) { return code; } -// setTaskStatus(pOperator->pTaskInfo, QUERY_NOT_COMPLETED); + // setTaskStatus(pOperator->pTaskInfo, QUERY_NOT_COMPLETED); return TSDB_CODE_SUCCESS; } @@ -4519,50 +4707,50 @@ static void doTableQueryInfoTimeWindowCheck(SExecTaskInfo* pTaskInfo, STableQuer (pTableQueryInfo->win.skey <= pTaskInfo->window.skey && pTableQueryInfo->win.ekey >= pTaskInfo->window.ekey)); } #endif - } -//STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win) { -// STsdbQueryCond cond = { -// .colList = pQueryAttr->tableCols, -// .order = pQueryAttr->order.order, -// .numOfCols = pQueryAttr->numOfCols, -// .type = BLOCK_LOAD_OFFSET_SEQ_ORDER, -// .loadExternalRows = false, -// }; +// STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win) { +// STsdbQueryCond cond = { +// .colList = pQueryAttr->tableCols, +// .order = pQueryAttr->order.order, +// .numOfCols = pQueryAttr->numOfCols, +// .type = BLOCK_LOAD_OFFSET_SEQ_ORDER, +// .loadExternalRows = false, +// }; // -// TIME_WINDOW_COPY(cond.twindow, *win); -// return cond; -//} +// TIME_WINDOW_COPY(cond.twindow, *win); +// return cond; +// } static STableIdInfo createTableIdInfo(STableQueryInfo* pTableQueryInfo) { STableIdInfo tidInfo; -// STableId* id = TSDB_TABLEID(pTableQueryInfo->pTable); -// -// tidInfo.uid = id->uid; -// tidInfo.tid = id->tid; -// tidInfo.key = pTableQueryInfo->lastKey; + // STableId* id = TSDB_TABLEID(pTableQueryInfo->pTable); + // + // tidInfo.uid = id->uid; + // tidInfo.tid = id->tid; + // tidInfo.key = pTableQueryInfo->lastKey; return tidInfo; } -//static void updateTableIdInfo(STableQueryInfo* pTableQueryInfo, SSDataBlock* pBlock, SHashObj* pTableIdInfo, int32_t order) { -// int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); -// pTableQueryInfo->lastKey = ((order == TSDB_ORDER_ASC)? pBlock->info.window.ekey:pBlock->info.window.skey) + step; +// static void updateTableIdInfo(STableQueryInfo* pTableQueryInfo, SSDataBlock* pBlock, SHashObj* pTableIdInfo, int32_t +// order) { +// int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); +// pTableQueryInfo->lastKey = ((order == TSDB_ORDER_ASC)? pBlock->info.window.ekey:pBlock->info.window.skey) + step; // -// if (pTableQueryInfo->pTable == NULL) { -// return; -// } +// if (pTableQueryInfo->pTable == NULL) { +// return; +// } // -// STableIdInfo tidInfo = createTableIdInfo(pTableQueryInfo); -// STableIdInfo *idinfo = taosHashGet(pTableIdInfo, &tidInfo.tid, sizeof(tidInfo.tid)); -// if (idinfo != NULL) { -// assert(idinfo->tid == tidInfo.tid && idinfo->uid == tidInfo.uid); -// idinfo->key = tidInfo.key; -// } else { -// taosHashPut(pTableIdInfo, &tidInfo.tid, sizeof(tidInfo.tid), &tidInfo, sizeof(STableIdInfo)); -// } -//} +// STableIdInfo tidInfo = createTableIdInfo(pTableQueryInfo); +// STableIdInfo *idinfo = taosHashGet(pTableIdInfo, &tidInfo.tid, sizeof(tidInfo.tid)); +// if (idinfo != NULL) { +// assert(idinfo->tid == tidInfo.tid && idinfo->uid == tidInfo.uid); +// idinfo->key = tidInfo.key; +// } else { +// taosHashPut(pTableIdInfo, &tidInfo.tid, sizeof(tidInfo.tid), &tidInfo, sizeof(STableIdInfo)); +// } +// } static void doCloseAllTimeWindow(STaskRuntimeEnv* pRuntimeEnv) { size_t numOfGroup = GET_NUM_OF_TABLEGROUP(pRuntimeEnv); @@ -4577,12 +4765,12 @@ static void doCloseAllTimeWindow(STaskRuntimeEnv* pRuntimeEnv) { } } -static SSDataBlock* doTableScanImpl(SOperatorInfo *pOperator, bool* newgroup) { - STableScanInfo *pTableScanInfo = pOperator->info; - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; +static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { + STableScanInfo* pTableScanInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SSDataBlock *pBlock = &pTableScanInfo->block; - STableGroupInfo *pTableGroupInfo = &pOperator->pTaskInfo->tableqinfoGroupInfo; + SSDataBlock* pBlock = &pTableScanInfo->block; + STableGroupInfo* pTableGroupInfo = &pOperator->pTaskInfo->tableqinfoGroupInfo; *newgroup = false; @@ -4595,21 +4783,21 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo *pOperator, bool* newgroup) { tsdbRetrieveDataBlockInfo(pTableScanInfo->pTsdbReadHandle, &pBlock->info); // todo opt -// if (pTableGroupInfo->numOfTables > 1 || (pRuntimeEnv->current == NULL && pTableGroupInfo->numOfTables == 1)) { -// STableQueryInfo** pTableQueryInfo = -// (STableQueryInfo**)taosHashGet(pTableGroupInfo->map, &pBlock->info.uid, sizeof(pBlock->info.uid)); -// if (pTableQueryInfo == NULL) { -// break; -// } -// -// pRuntimeEnv->current = *pTableQueryInfo; -// doTableQueryInfoTimeWindowCheck(pTaskInfo, *pTableQueryInfo, pTableScanInfo->order); -// } + // if (pTableGroupInfo->numOfTables > 1 || (pRuntimeEnv->current == NULL && pTableGroupInfo->numOfTables == 1)) { + // STableQueryInfo** pTableQueryInfo = + // (STableQueryInfo**)taosHashGet(pTableGroupInfo->map, &pBlock->info.uid, sizeof(pBlock->info.uid)); + // if (pTableQueryInfo == NULL) { + // break; + // } + // + // pRuntimeEnv->current = *pTableQueryInfo; + // doTableQueryInfoTimeWindowCheck(pTaskInfo, *pTableQueryInfo, pTableScanInfo->order); + // } // this function never returns error? uint32_t status = BLK_DATA_ALL_NEEDED; - int32_t code = loadDataBlock(pTaskInfo, pTableScanInfo, pBlock, &status); -// int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status); + int32_t code = loadDataBlock(pTaskInfo, pTableScanInfo, pBlock, &status); + // int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status); if (code != TSDB_CODE_SUCCESS) { longjmp(pOperator->pTaskInfo->env, code); } @@ -4625,9 +4813,9 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo *pOperator, bool* newgroup) { return NULL; } -static SSDataBlock* doTableScan(SOperatorInfo *pOperator, bool *newgroup) { - STableScanInfo *pTableScanInfo = pOperator->info; - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; +static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { + STableScanInfo* pTableScanInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; // The read handle is not initialized yet, since no qualified tables exists if (pTableScanInfo->pTsdbReadHandle == NULL) { @@ -4644,7 +4832,7 @@ static SSDataBlock* doTableScan(SOperatorInfo *pOperator, bool *newgroup) { } if (++pTableScanInfo->current >= pTableScanInfo->times) { - if (pTableScanInfo->reverseTimes <= 0/* || isTsdbCacheLastRow(pTableScanInfo->pTsdbReadHandle)*/) { + if (pTableScanInfo->reverseTimes <= 0 /* || isTsdbCacheLastRow(pTableScanInfo->pTsdbReadHandle)*/) { return NULL; } else { break; @@ -4652,17 +4840,17 @@ static SSDataBlock* doTableScan(SOperatorInfo *pOperator, bool *newgroup) { } // do prepare for the next round table scan operation -// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window); -// tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond); + // STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window); + // tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond); setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; -// if (pTaskInfo->pTsBuf) { -// bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf); -// assert(ret); -// } -// + // if (pTaskInfo->pTsBuf) { + // bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf); + // assert(ret); + // } + // if (pResultRowInfo->size > 0) { pResultRowInfo->curPos = 0; } @@ -4671,12 +4859,12 @@ static SSDataBlock* doTableScan(SOperatorInfo *pOperator, bool *newgroup) { GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); } - SSDataBlock *p = NULL; + SSDataBlock* p = NULL; // todo refactor if (pTableScanInfo->reverseTimes > 0) { setupEnvForReverseScan(pTableScanInfo, pTableScanInfo->pCtx, pTableScanInfo->numOfOutput); -// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window); -// tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond); + // STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window); + // tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond); qDebug("%s start to reverse scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); @@ -4691,12 +4879,12 @@ static SSDataBlock* doTableScan(SOperatorInfo *pOperator, bool *newgroup) { return p; } -static SSDataBlock* doBlockInfoScan(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } - STableScanInfo *pTableScanInfo = pOperator->info; + STableScanInfo* pTableScanInfo = pOperator->info; *newgroup = false; #if 0 STableBlockDist tableBlockDist = {0}; @@ -4738,11 +4926,21 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo *pOperator, bool* newgroup) { #endif } -static SSDataBlock* doStreamBlockScan(SOperatorInfo *pOperator, bool* newgroup) { - // NOTE: this operator does never check if current status is done or not - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SStreamBlockScanInfo* pInfo = pOperator->info; +static void doClearBufferedBlocks(SStreamBlockScanInfo* pInfo) { + size_t total = taosArrayGetSize(pInfo->pBlockLists); + pInfo->validBlockIndex = 0; + for (int32_t i = 0; i < total; ++i) { + SSDataBlock* p = taosArrayGetP(pInfo->pBlockLists, i); + blockDataDestroy(p); + } + taosArrayClear(pInfo->pBlockLists); +} + +static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) { + // NOTE: this operator does never check if current status is done or not + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SStreamBlockScanInfo* pInfo = pOperator->info; pTaskInfo->code = pOperator->_openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS) { @@ -4750,53 +4948,55 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo *pOperator, bool* newgroup) } if (pInfo->blockType == STREAM_DATA_TYPE_SSDATA_BLOCK) { - if (pInfo->blockValid) { - pInfo->blockValid = false; // this block can only be used once. - return pInfo->pRes; - } else { + size_t total = taosArrayGetSize(pInfo->pBlockLists); + if (pInfo->validBlockIndex >= total) { + doClearBufferedBlocks(pInfo); return NULL; } + + int32_t current = pInfo->validBlockIndex++; + return taosArrayGetP(pInfo->pBlockLists, current); + } else { + SDataBlockInfo* pBlockInfo = &pInfo->pRes->info; + blockDataCleanup(pInfo->pRes); + + while (tqNextDataBlock(pInfo->readerHandle)) { + pTaskInfo->code = tqRetrieveDataBlockInfo(pInfo->readerHandle, pBlockInfo); + if (pTaskInfo->code != TSDB_CODE_SUCCESS) { + terrno = pTaskInfo->code; + return NULL; + } + + if (pBlockInfo->rows == 0) { + return NULL; + } + + pInfo->pRes->pDataBlock = tqRetrieveDataBlock(pInfo->readerHandle); + if (pInfo->pRes->pDataBlock == NULL) { + // TODO add log + pTaskInfo->code = terrno; + return NULL; + } + + break; + } + + // record the scan action. + pInfo->numOfExec++; + pInfo->numOfRows += pBlockInfo->rows; + + return (pBlockInfo->rows == 0) ? NULL : pInfo->pRes; } - - SDataBlockInfo* pBlockInfo = &pInfo->pRes->info; - blockDataCleanup(pInfo->pRes); - - while (tqNextDataBlock(pInfo->readerHandle)) { - pTaskInfo->code = tqRetrieveDataBlockInfo(pInfo->readerHandle, pBlockInfo); - if (pTaskInfo->code != TSDB_CODE_SUCCESS) { - terrno = pTaskInfo->code; - return NULL; - } - - if (pBlockInfo->rows == 0) { - return NULL; - } - - pInfo->pRes->pDataBlock = tqRetrieveDataBlock(pInfo->readerHandle); - if (pInfo->pRes->pDataBlock == NULL) { - // TODO add log - pTaskInfo->code = terrno; - return NULL; - } - - break; - } - - // record the scan action. - pInfo->numOfExec++; - pInfo->numOfRows += pBlockInfo->rows; - - return (pBlockInfo->rows == 0)? NULL:pInfo->pRes; } int32_t loadRemoteDataCallback(void* param, const SDataBuf* pMsg, int32_t code) { - SSourceDataInfo* pSourceDataInfo = (SSourceDataInfo*) param; + SSourceDataInfo* pSourceDataInfo = (SSourceDataInfo*)param; pSourceDataInfo->pRsp = pMsg->pData; SRetrieveTableRsp* pRsp = pSourceDataInfo->pRsp; pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->compLen = htonl(pRsp->compLen); + pRsp->useconds = htobe64(pRsp->useconds); + pRsp->compLen = htonl(pRsp->compLen); pSourceDataInfo->status = EX_SOURCE_DATA_READY; tsem_post(&pSourceDataInfo->pEx->ready); @@ -4809,7 +5009,7 @@ static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { } void qProcessFetchRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { - SMsgSendInfo *pSendInfo = (SMsgSendInfo *) pMsg->ahandle; + SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->ahandle; assert(pMsg->ahandle != NULL); SDataBuf buf = {.len = pMsg->contLen, .pData = NULL}; @@ -4829,7 +5029,7 @@ void qProcessFetchRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { destroySendMsgInfo(pSendInfo); } -static int32_t doSendFetchDataRequest(SExchangeInfo *pExchangeInfo, SExecTaskInfo *pTaskInfo, int32_t sourceIndex) { +static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInfo* pTaskInfo, int32_t sourceIndex) { size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); SResFetchReq* pMsg = taosMemoryCalloc(1, sizeof(SResFetchReq)); @@ -4838,11 +5038,11 @@ static int32_t doSendFetchDataRequest(SExchangeInfo *pExchangeInfo, SExecTaskInf return pTaskInfo->code; } - SDownstreamSourceNode *pSource = taosArrayGet(pExchangeInfo->pSources, sourceIndex); - SSourceDataInfo *pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, sourceIndex); + SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, sourceIndex); + SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, sourceIndex); - qDebug("%s build fetch msg and send to vgId:%d, ep:%s, taskId:0x%" PRIx64 ", %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->addr.epSet.eps[0].fqdn, pSource->taskId, sourceIndex, totalSources); + qDebug("%s build fetch msg and send to vgId:%d, ep:%s, taskId:0x%" PRIx64 ", %d/%" PRIzu, GET_TASKID(pTaskInfo), + pSource->addr.nodeId, pSource->addr.epSet.eps[0].fqdn, pSource->taskId, sourceIndex, totalSources); pMsg->header.vgId = htonl(pSource->addr.nodeId); pMsg->sId = htobe64(pSource->schedId); @@ -4870,13 +5070,14 @@ static int32_t doSendFetchDataRequest(SExchangeInfo *pExchangeInfo, SExecTaskInf } // TODO if only one or two columnss required, how to extract data? -static int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData, int32_t compLen, - int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList) { +static int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, + char* pData, int32_t compLen, int32_t numOfOutput, int64_t startTs, + uint64_t* total, SArray* pColList) { blockDataEnsureCapacity(pRes, numOfRows); if (pColList == NULL) { // data from other sources int32_t* colLen = (int32_t*)pData; - char* pStart = pData + sizeof(int32_t) * numOfOutput; + char* pStart = pData + sizeof(int32_t) * numOfOutput; for (int32_t i = 0; i < numOfOutput; ++i) { colLen[i] = htonl(colLen[i]); @@ -4887,8 +5088,8 @@ static int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pColInfoData->varmeta.length = colLen[i]; pColInfoData->varmeta.allocLen = colLen[i]; - memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t)*numOfRows); - pStart += sizeof(int32_t)*numOfRows; + memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t) * numOfRows); + pStart += sizeof(int32_t) * numOfRows; pColInfoData->pData = taosMemoryMalloc(colLen[i]); } else { @@ -4903,10 +5104,9 @@ static int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* ASSERT(numOfOutput == taosArrayGetSize(pColList)); // data from mnode - for(int32_t i = 0; i < numOfOutput; ++i) { - - for(int32_t j = 0; j < numOfOutput; ++j) { - int16_t colIndex = *(int16_t*) taosArrayGet(pColList, j); + for (int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t j = 0; j < numOfOutput; ++j) { + int16_t colIndex = *(int16_t*)taosArrayGet(pColList, j); if (colIndex - 1 == i) { SColumnInfoData* pColInfoData = taosArrayGet(pRes->pDataBlock, j); @@ -4935,23 +5135,25 @@ static int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* return TSDB_CODE_SUCCESS; } -static void* setAllSourcesCompleted(SOperatorInfo *pOperator, int64_t startTs) { - SExchangeInfo *pExchangeInfo = pOperator->info; +static void* setAllSourcesCompleted(SOperatorInfo* pOperator, int64_t startTs) { + SExchangeInfo* pExchangeInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - int64_t el = taosGetTimestampUs() - startTs; + int64_t el = taosGetTimestampUs() - startTs; SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; pLoadInfo->totalElapsed += el; size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - qDebug("%s all %"PRIzu" sources are exhausted, total rows: %"PRIu64" bytes:%"PRIu64", elapsed:%.2f ms", GET_TASKID(pTaskInfo), totalSources, - pLoadInfo->totalRows, pLoadInfo->totalSize, pLoadInfo->totalElapsed/1000.0); + qDebug("%s all %" PRIzu " sources are exhausted, total rows: %" PRIu64 " bytes:%" PRIu64 ", elapsed:%.2f ms", + GET_TASKID(pTaskInfo), totalSources, pLoadInfo->totalRows, pLoadInfo->totalSize, + pLoadInfo->totalElapsed / 1000.0); doSetOperatorCompleted(pOperator); return NULL; } -static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo *pOperator, SExchangeInfo *pExchangeInfo, SExecTaskInfo *pTaskInfo) { +static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeInfo* pExchangeInfo, + SExecTaskInfo* pTaskInfo) { int32_t code = 0; int64_t startTs = taosGetTimestampUs(); size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); @@ -4961,32 +5163,34 @@ 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; } - SRetrieveTableRsp* pRsp = pDataInfo->pRsp; + SRetrieveTableRsp* pRsp = pDataInfo->pRsp; SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, i); - SSDataBlock* pRes = pExchangeInfo->pResult; + SSDataBlock* pRes = pExchangeInfo->pResult; SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; if (pRsp->numOfRows == 0) { - qDebug("%s vgId:%d, taskID:0x%" PRIx64 " index:%d completed, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 " try next", + qDebug("%s vgId:%d, taskID:0x%" PRIx64 " index:%d completed, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 + " 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; } SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; - code = setSDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, - pTableRsp->data, pTableRsp->compLen, pOperator->numOfOutput, startTs, &pDataInfo->totalRows, NULL); + code = + setSDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, + pTableRsp->compLen, pOperator->numOfOutput, startTs, &pDataInfo->totalRows, NULL); if (code != 0) { goto _error; } @@ -4994,18 +5198,17 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo *pOperator, SEx if (pRsp->completed == 1) { qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, rowsOfSource:%" PRIu64 ", 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; + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pDataInfo->totalRows, + pLoadInfo->totalRows, pLoadInfo->totalSize, i + 1, totalSources); + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; } else { 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; @@ -5025,19 +5228,19 @@ _error: return NULL; } -static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo *pOperator) { - SExchangeInfo *pExchangeInfo = pOperator->info; - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; +static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo* pOperator) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_RES_TO_RETURN) { return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); } - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); int64_t startTs = taosGetTimestampUs(); // Asynchronously send all fetch requests to all sources. - for(int32_t i = 0; i < totalSources; ++i) { + for (int32_t i = 0; i < totalSources; ++i) { int32_t code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i); if (code != TSDB_CODE_SUCCESS) { return NULL; @@ -5045,7 +5248,8 @@ static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo *pOperator) { } int64_t endTs = taosGetTimestampUs(); - qDebug("%s send all fetch request to %"PRIzu" sources completed, elapsed:%"PRId64, GET_TASKID(pTaskInfo), totalSources, endTs - startTs); + qDebug("%s send all fetch request to %" PRIzu " sources completed, elapsed:%" PRId64, GET_TASKID(pTaskInfo), + totalSources, endTs - startTs); tsem_wait(&pExchangeInfo->ready); @@ -5053,15 +5257,15 @@ static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo *pOperator) { return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); } -static int32_t prepareConcurrentlyLoad(SOperatorInfo *pOperator) { - SExchangeInfo *pExchangeInfo = pOperator->info; - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; +static int32_t prepareConcurrentlyLoad(SOperatorInfo* pOperator) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); int64_t startTs = taosGetTimestampUs(); // Asynchronously send all fetch requests to all sources. - for(int32_t i = 0; i < totalSources; ++i) { + for (int32_t i = 0; i < totalSources; ++i) { int32_t code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; @@ -5070,7 +5274,8 @@ static int32_t prepareConcurrentlyLoad(SOperatorInfo *pOperator) { } int64_t endTs = taosGetTimestampUs(); - qDebug("%s send all fetch request to %"PRIzu" sources completed, elapsed:%"PRId64, GET_TASKID(pTaskInfo), totalSources, endTs - startTs); + qDebug("%s send all fetch request to %" PRIzu " sources completed, elapsed:%" PRId64, GET_TASKID(pTaskInfo), + totalSources, endTs - startTs); tsem_wait(&pExchangeInfo->ready); pOperator->cost.openCost = taosGetTimestampUs() - startTs; @@ -5078,14 +5283,14 @@ static int32_t prepareConcurrentlyLoad(SOperatorInfo *pOperator) { return TSDB_CODE_SUCCESS; } -static SSDataBlock* seqLoadRemoteData(SOperatorInfo *pOperator) { - SExchangeInfo *pExchangeInfo = pOperator->info; - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; +static SSDataBlock* seqLoadRemoteData(SOperatorInfo* pOperator) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); int64_t startTs = taosGetTimestampUs(); - while(1) { + while (1) { if (pExchangeInfo->current >= totalSources) { return setAllSourcesCompleted(pOperator, startTs); } @@ -5094,51 +5299,54 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo *pOperator) { 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); - SRetrieveTableRsp* pRsp = pDataInfo->pRsp; + 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; } - SSDataBlock* pRes = pExchangeInfo->pResult; + SSDataBlock* pRes = pExchangeInfo->pResult; SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; - int32_t code = setSDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, - pTableRsp->data, pTableRsp->compLen, pOperator->numOfOutput, startTs, &pDataInfo->totalRows, NULL); + int32_t code = + setSDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, + pTableRsp->compLen, pOperator->numOfOutput, startTs, &pDataInfo->totalRows, NULL); if (pRsp->completed == 1) { qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, rowsOfSource:%" PRIu64 - ", 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, pExchangeInfo->current + 1, - totalSources); + ", 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, 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 ", totalBytes:%" PRIu64, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pLoadInfo->totalRows, pLoadInfo->totalSize); + 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); } return pExchangeInfo->pResult; } } -static int32_t prepareLoadRemoteData(SOperatorInfo *pOperator) { +static int32_t prepareLoadRemoteData(SOperatorInfo* pOperator) { if (OPTR_IS_OPENED(pOperator)) { return TSDB_CODE_SUCCESS; } - SExchangeInfo *pExchangeInfo = pOperator->info; + SExchangeInfo* pExchangeInfo = pOperator->info; if (pExchangeInfo->seqLoadData) { // do nothing for sequentially load data } else { @@ -5152,21 +5360,22 @@ static int32_t prepareLoadRemoteData(SOperatorInfo *pOperator) { return TSDB_CODE_SUCCESS; } -static SSDataBlock* doLoadRemoteData(SOperatorInfo *pOperator, bool* newgroup) { - SExchangeInfo *pExchangeInfo = pOperator->info; - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; +static SSDataBlock* doLoadRemoteData(SOperatorInfo* pOperator, bool* newgroup) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; pTaskInfo->code = pOperator->_openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS) { return NULL; } - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; if (pOperator->status == OP_EXEC_DONE) { - qDebug("%s all %"PRIzu" source(s) are exhausted, total rows:%"PRIu64" bytes:%"PRIu64", elapsed:%.2f ms", GET_TASKID(pTaskInfo), totalSources, - pLoadInfo->totalRows, pLoadInfo->totalSize, pLoadInfo->totalElapsed/1000.0); + qDebug("%s all %" PRIzu " source(s) are exhausted, total rows:%" PRIu64 " bytes:%" PRIu64 ", elapsed:%.2f ms", + GET_TASKID(pTaskInfo), totalSources, pLoadInfo->totalRows, pLoadInfo->totalSize, + pLoadInfo->totalElapsed / 1000.0); return NULL; } @@ -5194,11 +5403,11 @@ static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo) { return TSDB_CODE_OUT_OF_MEMORY; } - for(int32_t i = 0; i < numOfSources; ++i) { + for (int32_t i = 0; i < numOfSources; ++i) { SSourceDataInfo dataInfo = {0}; dataInfo.status = EX_SOURCE_DATA_NOT_READY; - dataInfo.pEx = pInfo; - dataInfo.index = i; + dataInfo.pEx = pInfo; + dataInfo.index = i; void* ret = taosArrayPush(pInfo->pSourceDataInfo, &dataInfo); if (ret == NULL) { @@ -5211,7 +5420,7 @@ static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo) { } SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) { - SExchangeInfo* pInfo = taosMemoryCalloc(1, sizeof(SExchangeInfo)); + SExchangeInfo* pInfo = taosMemoryCalloc(1, sizeof(SExchangeInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -5228,8 +5437,8 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock goto _error; } - for(int32_t i = 0; i < numOfSources; ++i) { - SNodeListNode* pNode = nodesListGetNode((SNodeList*) pSources, i); + for (int32_t i = 0; i < numOfSources; ++i) { + SNodeListNode* pNode = nodesListGetNode((SNodeList*)pSources, i); taosArrayPush(pInfo->pSources, pNode); } @@ -5238,25 +5447,25 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock goto _error; } - size_t size = pBlock->info.numOfCols; - pInfo->pResult = pBlock; + size_t size = pBlock->info.numOfCols; + pInfo->pResult = pBlock; pInfo->seqLoadData = true; tsem_init(&pInfo->ready, 0, 0); - pOperator->name = "ExchangeOperator"; + pOperator->name = "ExchangeOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_EXCHANGE; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = size; - pOperator->pTaskInfo = pTaskInfo; - pOperator->_openFn = prepareLoadRemoteData; // assign a dummy function. - pOperator->getNextFn = doLoadRemoteData; - pOperator->closeFn = destroyExchangeOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = size; + pOperator->pTaskInfo = pTaskInfo; + pOperator->_openFn = prepareLoadRemoteData; // assign a dummy function. + pOperator->getNextFn = doLoadRemoteData; + pOperator->closeFn = destroyExchangeOperatorInfo; #if 1 - { // todo refactor + { // todo refactor SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localPort = 0; @@ -5265,22 +5474,22 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock rpcInit.cfp = qProcessFetchRsp; rpcInit.sessions = tsMaxConnections; rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.user = (char *)"root"; + rpcInit.user = (char*)"root"; rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.ckey = "key"; rpcInit.spi = 1; - rpcInit.secret = (char *)"dcc5bed04851fec854c035b2e40263b6"; + rpcInit.secret = (char*)"dcc5bed04851fec854c035b2e40263b6"; pInfo->pTransporter = rpcOpen(&rpcInit); if (pInfo->pTransporter == NULL) { - return NULL; // todo + return NULL; // todo } } #endif return pOperator; - _error: +_error: if (pInfo != NULL) { destroyExchangeOperatorInfo(pInfo, numOfSources); } @@ -5301,12 +5510,12 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { pResBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); SArray* pResult = pResBlock->pDataBlock; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData colInfoData = {0}; - SExprInfo* p = taosArrayGetP(pExprInfo, i); + SExprInfo* p = taosArrayGetP(pExprInfo, i); SResSchema* pSchema = &p->base.resSchema; - colInfoData.info.type = pSchema->type; + colInfoData.info.type = pSchema->type; colInfoData.info.colId = pSchema->colId; colInfoData.info.bytes = pSchema->bytes; colInfoData.info.scale = pSchema->scale; @@ -5317,12 +5526,13 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { return pResBlock; } -SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, - SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, + int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, + SExecTaskInfo* pTaskInfo) { assert(repeatTime > 0); - STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -5332,26 +5542,26 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, } pInfo->block.pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData)); - for(int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t i = 0; i < numOfOutput; ++i) { SColumnInfoData idata = {0}; 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"; - 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; + 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; return pOperator; } @@ -5359,23 +5569,23 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); - pInfo->pTsdbReadHandle = pTsdbReadHandle; - pInfo->times = 1; - pInfo->reverseTimes = 0; - pInfo->order = pRuntimeEnv->pQueryAttr->order.order; - pInfo->current = 0; - pInfo->prevGroupId = -1; + pInfo->pTsdbReadHandle = pTsdbReadHandle; + pInfo->times = 1; + pInfo->reverseTimes = 0; + pInfo->order = pRuntimeEnv->pQueryAttr->order.order; + pInfo->current = 0; + pInfo->prevGroupId = -1; pRuntimeEnv->enableGroupData = true; SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "TableSeqScanOperator"; + pOperator->name = "TableSeqScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols; - pOperator->pRuntimeEnv = pRuntimeEnv; - pOperator->getNextFn = doTableScanImpl; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols; + pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->getNextFn = doTableScanImpl; return pOperator; } @@ -5383,7 +5593,7 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); - pInfo->pTsdbReadHandle = pTsdbReadHandle; + pInfo->pTsdbReadHandle = pTsdbReadHandle; pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); SColumnInfoData infoData = {{0}}; @@ -5393,20 +5603,21 @@ SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRunt taosArrayPush(pInfo->block.pDataBlock, &infoData); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "TableBlockInfoScanOperator"; -// pOperator->operatorType = OP_TableBlockInfoScan; + pOperator->name = "TableBlockInfoScanOperator"; + // pOperator->operatorType = OP_TableBlockInfoScan; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; -// pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + // pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols; pOperator->getNextFn = doBlockInfoScan; return pOperator; } -SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, + SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -5415,7 +5626,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock* } // set the extract column id to streamHandle - tqReadHandleSetColIdList((STqReadHandle* )streamReadHandle, pColList); + tqReadHandleSetColIdList((STqReadHandle*)streamReadHandle, pColList); int32_t code = tqReadHandleSetTbUidList(streamReadHandle, pTableIdList); if (code != 0) { taosMemoryFreeClear(pInfo); @@ -5423,33 +5634,40 @@ SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock* return NULL; } - pInfo->readerHandle = streamReadHandle; - pInfo->pRes = pResBlock; + pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES); + if (pInfo->pBlockLists == NULL) { + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); + return NULL; + } - pOperator->name = "StreamBlockScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; - pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = pResBlock->info.numOfCols; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doStreamBlockScan; - pOperator->closeFn = operatorDummyCloseFn; - pOperator->pTaskInfo = pTaskInfo; + pInfo->readerHandle = streamReadHandle; + pInfo->pRes = pResBlock; + + pOperator->name = "StreamBlockScanOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; + pOperator->blockingOptr = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = pResBlock->info.numOfCols; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doStreamBlockScan; + pOperator->closeFn = operatorDummyCloseFn; + pOperator->pTaskInfo = pTaskInfo; return pOperator; } static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t code) { - SOperatorInfo* operator = (SOperatorInfo *)param; - SSysTableScanInfo* pScanResInfo = (SSysTableScanInfo *)operator->info; + SOperatorInfo* operator=(SOperatorInfo*) param; + SSysTableScanInfo* pScanResInfo = (SSysTableScanInfo*)operator->info; if (TSDB_CODE_SUCCESS == code) { pScanResInfo->pRsp = pMsg->pData; 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; } @@ -5457,10 +5675,9 @@ static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t tsem_post(&pScanResInfo->ready); } - static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { if (pInfo->pCondition == NULL) { - return pInfo->pRes->info.rows == 0? NULL:pInfo->pRes; + return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; } SFilterInfo* filter = NULL; @@ -5475,7 +5692,7 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { SSDataBlock* px = createOneDataBlock(pInfo->pRes); blockDataEnsureCapacity(px, pInfo->pRes->info.rows); - //TODO refactor + // TODO refactor int32_t numOfRow = 0; for (int32_t i = 0; i < pInfo->pRes->info.numOfCols; ++i) { SColumnInfoData* pDest = taosArrayGet(px->pDataBlock, i); @@ -5495,49 +5712,49 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { px->info.rows = numOfRow; pInfo->pRes = px; - return pInfo->pRes->info.rows == 0? NULL:pInfo->pRes; + return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; } EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; ENodeType nType = nodeType(pNode); switch (nType) { case QUERY_NODE_OPERATOR: { - SOperatorNode *node = (SOperatorNode *)pNode; + SOperatorNode* node = (SOperatorNode*)pNode; if (OP_TYPE_EQUAL == node->opType) { - *(int32_t *)pContext = 1; + *(int32_t*)pContext = 1; return DEAL_RES_CONTINUE; } - *(int32_t *)pContext = 0; + *(int32_t*)pContext = 0; return DEAL_RES_IGNORE_CHILD; } case QUERY_NODE_COLUMN: { - if (1 != *(int32_t *)pContext) { + if (1 != *(int32_t*)pContext) { return DEAL_RES_CONTINUE; } - SColumnNode *node = (SColumnNode *)pNode; + SColumnNode* node = (SColumnNode*)pNode; if (TSDB_INS_USER_STABLES_DBNAME_COLID == node->colId) { - *(int32_t *)pContext = 2; + *(int32_t*)pContext = 2; return DEAL_RES_CONTINUE; } - *(int32_t *)pContext = 0; + *(int32_t*)pContext = 0; return DEAL_RES_CONTINUE; } case QUERY_NODE_VALUE: { - if (2 != *(int32_t *)pContext) { + if (2 != *(int32_t*)pContext) { return DEAL_RES_CONTINUE; } - SValueNode *node = (SValueNode *)pNode; - char *dbName = nodesGetValueFromNode(node); + SValueNode* node = (SValueNode*)pNode; + char* dbName = nodesGetValueFromNode(node); strncpy(pContext, varDataVal(dbName), varDataLen(dbName)); - *((char *)pContext + varDataLen(dbName)) = 0; + *((char*)pContext + varDataLen(dbName)) = 0; return DEAL_RES_ERROR; // stop walk } default: @@ -5547,8 +5764,7 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } - -void getDBNameFromCondition(SNode *pCondition, char *dbName) { +void getDBNameFromCondition(SNode* pCondition, char* dbName) { if (NULL == pCondition) { return; } @@ -5556,9 +5772,9 @@ void getDBNameFromCondition(SNode *pCondition, char *dbName) { nodesWalkNode(pCondition, getDBNameFromConditionWalker, dbName); } -static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { -// build message and send to mnode to fetch the content of system tables. - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; +static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { + // build message and send to mnode to fetch the content of system tables. + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSysTableScanInfo* pInfo = pOperator->info; // retrieve local table list info from vnode @@ -5569,10 +5785,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { blockDataCleanup(pInfo->pRes); - int32_t tableNameSlotId = 1; + int32_t tableNameSlotId = 1; SColumnInfoData* pTableNameCol = taosArrayGet(pInfo->pRes->pDataBlock, tableNameSlotId); - char * name = NULL; + char* name = NULL; int32_t numOfRows = 0; char n[TSDB_TABLE_NAME_LEN] = {0}; @@ -5584,19 +5800,19 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { break; } - for(int32_t i = 0; i < pInfo->pRes->info.numOfCols; ++i) { + for (int32_t i = 0; i < pInfo->pRes->info.numOfCols; ++i) { if (i == tableNameSlotId) { continue; } SColumnInfoData* pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, i); - int64_t tmp = 0; - char t[10] = {0}; + int64_t tmp = 0; + char t[10] = {0}; STR_TO_VARSTR(t, "_"); if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { colDataAppend(pColInfoData, numOfRows, t, false); } else { - colDataAppend(pColInfoData, numOfRows, (char*) &tmp, false); + colDataAppend(pColInfoData, numOfRows, (char*)&tmp, false); } } } @@ -5604,9 +5820,9 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { pInfo->loadInfo.totalRows += numOfRows; pInfo->pRes->info.rows = numOfRows; -// pInfo->elapsedTime; -// pInfo->totalBytes; - return (pInfo->pRes->info.rows == 0)? NULL:pInfo->pRes; + // pInfo->elapsedTime; + // pInfo->totalBytes; + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } else { // load the meta from mnode of the given epset int64_t startTs = taosGetTimestampUs(); @@ -5619,7 +5835,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { } int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req); - char* buf1 = taosMemoryCalloc(1, contLen); + char* buf1 = taosMemoryCalloc(1, contLen); tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req); // send the fetch remote task result reques @@ -5648,15 +5864,16 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { pInfo->req.showId = pRsp->handle; if (pRsp->numOfRows == 0) { -// 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, pExchangeInfo->totalRows); + // 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, pExchangeInfo->totalRows); return NULL; } SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp; - setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, - pTableRsp->data, pTableRsp->compLen, pOperator->numOfOutput, startTs, NULL, pInfo->scanCols); + setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data, pTableRsp->compLen, + pOperator->numOfOutput, startTs, NULL, pInfo->scanCols); return doFilterResult(pInfo); } @@ -5665,9 +5882,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) { } SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName, - SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId) { + SNode* pCondition, SEpSet epset, SArray* colList, + SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId) { SSysTableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SSysTableScanInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -5675,15 +5893,15 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB return NULL; } - pInfo->accountId = accountId; + pInfo->accountId = accountId; pInfo->showRewrite = showRewrite; - pInfo->pRes = pResBlock; - pInfo->capacity = 4096; - pInfo->pCondition = pCondition; - pInfo->scanCols = colList; + pInfo->pRes = pResBlock; + pInfo->capacity = 4096; + pInfo->pCondition = pCondition; + pInfo->scanCols = colList; // TODO remove it - int32_t tableType = 0; + int32_t tableType = 0; const char* name = tNameGetTableName(pName); if (strncasecmp(name, TSDB_INS_TABLE_USER_DATABASES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_DB; @@ -5700,7 +5918,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB } else if (strncasecmp(name, TSDB_INS_TABLE_USER_FUNCTIONS, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_FUNC; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_INDEXES, tListLen(pName->tname)) == 0) { -// tableType = TSDB_MGMT_TABLE_INDEX; + // tableType = TSDB_MGMT_TABLE_INDEX; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_STABLES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_STB; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_STREAMS, tListLen(pName->tname)) == 0) { @@ -5710,7 +5928,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_VGROUP; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, tListLen(pName->tname)) == 0) { -// tableType = TSDB_MGMT_TABLE_DIST; + // tableType = TSDB_MGMT_TABLE_DIST; } else { ASSERT(0); } @@ -5725,7 +5943,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB pInfo->epSet = epset; #if 1 - { // todo refactor + { // todo refactor SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localPort = 0; @@ -5734,35 +5952,35 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB rpcInit.cfp = qProcessFetchRsp; rpcInit.sessions = tsMaxConnections; rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.user = (char *)"root"; + rpcInit.user = (char*)"root"; rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.ckey = "key"; rpcInit.spi = 1; - rpcInit.secret = (char *)"dcc5bed04851fec854c035b2e40263b6"; + rpcInit.secret = (char*)"dcc5bed04851fec854c035b2e40263b6"; pInfo->pTransporter = rpcOpen(&rpcInit); if (pInfo->pTransporter == NULL) { - return NULL; // todo + return NULL; // todo } } #endif } - pOperator->name = "SysTableScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN; - pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = pResBlock->info.numOfCols; - pOperator->getNextFn = doSysTableScan; - pOperator->closeFn = destroySysTableScannerOperatorInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->name = "SysTableScanOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN; + pOperator->blockingOptr = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = pResBlock->info.numOfCols; + pOperator->getNextFn = doSysTableScan; + pOperator->closeFn = destroySysTableScannerOperatorInfo; + pOperator->pTaskInfo = pTaskInfo; return pOperator; } SArray* getOrderCheckColumns(STaskAttr* pQuery) { - int32_t numOfCols = (pQuery->pGroupbyExpr == NULL)? 0: taosArrayGetSize(pQuery->pGroupbyExpr->columnInfo); + int32_t numOfCols = (pQuery->pGroupbyExpr == NULL) ? 0 : taosArrayGetSize(pQuery->pGroupbyExpr->columnInfo); SArray* pOrderColumns = NULL; if (numOfCols > 0) { @@ -5781,12 +5999,12 @@ SArray* getOrderCheckColumns(STaskAttr* pQuery) { } { - numOfCols = (int32_t) taosArrayGetSize(pOrderColumns); - for(int32_t i = 0; i < numOfCols; ++i) { + numOfCols = (int32_t)taosArrayGetSize(pOrderColumns); + for (int32_t i = 0; i < numOfCols; ++i) { SColIndex* index = taosArrayGet(pOrderColumns, i); - for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { + for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { SExprBasicInfo* pExpr = &pQuery->pExpr1[j].base; - int32_t functionId = getExprFunctionId(&pQuery->pExpr1[j]); + int32_t functionId = getExprFunctionId(&pQuery->pExpr1[j]); if (index->colId == pExpr->pParam[0].pCol->colId && (functionId == FUNCTION_PRJ || functionId == FUNCTION_TAG || functionId == FUNCTION_TS)) { @@ -5801,7 +6019,7 @@ SArray* getOrderCheckColumns(STaskAttr* pQuery) { } SArray* getResultGroupCheckColumns(STaskAttr* pQuery) { - int32_t numOfCols = (pQuery->pGroupbyExpr == NULL)? 0 : taosArrayGetSize(pQuery->pGroupbyExpr->columnInfo); + int32_t numOfCols = (pQuery->pGroupbyExpr == NULL) ? 0 : taosArrayGetSize(pQuery->pGroupbyExpr->columnInfo); SArray* pOrderColumns = NULL; if (numOfCols > 0) { @@ -5810,23 +6028,23 @@ SArray* getResultGroupCheckColumns(STaskAttr* pQuery) { pOrderColumns = taosArrayInit(4, sizeof(SColIndex)); } - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColIndex* index = taosArrayGet(pOrderColumns, i); bool found = false; - for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { + for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { SExprBasicInfo* pExpr = &pQuery->pExpr1[j].base; - int32_t functionId = getExprFunctionId(&pQuery->pExpr1[j]); + int32_t functionId = getExprFunctionId(&pQuery->pExpr1[j]); // FUNCTION_TAG_DUMMY function needs to be ignored -// if (index->colId == pExpr->pColumns->info.colId && -// ((TSDB_COL_IS_TAG(pExpr->pColumns->flag) && functionId == FUNCTION_TAG) || -// (TSDB_COL_IS_NORMAL_COL(pExpr->pColumns->flag) && functionId == FUNCTION_PRJ))) { -// index->colIndex = j; -// index->colId = pExpr->resSchema.colId; -// found = true; -// break; -// } + // if (index->colId == pExpr->pColumns->info.colId && + // ((TSDB_COL_IS_TAG(pExpr->pColumns->flag) && functionId == FUNCTION_TAG) || + // (TSDB_COL_IS_NORMAL_COL(pExpr->pColumns->flag) && functionId == FUNCTION_PRJ))) { + // index->colIndex = j; + // index->colId = pExpr->resSchema.colId; + // found = true; + // break; + // } } assert(found && index->colIndex >= 0 && index->colIndex < pQuery->numOfOutput); @@ -5835,24 +6053,24 @@ SArray* getResultGroupCheckColumns(STaskAttr* pQuery) { return pOrderColumns; } -static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx *pCtx, int32_t numOfOutput, const char* pKey); -static void cleanupAggSup(SAggSupporter* pAggSup); +static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey); +static void cleanupAggSup(SAggSupporter* pAggSup); static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) { - SSortedMergeOperatorInfo* pInfo = (SSortedMergeOperatorInfo*) param; - taosArrayDestroy(pInfo->orderInfo); + SSortedMergeOperatorInfo* pInfo = (SSortedMergeOperatorInfo*)param; + taosArrayDestroy(pInfo->pSortInfo); taosArrayDestroy(pInfo->groupInfo); if (pInfo->pSortHandle != NULL) { tsortDestroySortHandle(pInfo->pSortHandle); } - blockDataDestroy(pInfo->binfo.pRes); + blockDataDestroy(pInfo->binfo.pRes); cleanupAggSup(&pInfo->aggSup); } static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) { - SSLimitOperatorInfo *pInfo = (SSLimitOperatorInfo*) param; + SSLimitOperatorInfo* pInfo = (SSLimitOperatorInfo*)param; taosArrayDestroy(pInfo->orderColumnList); pInfo->pRes = blockDataDestroy(pInfo->pRes); taosMemoryFreeClear(pInfo->prevRow); @@ -5867,10 +6085,10 @@ static void assignExprInfo(SExprInfo* dst, const SExprInfo* src) { dst->base.pParam = taosMemoryCalloc(src->base.numOfParams, sizeof(SColumn)); memcpy(dst->base.pParam, src->base.pParam, sizeof(SColumn) * src->base.numOfParams); -// memset(dst->base.param, 0, sizeof(SVariant) * tListLen(dst->base.param)); -// for (int32_t j = 0; j < src->base.numOfParams; ++j) { -// taosVariantAssign(&dst->base.param[j], &src->base.param[j]); -// } + // memset(dst->base.param, 0, sizeof(SVariant) * tListLen(dst->base.param)); + // for (int32_t j = 0; j < src->base.numOfParams; ++j) { + // taosVariantAssign(&dst->base.param[j], &src->base.param[j]); + // } } static SExprInfo* exprArrayDup(SArray* pExprList) { @@ -5886,7 +6104,7 @@ static SExprInfo* exprArrayDup(SArray* pExprList) { } // TODO merge aggregate super table -static void appendOneRowToDataBlock(SSDataBlock *pBlock, STupleHandle* pTupleHandle) { +static void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) { for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); @@ -5902,10 +6120,11 @@ static void appendOneRowToDataBlock(SSDataBlock *pBlock, STupleHandle* pTupleHan pBlock->info.rows += 1; } -static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, bool hasVarCol, int32_t capacity) { +static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, bool hasVarCol, + int32_t capacity) { blockDataCleanup(pDataBlock); - while(1) { + while (1) { STupleHandle* pTupleHandle = tsortNextTuple(pHandle); if (pTupleHandle == NULL) { break; @@ -5917,17 +6136,17 @@ static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataB } } - return (pDataBlock->info.rows > 0)? pDataBlock:NULL; + return (pDataBlock->info.rows > 0) ? pDataBlock : NULL; } SSDataBlock* loadNextDataBlock(void* param) { - SOperatorInfo* pOperator = (SOperatorInfo*) param; - bool newgroup = false; + SOperatorInfo* pOperator = (SOperatorInfo*)param; + bool newgroup = false; return pOperator->getNextFn(pOperator, &newgroup); } -static bool needToMerge(SSDataBlock* pBlock, SArray* groupInfo, char **buf, int32_t rowIndex) { +static bool needToMerge(SSDataBlock* pBlock, SArray* groupInfo, char** buf, int32_t rowIndex) { size_t size = taosArrayGetSize(groupInfo); if (size == 0) { return true; @@ -5937,7 +6156,7 @@ static bool needToMerge(SSDataBlock* pBlock, SArray* groupInfo, char **buf, int3 int32_t* index = taosArrayGet(groupInfo, i); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, *index); - bool isNull = colDataIsNull(pColInfo, rowIndex, pBlock->info.rows, NULL); + bool isNull = colDataIsNull(pColInfo, rowIndex, pBlock->info.rows, NULL); if ((isNull && buf[i] != NULL) || (!isNull && buf[i] == NULL)) { return false; @@ -5962,27 +6181,28 @@ static bool needToMerge(SSDataBlock* pBlock, SArray* groupInfo, char **buf, int3 return 0; } -static void doMergeResultImpl(SSortedMergeOperatorInfo* pInfo, SqlFunctionCtx *pCtx, int32_t numOfExpr, int32_t rowIndex) { - for (int32_t j = 0; j < numOfExpr; ++j) { // TODO set row index +static void doMergeResultImpl(SSortedMergeOperatorInfo* pInfo, SqlFunctionCtx* pCtx, int32_t numOfExpr, + int32_t rowIndex) { + for (int32_t j = 0; j < numOfExpr; ++j) { // TODO set row index pCtx[j].startRow = rowIndex; } for (int32_t j = 0; j < numOfExpr; ++j) { int32_t functionId = pCtx[j].functionId; -// pCtx[j].fpSet->addInput(&pCtx[j]); + // pCtx[j].fpSet->addInput(&pCtx[j]); -// if (functionId < 0) { -// SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1); -// doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_MERGE); -// } else { -// assert(!TSDB_FUNC_IS_SCALAR(functionId)); -// aAggs[functionId].mergeFunc(&pCtx[j]); -// } + // if (functionId < 0) { + // SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1); + // doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_MERGE); + // } else { + // assert(!TSDB_FUNC_IS_SCALAR(functionId)); + // aAggs[functionId].mergeFunc(&pCtx[j]); + // } } } -static void doFinalizeResultImpl(SqlFunctionCtx *pCtx, int32_t numOfExpr) { - for(int32_t j = 0; j < numOfExpr; ++j) { +static void doFinalizeResultImpl(SqlFunctionCtx* pCtx, int32_t numOfExpr) { + for (int32_t j = 0; j < numOfExpr; ++j) { int32_t functionId = pCtx[j].functionId; // if (functionId == FUNC_TAG_DUMMY || functionId == FUNC_TS_DUMMY) { // continue; @@ -5997,10 +6217,10 @@ static void doFinalizeResultImpl(SqlFunctionCtx *pCtx, int32_t numOfExpr) { } static bool saveCurrentTuple(char** rowColData, SArray* pColumnList, SSDataBlock* pBlock, int32_t rowIndex) { - int32_t size = (int32_t) taosArrayGetSize(pColumnList); + int32_t size = (int32_t)taosArrayGetSize(pColumnList); - for(int32_t i = 0; i < size; ++i) { - int32_t* index = taosArrayGet(pColumnList, i); + for (int32_t i = 0; i < size; ++i) { + int32_t* index = taosArrayGet(pColumnList, i); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, *index); char* data = colDataGetData(pColInfo, rowIndex); @@ -6014,11 +6234,11 @@ static void doMergeImpl(SOperatorInfo* pOperator, int32_t numOfExpr, SSDataBlock SSortedMergeOperatorInfo* pInfo = pOperator->info; SqlFunctionCtx* pCtx = pInfo->binfo.pCtx; - for(int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { pCtx[i].size = 1; } - for(int32_t i = 0; i < pBlock->info.rows; ++i) { + for (int32_t i = 0; i < pBlock->info.rows; ++i) { if (!pInfo->hasGroupVal) { ASSERT(i == 0); doMergeResultImpl(pInfo, pCtx, numOfExpr, i); @@ -6052,13 +6272,12 @@ static void doMergeImpl(SOperatorInfo* pOperator, int32_t numOfExpr, SSDataBlock static SSDataBlock* doMerge(SOperatorInfo* pOperator) { SSortedMergeOperatorInfo* pInfo = pOperator->info; - SSortHandle* pHandle = pInfo->pSortHandle; + SSortHandle* pHandle = pInfo->pSortHandle; SSDataBlock* pDataBlock = createOneDataBlock(pInfo->binfo.pRes); blockDataEnsureCapacity(pDataBlock, pInfo->binfo.capacity); - while(1) { - + while (1) { blockDataCleanup(pDataBlock); while (1) { STupleHandle* pTupleHandle = tsortNextTuple(pHandle); @@ -6078,7 +6297,8 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) { } setInputDataBlock(pOperator, pInfo->binfo.pCtx, pDataBlock, TSDB_ORDER_ASC); - // updateOutputBuf(&pInfo->binfo, &pAggInfo->bufCapacity, pBlock->info.rows * pAggInfo->resultRowFactor, pOperator->pRuntimeEnv, true); + // updateOutputBuf(&pInfo->binfo, &pAggInfo->bufCapacity, pBlock->info.rows * pAggInfo->resultRowFactor, + // pOperator->pRuntimeEnv, true); doMergeImpl(pOperator, pOperator->numOfOutput, pDataBlock); // flush to tuple store, and after all data have been handled, return to upstream node or sink node } @@ -6091,29 +6311,27 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) { // next group info data pInfo->binfo.pRes->info.rows += numOfRows; - return (pInfo->binfo.pRes->info.rows > 0)? pInfo->binfo.pRes:NULL; + return (pInfo->binfo.pRes->info.rows > 0) ? pInfo->binfo.pRes : NULL; } -static SSDataBlock* doSortedMerge(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSortedMergeOperatorInfo* pInfo = pOperator->info; if (pOperator->status == OP_RES_TO_RETURN) { return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pInfo->hasVarCol, pInfo->binfo.capacity); } - SSchema* p = blockDataExtractSchema(pInfo->binfo.pRes, NULL); int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->orderInfo, pInfo->nullFirst, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, - numOfBufPage, p, pInfo->binfo.pRes->info.numOfCols, "GET_TASKID(pTaskInfo)"); + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, + pInfo->binfo.pRes, "GET_TASKID(pTaskInfo)"); - taosMemoryFreeClear(p); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); - for(int32_t i = 0; i < pOperator->numOfDownstream; ++i) { + for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) { SGenericSource* ps = taosMemoryCalloc(1, sizeof(SGenericSource)); ps->param = pOperator->pDownstream[i]; tsortAddSource(pInfo->pSortHandle, ps); @@ -6128,30 +6346,8 @@ static SSDataBlock* doSortedMerge(SOperatorInfo *pOperator, bool* newgroup) { return doMerge(pOperator); } -static SArray* createBlockOrder(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pOrderVal) { - SArray* pOrderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); - - size_t numOfOrder = taosArrayGetSize(pOrderVal); - for (int32_t j = 0; j < numOfOrder; ++j) { - SBlockOrderInfo orderInfo = {0}; - SOrder* pOrder = taosArrayGet(pOrderVal, j); - orderInfo.order = pOrder->order; - - for (int32_t i = 0; i < numOfCols; ++i) { - SExprInfo* pExpr = &pExprInfo[i]; - if (pExpr->base.resSchema.colId == pOrder->col.colId) { - orderInfo.colIndex = i; - break; - } - } - - taosArrayPush(pOrderInfo, &orderInfo); - } - - return pOrderInfo; -} - -static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGroupInfo, SSortedMergeOperatorInfo* pInfo) { +static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGroupInfo, + SSortedMergeOperatorInfo* pInfo) { if (pGroupInfo == NULL || taosArrayGetSize(pGroupInfo) == 0) { return 0; } @@ -6164,10 +6360,10 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr return TSDB_CODE_OUT_OF_MEMORY; } - size_t numOfGroupCol = taosArrayGetSize(pInfo->groupInfo); - for(int32_t i = 0; i < numOfGroupCol; ++i) { + size_t numOfGroupCol = taosArrayGetSize(pInfo->groupInfo); + for (int32_t i = 0; i < numOfGroupCol; ++i) { SColumn* pCol = taosArrayGet(pGroupInfo, i); - for(int32_t j = 0; j < numOfCols; ++j) { + for (int32_t j = 0; j < numOfCols; ++j) { SExprInfo* pe = &pExprInfo[j]; if (pe->base.resSchema.colId == pCol->colId) { taosArrayPush(plist, pCol); @@ -6187,8 +6383,8 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr } int32_t offset = 0; - char *start = (char*)(pInfo->groupVal + (POINTER_BYTES * numOfGroupCol)); - for(int32_t i = 0; i < numOfGroupCol; ++i) { + char* start = (char*)(pInfo->groupVal + (POINTER_BYTES * numOfGroupCol)); + for (int32_t i = 0; i < numOfGroupCol; ++i) { pInfo->groupVal[i] = start + offset; SColumn* pCol = taosArrayGet(plist, i); offset += pCol->bytes; @@ -6199,14 +6395,16 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr return TSDB_CODE_SUCCESS; } -SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, + int32_t num, SArray* pSortInfo, SArray* pGroupInfo, + SExecTaskInfo* pTaskInfo) { SSortedMergeOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortedMergeOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->binfo.pCtx = createSqlFunctionCtx_rv(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset); + pInfo->binfo.pCtx = createSqlFunctionCtx_rv(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset); initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); if (pInfo->binfo.pCtx == NULL || pInfo->binfo.pRes == NULL) { @@ -6224,25 +6422,25 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t goto _error; } -// pInfo->resultRowFactor = (int32_t)(getRowNumForMultioutput(pRuntimeEnv->pQueryAttr, -// pRuntimeEnv->pQueryAttr->topBotQuery, false)); - pInfo->sortBufSize = 1024 * 16; // 1MB - pInfo->bufPageSize = 1024; - pInfo->orderInfo = createBlockOrder(pExprInfo, num, pOrderVal); + // pInfo->resultRowFactor = (int32_t)(getRowNumForMultioutput(pRuntimeEnv->pQueryAttr, + // pRuntimeEnv->pQueryAttr->topBotQuery, false)); + pInfo->sortBufSize = 1024 * 16; // 1MB + pInfo->bufPageSize = 1024; + pInfo->pSortInfo = pSortInfo; pInfo->binfo.capacity = blockDataGetCapacityInRow(pInfo->binfo.pRes, pInfo->bufPageSize); - pOperator->name = "SortedMerge"; + pOperator->name = "SortedMerge"; // pOperator->operatorType = OP_SortedMerge; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = num; - pOperator->pExpr = pExprInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = num; + pOperator->pExpr = pExprInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->getNextFn = doSortedMerge; - pOperator->closeFn = destroySortedMergeOperatorInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->getNextFn = doSortedMerge; + pOperator->closeFn = destroySortedMergeOperatorInfo; code = appendDownstream(pOperator, downstream, numOfDownstream); if (code != TSDB_CODE_SUCCESS) { @@ -6251,7 +6449,7 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t return pOperator; - _error: +_error: if (pInfo != NULL) { destroySortedMergeOperatorInfo(pInfo, num); } @@ -6262,42 +6460,42 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t return NULL; } -static SSDataBlock* doSort(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SOrderOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SSortOperatorInfo* pInfo = pOperator->info; + bool hasVarCol = pInfo->pDataBlock->info.hasVarCol; + if (pOperator->status == OP_RES_TO_RETURN) { - return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, pInfo->hasVarCol, pInfo->numOfRowsInRes); + return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, hasVarCol, pInfo->numOfRowsInRes); } - SSchema* p = blockDataExtractSchema(pInfo->pDataBlock, NULL); int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->orderInfo, pInfo->nullFirst, SORT_SINGLESOURCE_SORT, pInfo->bufPageSize, - numOfBufPage, p, pInfo->pDataBlock->info.numOfCols, "GET_TASKID(pTaskInfo)"); + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, pInfo->bufPageSize, numOfBufPage, + pInfo->pDataBlock, "GET_TASKID(pTaskInfo)"); - taosMemoryFreeClear(p); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); SGenericSource* ps = taosMemoryCalloc(1, sizeof(SGenericSource)); - ps->param = pOperator; + ps->param = pOperator->pDownstream[0]; tsortAddSource(pInfo->pSortHandle, ps); - // TODO set error code; int32_t code = tsortOpen(pInfo->pSortHandle); if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, terrno); } pOperator->status = OP_RES_TO_RETURN; - return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, pInfo->hasVarCol, pInfo->numOfRowsInRes); + return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, hasVarCol, pInfo->numOfRowsInRes); } -SOperatorInfo *createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SArray* pOrderVal, SExecTaskInfo* pTaskInfo) { - SOrderOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SOrderOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); +SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, + SExecTaskInfo* pTaskInfo) { + SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -6305,35 +6503,19 @@ SOperatorInfo *createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx return NULL; } - pInfo->sortBufSize = 1024 * 16; // 1MB - pInfo->bufPageSize = 1024; + pInfo->sortBufSize = 1024 * 16; // 1MB, TODO dynamic set the available sort buffer + pInfo->bufPageSize = 1024; pInfo->numOfRowsInRes = 1024; + pInfo->pDataBlock = pResBlock; + pInfo->pSortInfo = pSortInfo; - pInfo->orderInfo = createBlockOrder(pExprInfo, numOfCols, pOrderVal); + pOperator->name = "Sort"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; + pOperator->blockingOptr = true; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; - for(int32_t i = 0; i < numOfCols; ++i) { - if (IS_VAR_DATA_TYPE(pExprInfo[i].base.resSchema.type)) { - pInfo->hasVarCol = true; - break; - } - } - - if (pInfo->orderInfo == NULL || pInfo->pDataBlock == NULL) { - taosMemoryFreeClear(pOperator); - destroyOrderOperatorInfo(pInfo, numOfCols); - taosMemoryFreeClear(pInfo); - - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; - return NULL; - } - - pOperator->name = "Order"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; - pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - - pOperator->pTaskInfo = pTaskInfo; + pOperator->pTaskInfo = pTaskInfo; pOperator->getNextFn = doSort; pOperator->closeFn = destroyOrderOperatorInfo; @@ -6341,12 +6523,10 @@ SOperatorInfo *createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx return pOperator; } -static int32_t getTableScanOrder(STableScanInfo* pTableScanInfo) { - return pTableScanInfo->order; -} +static int32_t getTableScanOrder(STableScanInfo* pTableScanInfo) { return pTableScanInfo->order; } // this is a blocking operator -static int32_t doOpenAggregateOptr(SOperatorInfo *pOperator) { +static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { if (OPTR_IS_OPENED(pOperator)) { return TSDB_CODE_SUCCESS; } @@ -6382,15 +6562,15 @@ static int32_t doOpenAggregateOptr(SOperatorInfo *pOperator) { return TSDB_CODE_SUCCESS; } -static SSDataBlock* getAggregateResult(SOperatorInfo *pOperator, bool* newgroup) { - SAggOperatorInfo *pAggInfo = pOperator->info; +static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator, bool* newgroup) { + SAggOperatorInfo* pAggInfo = pOperator->info; SOptrBasicInfo* pInfo = &pAggInfo->binfo; if (pOperator->status == OP_EXEC_DONE) { return NULL; } - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; pTaskInfo->code = pOperator->_openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS) { return NULL; @@ -6399,38 +6579,38 @@ static SSDataBlock* getAggregateResult(SOperatorInfo *pOperator, bool* newgroup) getNumOfResult(pInfo->pCtx, pOperator->numOfOutput, pInfo->pRes); doSetOperatorCompleted(pOperator); - return (blockDataGetNumOfRows(pInfo->pRes) != 0)? pInfo->pRes:NULL; + return (blockDataGetNumOfRows(pInfo->pRes) != 0) ? pInfo->pRes : NULL; } -static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t *length) { - SAggOperatorInfo *pAggInfo = pOperator->info; - SAggSupporter *pSup = &pAggInfo->aggSup; +static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* length) { + SAggOperatorInfo* pAggInfo = pOperator->info; + SAggSupporter* pSup = &pAggInfo->aggSup; int32_t size = taosHashGetSize(pSup->pResultRowHashTable); - size_t keyLen = POINTER_BYTES; // estimate the key length + size_t keyLen = POINTER_BYTES; // estimate the key length int32_t totalSize = sizeof(int32_t) + size * (sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize); *result = taosMemoryCalloc(1, totalSize); - if(*result == NULL){ + if (*result == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return; } *(int32_t*)(*result) = size; int32_t offset = sizeof(int32_t); - void *pIter = taosHashIterate(pSup->pResultRowHashTable, NULL); + void* pIter = taosHashIterate(pSup->pResultRowHashTable, NULL); while (pIter) { - void *key = taosHashGetKey(pIter, &keyLen); - SResultRow **p1 = (SResultRow **)pIter; + void* key = taosHashGetKey(pIter, &keyLen); + SResultRow** p1 = (SResultRow**)pIter; // recalculate the result size int32_t realTotalSize = offset + sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize; - if (realTotalSize > totalSize){ - char *tmp = taosMemoryRealloc(*result, realTotalSize); - if (tmp == NULL){ + if (realTotalSize > totalSize) { + char* tmp = taosMemoryRealloc(*result, realTotalSize); + if (tmp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(*result); *result = NULL; return; - }else{ + } else { *result = tmp; } } @@ -6449,32 +6629,32 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char **result, int32_t pIter = taosHashIterate(pSup->pResultRowHashTable, pIter); } - if(length) { + if (length) { *length = offset; } return; } -static bool aggDecodeResultRow(SOperatorInfo* pOperator, char *result, int32_t length) { - if (!result || length <= 0){ +static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t length) { + if (!result || length <= 0) { return false; } - SAggOperatorInfo *pAggInfo = pOperator->info; - SAggSupporter *pSup = &pAggInfo->aggSup; - SOptrBasicInfo *pInfo = &pAggInfo->binfo; + SAggOperatorInfo* pAggInfo = pOperator->info; + SAggSupporter* pSup = &pAggInfo->aggSup; + SOptrBasicInfo* pInfo = &pAggInfo->binfo; // int32_t size = taosHashGetSize(pSup->pResultRowHashTable); int32_t count = *(int32_t*)(result); int32_t offset = sizeof(int32_t); - while(count-- > 0 && length > offset){ + while (count-- > 0 && length > offset) { int32_t keyLen = *(int32_t*)(result + offset); offset += sizeof(int32_t); - uint64_t tableGroupId = *(uint64_t *)(result + offset); - SResultRow *resultRow = getNewResultRow_rv(pSup->pResultBuf, tableGroupId, pSup->resultRowSize); - if (!resultRow){ + uint64_t tableGroupId = *(uint64_t*)(result + offset); + SResultRow* resultRow = getNewResultRow_rv(pSup->pResultBuf, tableGroupId, pSup->resultRowSize); + if (!resultRow) { terrno = TSDB_CODE_TSC_INVALID_INPUT; return false; } @@ -6483,7 +6663,7 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char *result, int32_t l offset += keyLen; int32_t valueLen = *(int32_t*)(result + offset); - if (valueLen != pSup->resultRowSize){ + if (valueLen != pSup->resultRowSize) { terrno = TSDB_CODE_TSC_INVALID_INPUT; return false; } @@ -6496,28 +6676,29 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char *result, int32_t l offset += valueLen; initResultRow(resultRow); - - pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = (SResultRowPosition) {.pageId = resultRow->pageId, .offset = resultRow->offset}; + pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = + (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset}; } - if (offset != length){ + if (offset != length) { terrno = TSDB_CODE_TSC_INVALID_INPUT; return false; } return true; } -static SSDataBlock* doMultiTableAggregate(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doMultiTableAggregate(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } SAggOperatorInfo* pAggInfo = pOperator->info; - SOptrBasicInfo* pInfo = &pAggInfo->binfo; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SOptrBasicInfo* pInfo = &pAggInfo->binfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, pAggInfo->binfo.rowCellInfoOffset); + toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, + pAggInfo->binfo.rowCellInfoOffset); if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; @@ -6527,10 +6708,10 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo *pOperator, bool* newgro } // table scan order - int32_t order = TSDB_ORDER_ASC; + int32_t order = TSDB_ORDER_ASC; SOperatorInfo* downstream = pOperator->pDownstream[0]; - while(1) { + while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -6539,11 +6720,11 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo *pOperator, bool* newgro break; } -// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfOutput); -// if (downstream->operatorType == OP_TableScan) { -// STableScanInfo* pScanInfo = downstream->info; -// order = getTableScanOrder(pScanInfo); -// } + // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfOutput); + // if (downstream->operatorType == OP_TableScan) { + // STableScanInfo* pScanInfo = downstream->info; + // order = getTableScanOrder(pScanInfo); + // } // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order); @@ -6556,8 +6737,9 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo *pOperator, bool* newgro key = pBlock->info.window.skey; TSKEY_MIN_SUB(key, -1); } - - setExecutionContext(pOperator->numOfOutput, pAggInfo->current->groupIndex, key, pTaskInfo, pAggInfo->current, pAggInfo); + + setExecutionContext(pOperator->numOfOutput, pAggInfo->current->groupIndex, key, pTaskInfo, pAggInfo->current, + pAggInfo); doAggregateImpl(pOperator, 0, pInfo->pCtx); } @@ -6566,7 +6748,8 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo *pOperator, bool* newgro updateNumOfRowsInResultRows(pInfo->pCtx, pOperator->numOfOutput, &pInfo->resultRowInfo, pInfo->rowCellInfoOffset); initGroupResInfo(&pAggInfo->groupResInfo, &pInfo->resultRowInfo); - toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, pAggInfo->binfo.rowCellInfoOffset); + toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, + pAggInfo->binfo.rowCellInfoOffset); if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -6575,9 +6758,9 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo *pOperator, bool* newgro return pInfo->pRes; } -static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) { SProjectOperatorInfo* pProjectInfo = pOperator->info; - SOptrBasicInfo *pInfo = &pProjectInfo->binfo; + SOptrBasicInfo* pInfo = &pProjectInfo->binfo; SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); @@ -6588,16 +6771,16 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) *newgroup = true; // todo dynamic set tags -// if (pTableQueryInfo != NULL) { -// setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput); -// } + // if (pTableQueryInfo != NULL) { + // setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput); + // } // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC); blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows); projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput); - if (pRes->info.rows >= pProjectInfo->binfo.capacity*0.8) { + if (pRes->info.rows >= pProjectInfo->binfo.capacity * 0.8) { copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); resetResultRowEntryResult(pInfo->pCtx, pOperator->numOfOutput); return pRes; @@ -6606,7 +6789,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) SOperatorInfo* downstream = pOperator->pDownstream[0]; - while(1) { + while (1) { bool prevVal = *newgroup; // The downstream exec may change the value of the newgroup, so use a local variable instead. @@ -6626,7 +6809,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) if (pRes->info.rows > 0) { pProjectInfo->existDataBlock = pBlock; break; - } else { // init output buffer for a new group data + } else { // init output buffer for a new group data initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfOutput); } } @@ -6647,18 +6830,18 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) } } -// copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); - return (pInfo->pRes->info.rows > 0)? pInfo->pRes:NULL; + // copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); + return (pInfo->pRes->info.rows > 0) ? pInfo->pRes : NULL; } -static SSDataBlock* doLimit(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doLimit(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } SLimitOperatorInfo* pInfo = pOperator->info; - SSDataBlock* pBlock = NULL; + SSDataBlock* pBlock = NULL; SOperatorInfo* pDownstream = pOperator->pDownstream[0]; while (1) { @@ -6675,7 +6858,7 @@ static SSDataBlock* doLimit(SOperatorInfo *pOperator, bool* newgroup) { break; } else if (pInfo->currentOffset >= pBlock->info.rows) { pInfo->currentOffset -= pBlock->info.rows; - } else { // TODO handle the data movement + } else { // TODO handle the data movement int32_t remain = (int32_t)(pBlock->info.rows - pInfo->currentOffset); pBlock->info.rows = remain; @@ -6703,46 +6886,15 @@ static SSDataBlock* doLimit(SOperatorInfo *pOperator, bool* newgroup) { 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) { +static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { if (OPTR_IS_OPENED(pOperator)) { return TSDB_CODE_SUCCESS; } STableIntervalOperatorInfo* pInfo = pOperator->info; - // int32_t order = pQueryAttr->order.order; - // STimeWindow win = pQueryAttr->window; + int32_t order = TSDB_ORDER_ASC; + // STimeWindow win = {0}; bool newgroup = false; SOperatorInfo* downstream = pOperator->pDownstream[0]; @@ -6756,41 +6908,99 @@ 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, TSDB_ORDER_ASC); + setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0); } closeAllResultRows(&pInfo->binfo.resultRowInfo); - finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset); + finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, + &pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset); initGroupResInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo); OPTR_SET_OPENED(pOperator); return TSDB_CODE_SUCCESS; } -static SSDataBlock* doIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgroup) { STableIntervalOperatorInfo* pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_EXEC_DONE) { 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; } blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset); + 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)) { doSetOperatorCompleted(pOperator); } - return pInfo->binfo.pRes->info.rows == 0? NULL:pInfo->binfo.pRes; + return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; +} + +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; + } + + // 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); + + 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) { @@ -6802,7 +7012,7 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { -// toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -6811,13 +7021,13 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { return pIntervalInfo->binfo.pRes; } - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + int32_t order = pQueryAttr->order.order; STimeWindow win = pQueryAttr->window; SOperatorInfo* downstream = pOperator->pDownstream[0]; - while(1) { + while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -6826,7 +7036,7 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { break; } -// setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); + // setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); @@ -6843,27 +7053,27 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { finalizeQueryResult(pIntervalInfo->binfo.pCtx, pOperator->numOfOutput); initGroupResInfo(&pRuntimeEnv->groupResInfo, &pIntervalInfo->binfo.resultRowInfo); -// toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } - return pIntervalInfo->binfo.pRes->info.rows == 0? NULL:pIntervalInfo->binfo.pRes; + return pIntervalInfo->binfo.pRes->info.rows == 0 ? NULL : pIntervalInfo->binfo.pRes; } -static SSDataBlock* doSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { int64_t st = taosGetTimestampUs(); -// copyToSDataBlock(NULL, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); + // copyToSDataBlock(NULL, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { doSetOperatorCompleted(pOperator); } @@ -6871,11 +7081,11 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgroup } STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; + int32_t order = pQueryAttr->order.order; SOperatorInfo* downstream = pOperator->pDownstream[0]; - while(1) { + while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -6887,7 +7097,7 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgroup // the pDataBlock are always the same one, no need to call this again STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; -// setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); + // setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey); @@ -6895,11 +7105,11 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgroup } pOperator->status = OP_RES_TO_RETURN; - pQueryAttr->order.order = order; // TODO : restore the order + pQueryAttr->order.order = order; // TODO : restore the order doCloseAllTimeWindow(pRuntimeEnv); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); -// copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); + // copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -6907,16 +7117,16 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgroup return pIntervalInfo->binfo.pRes; } -static SSDataBlock* doAllSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doAllSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { -// copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); + // copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -6925,11 +7135,11 @@ static SSDataBlock* doAllSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgr } STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; + int32_t order = pQueryAttr->order.order; SOperatorInfo* downstream = pOperator->pDownstream[0]; - while(1) { + while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -6941,7 +7151,7 @@ static SSDataBlock* doAllSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgr // the pDataBlock are always the same one, no need to call this again STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; -// setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); + // setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey); @@ -6949,35 +7159,35 @@ static SSDataBlock* doAllSTableIntervalAgg(SOperatorInfo *pOperator, bool* newgr } pOperator->status = OP_RES_TO_RETURN; - pQueryAttr->order.order = order; // TODO : restore the order + pQueryAttr->order.order = order; // TODO : restore the order doCloseAllTimeWindow(pRuntimeEnv); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); int64_t st = taosGetTimestampUs(); -// copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); + // copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } -// SQInfo* pQInfo = pRuntimeEnv->qinfo; -// pQInfo->summary.firstStageMergeTime += (taosGetTimestampUs() - st); + // SQInfo* pQInfo = pRuntimeEnv->qinfo; + // pQInfo->summary.firstStageMergeTime += (taosGetTimestampUs() - st); return pIntervalInfo->binfo.pRes; } -static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { +static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorInfo* pInfo, SSDataBlock* pSDataBlock) { STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; - STableQueryInfo* item = pRuntimeEnv->current; + STableQueryInfo* item = pRuntimeEnv->current; SColumnInfoData* pColInfoData = taosArrayGet(pSDataBlock->pDataBlock, pInfo->colIndex); SOptrBasicInfo* pBInfo = &pInfo->binfo; bool masterScan = IS_MAIN_SCAN(pRuntimeEnv); - int16_t bytes = pColInfoData->info.bytes; - int16_t type = pColInfoData->info.type; + int16_t bytes = pColInfoData->info.bytes; + int16_t type = pColInfoData->info.type; SColumnInfoData* pTsColInfoData = taosArrayGet(pSDataBlock->pDataBlock, 0); - TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; + TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { pInfo->reptScan = true; taosMemoryFreeClear(pInfo->prevData); @@ -7000,7 +7210,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } else if (memcmp(pInfo->prevData, val, bytes) == 0) { pInfo->curWindow.ekey = tsList[j]; pInfo->numOfRows += 1; - //pInfo->start = j; + // pInfo->start = j; if (j == 0 && pInfo->start != 0) { pInfo->numOfRows = 1; pInfo->start = 0; @@ -7008,49 +7218,48 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } else { SResultRow* pResult = NULL; pInfo->curWindow.ekey = pInfo->curWindow.skey; - int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.uid, &pInfo->curWindow, masterScan, - &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, - pBInfo->rowCellInfoOffset); + int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.uid, + &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, + pOperator->numOfOutput, pBInfo->rowCellInfoOffset); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); } -// doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, -// pSDataBlock->info.rows, pOperator->numOfOutput); + // doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, + // pSDataBlock->info.rows, pOperator->numOfOutput); pInfo->curWindow.skey = tsList[j]; pInfo->curWindow.ekey = tsList[j]; memcpy(pInfo->prevData, val, bytes); pInfo->numOfRows = 1; pInfo->start = j; - } } SResultRow* pResult = NULL; pInfo->curWindow.ekey = pInfo->curWindow.skey; - int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.uid, &pInfo->curWindow, masterScan, - &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, + int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.uid, &pInfo->curWindow, + masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); } -// doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, -// pSDataBlock->info.rows, pOperator->numOfOutput); + // doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, + // pSDataBlock->info.rows, pOperator->numOfOutput); } -static SSDataBlock* doStateWindowAgg(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } SStateWindowOperatorInfo* pWindowInfo = pOperator->info; - SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; + SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { -// toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); + // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; @@ -7059,9 +7268,9 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo *pOperator, bool* newgroup) { return pBInfo->pRes; } - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - STimeWindow win = pQueryAttr->window; + STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + int32_t order = pQueryAttr->order.order; + STimeWindow win = pQueryAttr->window; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); @@ -7075,7 +7284,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo *pOperator, bool* newgroup) { if (pWindowInfo->colIndex == -1) { pWindowInfo->colIndex = getGroupbyColumnIndex(pRuntimeEnv->pQueryAttr->pGroupbyExpr, pBlock); } - doStateWindowAggImpl(pOperator, pWindowInfo, pBlock); + doStateWindowAggImpl(pOperator, pWindowInfo, pBlock); } // restore the value @@ -7088,36 +7297,38 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo *pOperator, bool* newgroup) { finalizeQueryResult(pBInfo->pCtx, pOperator->numOfOutput); initGroupResInfo(&pRuntimeEnv->groupResInfo, &pBInfo->resultRowInfo); -// toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); + // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } - return pBInfo->pRes->info.rows == 0? NULL:pBInfo->pRes; + return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; } -static SSDataBlock* doSessionWindowAgg(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } - SSessionAggOperatorInfo* pWindowInfo = pOperator->info; - SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; + SSessionAggOperatorInfo* pInfo = pOperator->info; + SOptrBasicInfo* pBInfo = &pInfo->binfo; 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; + toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, + pBInfo->rowCellInfoOffset); + if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { + doSetOperatorCompleted(pOperator); + return NULL; } return pBInfo->pRes; } - int32_t order = TSDB_ORDER_ASC; + int32_t order = TSDB_ORDER_ASC; SOperatorInfo* downstream = pOperator->pDownstream[0]; - while(1) { + while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -7127,42 +7338,46 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo *pOperator, bool* newgroup) // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pBInfo->pCtx, pBlock, order); - doSessionWindowAggImpl(pOperator, pWindowInfo, pBlock); + doSessionWindowAggImpl(pOperator, pInfo, pBlock); } // restore the value pOperator->status = OP_RES_TO_RETURN; closeAllResultRows(&pBInfo->resultRowInfo); -// setTaskStatus(pOperator->pTaskInfo, QUERY_COMPLETED); - finalizeQueryResult(pBInfo->pCtx, pOperator->numOfOutput); + finalizeMultiTupleQueryResult(pBInfo->pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pBInfo->resultRowInfo, + pBInfo->rowCellInfoOffset); -// initGroupResInfo(&pBInfo->groupResInfo, &pBInfo->resultRowInfo); -// toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); - if (pBInfo->pRes->info.rows == 0/* || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)*/) { - pOperator->status = OP_EXEC_DONE; + initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo); + + blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity); + toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, + pBInfo->rowCellInfoOffset); + if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { + doSetOperatorCompleted(pOperator); } - return pBInfo->pRes->info.rows == 0? NULL:pBInfo->pRes; + return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; } -static SSDataBlock* hashGroupbyAggregate(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } - SGroupbyOperatorInfo *pInfo = pOperator->info; + SGroupbyOperatorInfo* pInfo = pOperator->info; 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)) { + 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; } - int32_t order = TSDB_ORDER_ASC; + int32_t order = TSDB_ORDER_ASC; SOperatorInfo* downstream = pOperator->pDownstream[0]; - while(1) { + while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -7172,23 +7387,26 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo *pOperator, bool* newgrou // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); -// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput); + // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput); doHashGroupbyAgg(pOperator, pBlock); } pOperator->status = OP_RES_TO_RETURN; closeAllResultRows(&pInfo->binfo.resultRowInfo); - finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset); -// if (!pRuntimeEnv->pQueryAttr->stableQuery) { // finalize include the update of result rows -// finalizeQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput); -// } else { -// updateNumOfRowsInResultRows(pInfo->binfo.pCtx, pOperator->numOfOutput, &pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset); -// } + finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, + &pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset); + // if (!pRuntimeEnv->pQueryAttr->stableQuery) { // finalize include the update of result rows + // finalizeQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput); + // } else { + // updateNumOfRowsInResultRows(pInfo->binfo.pCtx, pOperator->numOfOutput, &pInfo->binfo.resultRowInfo, + // pInfo->binfo.rowCellInfoOffset); + // } blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); initGroupResInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset); + 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; } @@ -7196,10 +7414,12 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo *pOperator, bool* newgrou return pInfo->binfo.pRes; } -static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo *pInfo, SResultInfo* pResultInfo, bool* newgroup, SExecTaskInfo* pTaskInfo) { +static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo* pInfo, SResultInfo* pResultInfo, bool* newgroup, + SExecTaskInfo* pTaskInfo) { pInfo->totalInputRows = pInfo->existNewGroupBlock->info.rows; - int64_t ekey = Q_STATUS_EQUAL(pTaskInfo->status, TASK_COMPLETED)? pTaskInfo->window.ekey:pInfo->existNewGroupBlock->info.window.ekey; + int64_t ekey = Q_STATUS_EQUAL(pTaskInfo->status, TASK_COMPLETED) ? pTaskInfo->window.ekey + : pInfo->existNewGroupBlock->info.window.ekey; taosResetFillInfo(pInfo->pFillInfo, getFillInfoStart(pInfo->pFillInfo)); taosFillSetStartInfo(pInfo->pFillInfo, pInfo->existNewGroupBlock->info.rows, ekey); @@ -7210,7 +7430,8 @@ static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo *pInfo, SResult *newgroup = true; } -static void doHandleRemainBlockFromNewGroup(SFillOperatorInfo *pInfo, SResultInfo *pResultInfo, bool *newgroup, SExecTaskInfo* pTaskInfo) { +static void doHandleRemainBlockFromNewGroup(SFillOperatorInfo* pInfo, SResultInfo* pResultInfo, bool* newgroup, + SExecTaskInfo* pTaskInfo) { if (taosFillHasMoreResults(pInfo->pFillInfo)) { *newgroup = false; doFillTimeIntervalGapsInResults(pInfo->pFillInfo, pInfo->pRes, (int32_t)pResultInfo->capacity, pInfo->p); @@ -7225,9 +7446,9 @@ static void doHandleRemainBlockFromNewGroup(SFillOperatorInfo *pInfo, SResultInf } } -static SSDataBlock* doFill(SOperatorInfo *pOperator, bool* newgroup) { - SFillOperatorInfo *pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; +static SSDataBlock* doFill(SOperatorInfo* pOperator, bool* newgroup) { + SFillOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SResultInfo* pResultInfo = &pOperator->resultInfo; blockDataCleanup(pInfo->pRes); @@ -7241,7 +7462,7 @@ static SSDataBlock* doFill(SOperatorInfo *pOperator, bool* newgroup) { } SOperatorInfo* pDownstream = pOperator->pDownstream[0]; - while(1) { + while (1) { publishOperatorProfEvent(pDownstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = pDownstream->getNextFn(pDownstream, newgroup); publishOperatorProfEvent(pDownstream, QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -7300,7 +7521,7 @@ static SSDataBlock* doFill(SOperatorInfo *pOperator, bool* newgroup) { // todo set the attribute of query scan count static int32_t getNumOfScanTimes(STaskAttr* pQueryAttr) { - for(int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { + for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]); if (functionId == FUNCTION_STDDEV || functionId == FUNCTION_PERCT) { return 2; @@ -7320,7 +7541,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { } if (pOperator->pDownstream != NULL) { - for(int32_t i = 0; i < pOperator->numOfDownstream; ++i) { + for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) { destroyOperatorInfo(pOperator->pDownstream[i]); } @@ -7332,13 +7553,13 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { taosMemoryFreeClear(pOperator); } -int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx *pCtx, int32_t numOfOutput, const char* pKey) { +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 || @@ -7378,14 +7599,14 @@ static STableQueryInfo* initTableQueryInfo(const STableGroupInfo* pTableGroupInf } int32_t index = 0; - for(int32_t i = 0; i < taosArrayGetSize(pTableGroupInfo->pGroupList); ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pTableGroupInfo->pGroupList); ++i) { SArray* pa = taosArrayGetP(pTableGroupInfo->pGroupList, i); - for(int32_t j = 0; j < taosArrayGetSize(pa); ++j) { + for (int32_t j = 0; j < taosArrayGetSize(pa); ++j) { STableKeyInfo* pk = taosArrayGet(pa, j); STableQueryInfo* pTQueryInfo = &pTableQueryInfo[index++]; - pTQueryInfo->uid = pk->uid; - pTQueryInfo->lastKey = pk->lastKey; + pTQueryInfo->uid = pk->uid; + pTQueryInfo->lastKey = pk->lastKey; pTQueryInfo->groupIndex = i; } } @@ -7395,10 +7616,11 @@ static STableQueryInfo* initTableQueryInfo(const STableGroupInfo* pTableGroupInf return pTableQueryInfo; } -SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, - SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { +SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, + SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, + const STableGroupInfo* pTableGroupInfo) { SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7434,7 +7656,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* } return pOperator; - _error: +_error: destroyAggOperatorInfo(pInfo, numOfCols); taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -7453,41 +7675,41 @@ static void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput) { } void destroyBasicOperatorInfo(void* param, int32_t numOfOutput) { - SOptrBasicInfo* pInfo = (SOptrBasicInfo*) param; + SOptrBasicInfo* pInfo = (SOptrBasicInfo*)param; doDestroyBasicInfo(pInfo, numOfOutput); } void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput) { - SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*) param; + SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*)param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); taosMemoryFreeClear(pInfo->prevData); } void destroyAggOperatorInfo(void* param, int32_t numOfOutput) { - SAggOperatorInfo* pInfo = (SAggOperatorInfo*) param; + SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); } void destroyIntervalOperatorInfo(void* param, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*) param; + STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*)param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); cleanupAggSup(&pInfo->aggSup); } void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) { - SSessionAggOperatorInfo* pInfo = (SSessionAggOperatorInfo*) param; + SSessionAggOperatorInfo* pInfo = (SSessionAggOperatorInfo*)param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); } void destroySFillOperatorInfo(void* param, int32_t numOfOutput) { - SFillOperatorInfo* pInfo = (SFillOperatorInfo*) param; + SFillOperatorInfo* pInfo = (SFillOperatorInfo*)param; pInfo->pFillInfo = taosDestroyFillInfo(pInfo->pFillInfo); pInfo->pRes = blockDataDestroy(pInfo->pRes); taosMemoryFreeClear(pInfo->p); } void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput) { - SGroupbyOperatorInfo* pInfo = (SGroupbyOperatorInfo*) param; + SGroupbyOperatorInfo* pInfo = (SGroupbyOperatorInfo*)param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); taosMemoryFreeClear(pInfo->keyBuf); taosArrayDestroy(pInfo->pGroupCols); @@ -7495,29 +7717,29 @@ void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput) { } static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) { - SProjectOperatorInfo* pInfo = (SProjectOperatorInfo*) param; + SProjectOperatorInfo* pInfo = (SProjectOperatorInfo*)param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); } static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) { - STagScanInfo* pInfo = (STagScanInfo*) param; + STagScanInfo* pInfo = (STagScanInfo*)param; pInfo->pRes = blockDataDestroy(pInfo->pRes); } static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { - SOrderOperatorInfo* pInfo = (SOrderOperatorInfo*) param; + SSortOperatorInfo* pInfo = (SSortOperatorInfo*)param; pInfo->pDataBlock = blockDataDestroy(pInfo->pDataBlock); - taosArrayDestroy(pInfo->orderInfo); + taosArrayDestroy(pInfo->pSortInfo); } static void destroyConditionOperatorInfo(void* param, int32_t numOfOutput) { - SFilterOperatorInfo* pInfo = (SFilterOperatorInfo*) param; + SFilterOperatorInfo* pInfo = (SFilterOperatorInfo*)param; doDestroyFilterInfo(pInfo->pFilterInfo, pInfo->numOfFilterCols); } static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) { - SDistinctOperatorInfo* pInfo = (SDistinctOperatorInfo*) param; + SDistinctOperatorInfo* pInfo = (SDistinctOperatorInfo*)param; taosHashCleanup(pInfo->pSet); taosMemoryFreeClear(pInfo->buf); taosArrayDestroy(pInfo->pDistinctDataInfo); @@ -7525,7 +7747,7 @@ static void destroyDistinctOperatorInfo(void* param, int32_t numOfOutput) { } static void destroySysTableScannerOperatorInfo(void* param, int32_t numOfOutput) { - SSysTableScanInfo* pInfo = (SSysTableScanInfo*) param; + SSysTableScanInfo* pInfo = (SSysTableScanInfo*)param; tsem_destroy(&pInfo->ready); blockDataDestroy(pInfo->pRes); @@ -7535,7 +7757,7 @@ static void destroySysTableScannerOperatorInfo(void* param, int32_t numOfOutput) } void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) { - SExchangeInfo* pExInfo = (SExchangeInfo*) param; + SExchangeInfo* pExInfo = (SExchangeInfo*)param; taosArrayDestroy(pExInfo->pSources); taosArrayDestroy(pExInfo->pSourceDataInfo); if (pExInfo->pResult != NULL) { @@ -7545,28 +7767,31 @@ void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) { tsem_destroy(&pExInfo->ready); } -SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { +SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, + SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, + const STableGroupInfo* pTableGroupInfo) { SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); int32_t numOfRows = 1; - 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); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; } - size_t tableGroup = taosArrayGetSize(pTableGroupInfo->pGroupList); + size_t tableGroup = taosArrayGetSize(pTableGroupInfo->pGroupList); initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)tableGroup); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "MultiTableAggregate"; + pOperator->name = "MultiTableAggregate"; // pOperator->operatorType = OP_MultiTableAggregate; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = numOfCols; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + pOperator->pTaskInfo = pTaskInfo; pOperator->getNextFn = doMultiTableAggregate; pOperator->closeFn = destroyAggOperatorInfo; @@ -7581,9 +7806,10 @@ _error: return NULL; } -SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, + SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { SProjectOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SProjectOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7594,8 +7820,8 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p goto _error; } -// initResultRowInfo(&pBInfo->resultRowInfo, 8); -// setFunctionResultOutput(pBInfo, MAIN_SCAN); + // initResultRowInfo(&pBInfo->resultRowInfo, 8); + // setFunctionResultOutput(pBInfo, MAIN_SCAN); pOperator->name = "ProjectOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; @@ -7608,7 +7834,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p pOperator->getNextFn = doProjectOperation; pOperator->closeFn = destroyProjectOperatorInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->pTaskInfo = pTaskInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -7616,92 +7842,63 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p return pOperator; - _error: +_error: pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; 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)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->limit = *pLimit; - pInfo->currentOffset = pLimit->offset; + pInfo->limit = *pLimit; + pInfo->currentOffset = pLimit->offset; pOperator->name = "LimitOperator"; -// pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LIMIT; + // 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); + int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: + +_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, +SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, + SSDataBlock* pResBlock, SInterval* pInterval, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } pInfo->order = TSDB_ORDER_ASC; - pInfo->precision = TSDB_TIME_PRECISION_MILLI; - pInfo->win = pTaskInfo->window; 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); -// pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); - if (code != TSDB_CODE_SUCCESS/* || pInfo->pTableQueryInfo == NULL*/) { + initExecTimeWindowInfo(&pInfo->timeWindowData, &pInfo->win); + + // pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); + if (code != TSDB_CODE_SUCCESS /* || pInfo->pTableQueryInfo == NULL*/) { goto _error; } @@ -7716,7 +7913,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; pOperator->_openFn = doOpenIntervalAgg; - pOperator->getNextFn = doIntervalAgg; + pOperator->getNextFn = doBuildIntervalResult; + pOperator->getStreamResFn= doStreamIntervalAgg; pOperator->closeFn = destroyIntervalOperatorInfo; code = appendDownstream(pOperator, &downstream, 1); @@ -7726,7 +7924,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* return pOperator; - _error: +_error: destroyIntervalOperatorInfo(pInfo, numOfCols); taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -7734,47 +7932,49 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* return NULL; } -SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { +SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, + SExprInfo* pExpr, int32_t numOfOutput) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); -// pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); -// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); + // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); + // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "AllTimeIntervalAggOperator"; -// pOperator->operatorType = OP_AllTimeWindow; + pOperator->name = "AllTimeIntervalAggOperator"; + // pOperator->operatorType = OP_AllTimeWindow; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->getNextFn = doAllIntervalAgg; pOperator->closeFn = destroyBasicOperatorInfo; - int32_t code = appendDownstream(pOperator, &downstream, 1); + int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; } -SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { +SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, + int32_t numOfOutput) { SStateWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStateWindowOperatorInfo)); - pInfo->colIndex = -1; - pInfo->reptScan = false; -// pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); -// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); + pInfo->colIndex = -1; + pInfo->reptScan = false; + // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); + // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "StateWindowOperator"; -// pOperator->operatorType = OP_StateWindow; + 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->status = OP_NOT_OPENED; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->getNextFn = doStateWindowAgg; pOperator->closeFn = destroyStateWindowOperatorInfo; @@ -7782,38 +7982,42 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper return pOperator; } -SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, + SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo) { SSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSessionAggOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - int32_t code = doInitAggInfoSup(&pInfo->aggSup, pInfo->binfo.pCtx, numOfCols, pTaskInfo->id.str); + int32_t numOfRows = 4096; + int32_t code = + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - pInfo->binfo.pRes = pResBlock; - pInfo->prevTs = INT64_MIN; - pInfo->reptScan = false; - pOperator->name = "SessionWindowAggOperator"; -// pOperator->operatorType = OP_SessionWindow; + pInfo->gap = gap; + pInfo->binfo.pRes = pResBlock; + pInfo->prevTs = INT64_MIN; + pInfo->reptScan = false; + pOperator->name = "SessionWindowAggOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = numOfCols; - pOperator->info = pInfo; - pOperator->getNextFn = doSessionWindowAgg; - pOperator->closeFn = destroySWindowOperatorInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->getNextFn = doSessionWindowAgg; + pOperator->closeFn = destroySWindowOperatorInfo; + pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_error: if (pInfo != NULL) { destroySWindowOperatorInfo(pInfo, numOfCols); } @@ -7824,71 +8028,73 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo return NULL; } -SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { +SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, + SExprInfo* pExpr, int32_t numOfOutput) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); -// pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); -// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); + // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); + // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "MultiTableTimeIntervalOperator"; -// pOperator->operatorType = OP_MultiTableTimeInterval; + pOperator->name = "MultiTableTimeIntervalOperator"; + // pOperator->operatorType = OP_MultiTableTimeInterval; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->getNextFn = doSTableIntervalAgg; pOperator->closeFn = destroyBasicOperatorInfo; - int32_t code = appendDownstream(pOperator, &downstream, 1); + int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; } -SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { +SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, + SExprInfo* pExpr, int32_t numOfOutput) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); -// pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); -// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); + // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); + // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "AllMultiTableTimeIntervalOperator"; -// pOperator->operatorType = OP_AllMultiTableTimeInterval; + pOperator->name = "AllMultiTableTimeIntervalOperator"; + // pOperator->operatorType = OP_AllMultiTableTimeInterval; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->getNextFn = doAllSTableIntervalAgg; pOperator->closeFn = destroyBasicOperatorInfo; - int32_t code = appendDownstream(pOperator, &downstream, 1); + int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; } -static int32_t initGroupOptrInfo(SGroupbyOperatorInfo *pInfo, SArray* pGroupColList) { +static int32_t initGroupOptrInfo(SGroupbyOperatorInfo* pInfo, SArray* pGroupColList) { pInfo->pGroupColVals = taosArrayInit(4, sizeof(SGroupKeys)); if (pInfo->pGroupColVals == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); - for(int32_t i = 0; i < numOfGroupCols; ++i) { + for (int32_t i = 0; i < numOfGroupCols; ++i) { SColumn* pCol = taosArrayGet(pGroupColList, i); pInfo->groupKeyLen += pCol->bytes; struct SGroupKeys key = {0}; - key.bytes = pCol->bytes; - key.type = pCol->type; + key.bytes = pCol->bytes; + key.type = pCol->type; key.isNull = false; - key.pData = taosMemoryCalloc(1, pCol->bytes); + key.pData = taosMemoryCalloc(1, pCol->bytes); if (key.pData == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -7906,10 +8112,11 @@ static int32_t initGroupOptrInfo(SGroupbyOperatorInfo *pInfo, SArray* pGroupColL return TSDB_CODE_SUCCESS; } -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, - SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, + SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, + const STableGroupInfo* pTableGroupInfo) { SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -7923,28 +8130,28 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx goto _error; } - pOperator->name = "GroupbyAggOperator"; + pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; -// pOperator->operatorType = OP_Groupby; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = numOfCols; - pOperator->info = pInfo; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = hashGroupbyAggregate; - pOperator->closeFn = destroyGroupbyOperatorInfo; + pOperator->status = OP_NOT_OPENED; + // pOperator->operatorType = OP_Groupby; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = hashGroupbyAggregate; + pOperator->closeFn = destroyGroupbyOperatorInfo; code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_error: taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); return NULL; } static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t numOfCols, int64_t* fillVal, - STimeWindow win, int32_t capacity, const char* id, SInterval* pInterval, int32_t fillType) { + STimeWindow win, int32_t capacity, const char* id, SInterval* pInterval, int32_t fillType) { struct SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfCols, (int64_t*)fillVal); TSKEY sk = TMIN(win.skey, win.ekey); @@ -7955,9 +8162,8 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t getAlignQueryTimeWindow(pInterval, TSDB_TIME_PRECISION_MILLI, win.skey, sk, ek, &w); int32_t order = TSDB_ORDER_ASC; - pInfo->pFillInfo = - taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval->sliding, - pInterval->slidingUnit, (int8_t)pInterval->precision, fillType, pColInfo, id); + pInfo->pFillInfo = taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval->sliding, + pInterval->slidingUnit, (int8_t)pInterval->precision, fillType, pColInfo, id); pInfo->p = taosMemoryCalloc(numOfCols, POINTER_BYTES); @@ -7968,90 +8174,92 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t } } -SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock, - int32_t fillType, char* fillVal, bool multigroupResult, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, + SInterval* pInterval, SSDataBlock* pResBlock, int32_t fillType, char* fillVal, + bool multigroupResult, SExecTaskInfo* pTaskInfo) { SFillOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SFillOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pInfo->pRes = pResBlock; + pInfo->pRes = pResBlock; pInfo->multigroupResult = multigroupResult; - pInfo->intervalInfo = *pInterval; + pInfo->intervalInfo = *pInterval; SResultInfo* pResultInfo = &pOperator->resultInfo; - int32_t code = initFillInfo(pInfo, pExpr, numOfCols, (int64_t*) fillVal, pTaskInfo->window, pResultInfo->capacity, pTaskInfo->id.str, pInterval, fillType); + int32_t code = initFillInfo(pInfo, pExpr, numOfCols, (int64_t*)fillVal, pTaskInfo->window, pResultInfo->capacity, + pTaskInfo->id.str, pInterval, fillType); if (code != TSDB_CODE_SUCCESS) { goto _error; } - pOperator->name = "FillOperator"; + pOperator->name = "FillOperator"; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; -// pOperator->operatorType = OP_Fill; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfCols; - pOperator->info = pInfo; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doFill; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + // pOperator->operatorType = OP_Fill; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doFill; + pOperator->pTaskInfo = pTaskInfo; - pOperator->closeFn = destroySFillOperatorInfo; + pOperator->closeFn = destroySFillOperatorInfo; code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_error: taosMemoryFreeClear(pOperator); taosMemoryFreeClear(pInfo); return NULL; } -SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput, void* pMerger, bool multigroupResult) { +SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, + int32_t numOfOutput, void* pMerger, bool multigroupResult) { SSLimitOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSLimitOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); -// pInfo->orderColumnList = getResultGroupCheckColumns(pQueryAttr); -// pInfo->slimit = pQueryAttr->slimit; -// pInfo->limit = pQueryAttr->limit; -// pInfo->capacity = pResultInfo->capacity; -// pInfo->threshold = (int64_t)(pInfo->capacity * 0.8); -// pInfo->currentOffset = pQueryAttr->limit.offset; -// pInfo->currentGroupOffset = pQueryAttr->slimit.offset; - pInfo->multigroupResult= multigroupResult; + // pInfo->orderColumnList = getResultGroupCheckColumns(pQueryAttr); + // pInfo->slimit = pQueryAttr->slimit; + // pInfo->limit = pQueryAttr->limit; + // pInfo->capacity = pResultInfo->capacity; + // pInfo->threshold = (int64_t)(pInfo->capacity * 0.8); + // pInfo->currentOffset = pQueryAttr->limit.offset; + // pInfo->currentGroupOffset = pQueryAttr->slimit.offset; + pInfo->multigroupResult = multigroupResult; // TODO refactor int32_t len = 0; - for(int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t i = 0; i < numOfOutput; ++i) { len += pExpr[i].base.resSchema.bytes; } - int32_t numOfCols = (pInfo->orderColumnList != NULL)? (int32_t) taosArrayGetSize(pInfo->orderColumnList):0; + int32_t numOfCols = (pInfo->orderColumnList != NULL) ? (int32_t)taosArrayGetSize(pInfo->orderColumnList) : 0; pInfo->prevRow = taosMemoryCalloc(1, (POINTER_BYTES * numOfCols + len)); int32_t offset = POINTER_BYTES * numOfCols; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { pInfo->prevRow[i] = (char*)pInfo->prevRow + offset; SColIndex* index = taosArrayGet(pInfo->orderColumnList, i); offset += pExpr[index->colIndex].base.resSchema.bytes; } - pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pOperator->resultInfo.capacity); + // pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pOperator->resultInfo.capacity); - - pOperator->name = "SLimitOperator"; + pOperator->name = "SLimitOperator"; // pOperator->operatorType = OP_SLimit; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; -// pOperator->exec = doSLimit; - pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->status = OP_NOT_OPENED; + // pOperator->exec = doSLimit; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->closeFn = destroySlimitOperatorInfo; - int32_t code = appendDownstream(pOperator, &downstream, 1); + int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; } -static SSDataBlock* doTagScan(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doTagScan(SOperatorInfo* pOperator, bool* newgroup) { #if 0 SOperatorInfo* pOperator = (SOperatorInfo*) param; if (pOperator->status == OP_EXEC_DONE) { @@ -8185,7 +8393,7 @@ static SSDataBlock* doTagScan(SOperatorInfo *pOperator, bool* newgroup) { SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput) { STagScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STagScanInfo)); -// pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); + // pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); size_t numOfGroup = GET_NUM_OF_TABLEGROUP(pRuntimeEnv); assert(numOfGroup == 0 || numOfGroup == 1); @@ -8194,26 +8402,26 @@ SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo pInfo->curPos = 0; SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "SeqTableTagScan"; + pOperator->name = "SeqTableTagScan"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; pOperator->getNextFn = doTagScan; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->closeFn = destroyTagScanOperatorInfo; return pOperator; } -static bool initMultiDistinctInfo(SDistinctOperatorInfo *pInfo, SOperatorInfo* pOperator, SSDataBlock *pBlock) { +static bool initMultiDistinctInfo(SDistinctOperatorInfo* pInfo, SOperatorInfo* pOperator, SSDataBlock* pBlock) { if (taosArrayGetSize(pInfo->pDistinctDataInfo) == pOperator->numOfOutput) { - // distinct info already inited + // distinct info already inited return true; } for (int i = 0; i < pOperator->numOfOutput; i++) { -// pInfo->totalBytes += pOperator->pExpr[i].base.colBytes; + // pInfo->totalBytes += pOperator->pExpr[i].base.colBytes; } for (int i = 0; i < pOperator->numOfOutput; i++) { int numOfBlock = (int)(taosArrayGetSize(pBlock->pDataBlock)); @@ -8227,20 +8435,20 @@ static bool initMultiDistinctInfo(SDistinctOperatorInfo *pInfo, SOperatorInfo* p } } pInfo->totalBytes += (int32_t)strlen(MULTI_KEY_DELIM) * (pOperator->numOfOutput); - pInfo->buf = taosMemoryCalloc(1, pInfo->totalBytes); - return taosArrayGetSize(pInfo->pDistinctDataInfo) == pOperator->numOfOutput ? true : false; + pInfo->buf = taosMemoryCalloc(1, pInfo->totalBytes); + return taosArrayGetSize(pInfo->pDistinctDataInfo) == pOperator->numOfOutput ? true : false; } -static void buildMultiDistinctKey(SDistinctOperatorInfo *pInfo, SSDataBlock *pBlock, int32_t rowId) { - char *p = pInfo->buf; - memset(p, 0, pInfo->totalBytes); +static void buildMultiDistinctKey(SDistinctOperatorInfo* pInfo, SSDataBlock* pBlock, int32_t rowId) { + char* p = pInfo->buf; + memset(p, 0, pInfo->totalBytes); for (int i = 0; i < taosArrayGetSize(pInfo->pDistinctDataInfo); i++) { - SDistinctDataInfo* pDistDataInfo = (SDistinctDataInfo *)taosArrayGet(pInfo->pDistinctDataInfo, i); + SDistinctDataInfo* pDistDataInfo = (SDistinctDataInfo*)taosArrayGet(pInfo->pDistinctDataInfo, i); SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, pDistDataInfo->index); - char *val = ((char *)pColDataInfo->pData) + pColDataInfo->info.bytes * rowId; - if (isNull(val, pDistDataInfo->type)) { - p += pDistDataInfo->bytes; + char* val = ((char*)pColDataInfo->pData) + pColDataInfo->info.bytes * rowId; + if (isNull(val, pDistDataInfo->type)) { + p += pDistDataInfo->bytes; continue; } if (IS_VAR_DATA_TYPE(pDistDataInfo->type)) { @@ -8255,18 +8463,18 @@ static void buildMultiDistinctKey(SDistinctOperatorInfo *pInfo, SSDataBlock *pBl } } -static SSDataBlock* hashDistinct(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* hashDistinct(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } SDistinctOperatorInfo* pInfo = pOperator->info; - SSDataBlock* pRes = pInfo->pRes; + SSDataBlock* pRes = pInfo->pRes; pRes->info.rows = 0; SSDataBlock* pBlock = NULL; - - while(1) { + + while (1) { publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC); pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup); publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC); @@ -8279,13 +8487,13 @@ static SSDataBlock* hashDistinct(SOperatorInfo *pOperator, bool* newgroup) { doSetOperatorCompleted(pOperator); break; } - // ensure result output buf + // ensure result output buf if (pRes->info.rows + pBlock->info.rows > pInfo->outputCapacity) { int32_t newSize = pRes->info.rows + pBlock->info.rows; for (int i = 0; i < taosArrayGetSize(pRes->pDataBlock); i++) { SColumnInfoData* pResultColInfoData = taosArrayGet(pRes->pDataBlock, i); - SDistinctDataInfo* pDistDataInfo = taosArrayGet(pInfo->pDistinctDataInfo, i); - char* tmp = taosMemoryRealloc(pResultColInfoData->pData, newSize * pDistDataInfo->bytes); + SDistinctDataInfo* pDistDataInfo = taosArrayGet(pInfo->pDistinctDataInfo, i); + char* tmp = taosMemoryRealloc(pResultColInfoData->pData, newSize * pDistDataInfo->bytes); if (tmp == NULL) { return NULL; } else { @@ -8302,53 +8510,53 @@ static SSDataBlock* hashDistinct(SOperatorInfo *pOperator, bool* newgroup) { taosHashPut(pInfo->pSet, pInfo->buf, pInfo->totalBytes, &dummy, sizeof(dummy)); for (int j = 0; j < taosArrayGetSize(pRes->pDataBlock); j++) { SDistinctDataInfo* pDistDataInfo = taosArrayGet(pInfo->pDistinctDataInfo, j); // distinct meta info - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pDistDataInfo->index); //src - SColumnInfoData* pResultColInfoData = taosArrayGet(pRes->pDataBlock, j); // dist + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pDistDataInfo->index); // src + SColumnInfoData* pResultColInfoData = taosArrayGet(pRes->pDataBlock, j); // dist char* val = ((char*)pColInfoData->pData) + pDistDataInfo->bytes * i; - char *start = pResultColInfoData->pData + pDistDataInfo->bytes * pInfo->pRes->info.rows; + char* start = pResultColInfoData->pData + pDistDataInfo->bytes * pInfo->pRes->info.rows; memcpy(start, val, pDistDataInfo->bytes); } pRes->info.rows += 1; - } + } } if (pRes->info.rows >= pInfo->threshold) { break; } } - return (pInfo->pRes->info.rows > 0)? pInfo->pRes:NULL; + return (pInfo->pRes->info.rows > 0) ? pInfo->pRes : NULL; } -SOperatorInfo* createDistinctOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { +SOperatorInfo* createDistinctOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, + int32_t numOfOutput) { SDistinctOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SDistinctOperatorInfo)); - pInfo->totalBytes = 0; - pInfo->buf = NULL; - pInfo->threshold = tsMaxNumOfDistinctResults; // distinct result threshold - pInfo->outputCapacity = 4096; - pInfo->pDistinctDataInfo = taosArrayInit(numOfOutput, sizeof(SDistinctDataInfo)); + pInfo->totalBytes = 0; + pInfo->buf = NULL; + pInfo->threshold = tsMaxNumOfDistinctResults; // distinct result threshold + pInfo->outputCapacity = 4096; + pInfo->pDistinctDataInfo = taosArrayInit(numOfOutput, sizeof(SDistinctDataInfo)); pInfo->pSet = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - pInfo->pRes = createOutputBuf(pExpr, numOfOutput, (int32_t) pInfo->outputCapacity); - + // pInfo->pRes = createOutputBuf(pExpr, numOfOutput, (int32_t) pInfo->outputCapacity); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "DistinctOperator"; + pOperator->name = "DistinctOperator"; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; -// pOperator->operatorType = OP_Distinct; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->status = OP_NOT_OPENED; + // pOperator->operatorType = OP_Distinct; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->getNextFn = hashDistinct; - pOperator->pExpr = pExpr; + pOperator->pExpr = pExpr; pOperator->closeFn = destroyDistinctOperatorInfo; - int32_t code = appendDownstream(pOperator, &downstream, 1); + int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; } -static int32_t getColumnIndexInSource(SQueriedTableInfo *pTableInfo, SExprBasicInfo *pExpr, SColumnInfo* pTagCols) { +static int32_t getColumnIndexInSource(SQueriedTableInfo* pTableInfo, SExprBasicInfo* pExpr, SColumnInfo* pTagCols) { int32_t j = 0; if (TSDB_COL_IS_TAG(pExpr->pParam[0].pCol->type)) { @@ -8356,7 +8564,7 @@ static int32_t getColumnIndexInSource(SQueriedTableInfo *pTableInfo, SExprBasicI return TSDB_TBNAME_COLUMN_INDEX; } - while(j < pTableInfo->numOfTags) { + while (j < pTableInfo->numOfTags) { if (pExpr->pParam[0].pCol->colId == pTagCols[j].colId) { return j; } @@ -8379,16 +8587,16 @@ static int32_t getColumnIndexInSource(SQueriedTableInfo *pTableInfo, SExprBasicI return INT32_MIN; // return a less than TSDB_TBNAME_COLUMN_INDEX value } -bool validateExprColumnInfo(SQueriedTableInfo *pTableInfo, SExprBasicInfo *pExpr, SColumnInfo* pTagCols) { +bool validateExprColumnInfo(SQueriedTableInfo* pTableInfo, SExprBasicInfo* pExpr, SColumnInfo* pTagCols) { int32_t j = getColumnIndexInSource(pTableInfo, pExpr, pTagCols); return j != INT32_MIN; } static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t numOfFilters, char** pMsg) { for (int32_t f = 0; f < numOfFilters; ++f) { - SColumnFilterInfo *pFilterMsg = (SColumnFilterInfo *)(*pMsg); + SColumnFilterInfo* pFilterMsg = (SColumnFilterInfo*)(*pMsg); - SColumnFilterInfo *pColFilter = &pColFilters[f]; + SColumnFilterInfo* pColFilter = &pColFilters[f]; pColFilter->filterstr = htons(pFilterMsg->filterstr); (*pMsg) += sizeof(SColumnFilterInfo); @@ -8396,12 +8604,13 @@ static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t if (pColFilter->filterstr) { pColFilter->len = htobe64(pFilterMsg->len); - pColFilter->pz = (int64_t)taosMemoryCalloc(1, (size_t)(pColFilter->len + 1 * TSDB_NCHAR_SIZE)); // note: null-terminator + pColFilter->pz = + (int64_t)taosMemoryCalloc(1, (size_t)(pColFilter->len + 1 * TSDB_NCHAR_SIZE)); // note: null-terminator if (pColFilter->pz == 0) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } - memcpy((void *)pColFilter->pz, (*pMsg), (size_t)pColFilter->len); + memcpy((void*)pColFilter->pz, (*pMsg), (size_t)pColFilter->len); (*pMsg) += (pColFilter->len + 1); } else { pColFilter->lowerBndi = htobe64(pFilterMsg->lowerBndi); @@ -8415,10 +8624,11 @@ static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t return TSDB_CODE_SUCCESS; } -static SResSchema createResSchema(int32_t type, int32_t bytes, int32_t slotId, int32_t scale, int32_t precision, const char* name) { +static SResSchema createResSchema(int32_t type, int32_t bytes, int32_t slotId, int32_t scale, int32_t precision, + const char* name) { SResSchema s = {0}; s.scale = scale; - s.type = type; + s.type = type; s.bytes = bytes; s.colId = slotId; s.precision = precision; @@ -8427,6 +8637,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; @@ -8437,7 +8664,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* *numOfExprs = numOfFuncs + numOfGroupKeys; SExprInfo* pExprs = taosMemoryCalloc(*numOfExprs, sizeof(SExprInfo)); - for(int32_t i = 0; i < (*numOfExprs); ++i) { + for (int32_t i = 0; i < (*numOfExprs); ++i) { STargetNode* pTargetNode = NULL; if (i < numOfFuncs) { pTargetNode = (STargetNode*)nodesListGetNode(pNodeList, i); @@ -8451,30 +8678,25 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* pExp->pExpr->_function.num = 1; pExp->pExpr->_function.functionId = -1; - pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); - pExp->base.numOfParams = 1; - - pExp->base.pParam[0].pCol = taosMemoryCalloc(1, sizeof(SColumn)); - SColumn* pCol = pExp->base.pParam[0].pCol; - // it is a project query, or group by column if (nodeType(pTargetNode->pExpr) == QUERY_NODE_COLUMN) { pExp->pExpr->nodeType = QUERY_NODE_COLUMN; - SColumnNode* pColNode = (SColumnNode*) pTargetNode->pExpr; + SColumnNode* pColNode = (SColumnNode*)pTargetNode->pExpr; + + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); + pExp->base.numOfParams = 1; SDataType* pType = &pColNode->node.resType; pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pColNode->colName); - 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; SDataType* pType = &pFuncNode->node.resType; - pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pFuncNode->node.aliasName); + pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, + pType->precision, pFuncNode->node.aliasName); pExp->pExpr->_function.functionId = pFuncNode->funcId; pExp->pExpr->_function.pFunctNode = pFuncNode; @@ -8482,31 +8704,36 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* // TODO: value parameter needs to be handled int32_t numOfParam = LIST_LENGTH(pFuncNode->pParameterList); + + pExp->base.pParam = taosMemoryCalloc(numOfParam, sizeof(SFunctParam)); + pExp->base.numOfParams = numOfParam; + for (int32_t j = 0; j < numOfParam; ++j) { SNode* p1 = nodesListGetNode(pFuncNode->pParameterList, j); - SColumnNode* pcn = (SColumnNode*)p1; // TODO refactor + if (p1->type == QUERY_NODE_COLUMN) { + SColumnNode* pcn = (SColumnNode*) p1; - 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].type = FUNC_PARAM_TYPE_COLUMN; + 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; + } } } else if (nodeType(pTargetNode->pExpr) == QUERY_NODE_OPERATOR) { pExp->pExpr->nodeType = QUERY_NODE_OPERATOR; - SOperatorNode* pNode = (SOperatorNode*) pTargetNode->pExpr; + SOperatorNode* pNode = (SOperatorNode*)pTargetNode->pExpr; + + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); + pExp->base.numOfParams = 1; SDataType* pType = &pNode->node.resType; pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pNode->node.aliasName); pExp->pExpr->_optrRoot.pRootNode = pTargetNode->pExpr; - 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); } @@ -8515,64 +8742,72 @@ 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); + snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId); pTaskInfo->id.str = strdup(p); return pTaskInfo; } -static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableGroupInfo *pTableGroupInfo, uint64_t queryId, uint64_t taskId); +static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, + STableGroupInfo* pTableGroupInfo, uint64_t queryId, uint64_t taskId); -static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId); +static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, + uint64_t queryId, uint64_t taskId); static SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo); static SArray* extractScanColumnId(SNodeList* pNodeList); static SArray* extractColumnInfo(SNodeList* pNodeList); -static SArray* extractColMatchInfo(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, uint64_t queryId, uint64_t taskId, STableGroupInfo* pTableGroupInfo) { +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; - size_t numOfCols = LIST_LENGTH(pScanPhyNode->pScanCols); + int32_t numOfCols = 0; tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); - SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols); + SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); - return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, pScanPhyNode->reverse, pColList, pTaskInfo); + return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, + pScanPhyNode->reverse, pColList, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == nodeType(pPhyNode)) { SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode; - SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc); + SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc); return createExchangeOperatorInfo(pExchange->pSrcEndPoints, pResBlock, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == nodeType(pPhyNode)) { SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table. - int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, queryId, taskId); + int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, + queryId, taskId); SArray* tableIdList = extractTableIdList(pTableGroupInfo); SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc); - SArray* colList = extractScanColumnId(pScanPhyNode->pScanCols); + SArray* colList = extractScanColumnId(pScanPhyNode->pScanCols); - SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pResBlock, colList, tableIdList, pTaskInfo); + SOperatorInfo* pOperator = + createStreamScanOperatorInfo(pHandle->reader, pResBlock, colList, tableIdList, pTaskInfo); taosArrayDestroy(tableIdList); return pOperator; } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == nodeType(pPhyNode)) { - SSystemTableScanPhysiNode * pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode; - SSDataBlock* pResBlock = createOutputBuf_rv1(pSysScanPhyNode->scan.node.pOutputDataBlockDesc); + SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode; + SSDataBlock* pResBlock = createOutputBuf_rv1(pSysScanPhyNode->scan.node.pOutputDataBlockDesc); struct SScanPhysiNode* pScanNode = &pSysScanPhyNode->scan; - SArray* colList = extractScanColumnId(pScanNode->pScanCols); + SArray* colList = extractScanColumnId(pScanNode->pScanCols); - SOperatorInfo* pOperator = createSysTableScanOperatorInfo(pHandle->meta, pResBlock, &pScanNode->tableName, - pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, - colList, pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId); + SOperatorInfo* pOperator = createSysTableScanOperatorInfo( + pHandle->meta, pResBlock, &pScanNode->tableName, pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, + colList, pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId); return pOperator; } else { ASSERT(0); @@ -8583,28 +8818,26 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa 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); + SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); - int32_t num = 0; - SExprInfo* pExprInfo = createExprInfo(((SProjectPhysiNode*)pPhyNode)->pProjections, NULL, &num); - SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); - return createProjectOperatorInfo(op, pExprInfo, num, pResBlock, pTaskInfo); - } + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(((SProjectPhysiNode*)pPhyNode)->pProjections, NULL, &num); + SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); + return createProjectOperatorInfo(op, pExprInfo, num, pResBlock, 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; SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode; - SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); - SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); + SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); + SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); if (pAggNode->pGroupKeys != NULL) { SArray* pColList = extractColumnInfo(pAggNode->pGroupKeys); @@ -8619,37 +8852,69 @@ 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; - int32_t num = 0; - SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num); + // todo: set the correct primary timestamp key column + int32_t num = 0; + 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 (pPhyNode->info.type == OP_MultiTableAggregate) { - size_t size = taosArrayGetSize(pPhyNode->pChildren); + } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == nodeType(pPhyNode)) { + size_t size = LIST_LENGTH(pPhyNode->pChildren); assert(size == 1); - for (int32_t i = 0; i < size; ++i) { - SPhysiNode* pChildNode = taosArrayGetP(pPhyNode->pChildren, i); - SOperatorInfo* op = doCreateOperatorTreeNode(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); - return createMultiTableAggOperatorInfo(op, pPhyNode->pTargets, pTaskInfo, pTableGroupInfo); - } - }*/ + SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + + SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode; + + SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); + SArray* info = createSortInfo(pSortPhyNode->pSortKeys); + return createSortOperatorInfo(op, pResBlock, info, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == nodeType(pPhyNode)) { + size_t size = LIST_LENGTH(pPhyNode->pChildren); + assert(size == 1); + + SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + + SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode; + + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(pSessionNode->window.pFuncs, NULL, &num); + SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); + return createSessionAggOperatorInfo(op, pExprInfo, num, pResBlock, pSessionNode->gap, pTaskInfo); + } else { + ASSERT(0); + } /*else if (pPhyNode->info.type == OP_MultiTableAggregate) { + size_t size = taosArrayGetSize(pPhyNode->pChildren); + assert(size == 1); + + for (int32_t i = 0; i < size; ++i) { + SPhysiNode* pChildNode = taosArrayGetP(pPhyNode->pChildren, i); + SOperatorInfo* op = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableGroupInfo); + return createMultiTableAggOperatorInfo(op, pPhyNode->pTargets, pTaskInfo, pTableGroupInfo); + } + }*/ } -static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STableGroupInfo* pGroupInfo, void* readHandle, uint64_t queryId, uint64_t taskId) { +static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STableGroupInfo* pGroupInfo, + void* readHandle, uint64_t queryId, uint64_t taskId) { STsdbQueryCond cond = {.loadExternalRows = false}; - cond.order = pTableScanNode->scan.order; + cond.order = pTableScanNode->scan.order; cond.numOfCols = LIST_LENGTH(pTableScanNode->scan.pScanCols); - cond.colList = taosMemoryCalloc(cond.numOfCols, sizeof(SColumnInfo)); + cond.colList = taosMemoryCalloc(cond.numOfCols, sizeof(SColumnInfo)); if (cond.colList == NULL) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; @@ -8657,7 +8922,7 @@ static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STa cond.twindow = pTableScanNode->scanRange; cond.type = BLOCK_LOAD_OFFSET_SEQ_ORDER; -// cond.type = pTableScanNode->scanFlag; + // cond.type = pTableScanNode->scanFlag; int32_t j = 0; for (int32_t i = 0; i < cond.numOfCols; ++i) { @@ -8667,7 +8932,7 @@ static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STa continue; } - cond.colList[j].type = pColNode->node.resType.type; + cond.colList[j].type = pColNode->node.resType.type; cond.colList[j].bytes = pColNode->node.resType.bytes; cond.colList[j].colId = pColNode->colId; j += 1; @@ -8678,18 +8943,18 @@ static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STa } SArray* extractScanColumnId(SNodeList* pNodeList) { - size_t numOfCols = LIST_LENGTH(pNodeList); + size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(int16_t)); if (pList == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { for (int32_t j = 0; j < numOfCols; ++j) { - STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, j); + STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, j); if (pNode->slotId == i) { - SColumnNode* pColNode = (SColumnNode*) pNode->pExpr; + SColumnNode* pColNode = (SColumnNode*)pNode->pExpr; taosArrayPush(pList, &pColNode->colId); break; } @@ -8700,24 +8965,24 @@ SArray* extractScanColumnId(SNodeList* pNodeList) { } SArray* extractColumnInfo(SNodeList* pNodeList) { - size_t numOfCols = LIST_LENGTH(pNodeList); + size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn)); if (pList == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - for(int32_t i = 0; i < numOfCols; ++i) { - STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, i); - SColumnNode* pColNode = (SColumnNode*) pNode->pExpr; + for (int32_t i = 0; i < numOfCols; ++i) { + STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i); + SColumnNode* pColNode = (SColumnNode*)pNode->pExpr; SColumn c = {0}; c.slotId = pColNode->slotId; - c.colId = pColNode->colId; - c.type = pColNode->node.resType.type; - c.bytes = pColNode->node.resType.bytes; - c.precision = pColNode->node.resType.precision; - c.scale = pColNode->node.resType.scale; + c.colId = pColNode->colId; + c.type = pColNode->node.resType.type; + c.bytes = pColNode->node.resType.bytes; + c.precision = pColNode->node.resType.precision; + c.scale = pColNode->node.resType.scale; taosArrayPush(pList, &c); } @@ -8725,29 +8990,75 @@ SArray* extractColumnInfo(SNodeList* pNodeList) { return pList; } -SArray* extractColMatchInfo(SNodeList* pNodeList) { - size_t numOfCols = LIST_LENGTH(pNodeList); +SArray* createSortInfo(SNodeList* pNodeList) { + size_t numOfCols = LIST_LENGTH(pNodeList); + SArray* pList = taosArrayInit(numOfCols, sizeof(SBlockOrderInfo)); + if (pList == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return pList; + } + + for (int32_t i = 0; i < numOfCols; ++i) { + STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i); + SOrderByExprNode* pSortKey = (SOrderByExprNode*)pNode->pExpr; + SBlockOrderInfo bi = {0}; + bi.order = (pSortKey->order == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; + bi.nullFirst = (pSortKey->nullOrder == NULL_ORDER_FIRST); + + SColumnNode* pColNode = (SColumnNode*)pSortKey->pExpr; + bi.slotId = pColNode->slotId; + // pColNode->order; + // SColumn c = {0}; + // c.slotId = pColNode->slotId; + // c.colId = pColNode->colId; + // c.type = pColNode->node.resType.type; + // c.bytes = pColNode->node.resType.bytes; + // c.precision = pColNode->node.resType.precision; + // c.scale = pColNode->node.resType.scale; + + taosArrayPush(pList, &bi); + } + + return pList; +} + +SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols) { + size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchInfo)); if (pList == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - for(int32_t i = 0; i < numOfCols; ++i) { - STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, i); - SColumnNode* pColNode = (SColumnNode*) pNode->pExpr; + for (int32_t i = 0; i < numOfCols; ++i) { + STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i); + SColumnNode* pColNode = (SColumnNode*)pNode->pExpr; SColMatchInfo c = {0}; c.colId = pColNode->colId; c.targetSlotId = pNode->slotId; - + c.output = true; taosArrayPush(pList, &c); } + *numOfOutputCols = 0; + + int32_t num = LIST_LENGTH(pOutputNodeList->pSlots); + 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; + } + } + return pList; } -int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId) { +int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, + uint64_t queryId, uint64_t taskId) { int32_t code = 0; if (tableType == TSDB_SUPER_TABLE) { code = tsdbQuerySTableByTagCond(metaHandle, tableUid, 0, NULL, 0, 0, NULL, pGroupInfo, NULL, 0, queryId, taskId); @@ -8776,40 +9087,42 @@ SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo) { return tableIdList; } -tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableGroupInfo *pTableGroupInfo, uint64_t queryId, uint64_t taskId) { +tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, + STableGroupInfo* pTableGroupInfo, uint64_t queryId, uint64_t taskId) { uint64_t uid = pTableScanNode->scan.uid; - int32_t code = doCreateTableGroup(pHandle->meta, pTableScanNode->scan.tableType, uid, pTableGroupInfo, queryId, taskId); + int32_t code = + doCreateTableGroup(pHandle->meta, pTableScanNode->scan.tableType, uid, pTableGroupInfo, queryId, taskId); if (code != TSDB_CODE_SUCCESS) { goto _error; } if (pTableGroupInfo->numOfTables == 0) { code = 0; - qDebug("no table qualified for query, TID:0x%"PRIx64", QID:0x%"PRIx64, taskId, queryId); + qDebug("no table qualified for query, TID:0x%" PRIx64 ", QID:0x%" PRIx64, taskId, queryId); goto _error; } return createDataReaderImpl(pTableScanNode, pTableGroupInfo, pHandle->reader, queryId, taskId); - _error: +_error: terrno = code; 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; + code = terrno; goto _complete; } @@ -8827,7 +9140,7 @@ _complete: return code; } -int32_t cloneExprFilterInfo(SColumnFilterInfo **dst, SColumnFilterInfo* src, int32_t filterNum) { +int32_t cloneExprFilterInfo(SColumnFilterInfo** dst, SColumnFilterInfo* src, int32_t filterNum) { if (filterNum <= 0) { return TSDB_CODE_SUCCESS; } @@ -8841,7 +9154,7 @@ int32_t cloneExprFilterInfo(SColumnFilterInfo **dst, SColumnFilterInfo* src, int 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); + void* pz = taosMemoryCalloc(1, (size_t)(*dst)[i].len + 1); if (pz == NULL) { if (i == 0) { @@ -8853,7 +9166,7 @@ int32_t cloneExprFilterInfo(SColumnFilterInfo **dst, SColumnFilterInfo* src, int return TSDB_CODE_QRY_OUT_OF_MEMORY; } - memcpy(pz, (void *)src->pz, (size_t)src->len + 1); + memcpy(pz, (void*)src->pz, (size_t)src->len + 1); (*dst)[i].pz = (int64_t)pz; } @@ -8862,7 +9175,8 @@ int32_t cloneExprFilterInfo(SColumnFilterInfo **dst, SColumnFilterInfo* src, int return TSDB_CODE_SUCCESS; } -static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SColumnInfo* pTagCols, SExprInfo* pExprs, int32_t numOfOutput, int32_t tagLen, bool superTable) { +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) { int16_t functId = getExprFunctionId(&pExprs[i]); @@ -8872,9 +9186,10 @@ static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SCol return TSDB_CODE_QRY_INVALID_MSG; } else { SColumnInfo* pCol = &pTableInfo->colList[j]; -// int32_t ret = getResultDataInfo(pCol->type, pCol->bytes, functId, (int32_t)pExprs[i].base.param[0].i, -// &pExprs[i].base.resSchema.type, &pExprs[i].base.resSchema.bytes, &pExprs[i].base.interBytes, tagLen, superTable, NULL); -// assert(ret == TSDB_CODE_SUCCESS); + // int32_t ret = getResultDataInfo(pCol->type, pCol->bytes, functId, (int32_t)pExprs[i].base.param[0].i, + // &pExprs[i].base.resSchema.type, &pExprs[i].base.resSchema.bytes, + // &pExprs[i].base.interBytes, tagLen, superTable, NULL); + // assert(ret == TSDB_CODE_SUCCESS); } } } @@ -8883,67 +9198,69 @@ static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SCol } // TODO tag length should be passed from client, refactor -int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { +int32_t createQueryFilter(char* data, uint16_t len, SFilterInfo** pFilters) { tExprNode* expr = NULL; - - TRY(TSDB_MAX_TAG_CONDITIONS) { - expr = exprTreeFromBinary(data, len); - } CATCH( code ) { + + TRY(TSDB_MAX_TAG_CONDITIONS) { expr = exprTreeFromBinary(data, len); } + CATCH(code) { CLEANUP_EXECUTE(); return code; - } END_TRY + } + END_TRY if (expr == NULL) { - //qError("failed to create expr tree"); + // qError("failed to create expr tree"); return TSDB_CODE_QRY_APP_ERROR; } -// int32_t ret = filterInitFromTree(expr, pFilters, 0); -// tExprTreeDestroy(expr, NULL); + // int32_t ret = filterInitFromTree(expr, pFilters, 0); + // tExprTreeDestroy(expr, NULL); -// return ret; + // 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; -// } +// 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]); +// 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]; +// 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; -// } +// 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]; +// 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; -// } +// 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->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; +// pSingleColFilter->bytes = pCols[i].bytes; // -// if (lower == TSDB_RELATION_IN) { -//// buildFilterSetFromBinary(&pSingleColFilter->q, (char *)(pSingleColFilter->filterInfo.pz), (int32_t)(pSingleColFilter->filterInfo.len)); +// if (lower == TSDB_RELATION_IN) { +//// buildFilterSetFromBinary(&pSingleColFilter->q, (char *)(pSingleColFilter->filterInfo.pz), +///(int32_t)(pSingleColFilter->filterInfo.len)); // } // } // @@ -8955,49 +9272,49 @@ int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { //} 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); + // 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->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); + // doCreateFilterInfo(pQueryAttr->tableCols, pQueryAttr->numOfCols, pQueryAttr->numOfFilterCols, + // &pQueryAttr->pFilterInfo, qId); pQueryAttr->createFilterOperator = true; return TSDB_CODE_SUCCESS; } -static void doUpdateExprColumnIndex(STaskAttr *pQueryAttr) { +static void doUpdateExprColumnIndex(STaskAttr* pQueryAttr) { assert(pQueryAttr->pExpr1 != NULL && pQueryAttr != NULL); for (int32_t k = 0; k < pQueryAttr->numOfOutput; ++k) { - SExprBasicInfo *pSqlExprMsg = &pQueryAttr->pExpr1[k].base; -// if (pSqlExprMsg->functionId == FUNCTION_ARITHM) { -// continue; -// } + SExprBasicInfo* pSqlExprMsg = &pQueryAttr->pExpr1[k].base; + // if (pSqlExprMsg->functionId == FUNCTION_ARITHM) { + // continue; + // } // todo opt performance - SColIndex *pColIndex = NULL;/*&pSqlExprMsg->colInfo;*/ + SColIndex* pColIndex = NULL; /*&pSqlExprMsg->colInfo;*/ if (TSDB_COL_IS_NORMAL_COL(pColIndex->flag)) { int32_t f = 0; for (f = 0; f < pQueryAttr->numOfCols; ++f) { @@ -9039,7 +9356,7 @@ void setResultBufSize(STaskAttr* pQueryAttr, SResultInfo* pResultInfo) { numOfRes = MIN_ROWS_FOR_PRJ_QUERY; } - pResultInfo->capacity = numOfRes; + pResultInfo->capacity = numOfRes; } else { // in case of non-prj query, a smaller output buffer will be used. pResultInfo->capacity = DEFAULT_MIN_ROWS; } @@ -9048,29 +9365,29 @@ void setResultBufSize(STaskAttr* pQueryAttr, SResultInfo* pResultInfo) { pResultInfo->totalRows = 0; } -//TODO refactor +// TODO refactor void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters) { - if (pFilter == NULL || numOfFilters == 0) { - return; - } + if (pFilter == NULL || numOfFilters == 0) { + return; + } - for (int32_t i = 0; i < numOfFilters; i++) { - if (pFilter[i].filterstr && pFilter[i].pz) { - taosMemoryFree((void*)(pFilter[i].pz)); - } + for (int32_t i = 0; i < numOfFilters; i++) { + if (pFilter[i].filterstr && pFilter[i].pz) { + taosMemoryFree((void*)(pFilter[i].pz)); } + } - taosMemoryFree(pFilter); + taosMemoryFree(pFilter); } static void doDestroyTableQueryInfo(STableGroupInfo* pTableqinfoGroupInfo) { if (pTableqinfoGroupInfo->pGroupList != NULL) { - int32_t numOfGroups = (int32_t) taosArrayGetSize(pTableqinfoGroupInfo->pGroupList); + int32_t numOfGroups = (int32_t)taosArrayGetSize(pTableqinfoGroupInfo->pGroupList); for (int32_t i = 0; i < numOfGroups; ++i) { - SArray *p = taosArrayGetP(pTableqinfoGroupInfo->pGroupList, i); + SArray* p = taosArrayGetP(pTableqinfoGroupInfo->pGroupList, i); size_t num = taosArrayGetSize(p); - for(int32_t j = 0; j < num; ++j) { + for (int32_t j = 0; j < num; ++j) { STableQueryInfo* item = taosArrayGetP(p, j); destroyTableQueryInfoImpl(item); } @@ -9087,12 +9404,12 @@ static void doDestroyTableQueryInfo(STableGroupInfo* pTableqinfoGroupInfo) { pTableqinfoGroupInfo->numOfTables = 0; } -void doDestroyTask(SExecTaskInfo *pTaskInfo) { +void doDestroyTask(SExecTaskInfo* pTaskInfo) { qDebug("%s execTask is freed", GET_TASKID(pTaskInfo)); doDestroyTableQueryInfo(&pTaskInfo->tableqinfoGroupInfo); -// taosArrayDestroy(pTaskInfo->summary.queryProfEvents); -// taosHashCleanup(pTaskInfo->summary.operatorProfResults); + // taosArrayDestroy(pTaskInfo->summary.queryProfEvents); + // taosHashCleanup(pTaskInfo->summary.operatorProfResults); taosMemoryFreeClear(pTaskInfo->sql); taosMemoryFreeClear(pTaskInfo->id.str); @@ -9109,7 +9426,7 @@ static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type // Binary data overflows for sort of unknown reasons. Let trim the overflow data if (varDataTLen(val) > bytes) { int32_t maxLen = bytes - VARSTR_HEADER_SIZE; - int32_t len = (varDataLen(val) > maxLen)? maxLen:varDataLen(val); + int32_t len = (varDataLen(val) > maxLen) ? maxLen : varDataLen(val); memcpy(varDataVal(output), varDataVal(val), len); varDataSetLen(output, len); } else { @@ -9122,8 +9439,8 @@ static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type static int64_t getQuerySupportBufSize(size_t numOfTables) { size_t s1 = sizeof(STableQueryInfo); -// size_t s3 = sizeof(STableCheckInfo); buffer consumption in tsdb - return (int64_t)(s1* 1.5 * numOfTables); + // size_t s3 = sizeof(STableCheckInfo); buffer consumption in tsdb + return (int64_t)(s1 * 1.5 * numOfTables); } int32_t checkForQueryBuf(size_t numOfTables) { @@ -9131,8 +9448,7 @@ int32_t checkForQueryBuf(size_t numOfTables) { if (tsQueryBufferSizeBytes < 0) { return TSDB_CODE_SUCCESS; } else if (tsQueryBufferSizeBytes > 0) { - - while(1) { + while (1) { int64_t s = tsQueryBufferSizeBytes; int64_t remain = s - t; if (remain >= 0) { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 85ba462c9a..7a57d62969 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -23,20 +23,19 @@ #include "tsort.h" #include "tutil.h" -typedef struct STupleHandle { +struct STupleHandle { SSDataBlock* pBlock; int32_t rowIndex; -} STupleHandle; +}; -typedef struct SSortHandle { +struct SSortHandle { int32_t type; int32_t pageSize; int32_t numOfPages; SDiskbasedBuf *pBuf; - SArray *pOrderInfo; - bool nullFirst; + SArray *pSortInfo; SArray *pOrderedSource; _sort_fetch_block_fn_t fetchfp; @@ -60,7 +59,7 @@ typedef struct SSortHandle { bool inMemSort; bool needAdjust; STupleHandle tupleHandle; -} SSortHandle; +}; static int32_t msortComparFn(const void *pLeft, const void *pRight, void *param); @@ -90,18 +89,18 @@ static SSDataBlock* createDataBlock_rv(SSchema* pSchema, int32_t numOfCols) { * @param type * @return */ -SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, bool nullFirst, int32_t type, int32_t pageSize, int32_t numOfPages, SSchema* pSchema, int32_t numOfCols, const char* idstr) { +SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr) { SSortHandle* pSortHandle = taosMemoryCalloc(1, sizeof(SSortHandle)); pSortHandle->type = type; pSortHandle->pageSize = pageSize; pSortHandle->numOfPages = numOfPages; - pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES); - pSortHandle->pOrderInfo = pOrderInfo; - pSortHandle->nullFirst = nullFirst; - pSortHandle->cmpParam.orderInfo = pOrderInfo; + pSortHandle->pSortInfo = pSortInfo; + pSortHandle->pDataBlock = createOneDataBlock(pBlock); + + pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES); + pSortHandle->cmpParam.orderInfo = pSortInfo; - pSortHandle->pDataBlock = createDataBlock_rv(pSchema, numOfCols); tsortSetComparFp(pSortHandle, msortComparFn); if (idstr != NULL) { @@ -364,14 +363,14 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { for(int32_t i = 0; i < pInfo->size; ++i) { SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i); - SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->colIndex); + SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->slotId); bool leftNull = false; if (pLeftColInfoData->hasNull) { leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg); } - SColumnInfoData* pRightColInfoData = TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->colIndex); + SColumnInfoData* pRightColInfoData = TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); bool rightNull = false; if (pRightColInfoData->hasNull) { rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg); @@ -415,6 +414,9 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { static int32_t doInternalMergeSort(SSortHandle* pHandle) { size_t numOfSources = taosArrayGetSize(pHandle->pOrderedSource); + if (numOfSources == 0) { + return 0; + } // Calculate the I/O counts to complete the data sort. double sortPass = floorl(log2(numOfSources) / log2(pHandle->numOfPages)); @@ -542,7 +544,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { if (size > sortBufSize) { // Perform the in-memory sort and then flush data in the buffer into disk. int64_t p = taosGetTimestampUs(); - blockDataSort(pHandle->pDataBlock, pHandle->pOrderInfo, pHandle->nullFirst); + blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo); int64_t el = taosGetTimestampUs() - p; pHandle->sortElapsed += el; @@ -555,7 +557,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { size_t size = blockDataGetSize(pHandle->pDataBlock); // Perform the in-memory sort and then flush data in the buffer into disk. - blockDataSort(pHandle->pDataBlock, pHandle->pOrderInfo, pHandle->nullFirst); + blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo); // All sorted data can fit in memory, external memory sort is not needed. Return to directly if (size <= sortBufSize) { @@ -603,6 +605,10 @@ int32_t tsortOpen(SSortHandle* pHandle) { ASSERT(numOfSources <= getNumOfInMemBufPages(pHandle->pBuf)); } + if (numOfSources == 0) { + return 0; + } + code = sortComparInit(&pHandle->cmpParam, pHandle->pOrderedSource, 0, numOfSources - 1, pHandle); if (code != TSDB_CODE_SUCCESS) { return code; diff --git a/source/libs/executor/test/executorTests.cpp b/source/libs/executor/test/executorTests.cpp index 7fb9b2ad7e..870a0b71fc 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); } @@ -966,7 +966,7 @@ TEST(testCase, inMem_sort_Test) { exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1"); taosArrayPush(pExprInfo, &exp1); - SOperatorInfo* pOperator = createOrderOperatorInfo(createDummyOperator(10000, 5, 1000, data_asc, 1), pExprInfo, pOrderVal, NULL); + SOperatorInfo* pOperator = createSortOperatorInfo(createDummyOperator(10000, 5, 1000, data_asc, 1), pExprInfo, pOrderVal, NULL); bool newgroup = false; SSDataBlock* pRes = pOperator->getNextFn(pOperator, &newgroup); @@ -1035,7 +1035,7 @@ TEST(testCase, external_sort_Test) { exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1"); // taosArrayPush(pExprInfo, &exp1); - SOperatorInfo* pOperator = createOrderOperatorInfo(createDummyOperator(10000, 1500, 1000, data_desc, 1), pExprInfo, pOrderVal, NULL); + SOperatorInfo* pOperator = createSortOperatorInfo(createDummyOperator(10000, 1500, 1000, data_desc, 1), pExprInfo, pOrderVal, NULL); bool newgroup = false; SSDataBlock* pRes = NULL; diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 586aed7a67..ecea24135f 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -98,14 +98,14 @@ int32_t docomp(const void* p1, const void* p2, void* param) { for(int32_t i = 0; i < pInfo->size; ++i) { SBlockOrderInfo* pOrder = (SBlockOrderInfo*)TARRAY_GET_ELEM(pInfo, i); - SColumnInfoData* pLeftColInfoData = (SColumnInfoData*)TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->colIndex); + SColumnInfoData* pLeftColInfoData = (SColumnInfoData*)TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->slotId); bool leftNull = false; if (pLeftColInfoData->hasNull) { leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg); } - SColumnInfoData* pRightColInfoData = (SColumnInfoData*) TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->colIndex); + SColumnInfoData* pRightColInfoData = (SColumnInfoData*) TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); bool rightNull = false; if (pRightColInfoData->hasNull) { rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg); diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index 598a28b2eb..2c0148e04f 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -33,6 +33,8 @@ extern "C" { #define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) #define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) #define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) +#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) +#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 9b3a7ff515..024da4e04b 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -173,7 +173,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .finalizeFunc = NULL }, { - .name = "power", + .name = "pow", .type = FUNCTION_TYPE_POW, .classification = FUNC_MGT_SCALAR_FUNC, .checkFunc = stubCheckAndGetResultType, @@ -291,6 +291,76 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .initFunc = NULL, .sprocessFunc = NULL, .finalizeFunc = NULL + }, + { + .name = "_rowts", + .type = FUNCTION_TYPE_ROWTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "tbname", + .type = FUNCTION_TYPE_TBNAME, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_qstartts", + .type = FUNCTION_TYPE_QSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = qStartTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_qendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = qEndTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_wstartts", + .type = FUNCTION_TYPE_WSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winStartTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_wendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winEndTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_wduration", + .type = FUNCTION_TYPE_WDURATION, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winDurFunction, + .finalizeFunc = NULL } }; @@ -298,6 +368,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; @@ -329,16 +400,43 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { break; } case FUNCTION_TYPE_CONCAT: + case FUNCTION_TYPE_ROWTS: + case FUNCTION_TYPE_TBNAME: { // todo break; + } - case FUNCTION_TYPE_ABS: { + 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: + case FUNCTION_TYPE_ROUND: { SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); int32_t paraType = pParam->node.resType.type; pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; break; } + case FUNCTION_TYPE_SIN: + case FUNCTION_TYPE_COS: + case FUNCTION_TYPE_TAN: + case FUNCTION_TYPE_ASIN: + case FUNCTION_TYPE_ACOS: + case FUNCTION_TYPE_ATAN: + case FUNCTION_TYPE_SQRT: + case FUNCTION_TYPE_LOG: + case FUNCTION_TYPE_POW: { + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + 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 10ac8bbf43..4034a0eb0f 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -44,6 +44,13 @@ static void doInitFunctionHashTable() { } } +static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) { + if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + return false; + } + return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification); +} + int32_t fmFuncMgtInit() { taosThreadOnce(&functionHashTableInit, doInitFunctionHashTable); return initFunctionCode; @@ -85,14 +92,24 @@ 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; } bool fmIsAggFunc(int32_t funcId) { - if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { - return false; - } - return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, FUNC_MGT_AGG_FUNC); + return isSpecificClassifyFunc(funcId, FUNC_MGT_AGG_FUNC); +} + +bool fmIsScalarFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); +} + +bool fmIsWindowPseudoColumnFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_WINDOW_PC_FUNC); +} + +bool fmIsWindowClauseFunc(int32_t funcId) { + return fmIsAggFunc(funcId) || fmIsWindowPseudoColumnFunc(funcId); } void fmFuncMgtDestroy() { diff --git a/source/libs/function/src/texpr.c b/source/libs/function/src/texpr.c index 814aa48b55..61ff6bb825 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 957f0799c5..0000000000 --- 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 086e75d99f..3ea986ad48 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 96% rename from source/libs/index/inc/index_fst.h rename to source/libs/index/inc/indexFst.h index cf5c3f306b..39ad5ffa8c 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_node.h" -#include "index_fst_automation.h" -#include "index_fst_counting_writer.h" -#include "index_fst_registry.h" -#include "index_fst_util.h" #define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) @@ -257,9 +257,9 @@ typedef struct FstMeta { } FstMeta; typedef struct Fst { - FstMeta* meta; - FstSlice* data; // - FstNode* root; // + FstMeta* meta; + FstSlice* data; // + FstNode* root; // TdThreadMutex mtx; } Fst; @@ -325,10 +325,10 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut); void fstStreamBuilderDestroy(FstStreamBuilder* b); -// set up bound range -// refator, simple code by marco -FstStreamBuilder* fstStreamBuilderRange(FstStreamBuilder* b, FstSlice* val, RangeType type); +// set up bound range +// refator later: to simple code by marco +void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type); #ifdef __cplusplus } 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 786d3eb7d2..3a0f74ee76 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/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 4dbf4cea04..4bbc739c73 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/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 20b70e2866..09cde6c131 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/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 f173dd9a15..d0bbc923d1 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/include/client/stream/stream.h b/source/libs/index/inc/indexSparse.h similarity index 56% rename from include/client/stream/stream.h rename to source/libs/index/inc/indexSparse.h index 79b247c61c..8035f6e08d 100644 --- a/include/client/stream/stream.h +++ b/source/libs/index/inc/indexSparse.h @@ -13,15 +13,31 @@ * along with this program. If not, see . */ -#ifndef _TD_STREAM_H_ -#define _TD_STREAM_H_ +#ifndef _TD_INDEX_SPARSE_H_ +#define _TD_INDEX_SPARSE_H_ + +#include "tarray.h" #ifdef __cplusplus extern "C" { #endif +typedef struct FstSparseSet { + SArray *dense; + SArray *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 /*_TD_STREAM_H_*/ \ No newline at end of file +#endif 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 3794898d3a..9712e4b30f 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 61dd952381..d3ca3a1acf 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" @@ -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 99% rename from source/libs/index/src/index_cache.c rename to source/libs/index/src/indexCache.c index bf907726bc..ca26cf38e5 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/indexCache.c @@ -13,9 +13,9 @@ * 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" 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 09f382bbdc..24bc7a93a2 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" @@ -1184,7 +1184,7 @@ StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstB sws->aut = automation; sws->inp = (SArray*)taosArrayInit(256, sizeof(uint8_t)); - sws->emptyOutput.null = false; + sws->emptyOutput.null = true; sws->emptyOutput.out = 0; sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); @@ -1239,8 +1239,8 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) { for (uint32_t i = 0; i < len; i++) { uint8_t b = data[i]; uint64_t res = 0; - bool null = fstNodeFindInput(node, b, &res); - if (null == false) { + bool find = fstNodeFindInput(node, b, &res); + if (find == true) { FstTransition trn; fstNodeGetTransitionAt(node, res, &trn); void* preState = autState; @@ -1293,7 +1293,6 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) { return false; } - StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback) { AutomationCtx* aut = sws->aut; FstOutput output = sws->emptyOutput; @@ -1356,6 +1355,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); taosMemoryFreeClear(buf); fstSliceDestroy(&slice); + taosArrayDestroy(nodes); return NULL; } if (FST_NODE_IS_FINAL(nextNode) && isMatch) { @@ -1364,15 +1364,12 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb taosMemoryFreeClear(buf); fstSliceDestroy(&slice); taosArrayDestroy(nodes); + nodes = NULL; return result; } taosMemoryFreeClear(buf); fstSliceDestroy(&slice); - } - for (size_t i = 0; i < taosArrayGetSize(nodes); i++) { - FstNode** node = (FstNode**)taosArrayGet(nodes, i); - fstNodeDestroy(*node); - } + }; taosArrayDestroy(nodes); return NULL; } @@ -1425,9 +1422,9 @@ void fstStreamBuilderDestroy(FstStreamBuilder* b) { taosMemoryFreeClear(b->max); taosMemoryFree(b); } -FstStreamBuilder* fstStreamBuilderRange(FstStreamBuilder* b, FstSlice* val, RangeType type) { +void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type) { if (b == NULL) { - return NULL; + return; } if (type == GE) { b->min->type = Included; @@ -1446,5 +1443,4 @@ FstStreamBuilder* fstStreamBuilderRange(FstStreamBuilder* b, FstSlice* val, Rang fstSliceDestroy(&(b->max->data)); b->max->data = fstSliceDeepCopy(val, 0, FST_SLICE_LEN(val) - 1); } - return b; } diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/indexFstAutomation.c similarity index 95% rename from source/libs/index/src/index_fst_automation.c rename to source/libs/index/src/indexFstAutomation.c index 668a527d4a..0702e3b94e 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)); @@ -85,10 +85,20 @@ static void* prefixStart(AutomationCtx* ctx) { }; static bool prefixIsMatch(AutomationCtx* ctx, void* sv) { StartWithStateValue* ssv = (StartWithStateValue*)sv; - return ssv->val == strlen(ctx->data); + if (ssv == NULL) { + return false; + } + if (ssv->type == FST_INT) { + return ssv->val == strlen(ctx->data); + } else { + return false; + } } static bool prefixCanMatch(AutomationCtx* ctx, void* sv) { StartWithStateValue* ssv = (StartWithStateValue*)sv; + if (ssv == NULL) { + return false; + } return ssv->val >= 0; } static bool prefixWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } @@ -154,15 +164,7 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { // add more search type } - char* dst = NULL; - if (data != NULL) { - char* src = (char*)data; - size_t len = strlen(src); - dst = (char*)taosMemoryCalloc(1, len * sizeof(char) + 1); - memcpy(dst, src, len); - } - - ctx->data = dst; + ctx->data = (data != NULL ? strdup((char*)data) : NULL); ctx->type = atype; ctx->stdata = (void*)sv; return ctx; diff --git a/source/libs/index/src/index_fst_common.c b/source/libs/index/src/indexFstCommon.c similarity index 74% rename from source/libs/index/src/index_fst_common.c rename to source/libs/index/src/indexFstCommon.c index 2d7586e8d9..e2544c7ac3 100644 --- a/source/libs/index/src/index_fst_common.c +++ b/source/libs/index/src/indexFstCommon.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_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 6a161ba7e9..76ff4309b5 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/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 a0d59150d7..e11f9dd37d 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/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 7b6b8df25f..34efee0d0d 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/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 f9581f7202..ec9a6943dc 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/indexSparse.c b/source/libs/index/src/indexSparse.c new file mode 100644 index 0000000000..8bcf04602f --- /dev/null +++ b/source/libs/index/src/indexSparse.c @@ -0,0 +1,71 @@ +/* + * 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 "indexSparse.h" + +FstSparseSet *sparSetCreate(int32_t sz) { + FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet)); + if (ss = NULL) { + return NULL; + } + + ss->dense = taosArrayInit(sz, sizeof(uint32_t)); + ss->sparse = taosArrayInit(sz, sizeof(uint32_t)); + ss->size = sz; + return ss; +} +void sparSetDestroy(FstSparseSet *ss) { + if (ss == NULL) { + return; + } + taosArrayDestroy(ss->dense); + taosArrayDestroy(ss->sparse); + taosMemoryFree(ss); +} +uint32_t sparSetLen(FstSparseSet *ss) { return ss == NULL ? 0 : ss->size; } +uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip) { + if (ss == NULL) { + return 0; + } + uint32_t i = ss->size; + taosArraySet(ss->dense, i, &ip); + taosArraySet(ss->sparse, ip, &i); + ss->size += 1; + return i; +} +uint32_t sparSetGet(FstSparseSet *ss, uint32_t i) { + if (i >= taosArrayGetSize(ss->dense)) { + return 0; + } + uint32_t *v = taosArrayGet(ss->dense, i); + return *v; +} +bool sparSetContains(FstSparseSet *ss, uint32_t ip) { + if (ip >= taosArrayGetSize(ss->sparse)) { + return false; + } + uint32_t i = *(uint32_t *)taosArrayGet(ss->sparse, ip); + if (i >= taosArrayGetSize(ss->dense)) { + return false; + } + uint32_t v = *(uint32_t *)taosArrayGet(ss->dense, i); + return v == ip; +} +void sparSetClear(FstSparseSet *ss) { + if (ss == NULL) { + return; + } + ss->size = 0; +} 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 53813e13e6..058c33b725 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 65c16ca65b..7b83cf465d 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 94923726dd..eff53108cd 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; } @@ -96,11 +96,41 @@ class FstReadMemory { char* ch = (char*)fstSliceData(s, &sz); std::string key(ch, sz); printf("key: %s, val: %" PRIu64 "\n", key.c_str(), (uint64_t)(rt->out.out)); + result.push_back(rt->out.out); swsResultDestroy(rt); } - for (size_t i = 0; i < result.size(); i++) { + streamWithStateDestroy(st); + fstStreamBuilderDestroy(sb); + return true; + } + bool SearchRange(AutomationCtx* ctx, const std::string& low, RangeType lowType, const std::string& high, + RangeType highType, std::vector& result) { + FstStreamBuilder* sb = fstSearch(_fst, ctx); + + FstSlice l = fstSliceCreate((uint8_t*)low.c_str(), low.size()); + FstSlice h = fstSliceCreate((uint8_t*)high.c_str(), high.size()); + + // range [low, high); + fstStreamBuilderSetRange(sb, &l, lowType); + fstStreamBuilderSetRange(sb, &h, highType); + + fstSliceDestroy(&l); + fstSliceDestroy(&h); + + StreamWithState* st = streamBuilderIntoStream(sb); + StreamWithStateResult* rt = NULL; + while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + // result.push_back((uint64_t)(rt->out.out)); + FstSlice* s = &rt->data; + int32_t sz = 0; + char* ch = (char*)fstSliceData(s, &sz); + std::string key(ch, sz); + printf("key: %s, val: %" PRIu64 "\n", key.c_str(), (uint64_t)(rt->out.out)); + result.push_back(rt->out.out); + swsResultDestroy(rt); } - std::cout << std::endl; + streamWithStateDestroy(st); + fstStreamBuilderDestroy(sb); return true; } bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector& result) { @@ -233,7 +263,7 @@ void checkFstLongTerm() { // taosMemoryFree(ctx); // delete m; } -void checkFstCheckIterator() { +void checkFstCheckIterator1() { FstWriter* fw = new FstWriter; int64_t s = taosGetTimestampUs(); int count = 2; @@ -243,8 +273,7 @@ void checkFstCheckIterator() { std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; fw->Put("Hello world", 1); - fw->Put("hello world", 2); - fw->Put("hello worle", 3); + fw->Put("Hello worle", 2); fw->Put("hello worlf", 4); delete fw; @@ -258,15 +287,227 @@ void checkFstCheckIterator() { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"H", AUTOMATION_PREFIX); + AutomationCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS); m->Search(ctx, result); std::cout << "size: " << result.size() << std::endl; // assert(result.size() == count); for (int i = 0; i < result.size(); i++) { // assert(result[i] == i); // check result } + automCtxDestroy(ctx); - taosMemoryFree(ctx); + delete m; +} +void checkFstCheckIterator2() { + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("a", 1); + fw->Put("b", 2); + fw->Put("c", 4); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + + // prefix search + std::vector result; + + AutomationCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS); + m->Search(ctx, result); + std::cout << "size: " << result.size() << std::endl; + // assert(result.size() == count); + for (int i = 0; i < result.size(); i++) { + // assert(result[i] == i); // check result + } + automCtxDestroy(ctx); + + delete m; +} +void checkFstCheckIteratorPrefix() { + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("Hello world", 1); + fw->Put("Hello worle", 2); + fw->Put("hello worlf", 4); + fw->Put("ja", 4); + fw->Put("jb", 4); + fw->Put("jc", 4); + fw->Put("jddddddddd", 4); + fw->Put("jefffffff", 4); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + { + // prefix search + std::vector result; + + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_PREFIX); + m->Search(ctx, result); + assert(result.size() == 1); + automCtxDestroy(ctx); + } + { + // prefix search + std::vector result; + + AutomationCtx* ctx = automCtxCreate((void*)"Hello", AUTOMATION_PREFIX); + m->Search(ctx, result); + assert(result.size() == 2); + automCtxDestroy(ctx); + } + { + std::vector result; + + AutomationCtx* ctx = automCtxCreate((void*)"jddd", AUTOMATION_PREFIX); + m->Search(ctx, result); + assert(result.size() == 1); + automCtxDestroy(ctx); + } + delete m; +} +void checkFstCheckIteratorRange1() { + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("a", 1); + fw->Put("b", 2); + fw->Put("c", 3); + fw->Put("d", 4); + fw->Put("e", 5); + fw->Put("f", 5); + fw->Put("G", 5); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + { + // prefix search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GE, "e", LT, result); + assert(result.size() == 3); + automCtxDestroy(ctx); + } + { + // prefix search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GT, "e", LT, result); + assert(result.size() == 2); + automCtxDestroy(ctx); + } + { + // prefix search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GT, "e", LE, result); + assert(result.size() == 3); + automCtxDestroy(ctx); + } + { + // prefix search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GE, "e", LE, result); + assert(result.size() == 4); + automCtxDestroy(ctx); + } + delete m; +} +void checkFstCheckIteratorRange2() { + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + // Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("ab", 1); + fw->Put("b", 2); + fw->Put("cdd", 3); + fw->Put("cde", 3); + fw->Put("ddd", 4); + fw->Put("ed", 5); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GE, "ed", LT, result); + assert(result.size() == 4); + automCtxDestroy(ctx); + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GE, "ed", LE, result); + assert(result.size() == 5); + automCtxDestroy(ctx); + // taosMemoryFree(ctx); + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GT, "ed", LE, result); + assert(result.size() == 4); + automCtxDestroy(ctx); + } + { + // range search + std::vector result; + AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + // [b, e) + m->SearchRange(ctx, "b", GT, "ed", LT, result); + assert(result.size() == 3); + automCtxDestroy(ctx); + } delete m; } @@ -332,7 +573,11 @@ int main(int argc, char* argv[]) { // path suid colName ver // iterTFileReader(argv[1], argv[2], argv[3], argv[4]); //} - checkFstCheckIterator(); + checkFstCheckIterator1(); + checkFstCheckIterator2(); + checkFstCheckIteratorPrefix(); + checkFstCheckIteratorRange1(); + checkFstCheckIteratorRange2(); // checkFstLongTerm(); // checkFstPrefixSearch(); diff --git a/source/libs/index/test/fstUT.cc b/source/libs/index/test/fstUT.cc index 1bdc7fc9c9..ab6c1a4704 100644 --- a/source/libs/index/test/fstUT.cc +++ b/source/libs/index/test/fstUT.cc @@ -6,16 +6,16 @@ #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" #include "tutil.h" -#include "tlog.h" static std::string dir = "/tmp/index"; diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 0e4eb060cf..ee9da50ab2 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 df9f8b8439..9b0452425a 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 6ba8cc9525..30f1a089f7 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/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 9d0b79ca80..e728078a38 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -260,9 +260,9 @@ static SNode* logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) { } static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) { + COPY_ALL_SCALAR_FIELDS; COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pProjections); - COPY_CHAR_ARRAY_FIELD(stmtName); return (SNode*)pDst; } @@ -307,10 +307,8 @@ static SNode* logicSubplanCopy(const SLogicSubplan* pSrc, SLogicSubplan* pDst) { } static SNode* dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) { - COPY_SCALAR_FIELD(dataBlockId); + COPY_ALL_SCALAR_FIELDS; CLONE_NODE_LIST_FIELD(pSlots); - COPY_SCALAR_FIELD(resultRowSize); - COPY_SCALAR_FIELD(precision); return (SNode*)pDst; } diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 15e03b9891..32040a2e3f 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -475,6 +475,10 @@ static int32_t jsonToLogicScanNode(const SJson* pJson, void* pObj) { } static const char* jkProjectLogicPlanProjections = "Projections"; +static const char* jkProjectLogicPlanLimit = "Limit"; +static const char* jkProjectLogicPlanOffset = "Offset"; +static const char* jkProjectLogicPlanSlimit = "SLimit"; +static const char* jkProjectLogicPlanSoffset = "SOffset"; static int32_t logicProjectNodeToJson(const void* pObj, SJson* pJson) { const SProjectLogicNode* pNode = (const SProjectLogicNode*)pObj; @@ -483,6 +487,18 @@ static int32_t logicProjectNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkProjectLogicPlanProjections, pNode->pProjections); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanLimit, pNode->limit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanOffset, pNode->offset); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanSlimit, pNode->slimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableMetaSize, pNode->soffset); + } return code; } @@ -494,6 +510,18 @@ static int32_t jsonToLogicProjectNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkProjectLogicPlanProjections, &pNode->pProjections); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkProjectLogicPlanLimit, &pNode->limit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkProjectLogicPlanOffset, &pNode->offset); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkProjectLogicPlanSlimit, &pNode->slimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkScanLogicPlanTableMetaSize, &pNode->soffset); + } return code; } @@ -802,6 +830,10 @@ static int32_t jsonToPhysiSysTableScanNode(const SJson* pJson, void* pObj) { } static const char* jkProjectPhysiPlanProjections = "Projections"; +static const char* jkProjectPhysiPlanLimit = "Limit"; +static const char* jkProjectPhysiPlanOffset = "Offset"; +static const char* jkProjectPhysiPlanSlimit = "SLimit"; +static const char* jkProjectPhysiPlanSoffset = "SOffset"; static int32_t physiProjectNodeToJson(const void* pObj, SJson* pJson) { const SProjectPhysiNode* pNode = (const SProjectPhysiNode*)pObj; @@ -810,6 +842,18 @@ static int32_t physiProjectNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkProjectPhysiPlanProjections, pNode->pProjections); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanLimit, pNode->limit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanOffset, pNode->offset); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanSlimit, pNode->slimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanSoffset, pNode->soffset); + } return code; } @@ -821,6 +865,18 @@ static int32_t jsonToPhysiProjectNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkProjectPhysiPlanProjections, &pNode->pProjections); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanLimit, &pNode->limit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanOffset, &pNode->offset); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanSlimit, &pNode->slimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanSoffset, &pNode->soffset); + } return code; } @@ -1001,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; @@ -1027,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; } @@ -1056,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; } @@ -2057,19 +2120,26 @@ static int32_t jsonToDownstreamSourceNode(const SJson* pJson, void* pObj) { static const char* jkDataBlockDescDataBlockId = "DataBlockId"; static const char* jkDataBlockDescSlots = "Slots"; -static const char* jkDataBlockResultRowSize = "ResultRowSize"; +static const char* jkDataBlockTotalRowSize = "TotalRowSize"; +static const char* jkDataBlockOutputRowSize = "OutputRowSize"; +static const char* jkDataBlockPrecision = "Precision"; static int32_t dataBlockDescNodeToJson(const void* pObj, SJson* pJson) { const SDataBlockDescNode* pNode = (const SDataBlockDescNode*)pObj; int32_t code = tjsonAddIntegerToObject(pJson, jkDataBlockDescDataBlockId, pNode->dataBlockId); if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkDataBlockResultRowSize, pNode->resultRowSize); + code = tjsonAddIntegerToObject(pJson, jkDataBlockTotalRowSize, pNode->totalRowSize); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkDataBlockOutputRowSize, pNode->outputRowSize); } - if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkDataBlockDescSlots, pNode->pSlots); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkDataBlockPrecision, pNode->precision); + } return code; } @@ -2079,12 +2149,17 @@ static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) { int32_t code = tjsonGetSmallIntValue(pJson, jkDataBlockDescDataBlockId, &pNode->dataBlockId); if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetIntValue(pJson, jkDataBlockResultRowSize, &pNode->resultRowSize); + code = tjsonGetIntValue(pJson, jkDataBlockTotalRowSize, &pNode->totalRowSize); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkDataBlockOutputRowSize, &pNode->outputRowSize); } - if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkDataBlockDescSlots, &pNode->pSlots); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetSmallIntValue(pJson, jkDataBlockPrecision, &pNode->precision); + } return code; } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 035a2f1caa..89b4476899 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,8 @@ 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_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_TABLES_STMT: case QUERY_NODE_SHOW_STABLES_STMT: @@ -204,49 +208,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 +373,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() { @@ -582,11 +901,11 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* nodesWalkSelectStmt(pSelect, clause, collectColumns, &cxt); taosHashCleanup(cxt.pColIdHash); if (TSDB_CODE_SUCCESS != cxt.errCode) { - nodesDestroyList(cxt.pCols); + nodesClearList(cxt.pCols); return cxt.errCode; } if (0 == LIST_LENGTH(cxt.pCols)) { - nodesDestroyList(cxt.pCols); + nodesClearList(cxt.pCols); cxt.pCols = NULL; } *pCols = cxt.pCols; diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 0fe5df183d..029ae7e91f 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -159,6 +159,10 @@ 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); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 8f07d66a62..5e2f8e4241 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -15,6 +15,7 @@ #include #include +#include "functionMgt.h" #include "nodes.h" #include "parToken.h" #include "ttokendef.h" @@ -338,6 +339,18 @@ cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C). cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C); } cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); } +/************************************************ select **************************************************************/ +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); } + /************************************************ select **************************************************************/ cmd ::= query_expression(A). { pCxt->pRootNode = A; } @@ -348,6 +361,7 @@ literal(A) ::= NK_STRING(B). literal(A) ::= NK_BOOL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B)); } literal(A) ::= TIMESTAMP(B) NK_STRING(C). { A = createRawExprNodeExt(pCxt, &B, &C, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &C)); } literal(A) ::= duration_literal(B). { A = B; } +literal(A) ::= NULL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } duration_literal(A) ::= NK_VARIABLE(B). { A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); } @@ -371,6 +385,7 @@ signed_literal(A) ::= NK_STRING(B). signed_literal(A) ::= NK_BOOL(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B); } signed_literal(A) ::= TIMESTAMP NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); } signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); } +signed_literal(A) ::= NULL. { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } %type literal_list { SNodeList* } %destructor literal_list { nodesDestroyList($$); } @@ -417,7 +432,7 @@ topic_name(A) ::= NK_ID(B). /************************************************ expression **********************************************************/ expression(A) ::= literal(B). { A = B; } //expression(A) ::= NK_QUESTION(B). { A = B; } -//expression(A) ::= pseudo_column(B). { A = B; } +expression(A) ::= pseudo_column(B). { A = B; } expression(A) ::= column_reference(B). { A = B; } expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); } @@ -467,7 +482,38 @@ expression_list(A) ::= expression_list(B) NK_COMMA expression(C). column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); } column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); } -//pseudo_column(A) ::= NK_NOW. { A = createFunctionNode(pCxt, NULL, NULL); } +//pseudo_column(A) ::= NK_NOW. { A = createFunctionNode(pCxt, NULL, NULL); } +pseudo_column(A) ::= NK_UNDERLINE(B) ROWTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= NK_UNDERLINE(B) QSTARTTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) QENDTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) WSTARTTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) WENDTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) WDURATION(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } /************************************************ predicate ***********************************************************/ predicate(A) ::= expression(B) compare_op(C) expression(D). { diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index c5a632482c..8783872ad8 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -577,11 +577,13 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral) { SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); CHECK_OUT_OF_MEM(val); - val->literal = strndup(pLiteral->z, pLiteral->n); - if (TK_NK_ID != pLiteral->type && (IS_VAR_DATA_TYPE(dataType) || TSDB_DATA_TYPE_TIMESTAMP == dataType)) { - trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n); + if (NULL != pLiteral) { + val->literal = strndup(pLiteral->z, pLiteral->n); + if (TK_NK_ID != pLiteral->type && (IS_VAR_DATA_TYPE(dataType) || TSDB_DATA_TYPE_TIMESTAMP == dataType)) { + trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n); + } + CHECK_OUT_OF_MEM(val->literal); } - CHECK_OUT_OF_MEM(val->literal); val->node.resType.type = dataType; val->node.resType.bytes = IS_VAR_DATA_TYPE(dataType) ? strlen(val->literal) : tDataTypes[dataType].bytes; if (TSDB_DATA_TYPE_TIMESTAMP == dataType) { @@ -717,8 +719,10 @@ SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset) { SLimitNode* limitNode = (SLimitNode*)nodesMakeNode(QUERY_NODE_LIMIT); CHECK_OUT_OF_MEM(limitNode); - // limitNode->limit = limit; - // limitNode->offset = offset; + limitNode->limit = strtol(pLimit->z, NULL, 10); + if (NULL != pOffset) { + limitNode->offset = strtol(pOffset->z, NULL, 10); + } return (SNode*)limitNode; } @@ -1312,3 +1316,30 @@ 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; +} diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 766e606823..213b14ae5d 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -31,6 +31,7 @@ static SKeyword keywordTable[] = { {"ACCOUNT", TK_ACCOUNT}, {"ALL", TK_ALL}, {"ALTER", TK_ALTER}, + {"ANALYZE", TK_ANALYZE}, {"AND", TK_AND}, {"AS", TK_AS}, {"ASC", TK_ASC}, @@ -56,6 +57,7 @@ static SKeyword keywordTable[] = { {"DOUBLE", TK_DOUBLE}, {"DROP", TK_DROP}, {"EXISTS", TK_EXISTS}, + {"EXPLAIN", TK_EXPLAIN}, {"FILE_FACTOR", TK_FILE_FACTOR}, {"FILL", TK_FILL}, {"FLOAT", TK_FLOAT}, @@ -99,17 +101,22 @@ static SKeyword keywordTable[] = { {"ON", TK_ON}, {"OR", TK_OR}, {"ORDER", TK_ORDER}, + {"PARTITION", TK_PARTITION}, {"PASS", TK_PASS}, {"PORT", TK_PORT}, {"PRECISION", TK_PRECISION}, {"PRIVILEGE", TK_PRIVILEGE}, {"PREV", TK_PREV}, + {"QENDTS", TK_QENDTS}, {"QNODE", TK_QNODE}, {"QNODES", TK_QNODES}, + {"QSTARTTS", TK_QSTARTTS}, {"QUORUM", TK_QUORUM}, + {"RATIO", TK_RATIO}, {"REPLICA", TK_REPLICA}, {"RETENTIONS", TK_RETENTIONS}, {"ROLLUP", TK_ROLLUP}, + {"ROWTS", TK_ROWTS}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, {"SHOW", TK_SHOW}, @@ -127,6 +134,7 @@ static SKeyword keywordTable[] = { {"TABLE", TK_TABLE}, {"TABLES", TK_TABLES}, {"TAGS", TK_TAGS}, + {"TBNAME", TK_TBNAME}, {"TIMESTAMP", TK_TIMESTAMP}, {"TINYINT", TK_TINYINT}, {"TOPIC", TK_TOPIC}, @@ -139,9 +147,13 @@ static SKeyword keywordTable[] = { {"USING", TK_USING}, {"VALUES", TK_VALUES}, {"VARCHAR", TK_VARCHAR}, + {"VERBOSE", TK_VERBOSE}, {"VGROUPS", TK_VGROUPS}, {"WAL", TK_WAL}, + {"WDURATION", TK_WDURATION}, + {"WENDTS", TK_WENDTS}, {"WHERE", TK_WHERE}, + {"WSTARTTS", TK_WSTARTTS}, // {"ID", TK_ID}, // {"STRING", TK_STRING}, // {"EQ", TK_EQ}, @@ -216,7 +228,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}, @@ -233,7 +244,6 @@ static SKeyword keywordTable[] = { // {"TRIGGER", TK_TRIGGER}, // {"VIEW", TK_VIEW}, // {"SEMI", TK_SEMI}, - // {"TBNAME", TK_TBNAME}, // {"VNODES", TK_VNODES}, // {"PARTITIONS", TK_PARTITIONS}, // {"TOPICS", TK_TOPICS}, @@ -427,6 +437,10 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { *tokenId = TK_NK_QUESTION; return 1; } + case '_': { + *tokenId = TK_NK_UNDERLINE; + return 1; + } case '`': case '\'': case '"': { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 6771eafa09..d453193d0f 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) { @@ -235,6 +239,8 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol nodesListAppend(pExpr->pAssociationList, (SNode*)pCol); if (NULL != pTable) { strcpy(pCol->tableAlias, pTable->tableAlias); + } else if (QUERY_NODE_COLUMN == nodeType(pExpr)) { + strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias); } strcpy(pCol->colName, pExpr->aliasName); pCol->node.resType = pExpr->resType; @@ -617,7 +623,6 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) { } static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { - // todo release if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) { return TSDB_CODE_SUCCESS; } @@ -631,11 +636,6 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea } if (TSDB_CODE_SUCCESS == code) { - // todo remove - //if (NULL != vgroupList && taosArrayGetSize(vgroupList) > 0 && 0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) { - // taosArrayPopTailBatch(vgroupList, taosArrayGetSize(vgroupList) - 1); - //} - code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList); } taosArrayDestroy(vgroupList); @@ -674,6 +674,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)); @@ -681,10 +682,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: { @@ -1488,12 +1488,6 @@ static int32_t nodeTypeToShowType(ENodeType nt) { static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { SShowReq showReq = { .type = nodeTypeToShowType(nodeType(pStmt)) }; - // if ('\0' != pStmt->dbName[0]) { - // SName name = {0}; - // tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); - // char dbFname[TSDB_DB_FNAME_LEN] = {0}; - // tNameGetFullDbName(&name, showReq.db); - // } pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { @@ -1811,6 +1805,13 @@ 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 translateQuery(STranslateContext* pCxt, SNode* pNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { @@ -1892,6 +1893,9 @@ 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; default: break; } @@ -1910,7 +1914,11 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) { } int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { - if (NULL != pRoot && QUERY_NODE_SELECT_STMT == nodeType(pRoot)) { + if (NULL == pRoot) { + return TSDB_CODE_SUCCESS; + } + + if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) { SSelectStmt* pSelect = (SSelectStmt*) pRoot; *numOfCols = LIST_LENGTH(pSelect->pProjectionList); *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); @@ -1928,6 +1936,14 @@ int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** p strcpy((*pSchema)[index].name, pExpr->aliasName); index +=1; } + } else if (QUERY_NODE_EXPLAIN_STMT == nodeType(pRoot)) { + *numOfCols = 1; + *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); + if (NULL == (*pSchema)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[0].bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE; } return TSDB_CODE_SUCCESS; @@ -2512,6 +2528,7 @@ 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; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 92bd6f111b..d9bff4b9ef 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -58,5 +58,7 @@ void qDestroyQuery(SQuery* pQueryNode) { taosMemoryFreeClear(pQueryNode->pCmdMsg->pMsg); taosMemoryFreeClear(pQueryNode->pCmdMsg); } + taosArrayDestroy(pQueryNode->pDbList); + taosArrayDestroy(pQueryNode->pTableList); taosMemoryFreeClear(pQueryNode); } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index b64eaee628..154b87ba4b 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -32,6 +32,7 @@ #include #include +#include "functionMgt.h" #include "nodes.h" #include "parToken.h" #include "ttokendef.h" @@ -99,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 259 +#define YYNOCODE 274 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SAlterOption yy11; - ENullOrder yy151; - EJoinType yy162; - SToken yy183; - bool yy215; - EOperatorType yy366; - SNode* yy378; - int32_t yy396; - EOrder yy400; - SNodeList* yy404; - EFillMode yy466; - SDataType yy504; + SAlterOption yy29; + SNodeList* yy40; + ENullOrder yy177; + EOrder yy210; + EOperatorType yy328; + SNode* yy364; + EJoinType yy392; + SDataType yy420; + SToken yy437; + int32_t yy460; + EFillMode yy478; + bool yy493; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -131,17 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 431 -#define YYNRULE 338 -#define YYNTOKEN 164 -#define YY_MAX_SHIFT 430 -#define YY_MIN_SHIFTREDUCE 664 -#define YY_MAX_SHIFTREDUCE 1001 -#define YY_ERROR_ACTION 1002 -#define YY_ACCEPT_ACTION 1003 -#define YY_NO_ACTION 1004 -#define YY_MIN_REDUCE 1005 -#define YY_MAX_REDUCE 1342 +#define YYNSTATE 438 +#define YYNRULE 354 +#define YYNTOKEN 176 +#define YY_MAX_SHIFT 437 +#define YY_MIN_SHIFTREDUCE 684 +#define YY_MAX_SHIFTREDUCE 1037 +#define YY_ERROR_ACTION 1038 +#define YY_ACCEPT_ACTION 1039 +#define YY_NO_ACTION 1040 +#define YY_MIN_REDUCE 1041 +#define YY_MAX_REDUCE 1394 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -208,393 +209,408 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1230) +#define YY_ACTTAB_COUNT (1305) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1235, 1220, 225, 1208, 1220, 349, 242, 346, 237, 1204, - /* 10 */ 1210, 1184, 31, 29, 27, 26, 25, 1097, 105, 1208, - /* 20 */ 1017, 1235, 362, 1208, 1235, 1204, 1209, 66, 346, 1204, - /* 30 */ 1209, 346, 320, 1235, 279, 361, 24, 170, 348, 362, - /* 40 */ 346, 348, 1196, 1108, 66, 1196, 361, 211, 1048, 250, - /* 50 */ 334, 285, 107, 1221, 1224, 61, 1221, 1224, 1260, 362, - /* 60 */ 1108, 194, 210, 1256, 269, 323, 196, 349, 283, 884, - /* 70 */ 109, 362, 282, 1185, 1321, 209, 1105, 907, 195, 43, - /* 80 */ 1108, 1148, 31, 29, 27, 26, 25, 117, 123, 335, - /* 90 */ 1334, 1319, 1108, 284, 10, 1099, 1104, 415, 414, 413, - /* 100 */ 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, - /* 110 */ 402, 401, 400, 399, 398, 270, 908, 211, 31, 29, - /* 120 */ 27, 26, 25, 9, 8, 23, 232, 1006, 902, 903, - /* 130 */ 904, 905, 906, 910, 911, 912, 1196, 27, 26, 25, - /* 140 */ 31, 29, 27, 26, 25, 1003, 1028, 907, 78, 64, - /* 150 */ 870, 77, 76, 75, 74, 73, 72, 71, 70, 69, - /* 160 */ 319, 773, 385, 384, 383, 777, 382, 779, 780, 381, - /* 170 */ 782, 378, 1274, 788, 375, 790, 791, 372, 369, 872, - /* 180 */ 291, 118, 286, 325, 321, 290, 908, 1196, 289, 1271, - /* 190 */ 287, 920, 1220, 288, 249, 23, 232, 884, 902, 903, - /* 200 */ 904, 905, 906, 910, 911, 912, 31, 29, 27, 26, - /* 210 */ 25, 324, 1235, 106, 1075, 423, 422, 78, 1321, 333, - /* 220 */ 77, 76, 75, 74, 73, 72, 71, 70, 69, 348, - /* 230 */ 43, 117, 238, 1196, 968, 1319, 1321, 218, 118, 89, - /* 240 */ 104, 874, 1220, 62, 1221, 1224, 1260, 1103, 1110, 1320, - /* 250 */ 227, 1256, 112, 1319, 316, 966, 967, 969, 970, 283, - /* 260 */ 875, 330, 1235, 282, 166, 997, 998, 870, 118, 333, - /* 270 */ 312, 1287, 1220, 219, 251, 217, 216, 263, 281, 348, - /* 280 */ 245, 244, 92, 1196, 284, 362, 264, 1175, 1177, 104, - /* 290 */ 359, 1172, 1235, 62, 1221, 1224, 1260, 1110, 120, 346, - /* 300 */ 227, 1256, 112, 1279, 939, 361, 1108, 362, 90, 348, - /* 310 */ 1027, 700, 360, 1196, 701, 1220, 700, 332, 113, 1267, - /* 320 */ 1268, 1288, 1272, 62, 1221, 1224, 1260, 277, 1108, 330, - /* 330 */ 227, 1256, 1333, 6, 702, 1235, 1026, 30, 28, 241, - /* 340 */ 240, 1294, 346, 165, 1220, 234, 258, 852, 873, 864, - /* 350 */ 92, 1196, 348, 10, 262, 397, 1196, 257, 256, 255, - /* 360 */ 254, 253, 151, 850, 1235, 857, 62, 1221, 1224, 1260, - /* 370 */ 909, 346, 12, 227, 1256, 1333, 90, 1196, 362, 21, - /* 380 */ 1086, 348, 871, 184, 1317, 1196, 114, 1267, 1268, 913, - /* 390 */ 1272, 122, 121, 1, 1155, 62, 1221, 1224, 1260, 1108, - /* 400 */ 224, 1220, 227, 1256, 1333, 1153, 30, 28, 944, 1084, - /* 410 */ 30, 28, 189, 1278, 234, 1138, 852, 427, 234, 363, - /* 420 */ 852, 1235, 943, 118, 9, 8, 270, 939, 346, 851, - /* 430 */ 305, 860, 850, 1155, 951, 1025, 850, 1024, 348, 239, - /* 440 */ 872, 12, 1196, 1085, 1153, 12, 20, 334, 853, 856, - /* 450 */ 865, 856, 201, 1221, 1224, 397, 31, 29, 27, 26, - /* 460 */ 25, 104, 1, 118, 1023, 247, 1, 30, 28, 1111, - /* 470 */ 306, 1321, 1083, 104, 1155, 234, 1196, 852, 1196, 59, - /* 480 */ 246, 1110, 1274, 1220, 117, 1153, 427, 362, 1319, 93, - /* 490 */ 427, 388, 248, 850, 1321, 1155, 1100, 1022, 851, 1270, - /* 500 */ 394, 345, 851, 1235, 393, 1196, 1176, 117, 1108, 337, - /* 510 */ 346, 1319, 1220, 52, 1021, 1020, 1076, 853, 856, 1093, - /* 520 */ 348, 853, 856, 7, 1196, 395, 1019, 1016, 1015, 394, - /* 530 */ 1101, 1014, 1235, 393, 63, 1221, 1224, 1260, 1196, 346, - /* 540 */ 330, 1259, 1256, 1095, 392, 391, 390, 427, 389, 348, - /* 550 */ 30, 28, 347, 1196, 395, 1196, 1196, 942, 234, 851, - /* 560 */ 852, 92, 1013, 63, 1221, 1224, 1260, 1196, 1196, 1196, - /* 570 */ 344, 1256, 1196, 392, 391, 390, 850, 389, 853, 856, - /* 580 */ 334, 899, 1220, 308, 30, 28, 1012, 90, 1011, 1091, - /* 590 */ 1274, 1010, 234, 118, 852, 98, 1009, 163, 1267, 329, - /* 600 */ 852, 328, 1235, 1196, 1321, 1008, 7, 1269, 137, 346, - /* 610 */ 850, 135, 30, 28, 1155, 139, 850, 117, 138, 348, - /* 620 */ 234, 1319, 852, 1196, 1005, 1154, 303, 1196, 141, 1196, - /* 630 */ 427, 140, 1196, 63, 1221, 1224, 1260, 1196, 850, 301, - /* 640 */ 7, 1257, 851, 1044, 1000, 1001, 1196, 1039, 87, 86, - /* 650 */ 85, 84, 83, 82, 81, 80, 79, 1037, 430, 387, - /* 660 */ 336, 853, 856, 58, 427, 292, 1220, 341, 1, 294, - /* 670 */ 427, 143, 187, 54, 142, 88, 851, 965, 156, 297, - /* 680 */ 859, 419, 851, 186, 338, 1220, 1235, 914, 881, 41, - /* 690 */ 154, 1018, 427, 346, 167, 853, 856, 317, 1149, 32, - /* 700 */ 32, 853, 856, 348, 851, 1235, 60, 1196, 1214, 182, - /* 710 */ 233, 160, 346, 845, 276, 1220, 858, 205, 1221, 1224, - /* 720 */ 1212, 1220, 348, 853, 856, 32, 1196, 175, 1290, 313, - /* 730 */ 331, 354, 330, 1236, 1220, 1235, 205, 1221, 1224, 173, - /* 740 */ 358, 1235, 346, 95, 342, 169, 862, 2, 346, 870, - /* 750 */ 1174, 181, 348, 92, 1235, 252, 1196, 311, 348, 339, - /* 760 */ 147, 346, 1196, 96, 260, 766, 204, 1221, 1224, 761, - /* 770 */ 259, 348, 107, 1221, 1224, 1196, 119, 98, 231, 90, - /* 780 */ 1220, 41, 861, 794, 261, 205, 1221, 1224, 1220, 115, - /* 790 */ 1267, 1268, 22, 1272, 878, 367, 265, 326, 267, 798, - /* 800 */ 1235, 804, 31, 29, 27, 26, 25, 346, 1235, 266, - /* 810 */ 1335, 96, 124, 97, 803, 346, 1220, 348, 99, 877, - /* 820 */ 268, 1196, 1220, 271, 235, 348, 98, 127, 42, 1196, - /* 830 */ 96, 205, 1221, 1224, 130, 876, 1235, 278, 280, 203, - /* 840 */ 1221, 1224, 1235, 346, 1220, 68, 307, 1098, 223, 346, - /* 850 */ 134, 1094, 136, 348, 100, 146, 101, 1196, 1096, 348, - /* 860 */ 1092, 102, 103, 1196, 1235, 149, 875, 206, 1221, 1224, - /* 870 */ 309, 346, 1220, 199, 1221, 1224, 1301, 318, 1220, 352, - /* 880 */ 856, 348, 1300, 1291, 159, 1196, 310, 314, 5, 152, - /* 890 */ 1281, 1220, 1235, 315, 226, 207, 1221, 1224, 1235, 346, - /* 900 */ 155, 4, 322, 327, 939, 346, 91, 874, 33, 348, - /* 910 */ 161, 1235, 162, 1196, 1275, 348, 228, 343, 346, 1196, - /* 920 */ 1220, 340, 17, 200, 1221, 1224, 1220, 1242, 348, 208, - /* 930 */ 1221, 1224, 1196, 110, 1183, 350, 351, 355, 177, 1220, - /* 940 */ 1235, 1318, 1232, 1221, 1224, 1336, 1235, 346, 1220, 168, - /* 950 */ 1182, 236, 357, 346, 356, 179, 188, 348, 51, 1235, - /* 960 */ 53, 1196, 1109, 348, 1051, 365, 346, 1196, 1235, 190, - /* 970 */ 185, 1231, 1221, 1224, 426, 346, 348, 1230, 1221, 1224, - /* 980 */ 1196, 197, 198, 1220, 192, 348, 193, 1190, 828, 1196, - /* 990 */ 214, 1221, 1224, 132, 1167, 1166, 111, 94, 1165, 213, - /* 1000 */ 1221, 1224, 275, 1235, 131, 1164, 1163, 1162, 1161, 1160, - /* 1010 */ 346, 1220, 830, 291, 1159, 286, 1158, 1220, 290, 1157, - /* 1020 */ 348, 289, 1156, 287, 1196, 1050, 288, 44, 1189, 1180, - /* 1030 */ 129, 1235, 126, 1087, 215, 1221, 1224, 1235, 346, 713, - /* 1040 */ 1049, 1047, 296, 274, 346, 1036, 273, 1035, 348, 272, - /* 1050 */ 1032, 1089, 1196, 67, 348, 133, 811, 304, 1196, 810, - /* 1060 */ 1088, 809, 212, 1221, 1224, 741, 1045, 1040, 202, 1221, - /* 1070 */ 1224, 145, 740, 739, 299, 738, 220, 128, 221, 293, - /* 1080 */ 737, 125, 144, 295, 736, 1038, 222, 298, 1031, 1030, - /* 1090 */ 300, 302, 65, 1188, 1187, 36, 1179, 14, 45, 150, - /* 1100 */ 148, 3, 34, 15, 32, 40, 48, 37, 39, 11, - /* 1110 */ 8, 1212, 153, 158, 986, 985, 164, 964, 229, 990, - /* 1120 */ 108, 157, 989, 900, 958, 230, 46, 1178, 957, 47, - /* 1130 */ 1004, 866, 936, 353, 935, 1004, 1004, 1004, 1004, 1004, - /* 1140 */ 991, 178, 1046, 19, 882, 366, 1004, 13, 243, 1004, - /* 1150 */ 18, 35, 172, 116, 174, 16, 370, 373, 171, 962, - /* 1160 */ 176, 376, 1004, 49, 379, 50, 772, 800, 1034, 1033, - /* 1170 */ 806, 38, 1029, 802, 795, 792, 733, 54, 725, 368, - /* 1180 */ 1211, 183, 371, 364, 789, 374, 801, 732, 396, 783, - /* 1190 */ 377, 731, 421, 781, 711, 730, 380, 729, 55, 728, - /* 1200 */ 727, 56, 57, 726, 724, 723, 787, 786, 180, 722, - /* 1210 */ 785, 386, 721, 720, 719, 784, 718, 717, 716, 416, - /* 1220 */ 417, 420, 424, 425, 428, 418, 854, 191, 429, 805, + /* 0 */ 1251, 337, 24, 172, 356, 356, 256, 241, 1247, 1254, + /* 10 */ 1220, 1221, 31, 29, 27, 26, 25, 1264, 369, 369, + /* 20 */ 9, 8, 93, 67, 67, 31, 29, 27, 26, 25, + /* 30 */ 286, 292, 337, 1373, 106, 60, 1053, 1280, 369, 1144, + /* 40 */ 1144, 341, 1135, 276, 353, 94, 118, 215, 1084, 249, + /* 50 */ 1371, 91, 1136, 93, 355, 979, 1211, 1213, 1238, 1144, + /* 60 */ 215, 165, 1319, 336, 110, 335, 1087, 44, 1373, 913, + /* 70 */ 63, 1265, 1266, 1269, 1312, 1184, 90, 943, 231, 1308, + /* 80 */ 1385, 118, 91, 1238, 1139, 1371, 107, 1111, 956, 1346, + /* 90 */ 943, 339, 114, 1319, 1320, 257, 1324, 422, 421, 420, + /* 100 */ 419, 418, 417, 416, 415, 414, 413, 412, 411, 410, + /* 110 */ 409, 408, 407, 406, 405, 298, 944, 293, 105, 242, + /* 120 */ 297, 213, 898, 296, 368, 294, 1147, 105, 295, 944, + /* 130 */ 31, 29, 27, 26, 25, 1146, 368, 1122, 23, 236, + /* 140 */ 938, 939, 940, 941, 942, 946, 947, 948, 27, 26, + /* 150 */ 25, 23, 236, 938, 939, 940, 941, 942, 946, 947, + /* 160 */ 948, 793, 392, 391, 390, 797, 389, 799, 800, 388, + /* 170 */ 802, 385, 1264, 808, 382, 810, 811, 379, 376, 229, + /* 180 */ 30, 28, 337, 277, 12, 30, 28, 980, 238, 277, + /* 190 */ 878, 246, 1280, 238, 1264, 878, 1251, 310, 255, 353, + /* 200 */ 254, 1191, 978, 93, 1247, 1253, 876, 228, 1251, 355, + /* 210 */ 308, 876, 1189, 1238, 1280, 11, 1247, 1253, 341, 369, + /* 220 */ 11, 340, 248, 119, 1141, 62, 1265, 1266, 1269, 1312, + /* 230 */ 105, 355, 91, 214, 1308, 1238, 1, 265, 1146, 1120, + /* 240 */ 1144, 1, 115, 1319, 1320, 1373, 1324, 63, 1265, 1266, + /* 250 */ 1269, 1312, 119, 1191, 720, 231, 1308, 113, 118, 243, + /* 260 */ 434, 6, 1371, 902, 1189, 434, 119, 430, 429, 168, + /* 270 */ 284, 312, 877, 1280, 1280, 319, 1339, 877, 30, 28, + /* 280 */ 353, 353, 124, 123, 222, 404, 238, 1264, 878, 1033, + /* 290 */ 1034, 326, 1331, 975, 879, 53, 882, 883, 204, 879, + /* 300 */ 926, 882, 883, 204, 876, 926, 290, 1280, 327, 330, + /* 310 */ 289, 313, 1137, 11, 340, 721, 1373, 720, 119, 1264, + /* 320 */ 223, 1191, 221, 220, 355, 288, 332, 328, 1238, 1372, + /* 330 */ 1064, 291, 1212, 1371, 1, 722, 119, 368, 1373, 1280, + /* 340 */ 63, 1265, 1266, 1269, 1312, 404, 353, 369, 231, 1308, + /* 350 */ 113, 118, 366, 30, 28, 1371, 355, 369, 434, 900, + /* 360 */ 1238, 238, 367, 878, 395, 167, 1264, 975, 1144, 1340, + /* 370 */ 877, 1238, 63, 1265, 1266, 1269, 1312, 1191, 1144, 876, + /* 380 */ 231, 1308, 1385, 250, 1063, 12, 1280, 192, 1189, 331, + /* 390 */ 1174, 1369, 879, 353, 882, 883, 204, 337, 926, 139, + /* 400 */ 251, 1062, 137, 355, 30, 28, 354, 1238, 105, 7, + /* 410 */ 369, 303, 238, 348, 878, 186, 1146, 44, 93, 63, + /* 420 */ 1265, 1266, 1269, 1312, 1061, 1238, 311, 231, 1308, 1385, + /* 430 */ 876, 1144, 945, 434, 1140, 987, 30, 28, 1330, 345, + /* 440 */ 147, 900, 1238, 306, 238, 877, 878, 91, 300, 1060, + /* 450 */ 1326, 146, 1264, 1059, 21, 1191, 901, 116, 1319, 1320, + /* 460 */ 7, 1324, 876, 949, 899, 1238, 1190, 879, 1323, 882, + /* 470 */ 883, 204, 1280, 926, 41, 30, 28, 40, 1004, 353, + /* 480 */ 1121, 1326, 369, 238, 434, 878, 1058, 252, 1208, 355, + /* 490 */ 1238, 119, 7, 1238, 1238, 122, 877, 1039, 341, 1322, + /* 500 */ 344, 876, 349, 1144, 1057, 205, 1265, 1266, 1269, 323, + /* 510 */ 1002, 1003, 1005, 1006, 1326, 290, 434, 1056, 879, 289, + /* 520 */ 882, 883, 204, 1055, 926, 1373, 346, 1238, 877, 898, + /* 530 */ 1052, 1, 1321, 9, 8, 903, 258, 401, 118, 270, + /* 540 */ 291, 400, 1371, 1264, 141, 1238, 253, 140, 271, 1133, + /* 550 */ 879, 352, 882, 883, 204, 434, 926, 143, 1238, 886, + /* 560 */ 142, 1051, 402, 1280, 1238, 20, 1050, 877, 1049, 1112, + /* 570 */ 353, 1238, 1129, 1373, 1264, 31, 29, 27, 26, 25, + /* 580 */ 355, 399, 398, 397, 1238, 396, 118, 1036, 1037, 879, + /* 590 */ 1371, 882, 883, 204, 1280, 926, 64, 1265, 1266, 1269, + /* 600 */ 1312, 353, 1238, 145, 1311, 1308, 144, 1238, 1131, 1238, + /* 610 */ 1048, 355, 1047, 1264, 315, 1238, 269, 1046, 1264, 264, + /* 620 */ 263, 262, 261, 260, 1045, 889, 99, 64, 1265, 1266, + /* 630 */ 1269, 1312, 935, 1280, 1001, 351, 1308, 153, 1280, 298, + /* 640 */ 353, 293, 1080, 1127, 297, 353, 42, 296, 1075, 294, + /* 650 */ 355, 1238, 295, 1238, 1238, 355, 1264, 1119, 1238, 1238, + /* 660 */ 1042, 885, 1044, 343, 299, 1238, 108, 1265, 1266, 1269, + /* 670 */ 301, 64, 1265, 1266, 1269, 1312, 1280, 169, 394, 1054, + /* 680 */ 1309, 78, 158, 353, 77, 76, 75, 74, 73, 72, + /* 690 */ 71, 70, 69, 355, 156, 324, 1264, 1238, 1073, 878, + /* 700 */ 237, 1264, 1185, 1238, 342, 1386, 162, 950, 283, 209, + /* 710 */ 1265, 1266, 1269, 1258, 401, 876, 1280, 1342, 400, 32, + /* 720 */ 304, 1280, 910, 353, 865, 1256, 338, 888, 353, 1281, + /* 730 */ 171, 871, 177, 355, 32, 361, 32, 1238, 355, 402, + /* 740 */ 320, 183, 1238, 1264, 175, 2, 190, 96, 898, 209, + /* 750 */ 1265, 1266, 1269, 97, 208, 1265, 1266, 1269, 399, 398, + /* 760 */ 397, 1210, 396, 1280, 121, 22, 259, 267, 266, 434, + /* 770 */ 353, 786, 268, 1264, 272, 31, 29, 27, 26, 25, + /* 780 */ 355, 877, 781, 99, 1238, 906, 333, 126, 31, 29, + /* 790 */ 27, 26, 25, 1280, 42, 1264, 108, 1265, 1266, 1269, + /* 800 */ 353, 273, 274, 879, 814, 882, 883, 818, 905, 824, + /* 810 */ 355, 823, 100, 129, 1238, 1280, 374, 235, 275, 97, + /* 820 */ 437, 98, 353, 99, 97, 278, 209, 1265, 1266, 1269, + /* 830 */ 43, 132, 355, 904, 189, 1387, 1238, 89, 287, 239, + /* 840 */ 285, 314, 227, 426, 317, 188, 59, 88, 209, 1265, + /* 850 */ 1266, 1269, 1041, 1134, 78, 136, 55, 77, 76, 75, + /* 860 */ 74, 73, 72, 71, 70, 69, 1130, 138, 61, 101, + /* 870 */ 1264, 184, 102, 1132, 1128, 103, 87, 86, 85, 84, + /* 880 */ 83, 82, 81, 80, 79, 104, 316, 148, 151, 925, + /* 890 */ 1280, 927, 928, 929, 930, 931, 903, 353, 1353, 325, + /* 900 */ 197, 1264, 365, 359, 154, 199, 883, 355, 322, 1343, + /* 910 */ 157, 1238, 1352, 230, 329, 5, 161, 198, 334, 318, + /* 920 */ 321, 1280, 149, 207, 1265, 1266, 1269, 125, 353, 975, + /* 930 */ 1333, 1264, 31, 29, 27, 26, 25, 111, 355, 4, + /* 940 */ 163, 902, 1238, 92, 1327, 33, 232, 17, 164, 347, + /* 950 */ 350, 1280, 1388, 1264, 210, 1265, 1266, 1269, 353, 1294, + /* 960 */ 1370, 362, 170, 179, 191, 1219, 1218, 357, 355, 358, + /* 970 */ 364, 240, 1238, 1280, 363, 1264, 181, 52, 1145, 54, + /* 980 */ 353, 372, 193, 187, 202, 1265, 1266, 1269, 65, 913, + /* 990 */ 355, 433, 195, 39, 1238, 1280, 200, 1264, 201, 196, + /* 1000 */ 1232, 874, 353, 873, 1226, 120, 211, 1265, 1266, 1269, + /* 1010 */ 848, 1203, 355, 1202, 95, 1201, 1238, 1280, 1200, 1264, + /* 1020 */ 1199, 1198, 1197, 1196, 353, 850, 1195, 1194, 203, 1265, + /* 1030 */ 1266, 1269, 119, 1193, 355, 1192, 1086, 1225, 1238, 1280, + /* 1040 */ 1216, 1264, 128, 1123, 733, 1085, 353, 1083, 279, 281, + /* 1050 */ 212, 1265, 1266, 1269, 1072, 280, 355, 1071, 1068, 1125, + /* 1060 */ 1238, 1280, 68, 1264, 135, 1124, 831, 830, 353, 761, + /* 1070 */ 829, 1081, 1277, 1265, 1266, 1269, 760, 759, 355, 758, + /* 1080 */ 757, 1076, 1238, 1280, 756, 224, 225, 1264, 302, 1074, + /* 1090 */ 353, 226, 1067, 305, 1276, 1265, 1266, 1269, 307, 1066, + /* 1100 */ 355, 309, 66, 1224, 1238, 1223, 36, 1280, 152, 150, + /* 1110 */ 14, 1264, 1215, 3, 353, 32, 1275, 1265, 1266, 1269, + /* 1120 */ 245, 244, 155, 15, 355, 37, 34, 10, 1238, 46, + /* 1130 */ 891, 1280, 160, 1264, 49, 1022, 1000, 994, 353, 993, + /* 1140 */ 218, 1265, 1266, 1269, 972, 109, 884, 1021, 355, 233, + /* 1150 */ 8, 159, 1238, 1280, 47, 1264, 48, 1026, 1256, 971, + /* 1160 */ 353, 19, 1025, 1027, 217, 1265, 1266, 1269, 35, 234, + /* 1170 */ 355, 166, 13, 117, 1238, 1280, 16, 1264, 936, 911, + /* 1180 */ 173, 18, 353, 174, 998, 176, 219, 1265, 1266, 1269, + /* 1190 */ 178, 50, 355, 360, 1214, 180, 1238, 1280, 55, 893, + /* 1200 */ 370, 182, 51, 38, 353, 1255, 185, 371, 216, 1265, + /* 1210 */ 1266, 1269, 887, 815, 355, 375, 134, 373, 1238, 112, + /* 1220 */ 247, 807, 812, 377, 378, 282, 809, 133, 380, 381, + /* 1230 */ 206, 1265, 1266, 1269, 892, 803, 895, 883, 383, 384, + /* 1240 */ 386, 801, 387, 806, 805, 804, 792, 393, 56, 826, + /* 1250 */ 45, 822, 57, 131, 58, 821, 820, 731, 825, 403, + /* 1260 */ 753, 752, 745, 751, 750, 749, 748, 747, 746, 744, + /* 1270 */ 743, 742, 1082, 741, 740, 739, 1070, 738, 1069, 737, + /* 1280 */ 736, 423, 424, 427, 428, 1065, 431, 425, 432, 1040, + /* 1290 */ 880, 194, 435, 436, 1040, 1040, 1040, 1040, 1040, 1040, + /* 1300 */ 130, 1040, 1040, 1040, 127, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 187, 167, 191, 208, 167, 204, 191, 194, 207, 214, - /* 10 */ 215, 210, 12, 13, 14, 15, 16, 188, 166, 208, - /* 20 */ 168, 187, 173, 208, 187, 214, 215, 178, 194, 214, - /* 30 */ 215, 194, 219, 187, 185, 20, 222, 223, 204, 173, - /* 40 */ 194, 204, 208, 194, 178, 208, 20, 47, 0, 173, - /* 50 */ 213, 185, 218, 219, 220, 218, 219, 220, 221, 173, - /* 60 */ 194, 18, 225, 226, 178, 219, 23, 204, 57, 69, - /* 70 */ 186, 173, 61, 210, 237, 199, 178, 77, 35, 175, - /* 80 */ 194, 197, 12, 13, 14, 15, 16, 250, 45, 255, - /* 90 */ 256, 254, 194, 82, 68, 167, 192, 49, 50, 51, + /* 0 */ 220, 185, 237, 238, 216, 216, 225, 219, 228, 229, + /* 10 */ 222, 222, 12, 13, 14, 15, 16, 179, 185, 185, + /* 20 */ 1, 2, 206, 190, 190, 12, 13, 14, 15, 16, + /* 30 */ 197, 197, 185, 252, 178, 184, 180, 199, 185, 206, + /* 40 */ 206, 225, 179, 190, 206, 194, 265, 47, 0, 208, + /* 50 */ 269, 235, 201, 206, 216, 4, 215, 216, 220, 206, + /* 60 */ 47, 245, 246, 247, 198, 249, 0, 187, 252, 69, + /* 70 */ 232, 233, 234, 235, 236, 209, 196, 77, 240, 241, + /* 80 */ 242, 265, 235, 220, 204, 269, 188, 189, 69, 251, + /* 90 */ 77, 244, 245, 246, 247, 185, 249, 49, 50, 51, /* 100 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - /* 110 */ 62, 63, 64, 65, 66, 46, 116, 47, 12, 13, - /* 120 */ 14, 15, 16, 1, 2, 125, 126, 0, 128, 129, - /* 130 */ 130, 131, 132, 133, 134, 135, 208, 14, 15, 16, - /* 140 */ 12, 13, 14, 15, 16, 164, 167, 77, 21, 106, - /* 150 */ 20, 24, 25, 26, 27, 28, 29, 30, 31, 32, - /* 160 */ 120, 83, 84, 85, 86, 87, 88, 89, 90, 91, - /* 170 */ 92, 93, 216, 95, 96, 97, 98, 99, 100, 20, - /* 180 */ 49, 138, 51, 143, 144, 54, 116, 208, 57, 233, - /* 190 */ 59, 69, 167, 62, 213, 125, 126, 69, 128, 129, - /* 200 */ 130, 131, 132, 133, 134, 135, 12, 13, 14, 15, - /* 210 */ 16, 20, 187, 176, 177, 170, 171, 21, 237, 194, - /* 220 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 204, - /* 230 */ 175, 250, 179, 208, 127, 254, 237, 35, 138, 184, - /* 240 */ 187, 20, 167, 218, 219, 220, 221, 192, 195, 250, - /* 250 */ 225, 226, 227, 254, 147, 148, 149, 150, 151, 57, - /* 260 */ 20, 173, 187, 61, 239, 159, 160, 20, 138, 194, - /* 270 */ 245, 246, 167, 71, 27, 73, 74, 30, 76, 204, - /* 280 */ 196, 179, 194, 208, 82, 173, 39, 203, 204, 187, - /* 290 */ 178, 194, 187, 218, 219, 220, 221, 195, 201, 194, - /* 300 */ 225, 226, 227, 136, 137, 20, 194, 173, 220, 204, - /* 310 */ 167, 22, 178, 208, 20, 167, 22, 229, 230, 231, - /* 320 */ 232, 246, 234, 218, 219, 220, 221, 38, 194, 173, - /* 330 */ 225, 226, 227, 43, 40, 187, 167, 12, 13, 12, - /* 340 */ 13, 236, 194, 122, 167, 20, 63, 22, 20, 22, - /* 350 */ 194, 208, 204, 68, 107, 46, 208, 110, 111, 112, - /* 360 */ 113, 114, 122, 38, 187, 38, 218, 219, 220, 221, - /* 370 */ 116, 194, 47, 225, 226, 227, 220, 208, 173, 125, - /* 380 */ 0, 204, 20, 178, 236, 208, 230, 231, 232, 135, - /* 390 */ 234, 108, 109, 68, 187, 218, 219, 220, 221, 194, - /* 400 */ 193, 167, 225, 226, 227, 198, 12, 13, 14, 0, - /* 410 */ 12, 13, 180, 236, 20, 183, 22, 92, 20, 92, - /* 420 */ 22, 187, 4, 138, 1, 2, 46, 137, 194, 104, - /* 430 */ 173, 104, 38, 187, 14, 167, 38, 167, 204, 193, - /* 440 */ 20, 47, 208, 0, 198, 47, 2, 213, 123, 124, - /* 450 */ 123, 124, 218, 219, 220, 46, 12, 13, 14, 15, - /* 460 */ 16, 187, 68, 138, 167, 179, 68, 12, 13, 195, - /* 470 */ 213, 237, 0, 187, 187, 20, 208, 22, 208, 172, - /* 480 */ 193, 195, 216, 167, 250, 198, 92, 173, 254, 182, - /* 490 */ 92, 79, 178, 38, 237, 187, 189, 167, 104, 233, - /* 500 */ 57, 47, 104, 187, 61, 208, 198, 250, 194, 3, - /* 510 */ 194, 254, 167, 172, 167, 167, 177, 123, 124, 188, - /* 520 */ 204, 123, 124, 68, 208, 82, 167, 167, 167, 57, - /* 530 */ 189, 167, 187, 61, 218, 219, 220, 221, 208, 194, - /* 540 */ 173, 225, 226, 188, 101, 102, 103, 92, 105, 204, - /* 550 */ 12, 13, 14, 208, 82, 208, 208, 139, 20, 104, - /* 560 */ 22, 194, 167, 218, 219, 220, 221, 208, 208, 208, - /* 570 */ 225, 226, 208, 101, 102, 103, 38, 105, 123, 124, - /* 580 */ 213, 127, 167, 69, 12, 13, 167, 220, 167, 188, - /* 590 */ 216, 167, 20, 138, 22, 81, 167, 230, 231, 232, - /* 600 */ 22, 234, 187, 208, 237, 167, 68, 233, 72, 194, - /* 610 */ 38, 75, 12, 13, 187, 72, 38, 250, 75, 204, - /* 620 */ 20, 254, 22, 208, 0, 198, 21, 208, 72, 208, - /* 630 */ 92, 75, 208, 218, 219, 220, 221, 208, 38, 34, - /* 640 */ 68, 226, 104, 0, 162, 163, 208, 0, 24, 25, - /* 650 */ 26, 27, 28, 29, 30, 31, 32, 0, 19, 188, - /* 660 */ 154, 123, 124, 68, 92, 22, 167, 81, 68, 22, - /* 670 */ 92, 72, 33, 78, 75, 36, 104, 69, 69, 22, - /* 680 */ 38, 42, 104, 44, 81, 167, 187, 69, 69, 81, - /* 690 */ 81, 168, 92, 194, 257, 123, 124, 248, 197, 81, - /* 700 */ 81, 123, 124, 204, 104, 187, 67, 208, 68, 70, - /* 710 */ 211, 242, 194, 69, 170, 167, 38, 218, 219, 220, - /* 720 */ 80, 167, 204, 123, 124, 81, 208, 69, 217, 211, - /* 730 */ 235, 69, 173, 187, 167, 187, 218, 219, 220, 81, - /* 740 */ 101, 187, 194, 81, 158, 251, 104, 238, 194, 20, - /* 750 */ 173, 69, 204, 194, 187, 202, 208, 118, 204, 156, - /* 760 */ 121, 194, 208, 81, 116, 69, 218, 219, 220, 69, - /* 770 */ 200, 204, 218, 219, 220, 208, 115, 81, 211, 220, - /* 780 */ 167, 81, 104, 69, 200, 218, 219, 220, 167, 230, - /* 790 */ 231, 232, 2, 234, 20, 81, 173, 249, 194, 69, - /* 800 */ 187, 69, 12, 13, 14, 15, 16, 194, 187, 212, - /* 810 */ 256, 81, 175, 81, 69, 194, 167, 204, 69, 20, - /* 820 */ 205, 208, 167, 173, 211, 204, 81, 175, 175, 208, - /* 830 */ 81, 218, 219, 220, 175, 20, 187, 169, 187, 218, - /* 840 */ 219, 220, 187, 194, 167, 173, 212, 187, 169, 194, - /* 850 */ 187, 187, 187, 204, 187, 172, 187, 208, 187, 204, - /* 860 */ 187, 187, 187, 208, 187, 172, 20, 218, 219, 220, - /* 870 */ 194, 194, 167, 218, 219, 220, 247, 146, 167, 145, - /* 880 */ 124, 204, 247, 217, 243, 208, 205, 141, 153, 209, - /* 890 */ 244, 167, 187, 208, 208, 218, 219, 220, 187, 194, - /* 900 */ 209, 140, 208, 152, 137, 194, 194, 20, 115, 204, - /* 910 */ 240, 187, 228, 208, 216, 204, 161, 157, 194, 208, - /* 920 */ 167, 155, 68, 218, 219, 220, 167, 224, 204, 218, - /* 930 */ 219, 220, 208, 241, 209, 208, 208, 119, 194, 167, - /* 940 */ 187, 253, 218, 219, 220, 258, 187, 194, 167, 252, - /* 950 */ 209, 208, 205, 194, 206, 172, 183, 204, 172, 187, - /* 960 */ 68, 208, 194, 204, 0, 190, 194, 208, 187, 173, - /* 970 */ 172, 218, 219, 220, 169, 194, 204, 218, 219, 220, - /* 980 */ 208, 181, 181, 167, 174, 204, 165, 0, 80, 208, - /* 990 */ 218, 219, 220, 33, 0, 0, 36, 115, 0, 218, - /* 1000 */ 219, 220, 42, 187, 44, 0, 0, 0, 0, 0, - /* 1010 */ 194, 167, 22, 49, 0, 51, 0, 167, 54, 0, - /* 1020 */ 204, 57, 0, 59, 208, 0, 62, 67, 0, 0, - /* 1030 */ 70, 187, 43, 0, 218, 219, 220, 187, 194, 48, - /* 1040 */ 0, 0, 4, 43, 194, 0, 36, 0, 204, 38, - /* 1050 */ 0, 0, 208, 77, 204, 75, 38, 19, 208, 38, - /* 1060 */ 0, 22, 218, 219, 220, 38, 0, 0, 218, 219, - /* 1070 */ 220, 33, 38, 38, 36, 38, 22, 117, 22, 41, - /* 1080 */ 38, 121, 44, 39, 38, 0, 22, 38, 0, 0, - /* 1090 */ 22, 22, 20, 0, 0, 122, 0, 142, 68, 117, - /* 1100 */ 43, 81, 136, 142, 81, 67, 4, 81, 70, 142, - /* 1110 */ 2, 80, 69, 81, 38, 38, 80, 69, 38, 38, - /* 1120 */ 68, 68, 38, 127, 69, 38, 68, 0, 69, 68, - /* 1130 */ 259, 22, 69, 120, 69, 259, 259, 259, 259, 259, - /* 1140 */ 69, 43, 0, 81, 69, 38, 259, 68, 38, 259, - /* 1150 */ 68, 81, 69, 80, 68, 81, 38, 38, 80, 69, - /* 1160 */ 68, 38, 259, 68, 38, 68, 22, 22, 0, 0, - /* 1170 */ 38, 68, 0, 38, 69, 69, 22, 78, 22, 68, - /* 1180 */ 80, 80, 68, 79, 69, 68, 38, 38, 47, 69, - /* 1190 */ 68, 38, 37, 69, 48, 38, 68, 38, 68, 38, - /* 1200 */ 38, 68, 68, 38, 38, 38, 94, 94, 117, 38, - /* 1210 */ 94, 82, 38, 38, 38, 94, 38, 38, 38, 38, - /* 1220 */ 36, 38, 22, 21, 21, 43, 22, 22, 20, 104, - /* 1230 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1240 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1250 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1260 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1270 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1280 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1290 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1300 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1310 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1320 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1330 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1340 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1350 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1360 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1370 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1380 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1390 */ 259, 259, 259, 259, + /* 110 */ 62, 63, 64, 65, 66, 49, 116, 51, 199, 191, + /* 120 */ 54, 211, 20, 57, 20, 59, 207, 199, 62, 116, + /* 130 */ 12, 13, 14, 15, 16, 207, 20, 0, 138, 139, + /* 140 */ 140, 141, 142, 143, 144, 145, 146, 147, 14, 15, + /* 150 */ 16, 138, 139, 140, 141, 142, 143, 144, 145, 146, + /* 160 */ 147, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 170 */ 92, 93, 179, 95, 96, 97, 98, 99, 100, 203, + /* 180 */ 12, 13, 185, 46, 68, 12, 13, 14, 20, 46, + /* 190 */ 22, 203, 199, 20, 179, 22, 220, 21, 125, 206, + /* 200 */ 127, 199, 151, 206, 228, 229, 38, 205, 220, 216, + /* 210 */ 34, 38, 210, 220, 199, 47, 228, 229, 225, 185, + /* 220 */ 47, 206, 191, 150, 190, 232, 233, 234, 235, 236, + /* 230 */ 199, 216, 235, 240, 241, 220, 68, 63, 207, 0, + /* 240 */ 206, 68, 245, 246, 247, 252, 249, 232, 233, 234, + /* 250 */ 235, 236, 150, 199, 22, 240, 241, 242, 265, 205, + /* 260 */ 92, 43, 269, 20, 210, 92, 150, 182, 183, 254, + /* 270 */ 38, 185, 104, 199, 199, 260, 261, 104, 12, 13, + /* 280 */ 206, 206, 108, 109, 35, 46, 20, 179, 22, 171, + /* 290 */ 172, 120, 148, 149, 126, 184, 128, 129, 130, 126, + /* 300 */ 132, 128, 129, 130, 38, 132, 57, 199, 234, 234, + /* 310 */ 61, 225, 201, 47, 206, 20, 252, 22, 150, 179, + /* 320 */ 71, 199, 73, 74, 216, 76, 155, 156, 220, 265, + /* 330 */ 179, 82, 210, 269, 68, 40, 150, 20, 252, 199, + /* 340 */ 232, 233, 234, 235, 236, 46, 206, 185, 240, 241, + /* 350 */ 242, 265, 190, 12, 13, 269, 216, 185, 92, 20, + /* 360 */ 220, 20, 190, 22, 79, 122, 179, 149, 206, 261, + /* 370 */ 104, 220, 232, 233, 234, 235, 236, 199, 206, 38, + /* 380 */ 240, 241, 242, 205, 179, 68, 199, 192, 210, 20, + /* 390 */ 195, 251, 126, 206, 128, 129, 130, 185, 132, 72, + /* 400 */ 191, 179, 75, 216, 12, 13, 14, 220, 199, 68, + /* 410 */ 185, 4, 20, 81, 22, 190, 207, 187, 206, 232, + /* 420 */ 233, 234, 235, 236, 179, 220, 19, 240, 241, 242, + /* 430 */ 38, 206, 116, 92, 204, 14, 12, 13, 251, 81, + /* 440 */ 33, 20, 220, 36, 20, 104, 22, 235, 41, 179, + /* 450 */ 230, 44, 179, 179, 138, 199, 20, 245, 246, 247, + /* 460 */ 68, 249, 38, 147, 20, 220, 210, 126, 248, 128, + /* 470 */ 129, 130, 199, 132, 67, 12, 13, 70, 128, 206, + /* 480 */ 0, 230, 185, 20, 92, 22, 179, 190, 206, 216, + /* 490 */ 220, 150, 68, 220, 220, 213, 104, 176, 225, 248, + /* 500 */ 3, 38, 170, 206, 179, 232, 233, 234, 235, 159, + /* 510 */ 160, 161, 162, 163, 230, 57, 92, 179, 126, 61, + /* 520 */ 128, 129, 130, 179, 132, 252, 168, 220, 104, 20, + /* 530 */ 179, 68, 248, 1, 2, 20, 27, 57, 265, 30, + /* 540 */ 82, 61, 269, 179, 72, 220, 225, 75, 39, 200, + /* 550 */ 126, 47, 128, 129, 130, 92, 132, 72, 220, 38, + /* 560 */ 75, 179, 82, 199, 220, 2, 179, 104, 179, 189, + /* 570 */ 206, 220, 200, 252, 179, 12, 13, 14, 15, 16, + /* 580 */ 216, 101, 102, 103, 220, 105, 265, 174, 175, 126, + /* 590 */ 269, 128, 129, 130, 199, 132, 232, 233, 234, 235, + /* 600 */ 236, 206, 220, 72, 240, 241, 75, 220, 200, 220, + /* 610 */ 179, 216, 179, 179, 69, 220, 107, 179, 179, 110, + /* 620 */ 111, 112, 113, 114, 179, 104, 81, 232, 233, 234, + /* 630 */ 235, 236, 128, 199, 69, 240, 241, 122, 199, 49, + /* 640 */ 206, 51, 0, 200, 54, 206, 81, 57, 0, 59, + /* 650 */ 216, 220, 62, 220, 220, 216, 179, 0, 220, 220, + /* 660 */ 0, 38, 179, 166, 22, 220, 232, 233, 234, 235, + /* 670 */ 22, 232, 233, 234, 235, 236, 199, 272, 200, 180, + /* 680 */ 241, 21, 69, 206, 24, 25, 26, 27, 28, 29, + /* 690 */ 30, 31, 32, 216, 81, 263, 179, 220, 0, 22, + /* 700 */ 223, 179, 209, 220, 270, 271, 257, 69, 182, 232, + /* 710 */ 233, 234, 235, 68, 57, 38, 199, 231, 61, 81, + /* 720 */ 22, 199, 69, 206, 69, 80, 250, 104, 206, 199, + /* 730 */ 266, 124, 69, 216, 81, 69, 81, 220, 216, 82, + /* 740 */ 223, 69, 220, 179, 81, 253, 226, 81, 20, 232, + /* 750 */ 233, 234, 235, 81, 232, 233, 234, 235, 101, 102, + /* 760 */ 103, 185, 105, 199, 115, 2, 214, 116, 212, 92, + /* 770 */ 206, 69, 212, 179, 185, 12, 13, 14, 15, 16, + /* 780 */ 216, 104, 69, 81, 220, 20, 264, 187, 12, 13, + /* 790 */ 14, 15, 16, 199, 81, 179, 232, 233, 234, 235, + /* 800 */ 206, 224, 206, 126, 69, 128, 129, 69, 20, 69, + /* 810 */ 216, 69, 69, 187, 220, 199, 81, 223, 217, 81, + /* 820 */ 19, 81, 206, 81, 81, 185, 232, 233, 234, 235, + /* 830 */ 187, 187, 216, 20, 33, 271, 220, 36, 199, 223, + /* 840 */ 181, 224, 181, 42, 217, 44, 68, 185, 232, 233, + /* 850 */ 234, 235, 0, 199, 21, 199, 78, 24, 25, 26, + /* 860 */ 27, 28, 29, 30, 31, 32, 199, 199, 67, 199, + /* 870 */ 179, 70, 199, 199, 199, 199, 24, 25, 26, 27, + /* 880 */ 28, 29, 30, 31, 32, 199, 206, 184, 184, 131, + /* 890 */ 199, 133, 134, 135, 136, 137, 20, 206, 262, 158, + /* 900 */ 18, 179, 101, 157, 221, 23, 129, 216, 220, 231, + /* 910 */ 221, 220, 262, 220, 220, 165, 258, 35, 164, 118, + /* 920 */ 153, 199, 121, 232, 233, 234, 235, 45, 206, 149, + /* 930 */ 259, 179, 12, 13, 14, 15, 16, 256, 216, 152, + /* 940 */ 255, 20, 220, 206, 230, 115, 173, 68, 243, 167, + /* 950 */ 169, 199, 273, 179, 232, 233, 234, 235, 206, 239, + /* 960 */ 268, 119, 267, 206, 195, 221, 221, 220, 216, 220, + /* 970 */ 217, 220, 220, 199, 218, 179, 184, 184, 206, 68, + /* 980 */ 206, 202, 185, 184, 232, 233, 234, 235, 106, 69, + /* 990 */ 216, 181, 186, 227, 220, 199, 193, 179, 193, 177, + /* 1000 */ 0, 104, 206, 126, 0, 123, 232, 233, 234, 235, + /* 1010 */ 80, 0, 216, 0, 115, 0, 220, 199, 0, 179, + /* 1020 */ 0, 0, 0, 0, 206, 22, 0, 0, 232, 233, + /* 1030 */ 234, 235, 150, 0, 216, 0, 0, 0, 220, 199, + /* 1040 */ 0, 179, 43, 0, 48, 0, 206, 0, 38, 43, + /* 1050 */ 232, 233, 234, 235, 0, 36, 216, 0, 0, 0, + /* 1060 */ 220, 199, 77, 179, 75, 0, 38, 38, 206, 38, + /* 1070 */ 22, 0, 232, 233, 234, 235, 38, 38, 216, 38, + /* 1080 */ 38, 0, 220, 199, 38, 22, 22, 179, 39, 0, + /* 1090 */ 206, 22, 0, 38, 232, 233, 234, 235, 22, 0, + /* 1100 */ 216, 22, 20, 0, 220, 0, 122, 199, 117, 43, + /* 1110 */ 154, 179, 0, 81, 206, 81, 232, 233, 234, 235, + /* 1120 */ 12, 13, 69, 154, 216, 81, 148, 154, 220, 68, + /* 1130 */ 22, 199, 81, 179, 4, 38, 69, 69, 206, 69, + /* 1140 */ 232, 233, 234, 235, 69, 68, 38, 38, 216, 38, + /* 1150 */ 2, 68, 220, 199, 68, 179, 68, 38, 80, 69, + /* 1160 */ 206, 81, 38, 69, 232, 233, 234, 235, 81, 38, + /* 1170 */ 216, 80, 68, 80, 220, 199, 81, 179, 128, 69, + /* 1180 */ 80, 68, 206, 69, 69, 68, 232, 233, 234, 235, + /* 1190 */ 68, 68, 216, 120, 0, 43, 220, 199, 78, 22, + /* 1200 */ 92, 117, 68, 68, 206, 80, 80, 79, 232, 233, + /* 1210 */ 234, 235, 104, 69, 216, 68, 33, 38, 220, 36, + /* 1220 */ 38, 94, 69, 38, 68, 42, 69, 44, 38, 68, + /* 1230 */ 232, 233, 234, 235, 126, 69, 128, 129, 38, 68, + /* 1240 */ 38, 69, 68, 94, 94, 94, 22, 82, 68, 38, + /* 1250 */ 67, 38, 68, 70, 68, 38, 22, 48, 104, 47, + /* 1260 */ 22, 38, 22, 38, 38, 38, 38, 38, 38, 38, + /* 1270 */ 38, 38, 0, 38, 38, 38, 0, 38, 0, 38, + /* 1280 */ 38, 38, 36, 38, 37, 0, 22, 43, 21, 274, + /* 1290 */ 22, 22, 21, 20, 274, 274, 274, 274, 274, 274, + /* 1300 */ 117, 274, 274, 274, 121, 274, 274, 274, 274, 274, + /* 1310 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1320 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1330 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1340 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1350 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1360 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1370 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1380 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1390 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1400 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1410 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1420 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1430 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1440 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1450 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, + /* 1460 */ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274, }; -#define YY_SHIFT_COUNT (430) +#define YY_SHIFT_COUNT (437) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1208) +#define YY_SHIFT_MAX (1285) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 43, 325, 394, 398, 398, 398, 398, 455, 398, 398, - /* 10 */ 285, 572, 600, 538, 572, 572, 572, 572, 572, 572, - /* 20 */ 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - /* 30 */ 572, 572, 572, 26, 26, 26, 130, 327, 327, 15, - /* 40 */ 15, 327, 15, 15, 69, 159, 191, 191, 100, 328, - /* 50 */ 159, 15, 15, 159, 15, 159, 328, 159, 159, 15, - /* 60 */ 309, 0, 70, 70, 247, 196, 202, 578, 131, 578, - /* 70 */ 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, - /* 80 */ 578, 578, 578, 578, 578, 578, 578, 578, 294, 380, - /* 90 */ 221, 221, 221, 409, 362, 328, 159, 159, 159, 412, - /* 100 */ 78, 78, 78, 78, 78, 127, 964, 106, 107, 11, - /* 110 */ 40, 289, 240, 167, 290, 167, 420, 506, 418, 729, - /* 120 */ 661, 648, 648, 729, 774, 69, 362, 799, 69, 69, - /* 130 */ 729, 69, 815, 159, 159, 159, 159, 159, 159, 159, - /* 140 */ 159, 159, 159, 159, 729, 815, 774, 309, 362, 799, - /* 150 */ 309, 846, 731, 734, 756, 731, 734, 756, 756, 735, - /* 160 */ 751, 746, 761, 767, 362, 887, 793, 755, 760, 766, - /* 170 */ 854, 159, 734, 756, 756, 734, 756, 818, 362, 799, - /* 180 */ 309, 412, 309, 362, 892, 729, 309, 815, 1230, 1230, - /* 190 */ 1230, 1230, 48, 624, 639, 960, 1038, 443, 472, 444, - /* 200 */ 790, 128, 194, 194, 194, 194, 194, 194, 194, 283, - /* 210 */ 122, 254, 123, 123, 123, 123, 536, 543, 556, 599, - /* 220 */ 643, 647, 657, 605, 514, 608, 609, 423, 482, 603, - /* 230 */ 586, 618, 454, 619, 640, 644, 658, 662, 682, 696, - /* 240 */ 642, 678, 700, 714, 730, 732, 745, 749, 595, 987, - /* 250 */ 908, 994, 995, 882, 998, 1005, 1006, 1007, 1008, 1009, - /* 260 */ 990, 1014, 1016, 1019, 1022, 1025, 1028, 1029, 989, 1033, - /* 270 */ 991, 1040, 1041, 1011, 1010, 1000, 1045, 1047, 1050, 1051, - /* 280 */ 976, 980, 1018, 1021, 1039, 1060, 1027, 1034, 1035, 1037, - /* 290 */ 1042, 1046, 1066, 1054, 1067, 1056, 1044, 1085, 1064, 1049, - /* 300 */ 1088, 1068, 1089, 1069, 1072, 1093, 1094, 973, 1096, 1030, - /* 310 */ 1057, 982, 1020, 1023, 955, 1043, 1026, 1048, 1052, 1053, - /* 320 */ 1055, 1058, 1059, 1032, 1031, 1061, 1062, 961, 1063, 1065, - /* 330 */ 1036, 966, 1070, 1073, 1071, 1074, 967, 1102, 1076, 1077, - /* 340 */ 1080, 1081, 1084, 1087, 1108, 996, 1078, 1075, 1079, 1082, - /* 350 */ 1083, 1090, 1086, 1092, 1013, 1095, 1127, 1098, 1091, 1097, - /* 360 */ 1099, 1100, 1101, 1109, 1103, 1104, 1105, 1107, 1110, 1111, - /* 370 */ 1106, 1118, 1114, 1115, 1119, 1117, 1120, 1123, 1122, 1124, - /* 380 */ 1126, 1128, 1112, 1113, 1116, 1121, 1144, 1129, 1130, 1132, - /* 390 */ 1125, 1133, 1134, 1135, 1148, 1145, 1146, 1141, 1154, 1149, - /* 400 */ 1153, 1157, 1159, 1161, 1162, 1165, 1156, 1166, 1167, 1171, - /* 410 */ 1174, 1175, 1176, 1178, 1179, 1180, 1142, 1181, 1184, 1182, - /* 420 */ 1168, 1183, 1155, 1169, 1172, 1200, 1202, 1204, 1205, 1203, - /* 430 */ 1208, + /* 0 */ 882, 168, 173, 266, 266, 266, 266, 341, 266, 266, + /* 10 */ 424, 463, 116, 392, 424, 424, 424, 424, 424, 424, + /* 20 */ 424, 424, 424, 424, 424, 424, 424, 424, 424, 424, + /* 30 */ 424, 424, 424, 317, 317, 317, 102, 1108, 1108, 73, + /* 40 */ 104, 104, 1108, 104, 104, 143, 339, 369, 369, 186, + /* 50 */ 436, 339, 104, 104, 339, 104, 339, 436, 339, 339, + /* 60 */ 104, 299, 0, 13, 13, 509, 833, 249, 677, 677, + /* 70 */ 677, 677, 677, 677, 677, 677, 677, 677, 677, 677, + /* 80 */ 677, 677, 677, 677, 677, 677, 677, 677, 590, 295, + /* 90 */ 137, 243, 243, 243, 239, 444, 436, 339, 339, 339, + /* 100 */ 285, 78, 78, 78, 78, 78, 660, 66, 118, 350, + /* 110 */ 458, 171, 232, 515, 144, 218, 144, 421, 497, 51, + /* 120 */ 607, 728, 649, 651, 651, 728, 765, 143, 444, 788, + /* 130 */ 143, 143, 728, 143, 813, 339, 339, 339, 339, 339, + /* 140 */ 339, 339, 339, 339, 339, 339, 728, 813, 765, 299, + /* 150 */ 444, 788, 299, 876, 741, 746, 777, 741, 746, 777, + /* 160 */ 777, 750, 754, 767, 787, 780, 444, 921, 830, 773, + /* 170 */ 781, 782, 879, 339, 746, 777, 777, 746, 777, 842, + /* 180 */ 444, 788, 299, 285, 299, 444, 911, 728, 299, 813, + /* 190 */ 1305, 1305, 1305, 1305, 1305, 48, 852, 801, 1183, 407, + /* 200 */ 480, 657, 563, 763, 758, 920, 776, 776, 776, 776, + /* 210 */ 776, 776, 776, 174, 19, 316, 134, 134, 134, 134, + /* 220 */ 327, 472, 485, 531, 642, 648, 698, 176, 545, 565, + /* 230 */ 613, 532, 413, 358, 332, 638, 504, 653, 645, 655, + /* 240 */ 663, 666, 672, 702, 521, 623, 713, 735, 738, 740, + /* 250 */ 742, 743, 778, 1000, 897, 877, 1004, 930, 1011, 1013, + /* 260 */ 899, 1015, 1018, 1020, 1021, 1022, 1023, 1003, 1026, 1027, + /* 270 */ 1033, 1035, 1036, 1037, 1040, 999, 1043, 996, 1045, 1047, + /* 280 */ 1010, 1019, 1006, 1054, 1057, 1058, 1059, 985, 989, 1028, + /* 290 */ 1029, 1048, 1065, 1031, 1038, 1039, 1041, 1042, 1046, 1071, + /* 300 */ 1063, 1081, 1064, 1049, 1089, 1069, 1055, 1092, 1076, 1099, + /* 310 */ 1079, 1082, 1103, 1105, 984, 1112, 1061, 1066, 991, 1032, + /* 320 */ 1034, 956, 1053, 1044, 1067, 1077, 1083, 1068, 1086, 1070, + /* 330 */ 1051, 1078, 1088, 1080, 969, 1075, 1090, 1091, 978, 1087, + /* 340 */ 1093, 1094, 1095, 973, 1130, 1097, 1109, 1111, 1119, 1124, + /* 350 */ 1131, 1148, 1050, 1100, 1110, 1104, 1113, 1114, 1115, 1117, + /* 360 */ 1122, 1073, 1123, 1194, 1152, 1084, 1134, 1120, 1125, 1126, + /* 370 */ 1177, 1135, 1128, 1144, 1179, 1182, 1147, 1153, 1185, 1156, + /* 380 */ 1157, 1190, 1161, 1166, 1200, 1171, 1172, 1202, 1174, 1127, + /* 390 */ 1149, 1150, 1151, 1224, 1165, 1180, 1211, 1154, 1184, 1186, + /* 400 */ 1213, 1217, 1234, 1209, 1212, 1238, 1223, 1225, 1226, 1227, + /* 410 */ 1228, 1229, 1230, 1240, 1231, 1232, 1233, 1235, 1236, 1237, + /* 420 */ 1239, 1241, 1242, 1272, 1243, 1246, 1244, 1276, 1245, 1247, + /* 430 */ 1278, 1285, 1264, 1267, 1268, 1269, 1271, 1273, }; -#define YY_REDUCE_COUNT (191) -#define YY_REDUCE_MIN (-205) -#define YY_REDUCE_MAX (850) +#define YY_REDUCE_COUNT (194) +#define YY_REDUCE_MIN (-235) +#define YY_REDUCE_MAX (998) static const short yy_reduce_ofst[] = { - /* 0 */ -19, -163, 25, 75, 105, 148, 177, 234, 316, 345, - /* 10 */ 367, -166, 415, 499, 518, 548, 554, 567, 613, 621, - /* 20 */ 649, 655, 677, 705, 711, 724, 753, 759, 772, 781, - /* 30 */ 816, 844, 850, 88, 156, 559, 257, -189, -185, -151, - /* 40 */ -134, -205, -114, -102, 55, 207, -187, -154, -1, -199, - /* 50 */ 53, 112, 134, 246, 205, 102, 84, 287, 286, 314, - /* 60 */ 307, -186, -186, -186, -124, -148, -116, -72, 37, -21, - /* 70 */ 143, 169, 268, 270, 297, 330, 347, 348, 359, 360, - /* 80 */ 361, 364, 395, 419, 421, 424, 429, 438, 45, -96, - /* 90 */ -44, 266, 374, 341, 97, -137, 274, 308, 427, 232, - /* 100 */ -171, 331, 355, 401, 471, 523, 339, 437, 449, 501, - /* 110 */ 469, 544, 511, 495, 495, 495, 546, 494, 509, 577, - /* 120 */ 553, 570, 584, 623, 597, 637, 604, 615, 652, 653, - /* 130 */ 650, 659, 668, 651, 660, 663, 664, 665, 667, 669, - /* 140 */ 671, 673, 674, 675, 672, 679, 634, 683, 676, 681, - /* 150 */ 693, 666, 629, 680, 685, 635, 691, 686, 694, 646, - /* 160 */ 641, 692, 670, 495, 712, 698, 684, 687, 688, 697, - /* 170 */ 703, 546, 725, 727, 728, 741, 743, 748, 744, 747, - /* 180 */ 783, 773, 786, 768, 775, 796, 798, 805, 800, 801, - /* 190 */ 810, 821, + /* 0 */ 321, -7, 15, 108, -162, 140, 187, 273, 364, 395, + /* 10 */ 434, 439, -184, 477, 517, 522, 564, 594, 616, 691, + /* 20 */ 722, 752, 774, 796, 818, 840, 862, 884, 908, 932, + /* 30 */ 954, 976, 998, -153, -3, 212, 86, -24, -12, -219, + /* 40 */ -167, -166, -220, -147, 34, -120, 2, 74, 75, 64, + /* 50 */ -212, -72, 162, 172, 54, 225, 31, -159, 178, 209, + /* 60 */ 297, -149, -235, -235, -235, -90, -144, -134, -137, 151, + /* 70 */ 205, 222, 245, 270, 274, 307, 325, 338, 344, 351, + /* 80 */ 382, 387, 389, 431, 433, 438, 445, 483, -102, 85, + /* 90 */ 230, 220, 251, 284, 111, 282, -211, -81, 122, 256, + /* 100 */ 195, 349, 372, 408, 443, 478, 499, 380, 405, 432, + /* 110 */ 493, 449, 526, 486, 476, 476, 476, 530, 464, 492, + /* 120 */ 520, 576, 552, 556, 560, 589, 577, 600, 596, 601, + /* 130 */ 626, 643, 640, 644, 659, 639, 654, 656, 667, 668, + /* 140 */ 670, 673, 674, 675, 676, 686, 662, 661, 617, 703, + /* 150 */ 680, 627, 704, 678, 636, 683, 688, 650, 689, 693, + /* 160 */ 694, 671, 658, 681, 685, 476, 737, 714, 705, 679, + /* 170 */ 692, 695, 720, 530, 744, 747, 749, 745, 751, 756, + /* 180 */ 757, 753, 792, 769, 793, 772, 779, 797, 799, 810, + /* 190 */ 766, 803, 805, 806, 822, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 10 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 20 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 30 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 40 */ 1002, 1002, 1002, 1002, 1055, 1002, 1002, 1002, 1002, 1002, - /* 50 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 60 */ 1053, 1002, 1262, 1002, 1168, 1002, 1002, 1002, 1002, 1002, - /* 70 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 80 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1055, - /* 90 */ 1273, 1273, 1273, 1053, 1002, 1002, 1002, 1002, 1002, 1137, - /* 100 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1337, 1002, 1090, - /* 110 */ 1297, 1002, 1289, 1265, 1279, 1266, 1002, 1322, 1282, 1002, - /* 120 */ 1173, 1170, 1170, 1002, 1002, 1055, 1002, 1002, 1055, 1055, - /* 130 */ 1002, 1055, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 140 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1053, 1002, 1002, - /* 150 */ 1053, 1002, 1304, 1302, 1002, 1304, 1302, 1002, 1002, 1316, - /* 160 */ 1312, 1295, 1293, 1279, 1002, 1002, 1002, 1340, 1328, 1324, - /* 170 */ 1002, 1002, 1302, 1002, 1002, 1302, 1002, 1181, 1002, 1002, - /* 180 */ 1053, 1002, 1053, 1002, 1106, 1002, 1053, 1002, 1140, 1140, - /* 190 */ 1056, 1007, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 200 */ 1002, 1002, 1234, 1315, 1314, 1233, 1239, 1238, 1237, 1002, - /* 210 */ 1002, 1002, 1228, 1229, 1227, 1226, 1002, 1002, 1002, 1002, - /* 220 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1263, 1002, 1325, - /* 230 */ 1329, 1002, 1002, 1002, 1213, 1002, 1002, 1002, 1002, 1002, - /* 240 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 250 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 260 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 270 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 280 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 290 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 300 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 310 */ 1002, 1002, 1286, 1296, 1002, 1002, 1002, 1002, 1002, 1002, - /* 320 */ 1002, 1002, 1002, 1002, 1213, 1002, 1313, 1002, 1272, 1268, - /* 330 */ 1002, 1002, 1264, 1002, 1002, 1323, 1002, 1002, 1002, 1002, - /* 340 */ 1002, 1002, 1002, 1002, 1258, 1002, 1002, 1002, 1002, 1002, - /* 350 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 360 */ 1002, 1212, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1134, - /* 370 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 380 */ 1002, 1002, 1119, 1117, 1116, 1115, 1002, 1112, 1002, 1002, - /* 390 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 400 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 410 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 420 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 430 */ 1002, + /* 0 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 10 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 20 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 30 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 40 */ 1038, 1038, 1038, 1038, 1038, 1091, 1038, 1038, 1038, 1038, + /* 50 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 60 */ 1038, 1089, 1038, 1314, 1038, 1204, 1038, 1038, 1038, 1038, + /* 70 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 80 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 90 */ 1091, 1325, 1325, 1325, 1089, 1038, 1038, 1038, 1038, 1038, + /* 100 */ 1173, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1389, 1038, + /* 110 */ 1126, 1349, 1038, 1341, 1317, 1331, 1318, 1038, 1374, 1334, + /* 120 */ 1227, 1038, 1209, 1206, 1206, 1038, 1038, 1091, 1038, 1038, + /* 130 */ 1091, 1091, 1038, 1091, 1038, 1038, 1038, 1038, 1038, 1038, + /* 140 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1089, + /* 150 */ 1038, 1038, 1089, 1038, 1356, 1354, 1038, 1356, 1354, 1038, + /* 160 */ 1038, 1368, 1364, 1347, 1345, 1331, 1038, 1038, 1038, 1392, + /* 170 */ 1380, 1376, 1038, 1038, 1354, 1038, 1038, 1354, 1038, 1217, + /* 180 */ 1038, 1038, 1089, 1038, 1089, 1038, 1142, 1038, 1089, 1038, + /* 190 */ 1229, 1176, 1176, 1092, 1043, 1038, 1038, 1038, 1038, 1038, + /* 200 */ 1038, 1038, 1038, 1038, 1038, 1038, 1279, 1367, 1366, 1278, + /* 210 */ 1291, 1290, 1289, 1038, 1038, 1038, 1273, 1274, 1272, 1271, + /* 220 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 230 */ 1038, 1315, 1038, 1377, 1381, 1038, 1038, 1038, 1257, 1038, + /* 240 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 250 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 260 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 270 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 280 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 290 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 300 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 310 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1338, + /* 320 */ 1348, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 330 */ 1038, 1257, 1038, 1365, 1038, 1324, 1320, 1038, 1038, 1316, + /* 340 */ 1038, 1038, 1375, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 350 */ 1038, 1310, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 360 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1256, 1038, + /* 370 */ 1038, 1038, 1038, 1038, 1038, 1038, 1170, 1038, 1038, 1038, + /* 380 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1155, + /* 390 */ 1153, 1152, 1151, 1038, 1148, 1038, 1038, 1038, 1038, 1038, + /* 400 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 410 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 420 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, + /* 430 */ 1038, 1038, 1038, 1038, 1038, 1038, 1038, 1038, }; /********** End of lemon-generated parsing tables *****************************/ @@ -824,142 +840,157 @@ static const char *const yyTokenName[] = { /* 120 */ "INTERVAL", /* 121 */ "TOPIC", /* 122 */ "AS", - /* 123 */ "NK_BOOL", - /* 124 */ "NK_VARIABLE", - /* 125 */ "BETWEEN", - /* 126 */ "IS", - /* 127 */ "NULL", - /* 128 */ "NK_LT", - /* 129 */ "NK_GT", - /* 130 */ "NK_LE", - /* 131 */ "NK_GE", - /* 132 */ "NK_NE", - /* 133 */ "MATCH", - /* 134 */ "NMATCH", - /* 135 */ "IN", - /* 136 */ "JOIN", - /* 137 */ "INNER", - /* 138 */ "SELECT", - /* 139 */ "DISTINCT", - /* 140 */ "WHERE", - /* 141 */ "PARTITION", - /* 142 */ "BY", - /* 143 */ "SESSION", - /* 144 */ "STATE_WINDOW", - /* 145 */ "SLIDING", - /* 146 */ "FILL", - /* 147 */ "VALUE", - /* 148 */ "NONE", - /* 149 */ "PREV", - /* 150 */ "LINEAR", - /* 151 */ "NEXT", - /* 152 */ "GROUP", - /* 153 */ "HAVING", - /* 154 */ "ORDER", - /* 155 */ "SLIMIT", - /* 156 */ "SOFFSET", - /* 157 */ "LIMIT", - /* 158 */ "OFFSET", - /* 159 */ "ASC", - /* 160 */ "DESC", - /* 161 */ "NULLS", - /* 162 */ "FIRST", - /* 163 */ "LAST", - /* 164 */ "cmd", - /* 165 */ "account_options", - /* 166 */ "alter_account_options", - /* 167 */ "literal", - /* 168 */ "alter_account_option", - /* 169 */ "user_name", - /* 170 */ "dnode_endpoint", - /* 171 */ "dnode_host_name", - /* 172 */ "not_exists_opt", - /* 173 */ "db_name", - /* 174 */ "db_options", - /* 175 */ "exists_opt", - /* 176 */ "alter_db_options", - /* 177 */ "alter_db_option", - /* 178 */ "full_table_name", - /* 179 */ "column_def_list", - /* 180 */ "tags_def_opt", - /* 181 */ "table_options", - /* 182 */ "multi_create_clause", - /* 183 */ "tags_def", - /* 184 */ "multi_drop_clause", - /* 185 */ "alter_table_clause", - /* 186 */ "alter_table_options", - /* 187 */ "column_name", - /* 188 */ "type_name", - /* 189 */ "create_subtable_clause", - /* 190 */ "specific_tags_opt", - /* 191 */ "literal_list", - /* 192 */ "drop_table_clause", - /* 193 */ "col_name_list", - /* 194 */ "table_name", - /* 195 */ "column_def", - /* 196 */ "func_name_list", - /* 197 */ "alter_table_option", - /* 198 */ "col_name", - /* 199 */ "db_name_cond_opt", - /* 200 */ "like_pattern_opt", - /* 201 */ "table_name_cond", - /* 202 */ "from_db_opt", - /* 203 */ "func_name", - /* 204 */ "function_name", - /* 205 */ "index_name", - /* 206 */ "index_options", - /* 207 */ "func_list", - /* 208 */ "duration_literal", - /* 209 */ "sliding_opt", - /* 210 */ "func", - /* 211 */ "expression_list", - /* 212 */ "topic_name", - /* 213 */ "query_expression", - /* 214 */ "signed", - /* 215 */ "signed_literal", - /* 216 */ "table_alias", - /* 217 */ "column_alias", - /* 218 */ "expression", - /* 219 */ "column_reference", - /* 220 */ "subquery", - /* 221 */ "predicate", - /* 222 */ "compare_op", - /* 223 */ "in_op", - /* 224 */ "in_predicate_value", - /* 225 */ "boolean_value_expression", - /* 226 */ "boolean_primary", - /* 227 */ "common_expression", - /* 228 */ "from_clause", - /* 229 */ "table_reference_list", - /* 230 */ "table_reference", - /* 231 */ "table_primary", - /* 232 */ "joined_table", - /* 233 */ "alias_opt", - /* 234 */ "parenthesized_joined_table", - /* 235 */ "join_type", - /* 236 */ "search_condition", - /* 237 */ "query_specification", - /* 238 */ "set_quantifier_opt", - /* 239 */ "select_list", - /* 240 */ "where_clause_opt", - /* 241 */ "partition_by_clause_opt", - /* 242 */ "twindow_clause_opt", - /* 243 */ "group_by_clause_opt", - /* 244 */ "having_clause_opt", - /* 245 */ "select_sublist", - /* 246 */ "select_item", - /* 247 */ "fill_opt", - /* 248 */ "fill_mode", - /* 249 */ "group_by_list", - /* 250 */ "query_expression_body", - /* 251 */ "order_by_clause_opt", - /* 252 */ "slimit_clause_opt", - /* 253 */ "limit_clause_opt", - /* 254 */ "query_primary", - /* 255 */ "sort_specification_list", - /* 256 */ "sort_specification", - /* 257 */ "ordering_specification_opt", - /* 258 */ "null_ordering_opt", + /* 123 */ "EXPLAIN", + /* 124 */ "ANALYZE", + /* 125 */ "VERBOSE", + /* 126 */ "NK_BOOL", + /* 127 */ "RATIO", + /* 128 */ "NULL", + /* 129 */ "NK_VARIABLE", + /* 130 */ "NK_UNDERLINE", + /* 131 */ "ROWTS", + /* 132 */ "TBNAME", + /* 133 */ "QSTARTTS", + /* 134 */ "QENDTS", + /* 135 */ "WSTARTTS", + /* 136 */ "WENDTS", + /* 137 */ "WDURATION", + /* 138 */ "BETWEEN", + /* 139 */ "IS", + /* 140 */ "NK_LT", + /* 141 */ "NK_GT", + /* 142 */ "NK_LE", + /* 143 */ "NK_GE", + /* 144 */ "NK_NE", + /* 145 */ "MATCH", + /* 146 */ "NMATCH", + /* 147 */ "IN", + /* 148 */ "JOIN", + /* 149 */ "INNER", + /* 150 */ "SELECT", + /* 151 */ "DISTINCT", + /* 152 */ "WHERE", + /* 153 */ "PARTITION", + /* 154 */ "BY", + /* 155 */ "SESSION", + /* 156 */ "STATE_WINDOW", + /* 157 */ "SLIDING", + /* 158 */ "FILL", + /* 159 */ "VALUE", + /* 160 */ "NONE", + /* 161 */ "PREV", + /* 162 */ "LINEAR", + /* 163 */ "NEXT", + /* 164 */ "GROUP", + /* 165 */ "HAVING", + /* 166 */ "ORDER", + /* 167 */ "SLIMIT", + /* 168 */ "SOFFSET", + /* 169 */ "LIMIT", + /* 170 */ "OFFSET", + /* 171 */ "ASC", + /* 172 */ "DESC", + /* 173 */ "NULLS", + /* 174 */ "FIRST", + /* 175 */ "LAST", + /* 176 */ "cmd", + /* 177 */ "account_options", + /* 178 */ "alter_account_options", + /* 179 */ "literal", + /* 180 */ "alter_account_option", + /* 181 */ "user_name", + /* 182 */ "dnode_endpoint", + /* 183 */ "dnode_host_name", + /* 184 */ "not_exists_opt", + /* 185 */ "db_name", + /* 186 */ "db_options", + /* 187 */ "exists_opt", + /* 188 */ "alter_db_options", + /* 189 */ "alter_db_option", + /* 190 */ "full_table_name", + /* 191 */ "column_def_list", + /* 192 */ "tags_def_opt", + /* 193 */ "table_options", + /* 194 */ "multi_create_clause", + /* 195 */ "tags_def", + /* 196 */ "multi_drop_clause", + /* 197 */ "alter_table_clause", + /* 198 */ "alter_table_options", + /* 199 */ "column_name", + /* 200 */ "type_name", + /* 201 */ "create_subtable_clause", + /* 202 */ "specific_tags_opt", + /* 203 */ "literal_list", + /* 204 */ "drop_table_clause", + /* 205 */ "col_name_list", + /* 206 */ "table_name", + /* 207 */ "column_def", + /* 208 */ "func_name_list", + /* 209 */ "alter_table_option", + /* 210 */ "col_name", + /* 211 */ "db_name_cond_opt", + /* 212 */ "like_pattern_opt", + /* 213 */ "table_name_cond", + /* 214 */ "from_db_opt", + /* 215 */ "func_name", + /* 216 */ "function_name", + /* 217 */ "index_name", + /* 218 */ "index_options", + /* 219 */ "func_list", + /* 220 */ "duration_literal", + /* 221 */ "sliding_opt", + /* 222 */ "func", + /* 223 */ "expression_list", + /* 224 */ "topic_name", + /* 225 */ "query_expression", + /* 226 */ "analyze_opt", + /* 227 */ "explain_options", + /* 228 */ "signed", + /* 229 */ "signed_literal", + /* 230 */ "table_alias", + /* 231 */ "column_alias", + /* 232 */ "expression", + /* 233 */ "pseudo_column", + /* 234 */ "column_reference", + /* 235 */ "subquery", + /* 236 */ "predicate", + /* 237 */ "compare_op", + /* 238 */ "in_op", + /* 239 */ "in_predicate_value", + /* 240 */ "boolean_value_expression", + /* 241 */ "boolean_primary", + /* 242 */ "common_expression", + /* 243 */ "from_clause", + /* 244 */ "table_reference_list", + /* 245 */ "table_reference", + /* 246 */ "table_primary", + /* 247 */ "joined_table", + /* 248 */ "alias_opt", + /* 249 */ "parenthesized_joined_table", + /* 250 */ "join_type", + /* 251 */ "search_condition", + /* 252 */ "query_specification", + /* 253 */ "set_quantifier_opt", + /* 254 */ "select_list", + /* 255 */ "where_clause_opt", + /* 256 */ "partition_by_clause_opt", + /* 257 */ "twindow_clause_opt", + /* 258 */ "group_by_clause_opt", + /* 259 */ "having_clause_opt", + /* 260 */ "select_sublist", + /* 261 */ "select_item", + /* 262 */ "fill_opt", + /* 263 */ "fill_mode", + /* 264 */ "group_by_list", + /* 265 */ "query_expression_body", + /* 266 */ "order_by_clause_opt", + /* 267 */ "slimit_clause_opt", + /* 268 */ "limit_clause_opt", + /* 269 */ "query_primary", + /* 270 */ "sort_specification_list", + /* 271 */ "sort_specification", + /* 272 */ "ordering_specification_opt", + /* 273 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1152,159 +1183,175 @@ static const char *const yyRuleName[] = { /* 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 */ "duration_literal ::= NK_VARIABLE", - /* 193 */ "signed ::= NK_INTEGER", - /* 194 */ "signed ::= NK_PLUS NK_INTEGER", - /* 195 */ "signed ::= NK_MINUS NK_INTEGER", - /* 196 */ "signed ::= NK_FLOAT", - /* 197 */ "signed ::= NK_PLUS NK_FLOAT", - /* 198 */ "signed ::= NK_MINUS NK_FLOAT", - /* 199 */ "signed_literal ::= signed", - /* 200 */ "signed_literal ::= NK_STRING", - /* 201 */ "signed_literal ::= NK_BOOL", - /* 202 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 203 */ "signed_literal ::= duration_literal", - /* 204 */ "literal_list ::= signed_literal", - /* 205 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 206 */ "db_name ::= NK_ID", - /* 207 */ "table_name ::= NK_ID", - /* 208 */ "column_name ::= NK_ID", - /* 209 */ "function_name ::= NK_ID", - /* 210 */ "table_alias ::= NK_ID", - /* 211 */ "column_alias ::= NK_ID", - /* 212 */ "user_name ::= NK_ID", - /* 213 */ "index_name ::= NK_ID", - /* 214 */ "topic_name ::= NK_ID", - /* 215 */ "expression ::= literal", - /* 216 */ "expression ::= column_reference", - /* 217 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 218 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 219 */ "expression ::= subquery", - /* 220 */ "expression ::= NK_LP expression NK_RP", - /* 221 */ "expression ::= NK_PLUS expression", - /* 222 */ "expression ::= NK_MINUS expression", - /* 223 */ "expression ::= expression NK_PLUS expression", - /* 224 */ "expression ::= expression NK_MINUS expression", - /* 225 */ "expression ::= expression NK_STAR expression", - /* 226 */ "expression ::= expression NK_SLASH expression", - /* 227 */ "expression ::= expression NK_REM expression", - /* 228 */ "expression_list ::= expression", - /* 229 */ "expression_list ::= expression_list NK_COMMA expression", - /* 230 */ "column_reference ::= column_name", - /* 231 */ "column_reference ::= table_name NK_DOT column_name", - /* 232 */ "predicate ::= expression compare_op expression", - /* 233 */ "predicate ::= expression BETWEEN expression AND expression", - /* 234 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 235 */ "predicate ::= expression IS NULL", - /* 236 */ "predicate ::= expression IS NOT NULL", - /* 237 */ "predicate ::= expression in_op in_predicate_value", - /* 238 */ "compare_op ::= NK_LT", - /* 239 */ "compare_op ::= NK_GT", - /* 240 */ "compare_op ::= NK_LE", - /* 241 */ "compare_op ::= NK_GE", - /* 242 */ "compare_op ::= NK_NE", - /* 243 */ "compare_op ::= NK_EQ", - /* 244 */ "compare_op ::= LIKE", - /* 245 */ "compare_op ::= NOT LIKE", - /* 246 */ "compare_op ::= MATCH", - /* 247 */ "compare_op ::= NMATCH", - /* 248 */ "in_op ::= IN", - /* 249 */ "in_op ::= NOT IN", - /* 250 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 251 */ "boolean_value_expression ::= boolean_primary", - /* 252 */ "boolean_value_expression ::= NOT boolean_primary", - /* 253 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 254 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 255 */ "boolean_primary ::= predicate", - /* 256 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 257 */ "common_expression ::= expression", - /* 258 */ "common_expression ::= boolean_value_expression", - /* 259 */ "from_clause ::= FROM table_reference_list", - /* 260 */ "table_reference_list ::= table_reference", - /* 261 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 262 */ "table_reference ::= table_primary", - /* 263 */ "table_reference ::= joined_table", - /* 264 */ "table_primary ::= table_name alias_opt", - /* 265 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 266 */ "table_primary ::= subquery alias_opt", - /* 267 */ "table_primary ::= parenthesized_joined_table", - /* 268 */ "alias_opt ::=", - /* 269 */ "alias_opt ::= table_alias", - /* 270 */ "alias_opt ::= AS table_alias", - /* 271 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 272 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 273 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 274 */ "join_type ::=", - /* 275 */ "join_type ::= INNER", - /* 276 */ "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", - /* 277 */ "set_quantifier_opt ::=", - /* 278 */ "set_quantifier_opt ::= DISTINCT", - /* 279 */ "set_quantifier_opt ::= ALL", - /* 280 */ "select_list ::= NK_STAR", - /* 281 */ "select_list ::= select_sublist", - /* 282 */ "select_sublist ::= select_item", - /* 283 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 284 */ "select_item ::= common_expression", - /* 285 */ "select_item ::= common_expression column_alias", - /* 286 */ "select_item ::= common_expression AS column_alias", - /* 287 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 288 */ "where_clause_opt ::=", - /* 289 */ "where_clause_opt ::= WHERE search_condition", - /* 290 */ "partition_by_clause_opt ::=", - /* 291 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 292 */ "twindow_clause_opt ::=", - /* 293 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 294 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 295 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 296 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 297 */ "sliding_opt ::=", - /* 298 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 299 */ "fill_opt ::=", - /* 300 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 301 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 302 */ "fill_mode ::= NONE", - /* 303 */ "fill_mode ::= PREV", - /* 304 */ "fill_mode ::= NULL", - /* 305 */ "fill_mode ::= LINEAR", - /* 306 */ "fill_mode ::= NEXT", - /* 307 */ "group_by_clause_opt ::=", - /* 308 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 309 */ "group_by_list ::= expression", - /* 310 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 311 */ "having_clause_opt ::=", - /* 312 */ "having_clause_opt ::= HAVING search_condition", - /* 313 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 314 */ "query_expression_body ::= query_primary", - /* 315 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 316 */ "query_primary ::= query_specification", - /* 317 */ "order_by_clause_opt ::=", - /* 318 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 319 */ "slimit_clause_opt ::=", - /* 320 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 321 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 322 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 323 */ "limit_clause_opt ::=", - /* 324 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 325 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 326 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 327 */ "subquery ::= NK_LP query_expression NK_RP", - /* 328 */ "search_condition ::= common_expression", - /* 329 */ "sort_specification_list ::= sort_specification", - /* 330 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 331 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 332 */ "ordering_specification_opt ::=", - /* 333 */ "ordering_specification_opt ::= ASC", - /* 334 */ "ordering_specification_opt ::= DESC", - /* 335 */ "null_ordering_opt ::=", - /* 336 */ "null_ordering_opt ::= NULLS FIRST", - /* 337 */ "null_ordering_opt ::= NULLS LAST", + /* 185 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 186 */ "analyze_opt ::=", + /* 187 */ "analyze_opt ::= ANALYZE", + /* 188 */ "explain_options ::=", + /* 189 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 190 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 191 */ "cmd ::= query_expression", + /* 192 */ "literal ::= NK_INTEGER", + /* 193 */ "literal ::= NK_FLOAT", + /* 194 */ "literal ::= NK_STRING", + /* 195 */ "literal ::= NK_BOOL", + /* 196 */ "literal ::= TIMESTAMP NK_STRING", + /* 197 */ "literal ::= duration_literal", + /* 198 */ "literal ::= NULL", + /* 199 */ "duration_literal ::= NK_VARIABLE", + /* 200 */ "signed ::= NK_INTEGER", + /* 201 */ "signed ::= NK_PLUS NK_INTEGER", + /* 202 */ "signed ::= NK_MINUS NK_INTEGER", + /* 203 */ "signed ::= NK_FLOAT", + /* 204 */ "signed ::= NK_PLUS NK_FLOAT", + /* 205 */ "signed ::= NK_MINUS NK_FLOAT", + /* 206 */ "signed_literal ::= signed", + /* 207 */ "signed_literal ::= NK_STRING", + /* 208 */ "signed_literal ::= NK_BOOL", + /* 209 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 210 */ "signed_literal ::= duration_literal", + /* 211 */ "signed_literal ::= NULL", + /* 212 */ "literal_list ::= signed_literal", + /* 213 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 214 */ "db_name ::= NK_ID", + /* 215 */ "table_name ::= NK_ID", + /* 216 */ "column_name ::= NK_ID", + /* 217 */ "function_name ::= NK_ID", + /* 218 */ "table_alias ::= NK_ID", + /* 219 */ "column_alias ::= NK_ID", + /* 220 */ "user_name ::= NK_ID", + /* 221 */ "index_name ::= NK_ID", + /* 222 */ "topic_name ::= NK_ID", + /* 223 */ "expression ::= literal", + /* 224 */ "expression ::= pseudo_column", + /* 225 */ "expression ::= column_reference", + /* 226 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 227 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 228 */ "expression ::= subquery", + /* 229 */ "expression ::= NK_LP expression NK_RP", + /* 230 */ "expression ::= NK_PLUS expression", + /* 231 */ "expression ::= NK_MINUS expression", + /* 232 */ "expression ::= expression NK_PLUS expression", + /* 233 */ "expression ::= expression NK_MINUS expression", + /* 234 */ "expression ::= expression NK_STAR expression", + /* 235 */ "expression ::= expression NK_SLASH expression", + /* 236 */ "expression ::= expression NK_REM expression", + /* 237 */ "expression_list ::= expression", + /* 238 */ "expression_list ::= expression_list NK_COMMA expression", + /* 239 */ "column_reference ::= column_name", + /* 240 */ "column_reference ::= table_name NK_DOT column_name", + /* 241 */ "pseudo_column ::= NK_UNDERLINE ROWTS", + /* 242 */ "pseudo_column ::= TBNAME", + /* 243 */ "pseudo_column ::= NK_UNDERLINE QSTARTTS", + /* 244 */ "pseudo_column ::= NK_UNDERLINE QENDTS", + /* 245 */ "pseudo_column ::= NK_UNDERLINE WSTARTTS", + /* 246 */ "pseudo_column ::= NK_UNDERLINE WENDTS", + /* 247 */ "pseudo_column ::= NK_UNDERLINE WDURATION", + /* 248 */ "predicate ::= expression compare_op expression", + /* 249 */ "predicate ::= expression BETWEEN expression AND expression", + /* 250 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 251 */ "predicate ::= expression IS NULL", + /* 252 */ "predicate ::= expression IS NOT NULL", + /* 253 */ "predicate ::= expression in_op in_predicate_value", + /* 254 */ "compare_op ::= NK_LT", + /* 255 */ "compare_op ::= NK_GT", + /* 256 */ "compare_op ::= NK_LE", + /* 257 */ "compare_op ::= NK_GE", + /* 258 */ "compare_op ::= NK_NE", + /* 259 */ "compare_op ::= NK_EQ", + /* 260 */ "compare_op ::= LIKE", + /* 261 */ "compare_op ::= NOT LIKE", + /* 262 */ "compare_op ::= MATCH", + /* 263 */ "compare_op ::= NMATCH", + /* 264 */ "in_op ::= IN", + /* 265 */ "in_op ::= NOT IN", + /* 266 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 267 */ "boolean_value_expression ::= boolean_primary", + /* 268 */ "boolean_value_expression ::= NOT boolean_primary", + /* 269 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 270 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 271 */ "boolean_primary ::= predicate", + /* 272 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 273 */ "common_expression ::= expression", + /* 274 */ "common_expression ::= boolean_value_expression", + /* 275 */ "from_clause ::= FROM table_reference_list", + /* 276 */ "table_reference_list ::= table_reference", + /* 277 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 278 */ "table_reference ::= table_primary", + /* 279 */ "table_reference ::= joined_table", + /* 280 */ "table_primary ::= table_name alias_opt", + /* 281 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 282 */ "table_primary ::= subquery alias_opt", + /* 283 */ "table_primary ::= parenthesized_joined_table", + /* 284 */ "alias_opt ::=", + /* 285 */ "alias_opt ::= table_alias", + /* 286 */ "alias_opt ::= AS table_alias", + /* 287 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 288 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 289 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 290 */ "join_type ::=", + /* 291 */ "join_type ::= INNER", + /* 292 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 293 */ "set_quantifier_opt ::=", + /* 294 */ "set_quantifier_opt ::= DISTINCT", + /* 295 */ "set_quantifier_opt ::= ALL", + /* 296 */ "select_list ::= NK_STAR", + /* 297 */ "select_list ::= select_sublist", + /* 298 */ "select_sublist ::= select_item", + /* 299 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 300 */ "select_item ::= common_expression", + /* 301 */ "select_item ::= common_expression column_alias", + /* 302 */ "select_item ::= common_expression AS column_alias", + /* 303 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 304 */ "where_clause_opt ::=", + /* 305 */ "where_clause_opt ::= WHERE search_condition", + /* 306 */ "partition_by_clause_opt ::=", + /* 307 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 308 */ "twindow_clause_opt ::=", + /* 309 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 310 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 311 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 312 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 313 */ "sliding_opt ::=", + /* 314 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 315 */ "fill_opt ::=", + /* 316 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 317 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 318 */ "fill_mode ::= NONE", + /* 319 */ "fill_mode ::= PREV", + /* 320 */ "fill_mode ::= NULL", + /* 321 */ "fill_mode ::= LINEAR", + /* 322 */ "fill_mode ::= NEXT", + /* 323 */ "group_by_clause_opt ::=", + /* 324 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 325 */ "group_by_list ::= expression", + /* 326 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 327 */ "having_clause_opt ::=", + /* 328 */ "having_clause_opt ::= HAVING search_condition", + /* 329 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 330 */ "query_expression_body ::= query_primary", + /* 331 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 332 */ "query_primary ::= query_specification", + /* 333 */ "order_by_clause_opt ::=", + /* 334 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 335 */ "slimit_clause_opt ::=", + /* 336 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 337 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 338 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 339 */ "limit_clause_opt ::=", + /* 340 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 341 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 342 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 343 */ "subquery ::= NK_LP query_expression NK_RP", + /* 344 */ "search_condition ::= common_expression", + /* 345 */ "sort_specification_list ::= sort_specification", + /* 346 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 347 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 348 */ "ordering_specification_opt ::=", + /* 349 */ "ordering_specification_opt ::= ASC", + /* 350 */ "ordering_specification_opt ::= DESC", + /* 351 */ "null_ordering_opt ::=", + /* 352 */ "null_ordering_opt ::= NULLS FIRST", + /* 353 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1431,145 +1478,148 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 164: /* cmd */ - case 167: /* literal */ - case 174: /* db_options */ - case 176: /* alter_db_options */ - case 178: /* full_table_name */ - case 181: /* table_options */ - case 185: /* alter_table_clause */ - case 186: /* alter_table_options */ - case 189: /* create_subtable_clause */ - case 192: /* drop_table_clause */ - case 195: /* column_def */ - case 198: /* col_name */ - case 199: /* db_name_cond_opt */ - case 200: /* like_pattern_opt */ - case 201: /* table_name_cond */ - case 202: /* from_db_opt */ - case 203: /* func_name */ - case 206: /* index_options */ - case 208: /* duration_literal */ - case 209: /* sliding_opt */ - case 210: /* func */ - case 213: /* query_expression */ - case 214: /* signed */ - case 215: /* signed_literal */ - case 218: /* expression */ - case 219: /* column_reference */ - case 220: /* subquery */ - case 221: /* predicate */ - case 224: /* in_predicate_value */ - case 225: /* boolean_value_expression */ - case 226: /* boolean_primary */ - case 227: /* common_expression */ - case 228: /* from_clause */ - case 229: /* table_reference_list */ - case 230: /* table_reference */ - case 231: /* table_primary */ - case 232: /* joined_table */ - case 234: /* parenthesized_joined_table */ - case 236: /* search_condition */ - case 237: /* query_specification */ - case 240: /* where_clause_opt */ - case 242: /* twindow_clause_opt */ - case 244: /* having_clause_opt */ - case 246: /* select_item */ - case 247: /* fill_opt */ - case 250: /* query_expression_body */ - case 252: /* slimit_clause_opt */ - case 253: /* limit_clause_opt */ - case 254: /* query_primary */ - case 256: /* sort_specification */ + case 176: /* cmd */ + case 179: /* literal */ + case 186: /* db_options */ + case 188: /* alter_db_options */ + case 190: /* full_table_name */ + case 193: /* table_options */ + case 197: /* alter_table_clause */ + case 198: /* alter_table_options */ + case 201: /* create_subtable_clause */ + case 204: /* drop_table_clause */ + case 207: /* column_def */ + case 210: /* col_name */ + case 211: /* db_name_cond_opt */ + case 212: /* like_pattern_opt */ + case 213: /* table_name_cond */ + case 214: /* from_db_opt */ + case 215: /* func_name */ + case 218: /* index_options */ + case 220: /* duration_literal */ + case 221: /* sliding_opt */ + case 222: /* func */ + case 225: /* query_expression */ + case 227: /* explain_options */ + case 228: /* signed */ + case 229: /* signed_literal */ + case 232: /* expression */ + case 233: /* pseudo_column */ + case 234: /* column_reference */ + case 235: /* subquery */ + case 236: /* predicate */ + case 239: /* in_predicate_value */ + case 240: /* boolean_value_expression */ + case 241: /* boolean_primary */ + case 242: /* common_expression */ + case 243: /* from_clause */ + case 244: /* table_reference_list */ + case 245: /* table_reference */ + case 246: /* table_primary */ + case 247: /* joined_table */ + case 249: /* parenthesized_joined_table */ + case 251: /* search_condition */ + case 252: /* query_specification */ + case 255: /* where_clause_opt */ + case 257: /* twindow_clause_opt */ + case 259: /* having_clause_opt */ + case 261: /* select_item */ + case 262: /* fill_opt */ + case 265: /* query_expression_body */ + case 267: /* slimit_clause_opt */ + case 268: /* limit_clause_opt */ + case 269: /* query_primary */ + case 271: /* sort_specification */ { - nodesDestroyNode((yypminor->yy378)); + nodesDestroyNode((yypminor->yy364)); } break; - case 165: /* account_options */ - case 166: /* alter_account_options */ - case 168: /* alter_account_option */ + case 177: /* account_options */ + case 178: /* alter_account_options */ + case 180: /* alter_account_option */ { } break; - case 169: /* user_name */ - case 170: /* dnode_endpoint */ - case 171: /* dnode_host_name */ - case 173: /* db_name */ - case 187: /* column_name */ - case 194: /* table_name */ - case 204: /* function_name */ - case 205: /* index_name */ - case 212: /* topic_name */ - case 216: /* table_alias */ - case 217: /* column_alias */ - case 233: /* alias_opt */ + case 181: /* user_name */ + case 182: /* dnode_endpoint */ + case 183: /* dnode_host_name */ + case 185: /* db_name */ + case 199: /* column_name */ + case 206: /* table_name */ + case 216: /* function_name */ + case 217: /* index_name */ + case 224: /* topic_name */ + case 230: /* table_alias */ + case 231: /* column_alias */ + case 248: /* alias_opt */ { } break; - case 172: /* not_exists_opt */ - case 175: /* exists_opt */ - case 238: /* set_quantifier_opt */ + case 184: /* not_exists_opt */ + case 187: /* exists_opt */ + case 226: /* analyze_opt */ + case 253: /* set_quantifier_opt */ { } break; - case 177: /* alter_db_option */ - case 197: /* alter_table_option */ + case 189: /* alter_db_option */ + case 209: /* alter_table_option */ { } break; - case 179: /* column_def_list */ - case 180: /* tags_def_opt */ - case 182: /* multi_create_clause */ - case 183: /* tags_def */ - case 184: /* multi_drop_clause */ - case 190: /* specific_tags_opt */ - case 191: /* literal_list */ - case 193: /* col_name_list */ - case 196: /* func_name_list */ - case 207: /* func_list */ - case 211: /* expression_list */ - case 239: /* select_list */ - case 241: /* partition_by_clause_opt */ - case 243: /* group_by_clause_opt */ - case 245: /* select_sublist */ - case 249: /* group_by_list */ - case 251: /* order_by_clause_opt */ - case 255: /* sort_specification_list */ + case 191: /* column_def_list */ + case 192: /* tags_def_opt */ + case 194: /* multi_create_clause */ + case 195: /* tags_def */ + case 196: /* multi_drop_clause */ + case 202: /* specific_tags_opt */ + case 203: /* literal_list */ + case 205: /* col_name_list */ + case 208: /* func_name_list */ + case 219: /* func_list */ + case 223: /* expression_list */ + case 254: /* select_list */ + case 256: /* partition_by_clause_opt */ + case 258: /* group_by_clause_opt */ + case 260: /* select_sublist */ + case 264: /* group_by_list */ + case 266: /* order_by_clause_opt */ + case 270: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy404)); + nodesDestroyList((yypminor->yy40)); } break; - case 188: /* type_name */ + case 200: /* type_name */ { } break; - case 222: /* compare_op */ - case 223: /* in_op */ + case 237: /* compare_op */ + case 238: /* in_op */ { } break; - case 235: /* join_type */ + case 250: /* join_type */ { } break; - case 248: /* fill_mode */ + case 263: /* fill_mode */ { } break; - case 257: /* ordering_specification_opt */ + case 272: /* ordering_specification_opt */ { } break; - case 258: /* null_ordering_opt */ + case 273: /* null_ordering_opt */ { } @@ -1868,344 +1918,360 @@ 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[] = { - { 164, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 164, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 165, 0 }, /* (2) account_options ::= */ - { 165, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 165, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 165, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 165, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 165, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 165, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 165, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 165, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 165, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 166, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 166, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 168, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 168, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 168, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 168, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 168, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 168, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 168, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 168, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 168, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 168, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 164, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 164, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 164, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 164, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 164, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ - { 164, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 164, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ - { 164, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ - { 164, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 164, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 164, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ - { 164, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 170, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ - { 171, -1 }, /* (37) dnode_host_name ::= NK_ID */ - { 171, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ - { 164, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ - { 164, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 164, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 164, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 164, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 164, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ - { 164, -2 }, /* (45) cmd ::= USE db_name */ - { 164, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 172, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ - { 172, 0 }, /* (48) not_exists_opt ::= */ - { 175, -2 }, /* (49) exists_opt ::= IF EXISTS */ - { 175, 0 }, /* (50) exists_opt ::= */ - { 174, 0 }, /* (51) db_options ::= */ - { 174, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ - { 174, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ - { 174, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ - { 174, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ - { 174, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ - { 174, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ - { 174, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ - { 174, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ - { 174, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ - { 174, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ - { 174, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ - { 174, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ - { 174, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ - { 174, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ - { 174, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ - { 174, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 174, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 174, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ - { 176, -1 }, /* (70) alter_db_options ::= alter_db_option */ - { 176, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ - { 177, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ - { 177, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ - { 177, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ - { 177, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ - { 177, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ - { 177, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ - { 164, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 164, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ - { 164, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 164, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ - { 164, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ - { 164, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ - { 164, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ - { 185, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ - { 185, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 185, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 185, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 185, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 185, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 185, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 185, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 185, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 185, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 182, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ - { 182, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 189, -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 */ - { 184, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ - { 184, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 192, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ - { 190, 0 }, /* (101) specific_tags_opt ::= */ - { 190, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 178, -1 }, /* (103) full_table_name ::= table_name */ - { 178, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ - { 179, -1 }, /* (105) column_def_list ::= column_def */ - { 179, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ - { 195, -2 }, /* (107) column_def ::= column_name type_name */ - { 195, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ - { 188, -1 }, /* (109) type_name ::= BOOL */ - { 188, -1 }, /* (110) type_name ::= TINYINT */ - { 188, -1 }, /* (111) type_name ::= SMALLINT */ - { 188, -1 }, /* (112) type_name ::= INT */ - { 188, -1 }, /* (113) type_name ::= INTEGER */ - { 188, -1 }, /* (114) type_name ::= BIGINT */ - { 188, -1 }, /* (115) type_name ::= FLOAT */ - { 188, -1 }, /* (116) type_name ::= DOUBLE */ - { 188, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 188, -1 }, /* (118) type_name ::= TIMESTAMP */ - { 188, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 188, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ - { 188, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ - { 188, -2 }, /* (122) type_name ::= INT UNSIGNED */ - { 188, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ - { 188, -1 }, /* (124) type_name ::= JSON */ - { 188, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 188, -1 }, /* (126) type_name ::= MEDIUMBLOB */ - { 188, -1 }, /* (127) type_name ::= BLOB */ - { 188, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 188, -1 }, /* (129) type_name ::= DECIMAL */ - { 188, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 188, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 180, 0 }, /* (132) tags_def_opt ::= */ - { 180, -1 }, /* (133) tags_def_opt ::= tags_def */ - { 183, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 181, 0 }, /* (135) table_options ::= */ - { 181, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ - { 181, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ - { 181, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ - { 181, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 181, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 181, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ - { 181, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ - { 186, -1 }, /* (143) alter_table_options ::= alter_table_option */ - { 186, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ - { 197, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ - { 197, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ - { 197, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ - { 193, -1 }, /* (148) col_name_list ::= col_name */ - { 193, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ - { 198, -1 }, /* (150) col_name ::= column_name */ - { 164, -2 }, /* (151) cmd ::= SHOW DNODES */ - { 164, -2 }, /* (152) cmd ::= SHOW USERS */ - { 164, -2 }, /* (153) cmd ::= SHOW DATABASES */ - { 164, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 164, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 164, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 164, -2 }, /* (157) cmd ::= SHOW MNODES */ - { 164, -2 }, /* (158) cmd ::= SHOW MODULES */ - { 164, -2 }, /* (159) cmd ::= SHOW QNODES */ - { 164, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ - { 164, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 164, -2 }, /* (162) cmd ::= SHOW STREAMS */ - { 199, 0 }, /* (163) db_name_cond_opt ::= */ - { 199, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ - { 200, 0 }, /* (165) like_pattern_opt ::= */ - { 200, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ - { 201, -1 }, /* (167) table_name_cond ::= table_name */ - { 202, 0 }, /* (168) from_db_opt ::= */ - { 202, -2 }, /* (169) from_db_opt ::= FROM db_name */ - { 196, -1 }, /* (170) func_name_list ::= func_name */ - { 196, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ - { 203, -1 }, /* (172) func_name ::= function_name */ - { 164, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 164, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 164, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 206, 0 }, /* (176) index_options ::= */ - { 206, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 206, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 207, -1 }, /* (179) func_list ::= func */ - { 207, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ - { 210, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ - { 164, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 164, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ - { 164, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ - { 164, -1 }, /* (185) cmd ::= query_expression */ - { 167, -1 }, /* (186) literal ::= NK_INTEGER */ - { 167, -1 }, /* (187) literal ::= NK_FLOAT */ - { 167, -1 }, /* (188) literal ::= NK_STRING */ - { 167, -1 }, /* (189) literal ::= NK_BOOL */ - { 167, -2 }, /* (190) literal ::= TIMESTAMP NK_STRING */ - { 167, -1 }, /* (191) literal ::= duration_literal */ - { 208, -1 }, /* (192) duration_literal ::= NK_VARIABLE */ - { 214, -1 }, /* (193) signed ::= NK_INTEGER */ - { 214, -2 }, /* (194) signed ::= NK_PLUS NK_INTEGER */ - { 214, -2 }, /* (195) signed ::= NK_MINUS NK_INTEGER */ - { 214, -1 }, /* (196) signed ::= NK_FLOAT */ - { 214, -2 }, /* (197) signed ::= NK_PLUS NK_FLOAT */ - { 214, -2 }, /* (198) signed ::= NK_MINUS NK_FLOAT */ - { 215, -1 }, /* (199) signed_literal ::= signed */ - { 215, -1 }, /* (200) signed_literal ::= NK_STRING */ - { 215, -1 }, /* (201) signed_literal ::= NK_BOOL */ - { 215, -2 }, /* (202) signed_literal ::= TIMESTAMP NK_STRING */ - { 215, -1 }, /* (203) signed_literal ::= duration_literal */ - { 191, -1 }, /* (204) literal_list ::= signed_literal */ - { 191, -3 }, /* (205) literal_list ::= literal_list NK_COMMA signed_literal */ - { 173, -1 }, /* (206) db_name ::= NK_ID */ - { 194, -1 }, /* (207) table_name ::= NK_ID */ - { 187, -1 }, /* (208) column_name ::= NK_ID */ - { 204, -1 }, /* (209) function_name ::= NK_ID */ - { 216, -1 }, /* (210) table_alias ::= NK_ID */ - { 217, -1 }, /* (211) column_alias ::= NK_ID */ - { 169, -1 }, /* (212) user_name ::= NK_ID */ - { 205, -1 }, /* (213) index_name ::= NK_ID */ - { 212, -1 }, /* (214) topic_name ::= NK_ID */ - { 218, -1 }, /* (215) expression ::= literal */ - { 218, -1 }, /* (216) expression ::= column_reference */ - { 218, -4 }, /* (217) expression ::= function_name NK_LP expression_list NK_RP */ - { 218, -4 }, /* (218) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 218, -1 }, /* (219) expression ::= subquery */ - { 218, -3 }, /* (220) expression ::= NK_LP expression NK_RP */ - { 218, -2 }, /* (221) expression ::= NK_PLUS expression */ - { 218, -2 }, /* (222) expression ::= NK_MINUS expression */ - { 218, -3 }, /* (223) expression ::= expression NK_PLUS expression */ - { 218, -3 }, /* (224) expression ::= expression NK_MINUS expression */ - { 218, -3 }, /* (225) expression ::= expression NK_STAR expression */ - { 218, -3 }, /* (226) expression ::= expression NK_SLASH expression */ - { 218, -3 }, /* (227) expression ::= expression NK_REM expression */ - { 211, -1 }, /* (228) expression_list ::= expression */ - { 211, -3 }, /* (229) expression_list ::= expression_list NK_COMMA expression */ - { 219, -1 }, /* (230) column_reference ::= column_name */ - { 219, -3 }, /* (231) column_reference ::= table_name NK_DOT column_name */ - { 221, -3 }, /* (232) predicate ::= expression compare_op expression */ - { 221, -5 }, /* (233) predicate ::= expression BETWEEN expression AND expression */ - { 221, -6 }, /* (234) predicate ::= expression NOT BETWEEN expression AND expression */ - { 221, -3 }, /* (235) predicate ::= expression IS NULL */ - { 221, -4 }, /* (236) predicate ::= expression IS NOT NULL */ - { 221, -3 }, /* (237) predicate ::= expression in_op in_predicate_value */ - { 222, -1 }, /* (238) compare_op ::= NK_LT */ - { 222, -1 }, /* (239) compare_op ::= NK_GT */ - { 222, -1 }, /* (240) compare_op ::= NK_LE */ - { 222, -1 }, /* (241) compare_op ::= NK_GE */ - { 222, -1 }, /* (242) compare_op ::= NK_NE */ - { 222, -1 }, /* (243) compare_op ::= NK_EQ */ - { 222, -1 }, /* (244) compare_op ::= LIKE */ - { 222, -2 }, /* (245) compare_op ::= NOT LIKE */ - { 222, -1 }, /* (246) compare_op ::= MATCH */ - { 222, -1 }, /* (247) compare_op ::= NMATCH */ - { 223, -1 }, /* (248) in_op ::= IN */ - { 223, -2 }, /* (249) in_op ::= NOT IN */ - { 224, -3 }, /* (250) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 225, -1 }, /* (251) boolean_value_expression ::= boolean_primary */ - { 225, -2 }, /* (252) boolean_value_expression ::= NOT boolean_primary */ - { 225, -3 }, /* (253) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 225, -3 }, /* (254) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 226, -1 }, /* (255) boolean_primary ::= predicate */ - { 226, -3 }, /* (256) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 227, -1 }, /* (257) common_expression ::= expression */ - { 227, -1 }, /* (258) common_expression ::= boolean_value_expression */ - { 228, -2 }, /* (259) from_clause ::= FROM table_reference_list */ - { 229, -1 }, /* (260) table_reference_list ::= table_reference */ - { 229, -3 }, /* (261) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 230, -1 }, /* (262) table_reference ::= table_primary */ - { 230, -1 }, /* (263) table_reference ::= joined_table */ - { 231, -2 }, /* (264) table_primary ::= table_name alias_opt */ - { 231, -4 }, /* (265) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 231, -2 }, /* (266) table_primary ::= subquery alias_opt */ - { 231, -1 }, /* (267) table_primary ::= parenthesized_joined_table */ - { 233, 0 }, /* (268) alias_opt ::= */ - { 233, -1 }, /* (269) alias_opt ::= table_alias */ - { 233, -2 }, /* (270) alias_opt ::= AS table_alias */ - { 234, -3 }, /* (271) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 234, -3 }, /* (272) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 232, -6 }, /* (273) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 235, 0 }, /* (274) join_type ::= */ - { 235, -1 }, /* (275) join_type ::= INNER */ - { 237, -9 }, /* (276) 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 */ - { 238, 0 }, /* (277) set_quantifier_opt ::= */ - { 238, -1 }, /* (278) set_quantifier_opt ::= DISTINCT */ - { 238, -1 }, /* (279) set_quantifier_opt ::= ALL */ - { 239, -1 }, /* (280) select_list ::= NK_STAR */ - { 239, -1 }, /* (281) select_list ::= select_sublist */ - { 245, -1 }, /* (282) select_sublist ::= select_item */ - { 245, -3 }, /* (283) select_sublist ::= select_sublist NK_COMMA select_item */ - { 246, -1 }, /* (284) select_item ::= common_expression */ - { 246, -2 }, /* (285) select_item ::= common_expression column_alias */ - { 246, -3 }, /* (286) select_item ::= common_expression AS column_alias */ - { 246, -3 }, /* (287) select_item ::= table_name NK_DOT NK_STAR */ - { 240, 0 }, /* (288) where_clause_opt ::= */ - { 240, -2 }, /* (289) where_clause_opt ::= WHERE search_condition */ - { 241, 0 }, /* (290) partition_by_clause_opt ::= */ - { 241, -3 }, /* (291) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 242, 0 }, /* (292) twindow_clause_opt ::= */ - { 242, -6 }, /* (293) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 242, -4 }, /* (294) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 242, -6 }, /* (295) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 242, -8 }, /* (296) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 209, 0 }, /* (297) sliding_opt ::= */ - { 209, -4 }, /* (298) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 247, 0 }, /* (299) fill_opt ::= */ - { 247, -4 }, /* (300) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 247, -6 }, /* (301) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 248, -1 }, /* (302) fill_mode ::= NONE */ - { 248, -1 }, /* (303) fill_mode ::= PREV */ - { 248, -1 }, /* (304) fill_mode ::= NULL */ - { 248, -1 }, /* (305) fill_mode ::= LINEAR */ - { 248, -1 }, /* (306) fill_mode ::= NEXT */ - { 243, 0 }, /* (307) group_by_clause_opt ::= */ - { 243, -3 }, /* (308) group_by_clause_opt ::= GROUP BY group_by_list */ - { 249, -1 }, /* (309) group_by_list ::= expression */ - { 249, -3 }, /* (310) group_by_list ::= group_by_list NK_COMMA expression */ - { 244, 0 }, /* (311) having_clause_opt ::= */ - { 244, -2 }, /* (312) having_clause_opt ::= HAVING search_condition */ - { 213, -4 }, /* (313) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 250, -1 }, /* (314) query_expression_body ::= query_primary */ - { 250, -4 }, /* (315) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 254, -1 }, /* (316) query_primary ::= query_specification */ - { 251, 0 }, /* (317) order_by_clause_opt ::= */ - { 251, -3 }, /* (318) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 252, 0 }, /* (319) slimit_clause_opt ::= */ - { 252, -2 }, /* (320) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 252, -4 }, /* (321) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 252, -4 }, /* (322) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 253, 0 }, /* (323) limit_clause_opt ::= */ - { 253, -2 }, /* (324) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 253, -4 }, /* (325) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 253, -4 }, /* (326) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 220, -3 }, /* (327) subquery ::= NK_LP query_expression NK_RP */ - { 236, -1 }, /* (328) search_condition ::= common_expression */ - { 255, -1 }, /* (329) sort_specification_list ::= sort_specification */ - { 255, -3 }, /* (330) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 256, -3 }, /* (331) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 257, 0 }, /* (332) ordering_specification_opt ::= */ - { 257, -1 }, /* (333) ordering_specification_opt ::= ASC */ - { 257, -1 }, /* (334) ordering_specification_opt ::= DESC */ - { 258, 0 }, /* (335) null_ordering_opt ::= */ - { 258, -2 }, /* (336) null_ordering_opt ::= NULLS FIRST */ - { 258, -2 }, /* (337) null_ordering_opt ::= NULLS LAST */ + { 176, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 176, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 177, 0 }, /* (2) account_options ::= */ + { 177, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 177, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 177, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 177, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 177, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 177, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 177, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 177, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 177, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 178, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 178, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 180, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 180, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 180, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 180, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 180, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 180, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 180, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 180, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 180, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 180, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 176, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 176, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 176, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 176, -3 }, /* (27) cmd ::= DROP USER user_name */ + { 176, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ + { 176, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 176, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ + { 176, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ + { 176, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 176, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 176, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ + { 176, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 182, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ + { 183, -1 }, /* (37) dnode_host_name ::= NK_ID */ + { 183, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ + { 176, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ + { 176, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 176, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 176, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 176, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 176, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ + { 176, -2 }, /* (45) cmd ::= USE db_name */ + { 176, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 184, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ + { 184, 0 }, /* (48) not_exists_opt ::= */ + { 187, -2 }, /* (49) exists_opt ::= IF EXISTS */ + { 187, 0 }, /* (50) exists_opt ::= */ + { 186, 0 }, /* (51) db_options ::= */ + { 186, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ + { 186, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ + { 186, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ + { 186, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ + { 186, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ + { 186, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ + { 186, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ + { 186, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ + { 186, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ + { 186, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ + { 186, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ + { 186, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ + { 186, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ + { 186, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ + { 186, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ + { 186, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 186, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 186, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ + { 188, -1 }, /* (70) alter_db_options ::= alter_db_option */ + { 188, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ + { 189, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ + { 189, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ + { 189, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ + { 189, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ + { 189, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ + { 189, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ + { 176, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 176, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ + { 176, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 176, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ + { 176, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ + { 176, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ + { 176, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ + { 197, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ + { 197, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 197, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 197, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 197, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 197, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 197, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 197, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 197, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 197, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + { 194, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ + { 194, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 201, -9 }, /* (97) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 196, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ + { 196, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 204, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ + { 202, 0 }, /* (101) specific_tags_opt ::= */ + { 202, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 190, -1 }, /* (103) full_table_name ::= table_name */ + { 190, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ + { 191, -1 }, /* (105) column_def_list ::= column_def */ + { 191, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ + { 207, -2 }, /* (107) column_def ::= column_name type_name */ + { 207, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ + { 200, -1 }, /* (109) type_name ::= BOOL */ + { 200, -1 }, /* (110) type_name ::= TINYINT */ + { 200, -1 }, /* (111) type_name ::= SMALLINT */ + { 200, -1 }, /* (112) type_name ::= INT */ + { 200, -1 }, /* (113) type_name ::= INTEGER */ + { 200, -1 }, /* (114) type_name ::= BIGINT */ + { 200, -1 }, /* (115) type_name ::= FLOAT */ + { 200, -1 }, /* (116) type_name ::= DOUBLE */ + { 200, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 200, -1 }, /* (118) type_name ::= TIMESTAMP */ + { 200, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 200, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ + { 200, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ + { 200, -2 }, /* (122) type_name ::= INT UNSIGNED */ + { 200, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ + { 200, -1 }, /* (124) type_name ::= JSON */ + { 200, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 200, -1 }, /* (126) type_name ::= MEDIUMBLOB */ + { 200, -1 }, /* (127) type_name ::= BLOB */ + { 200, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 200, -1 }, /* (129) type_name ::= DECIMAL */ + { 200, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 200, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 192, 0 }, /* (132) tags_def_opt ::= */ + { 192, -1 }, /* (133) tags_def_opt ::= tags_def */ + { 195, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 193, 0 }, /* (135) table_options ::= */ + { 193, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ + { 193, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ + { 193, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ + { 193, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 193, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ + { 193, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ + { 193, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ + { 198, -1 }, /* (143) alter_table_options ::= alter_table_option */ + { 198, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ + { 209, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ + { 209, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ + { 209, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ + { 205, -1 }, /* (148) col_name_list ::= col_name */ + { 205, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ + { 210, -1 }, /* (150) col_name ::= column_name */ + { 176, -2 }, /* (151) cmd ::= SHOW DNODES */ + { 176, -2 }, /* (152) cmd ::= SHOW USERS */ + { 176, -2 }, /* (153) cmd ::= SHOW DATABASES */ + { 176, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 176, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 176, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 176, -2 }, /* (157) cmd ::= SHOW MNODES */ + { 176, -2 }, /* (158) cmd ::= SHOW MODULES */ + { 176, -2 }, /* (159) cmd ::= SHOW QNODES */ + { 176, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ + { 176, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 176, -2 }, /* (162) cmd ::= SHOW STREAMS */ + { 211, 0 }, /* (163) db_name_cond_opt ::= */ + { 211, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ + { 212, 0 }, /* (165) like_pattern_opt ::= */ + { 212, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ + { 213, -1 }, /* (167) table_name_cond ::= table_name */ + { 214, 0 }, /* (168) from_db_opt ::= */ + { 214, -2 }, /* (169) from_db_opt ::= FROM db_name */ + { 208, -1 }, /* (170) func_name_list ::= func_name */ + { 208, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ + { 215, -1 }, /* (172) func_name ::= function_name */ + { 176, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 176, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 176, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 218, 0 }, /* (176) index_options ::= */ + { 218, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 218, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 219, -1 }, /* (179) func_list ::= func */ + { 219, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ + { 222, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ + { 176, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 176, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ + { 176, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ + { 176, -4 }, /* (185) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 226, 0 }, /* (186) analyze_opt ::= */ + { 226, -1 }, /* (187) analyze_opt ::= ANALYZE */ + { 227, 0 }, /* (188) explain_options ::= */ + { 227, -3 }, /* (189) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 227, -3 }, /* (190) explain_options ::= explain_options RATIO NK_FLOAT */ + { 176, -1 }, /* (191) cmd ::= query_expression */ + { 179, -1 }, /* (192) literal ::= NK_INTEGER */ + { 179, -1 }, /* (193) literal ::= NK_FLOAT */ + { 179, -1 }, /* (194) literal ::= NK_STRING */ + { 179, -1 }, /* (195) literal ::= NK_BOOL */ + { 179, -2 }, /* (196) literal ::= TIMESTAMP NK_STRING */ + { 179, -1 }, /* (197) literal ::= duration_literal */ + { 179, -1 }, /* (198) literal ::= NULL */ + { 220, -1 }, /* (199) duration_literal ::= NK_VARIABLE */ + { 228, -1 }, /* (200) signed ::= NK_INTEGER */ + { 228, -2 }, /* (201) signed ::= NK_PLUS NK_INTEGER */ + { 228, -2 }, /* (202) signed ::= NK_MINUS NK_INTEGER */ + { 228, -1 }, /* (203) signed ::= NK_FLOAT */ + { 228, -2 }, /* (204) signed ::= NK_PLUS NK_FLOAT */ + { 228, -2 }, /* (205) signed ::= NK_MINUS NK_FLOAT */ + { 229, -1 }, /* (206) signed_literal ::= signed */ + { 229, -1 }, /* (207) signed_literal ::= NK_STRING */ + { 229, -1 }, /* (208) signed_literal ::= NK_BOOL */ + { 229, -2 }, /* (209) signed_literal ::= TIMESTAMP NK_STRING */ + { 229, -1 }, /* (210) signed_literal ::= duration_literal */ + { 229, -1 }, /* (211) signed_literal ::= NULL */ + { 203, -1 }, /* (212) literal_list ::= signed_literal */ + { 203, -3 }, /* (213) literal_list ::= literal_list NK_COMMA signed_literal */ + { 185, -1 }, /* (214) db_name ::= NK_ID */ + { 206, -1 }, /* (215) table_name ::= NK_ID */ + { 199, -1 }, /* (216) column_name ::= NK_ID */ + { 216, -1 }, /* (217) function_name ::= NK_ID */ + { 230, -1 }, /* (218) table_alias ::= NK_ID */ + { 231, -1 }, /* (219) column_alias ::= NK_ID */ + { 181, -1 }, /* (220) user_name ::= NK_ID */ + { 217, -1 }, /* (221) index_name ::= NK_ID */ + { 224, -1 }, /* (222) topic_name ::= NK_ID */ + { 232, -1 }, /* (223) expression ::= literal */ + { 232, -1 }, /* (224) expression ::= pseudo_column */ + { 232, -1 }, /* (225) expression ::= column_reference */ + { 232, -4 }, /* (226) expression ::= function_name NK_LP expression_list NK_RP */ + { 232, -4 }, /* (227) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 232, -1 }, /* (228) expression ::= subquery */ + { 232, -3 }, /* (229) expression ::= NK_LP expression NK_RP */ + { 232, -2 }, /* (230) expression ::= NK_PLUS expression */ + { 232, -2 }, /* (231) expression ::= NK_MINUS expression */ + { 232, -3 }, /* (232) expression ::= expression NK_PLUS expression */ + { 232, -3 }, /* (233) expression ::= expression NK_MINUS expression */ + { 232, -3 }, /* (234) expression ::= expression NK_STAR expression */ + { 232, -3 }, /* (235) expression ::= expression NK_SLASH expression */ + { 232, -3 }, /* (236) expression ::= expression NK_REM expression */ + { 223, -1 }, /* (237) expression_list ::= expression */ + { 223, -3 }, /* (238) expression_list ::= expression_list NK_COMMA expression */ + { 234, -1 }, /* (239) column_reference ::= column_name */ + { 234, -3 }, /* (240) column_reference ::= table_name NK_DOT column_name */ + { 233, -2 }, /* (241) pseudo_column ::= NK_UNDERLINE ROWTS */ + { 233, -1 }, /* (242) pseudo_column ::= TBNAME */ + { 233, -2 }, /* (243) pseudo_column ::= NK_UNDERLINE QSTARTTS */ + { 233, -2 }, /* (244) pseudo_column ::= NK_UNDERLINE QENDTS */ + { 233, -2 }, /* (245) pseudo_column ::= NK_UNDERLINE WSTARTTS */ + { 233, -2 }, /* (246) pseudo_column ::= NK_UNDERLINE WENDTS */ + { 233, -2 }, /* (247) pseudo_column ::= NK_UNDERLINE WDURATION */ + { 236, -3 }, /* (248) predicate ::= expression compare_op expression */ + { 236, -5 }, /* (249) predicate ::= expression BETWEEN expression AND expression */ + { 236, -6 }, /* (250) predicate ::= expression NOT BETWEEN expression AND expression */ + { 236, -3 }, /* (251) predicate ::= expression IS NULL */ + { 236, -4 }, /* (252) predicate ::= expression IS NOT NULL */ + { 236, -3 }, /* (253) predicate ::= expression in_op in_predicate_value */ + { 237, -1 }, /* (254) compare_op ::= NK_LT */ + { 237, -1 }, /* (255) compare_op ::= NK_GT */ + { 237, -1 }, /* (256) compare_op ::= NK_LE */ + { 237, -1 }, /* (257) compare_op ::= NK_GE */ + { 237, -1 }, /* (258) compare_op ::= NK_NE */ + { 237, -1 }, /* (259) compare_op ::= NK_EQ */ + { 237, -1 }, /* (260) compare_op ::= LIKE */ + { 237, -2 }, /* (261) compare_op ::= NOT LIKE */ + { 237, -1 }, /* (262) compare_op ::= MATCH */ + { 237, -1 }, /* (263) compare_op ::= NMATCH */ + { 238, -1 }, /* (264) in_op ::= IN */ + { 238, -2 }, /* (265) in_op ::= NOT IN */ + { 239, -3 }, /* (266) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 240, -1 }, /* (267) boolean_value_expression ::= boolean_primary */ + { 240, -2 }, /* (268) boolean_value_expression ::= NOT boolean_primary */ + { 240, -3 }, /* (269) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 240, -3 }, /* (270) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 241, -1 }, /* (271) boolean_primary ::= predicate */ + { 241, -3 }, /* (272) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 242, -1 }, /* (273) common_expression ::= expression */ + { 242, -1 }, /* (274) common_expression ::= boolean_value_expression */ + { 243, -2 }, /* (275) from_clause ::= FROM table_reference_list */ + { 244, -1 }, /* (276) table_reference_list ::= table_reference */ + { 244, -3 }, /* (277) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 245, -1 }, /* (278) table_reference ::= table_primary */ + { 245, -1 }, /* (279) table_reference ::= joined_table */ + { 246, -2 }, /* (280) table_primary ::= table_name alias_opt */ + { 246, -4 }, /* (281) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 246, -2 }, /* (282) table_primary ::= subquery alias_opt */ + { 246, -1 }, /* (283) table_primary ::= parenthesized_joined_table */ + { 248, 0 }, /* (284) alias_opt ::= */ + { 248, -1 }, /* (285) alias_opt ::= table_alias */ + { 248, -2 }, /* (286) alias_opt ::= AS table_alias */ + { 249, -3 }, /* (287) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 249, -3 }, /* (288) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 247, -6 }, /* (289) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 250, 0 }, /* (290) join_type ::= */ + { 250, -1 }, /* (291) join_type ::= INNER */ + { 252, -9 }, /* (292) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 253, 0 }, /* (293) set_quantifier_opt ::= */ + { 253, -1 }, /* (294) set_quantifier_opt ::= DISTINCT */ + { 253, -1 }, /* (295) set_quantifier_opt ::= ALL */ + { 254, -1 }, /* (296) select_list ::= NK_STAR */ + { 254, -1 }, /* (297) select_list ::= select_sublist */ + { 260, -1 }, /* (298) select_sublist ::= select_item */ + { 260, -3 }, /* (299) select_sublist ::= select_sublist NK_COMMA select_item */ + { 261, -1 }, /* (300) select_item ::= common_expression */ + { 261, -2 }, /* (301) select_item ::= common_expression column_alias */ + { 261, -3 }, /* (302) select_item ::= common_expression AS column_alias */ + { 261, -3 }, /* (303) select_item ::= table_name NK_DOT NK_STAR */ + { 255, 0 }, /* (304) where_clause_opt ::= */ + { 255, -2 }, /* (305) where_clause_opt ::= WHERE search_condition */ + { 256, 0 }, /* (306) partition_by_clause_opt ::= */ + { 256, -3 }, /* (307) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 257, 0 }, /* (308) twindow_clause_opt ::= */ + { 257, -6 }, /* (309) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 257, -4 }, /* (310) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 257, -6 }, /* (311) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 257, -8 }, /* (312) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 221, 0 }, /* (313) sliding_opt ::= */ + { 221, -4 }, /* (314) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 262, 0 }, /* (315) fill_opt ::= */ + { 262, -4 }, /* (316) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 262, -6 }, /* (317) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 263, -1 }, /* (318) fill_mode ::= NONE */ + { 263, -1 }, /* (319) fill_mode ::= PREV */ + { 263, -1 }, /* (320) fill_mode ::= NULL */ + { 263, -1 }, /* (321) fill_mode ::= LINEAR */ + { 263, -1 }, /* (322) fill_mode ::= NEXT */ + { 258, 0 }, /* (323) group_by_clause_opt ::= */ + { 258, -3 }, /* (324) group_by_clause_opt ::= GROUP BY group_by_list */ + { 264, -1 }, /* (325) group_by_list ::= expression */ + { 264, -3 }, /* (326) group_by_list ::= group_by_list NK_COMMA expression */ + { 259, 0 }, /* (327) having_clause_opt ::= */ + { 259, -2 }, /* (328) having_clause_opt ::= HAVING search_condition */ + { 225, -4 }, /* (329) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 265, -1 }, /* (330) query_expression_body ::= query_primary */ + { 265, -4 }, /* (331) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 269, -1 }, /* (332) query_primary ::= query_specification */ + { 266, 0 }, /* (333) order_by_clause_opt ::= */ + { 266, -3 }, /* (334) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 267, 0 }, /* (335) slimit_clause_opt ::= */ + { 267, -2 }, /* (336) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 267, -4 }, /* (337) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 267, -4 }, /* (338) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 268, 0 }, /* (339) limit_clause_opt ::= */ + { 268, -2 }, /* (340) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 268, -4 }, /* (341) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 268, -4 }, /* (342) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 235, -3 }, /* (343) subquery ::= NK_LP query_expression NK_RP */ + { 251, -1 }, /* (344) search_condition ::= common_expression */ + { 270, -1 }, /* (345) sort_specification_list ::= sort_specification */ + { 270, -3 }, /* (346) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 271, -3 }, /* (347) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 272, 0 }, /* (348) ordering_specification_opt ::= */ + { 272, -1 }, /* (349) ordering_specification_opt ::= ASC */ + { 272, -1 }, /* (350) ordering_specification_opt ::= DESC */ + { 273, 0 }, /* (351) null_ordering_opt ::= */ + { 273, -2 }, /* (352) null_ordering_opt ::= NULLS FIRST */ + { 273, -2 }, /* (353) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2294,11 +2360,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,165,&yymsp[0].minor); + yy_destructor(yypParser,177,&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,166,&yymsp[0].minor); + yy_destructor(yypParser,178,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2312,20 +2378,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,165,&yymsp[-2].minor); +{ yy_destructor(yypParser,177,&yymsp[-2].minor); { } - yy_destructor(yypParser,167,&yymsp[0].minor); + yy_destructor(yypParser,179,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,168,&yymsp[0].minor); +{ yy_destructor(yypParser,180,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,166,&yymsp[-1].minor); +{ yy_destructor(yypParser,178,&yymsp[-1].minor); { } - yy_destructor(yypParser,168,&yymsp[0].minor); + yy_destructor(yypParser,180,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2339,31 +2405,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,167,&yymsp[0].minor); + yy_destructor(yypParser,179,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy183, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy437, 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.yy183, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy437, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy437); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy183, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy437, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy437, &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.yy183); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy437); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -2380,17 +2446,17 @@ 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 206: /* db_name ::= NK_ID */ yytestcase(yyruleno==206); - case 207: /* table_name ::= NK_ID */ yytestcase(yyruleno==207); - case 208: /* column_name ::= NK_ID */ yytestcase(yyruleno==208); - case 209: /* function_name ::= NK_ID */ yytestcase(yyruleno==209); - case 210: /* table_alias ::= NK_ID */ yytestcase(yyruleno==210); - case 211: /* column_alias ::= NK_ID */ yytestcase(yyruleno==211); - case 212: /* user_name ::= NK_ID */ yytestcase(yyruleno==212); - case 213: /* index_name ::= NK_ID */ yytestcase(yyruleno==213); - case 214: /* topic_name ::= NK_ID */ yytestcase(yyruleno==214); -{ yylhsminor.yy183 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy183 = yylhsminor.yy183; + case 214: /* db_name ::= NK_ID */ yytestcase(yyruleno==214); + case 215: /* table_name ::= NK_ID */ yytestcase(yyruleno==215); + case 216: /* column_name ::= NK_ID */ yytestcase(yyruleno==216); + case 217: /* function_name ::= NK_ID */ yytestcase(yyruleno==217); + case 218: /* table_alias ::= NK_ID */ yytestcase(yyruleno==218); + case 219: /* column_alias ::= NK_ID */ yytestcase(yyruleno==219); + case 220: /* user_name ::= NK_ID */ yytestcase(yyruleno==220); + case 221: /* index_name ::= NK_ID */ yytestcase(yyruleno==221); + case 222: /* topic_name ::= NK_ID */ yytestcase(yyruleno==222); +{ yylhsminor.yy437 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy437 = yylhsminor.yy437; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2405,186 +2471,187 @@ 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.yy215, &yymsp[-1].minor.yy183, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy493, &yymsp[-1].minor.yy437, yymsp[0].minor.yy364); } break; case 44: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy215, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy493, &yymsp[0].minor.yy437); } break; case 45: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy437); } break; case 46: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy183, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy437, yymsp[0].minor.yy364); } break; case 47: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy215 = true; } +{ yymsp[-2].minor.yy493 = true; } break; case 48: /* not_exists_opt ::= */ case 50: /* exists_opt ::= */ yytestcase(yyruleno==50); - case 277: /* set_quantifier_opt ::= */ yytestcase(yyruleno==277); -{ yymsp[1].minor.yy215 = false; } + case 186: /* analyze_opt ::= */ yytestcase(yyruleno==186); + case 293: /* set_quantifier_opt ::= */ yytestcase(yyruleno==293); +{ yymsp[1].minor.yy493 = false; } break; case 49: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy215 = true; } +{ yymsp[-1].minor.yy493 = true; } break; case 51: /* db_options ::= */ -{ yymsp[1].minor.yy378 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy364 = createDefaultDatabaseOptions(pCxt); } break; case 52: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 53: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 54: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 55: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 56: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 57: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 58: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 59: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 60: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 61: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 62: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 63: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 64: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 65: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 66: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 67: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 68: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 69: /* db_options ::= db_options RETENTIONS NK_STRING */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-2].minor.yy364, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 70: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy378 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy378 = setDatabaseOption(pCxt, yylhsminor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy364 = setDatabaseOption(pCxt, yylhsminor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; case 71: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setDatabaseOption(pCxt, yymsp[-1].minor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; case 72: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 73: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 74: /* alter_db_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_KEEP; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = DB_OPTION_KEEP; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 75: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_WAL; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = DB_OPTION_WAL; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 76: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 77: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 78: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 80: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==80); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy215, yymsp[-5].minor.yy378, yymsp[-3].minor.yy404, yymsp[-1].minor.yy404, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy493, yymsp[-5].minor.yy364, yymsp[-3].minor.yy40, yymsp[-1].minor.yy40, yymsp[0].minor.yy364); } break; case 79: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy404); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy40); } break; case 81: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy404); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy40); } break; case 82: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy215, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy493, yymsp[0].minor.yy364); } break; case 83: /* cmd ::= ALTER TABLE alter_table_clause */ case 84: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==84); - case 185: /* cmd ::= query_expression */ yytestcase(yyruleno==185); -{ pCxt->pRootNode = yymsp[0].minor.yy378; } + case 191: /* cmd ::= query_expression */ yytestcase(yyruleno==191); +{ pCxt->pRootNode = yymsp[0].minor.yy364; } break; case 85: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy378 = createAlterTableOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableOption(pCxt, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; case 86: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 87: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy378 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy378, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy183); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy364, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy437); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; case 88: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 89: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy378 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 90: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 91: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy378 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy378, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy183); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy364, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy437); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; case 92: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 93: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy378 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy364, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 94: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy378 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy378, &yymsp[-2].minor.yy183, yymsp[0].minor.yy378); } - yymsp[-5].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy364, &yymsp[-2].minor.yy437, yymsp[0].minor.yy364); } + yymsp[-5].minor.yy364 = yylhsminor.yy364; break; case 95: /* multi_create_clause ::= create_subtable_clause */ case 98: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==98); @@ -2592,187 +2659,187 @@ static YYACTIONTYPE yy_reduce( 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 204: /* literal_list ::= signed_literal */ yytestcase(yyruleno==204); - case 282: /* select_sublist ::= select_item */ yytestcase(yyruleno==282); - case 329: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==329); -{ yylhsminor.yy404 = createNodeList(pCxt, yymsp[0].minor.yy378); } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 212: /* literal_list ::= signed_literal */ yytestcase(yyruleno==212); + case 298: /* select_sublist ::= select_item */ yytestcase(yyruleno==298); + case 345: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==345); +{ yylhsminor.yy40 = createNodeList(pCxt, yymsp[0].minor.yy364); } + yymsp[0].minor.yy40 = yylhsminor.yy40; 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.yy404 = addNodeToList(pCxt, yymsp[-1].minor.yy404, yymsp[0].minor.yy378); } - yymsp[-1].minor.yy404 = yylhsminor.yy404; +{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-1].minor.yy40, yymsp[0].minor.yy364); } + yymsp[-1].minor.yy40 = yylhsminor.yy40; 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.yy378 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy215, yymsp[-7].minor.yy378, yymsp[-5].minor.yy378, yymsp[-4].minor.yy404, yymsp[-1].minor.yy404); } - yymsp[-8].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy493, yymsp[-7].minor.yy364, yymsp[-5].minor.yy364, yymsp[-4].minor.yy40, yymsp[-1].minor.yy40); } + yymsp[-8].minor.yy364 = yylhsminor.yy364; break; case 100: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy378 = createDropTableClause(pCxt, yymsp[-1].minor.yy215, yymsp[0].minor.yy378); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createDropTableClause(pCxt, yymsp[-1].minor.yy493, yymsp[0].minor.yy364); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; case 101: /* specific_tags_opt ::= */ case 132: /* tags_def_opt ::= */ yytestcase(yyruleno==132); - case 290: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==290); - case 307: /* group_by_clause_opt ::= */ yytestcase(yyruleno==307); - case 317: /* order_by_clause_opt ::= */ yytestcase(yyruleno==317); -{ yymsp[1].minor.yy404 = NULL; } + case 306: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==306); + case 323: /* group_by_clause_opt ::= */ yytestcase(yyruleno==323); + case 333: /* order_by_clause_opt ::= */ yytestcase(yyruleno==333); +{ yymsp[1].minor.yy40 = NULL; } break; case 102: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy404 = yymsp[-1].minor.yy404; } +{ yymsp[-2].minor.yy40 = yymsp[-1].minor.yy40; } break; case 103: /* full_table_name ::= table_name */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy183, NULL); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy437, NULL); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; case 104: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183, NULL); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createRealTableNode(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437, NULL); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; 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 205: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==205); - case 283: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==283); - case 330: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==330); -{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, yymsp[0].minor.yy378); } - yymsp[-2].minor.yy404 = yylhsminor.yy404; + case 213: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==213); + case 299: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==299); + case 346: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==346); +{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, yymsp[0].minor.yy364); } + yymsp[-2].minor.yy40 = yylhsminor.yy40; break; case 107: /* column_def ::= column_name type_name */ -{ yylhsminor.yy378 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504, NULL); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy437, yymsp[0].minor.yy420, NULL); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; case 108: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy378 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy437, yymsp[-2].minor.yy420, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; case 109: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 110: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 111: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 112: /* type_name ::= INT */ case 113: /* type_name ::= INTEGER */ yytestcase(yyruleno==113); -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_INT); } break; case 114: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 115: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 116: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 117: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 118: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 119: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 120: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 121: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 122: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 123: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy420 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 124: /* type_name ::= JSON */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 125: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 126: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 127: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 128: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy420 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 129: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy420 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 130: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy420 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 131: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy420 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 133: /* tags_def_opt ::= tags_def */ - case 281: /* select_list ::= select_sublist */ yytestcase(yyruleno==281); -{ yylhsminor.yy404 = yymsp[0].minor.yy404; } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 297: /* select_list ::= select_sublist */ yytestcase(yyruleno==297); +{ yylhsminor.yy40 = yymsp[0].minor.yy40; } + yymsp[0].minor.yy40 = yylhsminor.yy40; break; case 134: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy404 = yymsp[-1].minor.yy404; } +{ yymsp[-3].minor.yy40 = yymsp[-1].minor.yy40; } break; case 135: /* table_options ::= */ -{ yymsp[1].minor.yy378 = createDefaultTableOptions(pCxt); } +{ yymsp[1].minor.yy364 = createDefaultTableOptions(pCxt); } break; case 136: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 137: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 138: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 139: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy378 = setTableSmaOption(pCxt, yymsp[-4].minor.yy378, yymsp[-1].minor.yy404); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableSmaOption(pCxt, yymsp[-4].minor.yy364, yymsp[-1].minor.yy40); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 140: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ yylhsminor.yy378 = setTableRollupOption(pCxt, yymsp[-4].minor.yy378, yymsp[-1].minor.yy404); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableRollupOption(pCxt, yymsp[-4].minor.yy364, yymsp[-1].minor.yy40); } + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; case 141: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 142: /* table_options ::= table_options DELAY NK_INTEGER */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-2].minor.yy364, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; case 143: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy378 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy378 = setTableOption(pCxt, yylhsminor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy364 = setTableOption(pCxt, yylhsminor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; case 144: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = setTableOption(pCxt, yymsp[-1].minor.yy364, yymsp[0].minor.yy29.type, &yymsp[0].minor.yy29.val); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; case 145: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy11.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 146: /* alter_table_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 147: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy29.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy29.val = yymsp[0].minor.yy0; } break; case 150: /* col_name ::= column_name */ -{ yylhsminor.yy378 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy183); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy437); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; case 151: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -2784,13 +2851,13 @@ static YYACTIONTYPE yy_reduce( { 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.yy378, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy364, yymsp[0].minor.yy364); } 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.yy378, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy364, yymsp[0].minor.yy364); } break; case 156: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy378, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy364, NULL); } break; case 157: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -2805,526 +2872,566 @@ static YYACTIONTYPE yy_reduce( { 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.yy378, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } break; case 162: /* 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.yy378 = createDefaultDatabaseCondValue(pCxt); } +{ yymsp[1].minor.yy364 = createDefaultDatabaseCondValue(pCxt); } break; case 164: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy437); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; case 165: /* like_pattern_opt ::= */ case 176: /* index_options ::= */ yytestcase(yyruleno==176); - case 288: /* where_clause_opt ::= */ yytestcase(yyruleno==288); - case 292: /* twindow_clause_opt ::= */ yytestcase(yyruleno==292); - case 297: /* sliding_opt ::= */ yytestcase(yyruleno==297); - case 299: /* fill_opt ::= */ yytestcase(yyruleno==299); - case 311: /* having_clause_opt ::= */ yytestcase(yyruleno==311); - case 319: /* slimit_clause_opt ::= */ yytestcase(yyruleno==319); - case 323: /* limit_clause_opt ::= */ yytestcase(yyruleno==323); -{ yymsp[1].minor.yy378 = NULL; } + case 304: /* where_clause_opt ::= */ yytestcase(yyruleno==304); + case 308: /* twindow_clause_opt ::= */ yytestcase(yyruleno==308); + case 313: /* sliding_opt ::= */ yytestcase(yyruleno==313); + case 315: /* fill_opt ::= */ yytestcase(yyruleno==315); + case 327: /* having_clause_opt ::= */ yytestcase(yyruleno==327); + case 335: /* slimit_clause_opt ::= */ yytestcase(yyruleno==335); + case 339: /* limit_clause_opt ::= */ yytestcase(yyruleno==339); +{ yymsp[1].minor.yy364 = NULL; } break; case 166: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 167: /* table_name_cond ::= table_name */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy183); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy437); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; case 169: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy183); } +{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy437); } break; case 172: /* func_name ::= function_name */ -{ yylhsminor.yy378 = createFunctionNode(pCxt, &yymsp[0].minor.yy183, NULL); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createFunctionNode(pCxt, &yymsp[0].minor.yy437, NULL); } + yymsp[0].minor.yy364 = yylhsminor.yy364; 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.yy215, &yymsp[-3].minor.yy183, &yymsp[-1].minor.yy183, NULL, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy493, &yymsp[-3].minor.yy437, &yymsp[-1].minor.yy437, NULL, yymsp[0].minor.yy364); } 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.yy215, &yymsp[-5].minor.yy183, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404, NULL); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy493, &yymsp[-5].minor.yy437, &yymsp[-3].minor.yy437, yymsp[-1].minor.yy40, NULL); } break; case 175: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy493, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437); } break; case 177: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy378 = createIndexOption(pCxt, yymsp[-6].minor.yy404, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), NULL, yymsp[0].minor.yy378); } +{ yymsp[-8].minor.yy364 = createIndexOption(pCxt, yymsp[-6].minor.yy40, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), NULL, yymsp[0].minor.yy364); } 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.yy378 = createIndexOption(pCxt, yymsp[-8].minor.yy404, releaseRawExprNode(pCxt, yymsp[-4].minor.yy378), releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), yymsp[0].minor.yy378); } +{ yymsp[-10].minor.yy364 = createIndexOption(pCxt, yymsp[-8].minor.yy40, releaseRawExprNode(pCxt, yymsp[-4].minor.yy364), releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), yymsp[0].minor.yy364); } break; case 181: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy378 = createFunctionNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy364 = createFunctionNode(pCxt, &yymsp[-3].minor.yy437, yymsp[-1].minor.yy40); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, yymsp[0].minor.yy378, NULL); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy493, &yymsp[-2].minor.yy437, yymsp[0].minor.yy364, NULL); } break; case 183: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, NULL, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy493, &yymsp[-2].minor.yy437, NULL, &yymsp[0].minor.yy437); } break; case 184: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy215, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy493, &yymsp[0].minor.yy437); } break; - case 186: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 185: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy493, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } break; - case 187: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 187: /* analyze_opt ::= ANALYZE */ + case 294: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==294); +{ yymsp[0].minor.yy493 = true; } break; - case 188: /* literal ::= NK_STRING */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 188: /* explain_options ::= */ +{ yymsp[1].minor.yy364 = createDefaultExplainOptions(pCxt); } break; - case 189: /* literal ::= NK_BOOL */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 189: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy364 = setExplainVerbose(pCxt, yymsp[-2].minor.yy364, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 190: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + case 190: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy364 = setExplainRatio(pCxt, yymsp[-2].minor.yy364, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 191: /* literal ::= duration_literal */ - case 199: /* signed_literal ::= signed */ yytestcase(yyruleno==199); - case 215: /* expression ::= literal */ yytestcase(yyruleno==215); - case 216: /* expression ::= column_reference */ yytestcase(yyruleno==216); - case 219: /* expression ::= subquery */ yytestcase(yyruleno==219); - case 251: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==251); - case 255: /* boolean_primary ::= predicate */ yytestcase(yyruleno==255); - case 257: /* common_expression ::= expression */ yytestcase(yyruleno==257); - case 258: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==258); - case 260: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==260); - case 262: /* table_reference ::= table_primary */ yytestcase(yyruleno==262); - case 263: /* table_reference ::= joined_table */ yytestcase(yyruleno==263); - case 267: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==267); - case 314: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==314); - case 316: /* query_primary ::= query_specification */ yytestcase(yyruleno==316); -{ yylhsminor.yy378 = yymsp[0].minor.yy378; } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 192: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 192: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 193: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 193: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 194: /* literal ::= NK_STRING */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 194: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 195: /* literal ::= NK_BOOL */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 195: /* signed ::= NK_MINUS NK_INTEGER */ + case 196: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; + break; + case 197: /* literal ::= duration_literal */ + case 206: /* signed_literal ::= signed */ yytestcase(yyruleno==206); + case 223: /* expression ::= literal */ yytestcase(yyruleno==223); + case 224: /* expression ::= pseudo_column */ yytestcase(yyruleno==224); + case 225: /* expression ::= column_reference */ yytestcase(yyruleno==225); + case 228: /* expression ::= subquery */ yytestcase(yyruleno==228); + case 267: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==267); + case 271: /* boolean_primary ::= predicate */ yytestcase(yyruleno==271); + case 273: /* common_expression ::= expression */ yytestcase(yyruleno==273); + case 274: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==274); + case 276: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==276); + case 278: /* table_reference ::= table_primary */ yytestcase(yyruleno==278); + case 279: /* table_reference ::= joined_table */ yytestcase(yyruleno==279); + case 283: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==283); + case 330: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==330); + case 332: /* query_primary ::= query_specification */ yytestcase(yyruleno==332); +{ yylhsminor.yy364 = yymsp[0].minor.yy364; } + yymsp[0].minor.yy364 = yylhsminor.yy364; + break; + case 198: /* literal ::= NULL */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; + break; + case 199: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; + break; + case 200: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy364 = yylhsminor.yy364; + break; + case 201: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + break; + case 202: /* 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.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 196: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 203: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 197: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 204: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 198: /* signed ::= NK_MINUS NK_FLOAT */ + case 205: /* 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.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 200: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 207: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 201: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 208: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 202: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 209: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 203: /* signed_literal ::= duration_literal */ - case 328: /* search_condition ::= common_expression */ yytestcase(yyruleno==328); -{ yylhsminor.yy378 = releaseRawExprNode(pCxt, yymsp[0].minor.yy378); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 210: /* signed_literal ::= duration_literal */ + case 344: /* search_condition ::= common_expression */ yytestcase(yyruleno==344); +{ yylhsminor.yy364 = releaseRawExprNode(pCxt, yymsp[0].minor.yy364); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 217: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy183, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404)); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 211: /* signed_literal ::= NULL */ +{ yymsp[0].minor.yy364 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; - case 218: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy183, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy183, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 226: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy437, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy437, yymsp[-1].minor.yy40)); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; - case 220: /* expression ::= NK_LP expression NK_RP */ - case 256: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==256); -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 227: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy437, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy437, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; - case 221: /* expression ::= NK_PLUS expression */ + case 229: /* expression ::= NK_LP expression NK_RP */ + case 272: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==272); +{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364)); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; + break; + case 230: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy364)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 222: /* expression ::= NK_MINUS expression */ + case 231: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy364), NULL)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 223: /* expression ::= expression NK_PLUS expression */ + case 232: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 224: /* expression ::= expression NK_MINUS expression */ + case 233: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 225: /* expression ::= expression NK_STAR expression */ + case 234: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 226: /* expression ::= expression NK_SLASH expression */ + case 235: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 227: /* expression ::= expression NK_REM expression */ + case 236: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 228: /* expression_list ::= expression */ -{ yylhsminor.yy404 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 237: /* expression_list ::= expression */ +{ yylhsminor.yy40 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364)); } + yymsp[0].minor.yy40 = yylhsminor.yy40; break; - case 229: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); } - yymsp[-2].minor.yy404 = yylhsminor.yy404; + case 238: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, releaseRawExprNode(pCxt, yymsp[0].minor.yy364)); } + yymsp[-2].minor.yy40 = yylhsminor.yy40; break; - case 230: /* column_reference ::= column_name */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy183, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy183)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 239: /* column_reference ::= column_name */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy437, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy437)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 231: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183, createColumnNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 240: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437, createColumnNode(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy437)); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 232: /* predicate ::= expression compare_op expression */ - case 237: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==237); + case 241: /* pseudo_column ::= NK_UNDERLINE ROWTS */ + case 243: /* pseudo_column ::= NK_UNDERLINE QSTARTTS */ yytestcase(yyruleno==243); + case 244: /* pseudo_column ::= NK_UNDERLINE QENDTS */ yytestcase(yyruleno==244); + case 245: /* pseudo_column ::= NK_UNDERLINE WSTARTTS */ yytestcase(yyruleno==245); + case 246: /* pseudo_column ::= NK_UNDERLINE WENDTS */ yytestcase(yyruleno==246); + case 247: /* pseudo_column ::= NK_UNDERLINE WDURATION */ yytestcase(yyruleno==247); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy366, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken t = yymsp[-1].minor.yy0; + t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; + yylhsminor.yy364 = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 233: /* predicate ::= expression BETWEEN expression AND expression */ + case 242: /* pseudo_column ::= TBNAME */ +{ yylhsminor.yy364 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy364 = yylhsminor.yy364; + break; + case 248: /* predicate ::= expression compare_op expression */ + case 253: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==253); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy378), releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy328, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 234: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 249: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[-5].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy364), releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-5].minor.yy378 = yylhsminor.yy378; + yymsp[-4].minor.yy364 = yylhsminor.yy364; break; - case 235: /* predicate ::= expression IS NULL */ + case 250: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[-5].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-5].minor.yy364 = yylhsminor.yy364; break; - case 236: /* predicate ::= expression IS NOT NULL */ + case 251: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), NULL)); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 238: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy366 = OP_TYPE_LOWER_THAN; } - break; - case 239: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy366 = OP_TYPE_GREATER_THAN; } - break; - case 240: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy366 = OP_TYPE_LOWER_EQUAL; } - break; - case 241: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy366 = OP_TYPE_GREATER_EQUAL; } - break; - case 242: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy366 = OP_TYPE_NOT_EQUAL; } - break; - case 243: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy366 = OP_TYPE_EQUAL; } - break; - case 244: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy366 = OP_TYPE_LIKE; } - break; - case 245: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy366 = OP_TYPE_NOT_LIKE; } - break; - case 246: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy366 = OP_TYPE_MATCH; } - break; - case 247: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy366 = OP_TYPE_NMATCH; } - break; - case 248: /* in_op ::= IN */ -{ yymsp[0].minor.yy366 = OP_TYPE_IN; } - break; - case 249: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy366 = OP_TYPE_NOT_IN; } - break; - case 250: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; - break; - case 252: /* boolean_value_expression ::= NOT boolean_primary */ + case 252: /* predicate ::= expression IS NOT NULL */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), NULL)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; - case 253: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 254: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy328 = OP_TYPE_LOWER_THAN; } + break; + case 255: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy328 = OP_TYPE_GREATER_THAN; } + break; + case 256: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy328 = OP_TYPE_LOWER_EQUAL; } + break; + case 257: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy328 = OP_TYPE_GREATER_EQUAL; } + break; + case 258: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy328 = OP_TYPE_NOT_EQUAL; } + break; + case 259: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy328 = OP_TYPE_EQUAL; } + break; + case 260: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy328 = OP_TYPE_LIKE; } + break; + case 261: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy328 = OP_TYPE_NOT_LIKE; } + break; + case 262: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy328 = OP_TYPE_MATCH; } + break; + case 263: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy328 = OP_TYPE_NMATCH; } + break; + case 264: /* in_op ::= IN */ +{ yymsp[0].minor.yy328 = OP_TYPE_IN; } + break; + case 265: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy328 = OP_TYPE_NOT_IN; } + break; + case 266: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy40)); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; + break; + case 268: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy364), NULL)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 254: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 269: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 259: /* from_clause ::= FROM table_reference_list */ - case 289: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==289); - case 312: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==312); -{ yymsp[-1].minor.yy378 = yymsp[0].minor.yy378; } + case 270: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy364); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); + } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 261: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy378 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy378, yymsp[0].minor.yy378, NULL); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 275: /* from_clause ::= FROM table_reference_list */ + case 305: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==305); + case 328: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==328); +{ yymsp[-1].minor.yy364 = yymsp[0].minor.yy364; } break; - case 264: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + case 277: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy364 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy364, yymsp[0].minor.yy364, NULL); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 265: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, &yymsp[-3].minor.yy183, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 280: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy364 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 266: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy378 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378), &yymsp[0].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + case 281: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy364 = createRealTableNode(pCxt, &yymsp[-3].minor.yy437, &yymsp[-1].minor.yy437, &yymsp[0].minor.yy437); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; - case 268: /* alias_opt ::= */ -{ yymsp[1].minor.yy183 = nil_token; } + case 282: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy364 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364), &yymsp[0].minor.yy437); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 269: /* alias_opt ::= table_alias */ -{ yylhsminor.yy183 = yymsp[0].minor.yy183; } - yymsp[0].minor.yy183 = yylhsminor.yy183; + case 284: /* alias_opt ::= */ +{ yymsp[1].minor.yy437 = nil_token; } break; - case 270: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy183 = yymsp[0].minor.yy183; } + case 285: /* alias_opt ::= table_alias */ +{ yylhsminor.yy437 = yymsp[0].minor.yy437; } + yymsp[0].minor.yy437 = yylhsminor.yy437; break; - case 271: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 272: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==272); -{ yymsp[-2].minor.yy378 = yymsp[-1].minor.yy378; } + case 286: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy437 = yymsp[0].minor.yy437; } break; - case 273: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy378 = createJoinTableNode(pCxt, yymsp[-4].minor.yy162, yymsp[-5].minor.yy378, yymsp[-2].minor.yy378, yymsp[0].minor.yy378); } - yymsp[-5].minor.yy378 = yylhsminor.yy378; + case 287: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 288: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==288); +{ yymsp[-2].minor.yy364 = yymsp[-1].minor.yy364; } break; - case 274: /* join_type ::= */ -{ yymsp[1].minor.yy162 = JOIN_TYPE_INNER; } + case 289: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy364 = createJoinTableNode(pCxt, yymsp[-4].minor.yy392, yymsp[-5].minor.yy364, yymsp[-2].minor.yy364, yymsp[0].minor.yy364); } + yymsp[-5].minor.yy364 = yylhsminor.yy364; break; - case 275: /* join_type ::= INNER */ -{ yymsp[0].minor.yy162 = JOIN_TYPE_INNER; } + case 290: /* join_type ::= */ +{ yymsp[1].minor.yy392 = JOIN_TYPE_INNER; } break; - case 276: /* 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 291: /* join_type ::= INNER */ +{ yymsp[0].minor.yy392 = JOIN_TYPE_INNER; } + break; + case 292: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy378 = createSelectStmt(pCxt, yymsp[-7].minor.yy215, yymsp[-6].minor.yy404, yymsp[-5].minor.yy378); - yymsp[-8].minor.yy378 = addWhereClause(pCxt, yymsp[-8].minor.yy378, yymsp[-4].minor.yy378); - yymsp[-8].minor.yy378 = addPartitionByClause(pCxt, yymsp[-8].minor.yy378, yymsp[-3].minor.yy404); - yymsp[-8].minor.yy378 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy378, yymsp[-2].minor.yy378); - yymsp[-8].minor.yy378 = addGroupByClause(pCxt, yymsp[-8].minor.yy378, yymsp[-1].minor.yy404); - yymsp[-8].minor.yy378 = addHavingClause(pCxt, yymsp[-8].minor.yy378, yymsp[0].minor.yy378); + yymsp[-8].minor.yy364 = createSelectStmt(pCxt, yymsp[-7].minor.yy493, yymsp[-6].minor.yy40, yymsp[-5].minor.yy364); + yymsp[-8].minor.yy364 = addWhereClause(pCxt, yymsp[-8].minor.yy364, yymsp[-4].minor.yy364); + yymsp[-8].minor.yy364 = addPartitionByClause(pCxt, yymsp[-8].minor.yy364, yymsp[-3].minor.yy40); + yymsp[-8].minor.yy364 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy364, yymsp[-2].minor.yy364); + yymsp[-8].minor.yy364 = addGroupByClause(pCxt, yymsp[-8].minor.yy364, yymsp[-1].minor.yy40); + yymsp[-8].minor.yy364 = addHavingClause(pCxt, yymsp[-8].minor.yy364, yymsp[0].minor.yy364); } break; - case 278: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy215 = true; } + case 295: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy493 = false; } break; - case 279: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy215 = false; } + case 296: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy40 = NULL; } break; - case 280: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy404 = NULL; } - break; - case 284: /* select_item ::= common_expression */ + case 300: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy364); + yylhsminor.yy364 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364), &t); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + yymsp[0].minor.yy364 = yylhsminor.yy364; break; - case 285: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378), &yymsp[0].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + case 301: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy364 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364), &yymsp[0].minor.yy437); } + yymsp[-1].minor.yy364 = yylhsminor.yy364; break; - case 286: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), &yymsp[0].minor.yy183); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 302: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy364 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), &yymsp[0].minor.yy437); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 287: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy378 = createColumnNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 303: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy364 = createColumnNode(pCxt, &yymsp[-2].minor.yy437, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 291: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 308: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==308); - case 318: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==318); -{ yymsp[-2].minor.yy404 = yymsp[0].minor.yy404; } + case 307: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 324: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==324); + case 334: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==334); +{ yymsp[-2].minor.yy40 = yymsp[0].minor.yy40; } break; - case 293: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy378 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } + case 309: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy364 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), releaseRawExprNode(pCxt, yymsp[-1].minor.yy364)); } break; - case 294: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy378 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } + case 310: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy364 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy364)); } break; - case 295: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy378 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), NULL, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } + case 311: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy364 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), NULL, yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } break; - case 296: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy378 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy378), releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } + case 312: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy364 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy364), releaseRawExprNode(pCxt, yymsp[-3].minor.yy364), yymsp[-1].minor.yy364, yymsp[0].minor.yy364); } break; - case 298: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy378 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy378); } + case 314: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy364 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy364); } break; - case 300: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy378 = createFillNode(pCxt, yymsp[-1].minor.yy466, NULL); } + case 316: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy364 = createFillNode(pCxt, yymsp[-1].minor.yy478, NULL); } break; - case 301: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy378 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } + case 317: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy364 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy40)); } break; - case 302: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy466 = FILL_MODE_NONE; } + case 318: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy478 = FILL_MODE_NONE; } break; - case 303: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy466 = FILL_MODE_PREV; } + case 319: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy478 = FILL_MODE_PREV; } break; - case 304: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy466 = FILL_MODE_NULL; } + case 320: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy478 = FILL_MODE_NULL; } break; - case 305: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy466 = FILL_MODE_LINEAR; } + case 321: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy478 = FILL_MODE_LINEAR; } break; - case 306: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy466 = FILL_MODE_NEXT; } + case 322: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy478 = FILL_MODE_NEXT; } break; - case 309: /* group_by_list ::= expression */ -{ yylhsminor.yy404 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 325: /* group_by_list ::= expression */ +{ yylhsminor.yy40 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } + yymsp[0].minor.yy40 = yylhsminor.yy40; break; - case 310: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy404 = yylhsminor.yy404; + case 326: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy364))); } + yymsp[-2].minor.yy40 = yylhsminor.yy40; break; - case 313: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 329: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy378 = addOrderByClause(pCxt, yymsp[-3].minor.yy378, yymsp[-2].minor.yy404); - yylhsminor.yy378 = addSlimitClause(pCxt, yylhsminor.yy378, yymsp[-1].minor.yy378); - yylhsminor.yy378 = addLimitClause(pCxt, yylhsminor.yy378, yymsp[0].minor.yy378); + yylhsminor.yy364 = addOrderByClause(pCxt, yymsp[-3].minor.yy364, yymsp[-2].minor.yy40); + yylhsminor.yy364 = addSlimitClause(pCxt, yylhsminor.yy364, yymsp[-1].minor.yy364); + yylhsminor.yy364 = addLimitClause(pCxt, yylhsminor.yy364, yymsp[0].minor.yy364); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; - case 315: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy378 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy378, yymsp[0].minor.yy378); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 331: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy364 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy364, yymsp[0].minor.yy364); } + yymsp[-3].minor.yy364 = yylhsminor.yy364; break; - case 320: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 324: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==324); -{ yymsp[-1].minor.yy378 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 336: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 340: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==340); +{ yymsp[-1].minor.yy364 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 321: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 325: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==325); -{ yymsp[-3].minor.yy378 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 337: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 341: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==341); +{ yymsp[-3].minor.yy364 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 322: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 326: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==326); -{ yymsp[-3].minor.yy378 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 338: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 342: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==342); +{ yymsp[-3].minor.yy364 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 327: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy378); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 343: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy364 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy364); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 331: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy378 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), yymsp[-1].minor.yy400, yymsp[0].minor.yy151); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 347: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy364 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy364), yymsp[-1].minor.yy210, yymsp[0].minor.yy177); } + yymsp[-2].minor.yy364 = yylhsminor.yy364; break; - case 332: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy400 = ORDER_ASC; } + case 348: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy210 = ORDER_ASC; } break; - case 333: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy400 = ORDER_ASC; } + case 349: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy210 = ORDER_ASC; } break; - case 334: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy400 = ORDER_DESC; } + case 350: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy210 = ORDER_DESC; } break; - case 335: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy151 = NULL_ORDER_DEFAULT; } + case 351: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy177 = NULL_ORDER_DEFAULT; } break; - case 336: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy151 = NULL_ORDER_FIRST; } + case 352: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy177 = NULL_ORDER_FIRST; } break; - case 337: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy151 = NULL_ORDER_LAST; } + case 353: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy177 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 3057e06fe1..6dc3b53ae3 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -206,6 +206,13 @@ TEST_F(ParserTest, selectExpression) { ASSERT_TRUE(run()); } +TEST_F(ParserTest, selectPseudoColumn) { + setDatabase("root", "test"); + + bind("SELECT _wstartts, _wendts, count(*) FROM t1 interval(10s)"); + ASSERT_TRUE(run()); +} + TEST_F(ParserTest, selectClause) { setDatabase("root", "test"); @@ -480,7 +487,10 @@ TEST_F(ParserTest, createTable) { bind("create table " "if not exists test.t1 using test.st1 (tag1, tag2) tags(1, 'abc') " "if not exists test.t2 using test.st1 (tag1, tag2) tags(2, 'abc') " - "if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc')" + "if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc') " + "if not exists test.t4 using test.st1 (tag1, tag2) tags(3, null) " + "if not exists test.t5 using test.st1 (tag1, tag2) tags(null, 'abc') " + "if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)" ); ASSERT_TRUE(run()); @@ -637,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 740fb678fd..7f6d8826e6 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -142,6 +142,46 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanCols, STab return SCAN_TYPE_TAG; } +static SNodeptr createPrimaryKeyCol(uint64_t tableId) { + SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN); + if (NULL == pCol) { + return NULL; + } + pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP; + pCol->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; + pCol->tableId = tableId; + pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID; + pCol->colType = COLUMN_TYPE_COLUMN; + strcpy(pCol->colName, "#primarykey"); + return pCol; +} + +static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) { + if (NULL == *pCols) { + *pCols = nodesMakeList(); + if (NULL == *pCols) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + bool found = false; + SNode* pCol = NULL; + FOREACH(pCol, *pCols) { + if (PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pCol)->colId) { + found = true; + break; + } + } + + if (!found) { + if (TSDB_CODE_SUCCESS != nodesListStrictAppend(*pCols, createPrimaryKeyCol(tableId))) { + nodesDestroyList(*pCols); + return TSDB_CODE_OUT_OF_MEMORY; + } + } + return TSDB_CODE_SUCCESS; +} + static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, SLogicNode** pLogicNode) { SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN); if (NULL == pScan) { @@ -157,11 +197,16 @@ 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; int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, &pCols); - if (TSDB_CODE_SUCCESS == code && NULL != pCols) { + if (TSDB_CODE_SUCCESS == code) { + code = addPrimaryKeyCol(pScan->pMeta->uid, &pCols); + } + + if (TSDB_CODE_SUCCESS == code) { pScan->pScanCols = nodesCloneList(pCols); if (NULL == pScan) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -171,13 +216,15 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect pScan->scanType = getScanType(pCxt, pCols, pScan->pMeta); // set output - if (TSDB_CODE_SUCCESS == code && NULL != pCols) { + if (TSDB_CODE_SUCCESS == code) { pScan->node.pTargets = nodesCloneList(pCols); if (NULL == pScan) { code = TSDB_CODE_OUT_OF_MEMORY; } } + nodesClearList(pCols); + if (TSDB_CODE_SUCCESS == code) { *pLogicNode = (SLogicNode*)pScan; } else { @@ -411,7 +458,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, } static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) { - int32_t code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pWindow->pFuncs); + int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs); if (TSDB_CODE_SUCCESS == code) { code = rewriteExpr(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW); @@ -548,6 +595,22 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel return TSDB_CODE_OUT_OF_MEMORY; } + if (NULL != pSelect->pLimit) { + pProject->limit = ((SLimitNode*)pSelect->pLimit)->limit; + pProject->offset = ((SLimitNode*)pSelect->pLimit)->offset; + } else { + pProject->limit = -1; + pProject->offset = -1; + } + + if (NULL != pSelect->pSlimit) { + pProject->slimit = ((SLimitNode*)pSelect->pSlimit)->limit; + pProject->soffset = ((SLimitNode*)pSelect->pSlimit)->offset; + } else { + pProject->slimit = -1; + pProject->soffset = -1; + } + int32_t code = TSDB_CODE_SUCCESS; pProject->pProjections = nodesCloneList(pSelect->pProjectionList); @@ -569,15 +632,42 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel return code; } +static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { + if (NULL == pSelect->pPartitionByList) { + return TSDB_CODE_SUCCESS; + } + + SPartitionLogicNode* pPartition = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PARTITION); + if (NULL == pPartition) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { + if (!pSelect->isDistinct) { + return TSDB_CODE_SUCCESS; + } + + return TSDB_CODE_SUCCESS; +} + static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { SLogicNode* pRoot = NULL; int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot); if (TSDB_CODE_SUCCESS == code) { code = createChildLogicNode(pCxt, pSelect, createWindowLogicNode, &pRoot); } + if (TSDB_CODE_SUCCESS == code) { + code = createChildLogicNode(pCxt, pSelect, createPartitionLogicNode, &pRoot); + } if (TSDB_CODE_SUCCESS == code) { code = createChildLogicNode(pCxt, pSelect, createAggLogicNode, &pRoot); } + if (TSDB_CODE_SUCCESS == code) { + code = createChildLogicNode(pCxt, pSelect, createDistinctLogicNode, &pRoot); + } if (TSDB_CODE_SUCCESS == code) { code = createChildLogicNode(pCxt, pSelect, createSortLogicNode, &pRoot); } @@ -603,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; @@ -615,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 c95845f8c7..9ef1c01cd1 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -36,10 +36,6 @@ typedef struct SPhysiPlanContext { } SPhysiPlanContext; static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) { - if (QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode)) { - return getSlotKey(((SOrderByExprNode*)pNode)->pExpr, pStmtName, pKey); - } - if (QUERY_NODE_COLUMN == nodeType(pNode)) { SColumnNode* pCol = (SColumnNode*)pNode; if (NULL != pStmtName) { @@ -135,7 +131,8 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD code = putSlotToHash(pDataBlockDesc->dataBlockId, slotId, pNode, pHash); } if (TSDB_CODE_SUCCESS == code) { - pDataBlockDesc->resultRowSize += ((SExprNode*)pNode)->resType.bytes; + pDataBlockDesc->totalRowSize += ((SExprNode*)pNode)->resType.bytes; + pDataBlockDesc->outputRowSize += ((SExprNode*)pNode)->resType.bytes; ++slotId; } else { break; @@ -184,15 +181,19 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, int16_t nextSlotId = taosHashGetSize(pHash), slotId = 0; SNode* pNode = NULL; FOREACH(pNode, pList) { + SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode; char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0}; - int32_t len = getSlotKey(pNode, pStmtName, name); + int32_t len = getSlotKey(pExpr, pStmtName, name); SSlotIndex* pIndex = taosHashGet(pHash, name, len); if (NULL == pIndex) { - code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, nextSlotId, output)); + code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pExpr, nextSlotId, output)); if (TSDB_CODE_SUCCESS == code) { code = putSlotToHashImpl(pDataBlockDesc->dataBlockId, nextSlotId, name, len, pHash); } - pDataBlockDesc->resultRowSize += ((SExprNode*)pNode)->resType.bytes; + pDataBlockDesc->totalRowSize += ((SExprNode*)pExpr)->resType.bytes; + if (output) { + pDataBlockDesc->outputRowSize += ((SExprNode*)pExpr)->resType.bytes; + } slotId = nextSlotId; ++nextSlotId; } else { @@ -314,20 +315,6 @@ static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pL return TSDB_CODE_SUCCESS; } -static SNodeptr createPrimaryKeyCol(SPhysiPlanContext* pCxt, uint64_t tableId) { - SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN); - if (NULL == pCol) { - return NULL; - } - pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP; - pCol->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; - pCol->tableId = tableId; - pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID; - pCol->colType = COLUMN_TYPE_COLUMN; - strcpy(pCol->colName, "#primarykey"); - return pCol; -} - static int32_t colIdCompare(const void* pLeft, const void* pRight) { SColumnNode* pLeftCol = *(SColumnNode**)pLeft; SColumnNode* pRightCol = *(SColumnNode**)pRight; @@ -356,35 +343,10 @@ static int32_t sortScanCols(SNodeList* pScanCols) { } static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhysiNode, SNodeList* pScanCols) { - if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(pScanPhysiNode) - || QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN == nodeType(pScanPhysiNode)) { - pScanPhysiNode->pScanCols = nodesMakeList(); - if (NULL == pScanPhysiNode->pScanCols) { - return TSDB_CODE_OUT_OF_MEMORY; - } - if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pScanPhysiNode->pScanCols, createPrimaryKeyCol(pCxt, pScanPhysiNode->uid))) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - SNode* pNode; - FOREACH(pNode, pScanCols) { - if (PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pNode)->colId) { - SColumnNode* pCol = nodesListGetNode(pScanPhysiNode->pScanCols, 0); - strcpy(pCol->tableAlias, ((SColumnNode*)pNode)->tableAlias); - strcpy(pCol->colName, ((SColumnNode*)pNode)->colName); - continue; - } - if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pScanPhysiNode->pScanCols, nodesCloneNode(pNode))) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - } else { - pScanPhysiNode->pScanCols = nodesCloneList(pScanCols); - if (NULL == pScanPhysiNode->pScanCols) { - return TSDB_CODE_OUT_OF_MEMORY; - } + pScanPhysiNode->pScanCols = nodesCloneList(pScanCols); + if (NULL == pScanPhysiNode->pScanCols) { + return TSDB_CODE_OUT_OF_MEMORY; } - return sortScanCols(pScanPhysiNode->pScanCols); } @@ -436,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; @@ -600,7 +563,7 @@ static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) { return collectAndRewrite(pContext, pNode); } case QUERY_NODE_FUNCTION: { - if (!fmIsAggFunc(((SFunctionNode*)(*pNode))->funcId)) { + if (fmIsScalarFunc(((SFunctionNode*)(*pNode))->funcId)) { return collectAndRewrite(pContext, pNode); } } @@ -711,6 +674,11 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild return TSDB_CODE_OUT_OF_MEMORY; } + pProject->limit = pProjectLogicNode->limit; + pProject->offset = pProjectLogicNode->offset; + pProject->slimit = pProjectLogicNode->slimit; + pProject->soffset = pProjectLogicNode->soffset; + int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, pProjectLogicNode->pProjections, &pProject->pProjections); if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, pProject->node.pOutputDataBlockDesc); @@ -813,6 +781,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) { @@ -1113,6 +1082,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, @@ -1124,5 +1117,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 ca6c7a2577..2b5fd12e22 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 df546c32be..3ce225abab 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 3d17cc260b..d19d88f455 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -192,6 +192,9 @@ TEST_F(PlannerTest, interval) { bind("SELECT count(*) FROM t1 interval(10s)"); ASSERT_TRUE(run()); + + bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); + ASSERT_TRUE(run()); } TEST_F(PlannerTest, sessionWindow) { @@ -204,7 +207,7 @@ TEST_F(PlannerTest, sessionWindow) { TEST_F(PlannerTest, orderBy) { setDatabase("root", "test"); - bind("SELECT * FROM t1 order by c1"); + bind("SELECT c1 FROM t1 order by c1"); ASSERT_TRUE(run()); bind("SELECT c1 FROM t1 order by c2"); @@ -214,11 +217,42 @@ TEST_F(PlannerTest, orderBy) { ASSERT_TRUE(run()); } +TEST_F(PlannerTest, limit) { + setDatabase("root", "test"); + + bind("SELECT * FROM t1 limit 2"); + ASSERT_TRUE(run()); + + bind("SELECT * FROM t1 limit 5 offset 2"); + ASSERT_TRUE(run()); + + bind("SELECT * FROM t1 limit 2, 5"); + ASSERT_TRUE(run()); +} + +TEST_F(PlannerTest, slimit) { + setDatabase("root", "test"); + + bind("SELECT * FROM t1 partition by c1 slimit 2"); + ASSERT_TRUE(run()); + + bind("SELECT * FROM t1 partition by c1 slimit 5 soffset 2"); + ASSERT_TRUE(run()); + + bind("SELECT * FROM t1 partition by c1 slimit 2, 5"); + ASSERT_TRUE(run()); +} + TEST_F(PlannerTest, showTables) { setDatabase("root", "test"); bind("show tables"); ASSERT_TRUE(run()); + + setDatabase("root", "information_schema"); + + bind("show tables"); + ASSERT_TRUE(run()); } TEST_F(PlannerTest, showStables) { @@ -248,3 +282,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/qworker/inc/qworkerMsg.h b/source/libs/qworker/inc/qworkerMsg.h index be1d47a189..313b9459e2 100644 --- a/source/libs/qworker/inc/qworkerMsg.h +++ b/source/libs/qworker/inc/qworkerMsg.h @@ -32,19 +32,18 @@ int32_t qwProcessHb(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req); int32_t qwBuildAndSendDropRsp(SQWConnInfo *pConn, int32_t code); int32_t qwBuildAndSendCancelRsp(SQWConnInfo *pConn, int32_t code); -int32_t qwBuildAndSendFetchRsp(SQWConnInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code); -void qwBuildFetchRsp(void *msg, SOutputData *input, int32_t len, bool qComplete); +int32_t qwBuildAndSendFetchRsp(SQWConnInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, + int32_t code); +void qwBuildFetchRsp(void *msg, SOutputData *input, int32_t len, bool qComplete); int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, SQWConnInfo *pConn); int32_t qwBuildAndSendReadyRsp(SQWConnInfo *pConn, int32_t code); int32_t qwBuildAndSendQueryRsp(SQWConnInfo *pConn, int32_t code); -void qwFreeFetchRsp(void *msg); +void qwFreeFetchRsp(void *msg); int32_t qwMallocFetchRsp(int32_t length, SRetrieveTableRsp **rsp); int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp); int32_t qwBuildAndSendHbRsp(SQWConnInfo *pConn, SSchedulerHbRsp *rsp, int32_t code); int32_t qwRegisterBrokenLinkArg(QW_FPARAMS_DEF, SQWConnInfo *pConn); - - #ifdef __cplusplus } #endif diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 71e7415ea5..42d10a2361 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -432,7 +432,7 @@ int32_t qwKillTaskHandle(QW_FPARAMS_DEF, SQWTaskCtx *ctx) { void qwFreeTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx) { - rpcReleaseHandle(ctx->connInfo.handle, TAOS_CONN_SERVER); + tmsgReleaseHandle(ctx->connInfo.handle, TAOS_CONN_SERVER); ctx->connInfo.handle = NULL; qwFreeTaskHandle(QW_FPARAMS(), &ctx->taskHandle); @@ -763,8 +763,8 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu dropConnection = &ctx->connInfo; QW_ERR_JRET(qwDropTask(QW_FPARAMS())); dropConnection = NULL; - - qwBuildAndSendDropRsp(&ctx->connInfo, code); + + qwBuildAndSendDropRsp(&ctx->connInfo, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", ctx->connInfo.handle, code, tstrerror(code)); QW_ERR_JRET(TSDB_CODE_QRY_TASK_DROPPED); @@ -804,7 +804,7 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu qwBuildAndSendDropRsp(&ctx->connInfo, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", ctx->connInfo.handle, code, tstrerror(code)); - + QW_ERR_JRET(TSDB_CODE_QRY_TASK_DROPPED); } @@ -830,12 +830,12 @@ _return: } if (dropConnection) { - qwBuildAndSendDropRsp(dropConnection, code); + qwBuildAndSendDropRsp(dropConnection, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", dropConnection->handle, code, tstrerror(code)); } if (cancelConnection) { - qwBuildAndSendCancelRsp(cancelConnection, code); + qwBuildAndSendCancelRsp(cancelConnection, code); QW_TASK_DLOG("cancel rsp send, handle:%p, code:%x - %s", cancelConnection->handle, code, tstrerror(code)); } @@ -886,9 +886,9 @@ int32_t qwHandlePostPhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inp QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } - qwBuildAndSendDropRsp(&ctx->connInfo, code); + qwBuildAndSendDropRsp(&ctx->connInfo, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", ctx->connInfo.handle, code, tstrerror(code)); - + QW_ERR_JRET(qwDropTask(QW_FPARAMS())); QW_ERR_JRET(TSDB_CODE_QRY_TASK_DROPPED); } @@ -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); @@ -986,7 +986,7 @@ _return: input.code = code; code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL); - + if (!queryRsped) { qwBuildAndSendQueryRsp(&qwMsg->connInfo, code); QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); @@ -1228,7 +1228,7 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) { } else if (ctx->phase > 0) { qwBuildAndSendDropRsp(&qwMsg->connInfo, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); - + QW_ERR_JRET(qwDropTask(QW_FPARAMS())); rsped = true; } else { @@ -1241,7 +1241,7 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) { QW_SET_EVENT_RECEIVED(ctx, QW_EVENT_DROP); } - + _return: if (code) { @@ -1282,7 +1282,7 @@ int32_t qwProcessHb(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) { QW_LOCK(QW_WRITE, &sch->hbConnLock); if (sch->hbConnInfo.handle) { - rpcReleaseHandle(sch->hbConnInfo.handle, TAOS_CONN_SERVER); + tmsgReleaseHandle(sch->hbConnInfo.handle, TAOS_CONN_SERVER); } memcpy(&sch->hbConnInfo, &qwMsg->connInfo, sizeof(qwMsg->connInfo)); @@ -1352,7 +1352,8 @@ _return: for (int32_t j = 0; j < i; ++j) { qwBuildAndSendHbRsp(&rspList[j].connInfo, &rspList[j].rsp, code); - QW_DLOG("hb rsp send, handle:%p, code:%x - %s, taskNum:%d", rspList[j].connInfo.handle, code, tstrerror(code), (rspList[j].rsp.taskStatus ? (int32_t)taosArrayGetSize(rspList[j].rsp.taskStatus) : 0)); + QW_DLOG("hb rsp send, handle:%p, code:%x - %s, taskNum:%d", rspList[j].connInfo.handle, code, tstrerror(code), + (rspList[j].rsp.taskStatus ? (int32_t)taosArrayGetSize(rspList[j].rsp.taskStatus) : 0)); tFreeSSchedulerHbRsp(&rspList[j].rsp); } diff --git a/source/libs/qworker/src/qworkerMsg.c b/source/libs/qworker/src/qworkerMsg.c index ff9527f7b9..80ae013653 100644 --- a/source/libs/qworker/src/qworkerMsg.c +++ b/source/libs/qworker/src/qworkerMsg.c @@ -62,7 +62,7 @@ int32_t qwBuildAndSendQueryRsp(SQWConnInfo *pConn, int32_t code) { .code = code, }; - rpcSendResponse(&rpcRsp); + tmsgSendRsp(&rpcRsp); return TSDB_CODE_SUCCESS; } @@ -80,7 +80,7 @@ int32_t qwBuildAndSendReadyRsp(SQWConnInfo *pConn, int32_t code) { .code = code, }; - rpcSendResponse(&rpcRsp); + tmsgSendRsp(&rpcRsp); return TSDB_CODE_SUCCESS; } @@ -99,7 +99,7 @@ int32_t qwBuildAndSendHbRsp(SQWConnInfo *pConn, SSchedulerHbRsp *pStatus, int32_ .code = code, }; - rpcSendResponse(&rpcRsp); + tmsgSendRsp(&rpcRsp); return TSDB_CODE_SUCCESS; } @@ -120,7 +120,7 @@ int32_t qwBuildAndSendFetchRsp(SQWConnInfo *pConn, SRetrieveTableRsp *pRsp, int3 .code = code, }; - rpcSendResponse(&rpcRsp); + tmsgSendRsp(&rpcRsp); return TSDB_CODE_SUCCESS; } @@ -138,7 +138,7 @@ int32_t qwBuildAndSendCancelRsp(SQWConnInfo *pConn, int32_t code) { .code = code, }; - rpcSendResponse(&rpcRsp); + tmsgSendRsp(&rpcRsp); return TSDB_CODE_SUCCESS; } @@ -155,7 +155,7 @@ int32_t qwBuildAndSendDropRsp(SQWConnInfo *pConn, int32_t code) { .code = code, }; - rpcSendResponse(&rpcRsp); + tmsgSendRsp(&rpcRsp); return TSDB_CODE_SUCCESS; } @@ -210,7 +210,7 @@ int32_t qwBuildAndSendShowRsp(SRpcMsg *pMsg, int32_t code) { .code = code, }; - rpcSendResponse(&rpcMsg); + tmsgSendRsp(&rpcMsg); return TSDB_CODE_SUCCESS; } @@ -227,7 +227,7 @@ int32_t qwBuildAndSendShowFetchRsp(SRpcMsg *pMsg, SVShowTablesFetchReq* pFetchRe .code = 0, }; - rpcSendResponse(&rpcMsg); + tmsgSendRsp(&rpcMsg); return TSDB_CODE_SUCCESS; } @@ -287,7 +287,7 @@ int32_t qwRegisterBrokenLinkArg(QW_FPARAMS_DEF, SQWConnInfo *pConn) { .code = TSDB_CODE_RPC_NETWORK_UNAVAIL, }; - rpcRegisterBrokenLinkArg(&pMsg); + tmsgRegisterBrokenLinkArg(&mgmt->msgCb, &pMsg); return TSDB_CODE_SUCCESS; } @@ -579,7 +579,6 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { return TSDB_CODE_SUCCESS; } - int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; @@ -598,5 +597,3 @@ int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) SVShowTablesFetchReq *pFetchReq = pMsg->pCont; QW_RET(qwBuildAndSendShowFetchRsp(pMsg, pFetchReq)); } - - diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 7b2cb9ca67..1cc259d4da 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -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 feada84685..d8e97e7e12 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1,14 +1,9 @@ -#include "sclfunc.h" -#include +#include "function.h" +#include "scalar.h" +#include "tdatablock.h" #include "sclInt.h" #include "sclvector.h" -static void assignBasicParaInfo(struct SScalarParam* dst, const struct SScalarParam* src) { -// dst->type = src->type; -// dst->bytes = src->bytes; -// dst->num = src->num; -} - /** Math functions **/ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { SColumnInfoData *pInputData = pInput->columnData; @@ -107,94 +102,13 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu return TSDB_CODE_SUCCESS; } -int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { -#if 0 - if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) { - return TSDB_CODE_FAILED; - } - - char **input = NULL, *output = NULL; - bool hasNullInput = false; - input = taosMemoryCalloc(inputNum, sizeof(char *)); - for (int32_t i = 0; i < pOutput->num; ++i) { - for (int32_t j = 0; j < inputNum; ++j) { - if (pInput[j].num == 1) { - input[j] = pInput[j].data; - } else { - input[j] = pInput[j].data + i * pInput[j].bytes; - } - if (isNull(input[j], pInput[j].type)) { - hasNullInput = true; - break; - } - } - output = pOutput->data + i * pOutput->bytes; - - if (hasNullInput) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double base; - GET_TYPED_DATA(base, double, pInput[1].type, input[1]); - double v; - GET_TYPED_DATA(v, double, pInput[0].type, input[0]); - double result = log(v) / log(base); - SET_TYPED_DATA(output, pOutput->type, result); - } - - taosMemoryFree(input); -#endif - - return TSDB_CODE_SUCCESS; -} - -int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { -#if 0 - if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) { - return TSDB_CODE_FAILED; - } - - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - char **input = NULL, *output = NULL; - bool hasNullInput = false; - input = taosMemoryCalloc(inputNum, sizeof(char *)); - for (int32_t i = 0; i < pOutput->num; ++i) { - for (int32_t j = 0; j < inputNum; ++j) { - if (pInput[j].num == 1) { - input[j] = pInput[j].data; - } else { - input[j] = pInput[j].data + i * pInput[j].bytes; - } - if (isNull(input[j], pInput[j].type)) { - hasNullInput = true; - break; - } - } - output = pOutput->data + i * pOutput->bytes; - - if (hasNullInput) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double base; - GET_TYPED_DATA(base, double, pInput[1].type, input[1]); - double v; - GET_TYPED_DATA(v, double, pInput[0].type, input[0]); - double result = pow(v, base); - SET_TYPED_DATA(output, pOutput->type, result); - } - - taosMemoryFree(input); -#endif - return TSDB_CODE_SUCCESS; -} - typedef float (*_float_fn)(float); typedef double (*_double_fn)(double); +typedef double (*_double_fn_2)(double, double); + +double tlog(double v, double base) { + return log(v) / log(base); +} int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn valFn) { int32_t type = GET_PARAM_TYPE(pInput); @@ -221,6 +135,35 @@ int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarPa return TSDB_CODE_SUCCESS; } +int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn_2 valFn) { + if (inputNum != 2 || !IS_NUMERIC_TYPE(GET_PARAM_TYPE(&pInput[0])) || !IS_NUMERIC_TYPE(GET_PARAM_TYPE(&pInput[1]))) { + return TSDB_CODE_FAILED; + } + + SColumnInfoData *pInputData[2]; + SColumnInfoData *pOutputData = pOutput->columnData; + _getDoubleValue_fn_t getValueFn[2]; + + for (int32_t i = 0; i < inputNum; ++i) { + pInputData[i] = pInput[i].columnData; + getValueFn[i]= getVectorDoubleValueFn(GET_PARAM_TYPE(&pInput[i])); + } + + double *out = (double *)pOutputData->pData; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData[0]->nullbitmap, i) || + colDataIsNull_f(pInputData[1]->nullbitmap, 0)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, 0)); + } + + pOutput->numOfRows = pInput->numOfRows; + return TSDB_CODE_SUCCESS; +} + int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _float_fn f1, _double_fn d1) { int32_t type = GET_PARAM_TYPE(pInput); if (inputNum != 1 || !IS_NUMERIC_TYPE(type)) { @@ -292,6 +235,14 @@ int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp return doScalarFunctionUnique(pInput, inputNum, pOutput, acos); } +int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doScalarFunctionUnique2(pInput, inputNum, pOutput, pow); +} + +int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doScalarFunctionUnique2(pInput, inputNum, pOutput, tlog); +} + int32_t sqrtFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { return doScalarFunctionUnique(pInput, inputNum, pOutput, sqrt); } @@ -426,3 +377,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; +} \ No newline at end of file diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index b3211babf1..153222516c 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -2833,11 +2833,11 @@ TEST(ScalarFunctionTest, logFunction_column) { int32_t rowNum = 3; int32_t type; int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {2.0, 4.0, 3.0}; + double result[] = {2.0, 3.0, 4.0}; pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); //TINYINT - int8_t val_tinyint[2][3] = {{25, 81, 64}, {5, 3, 4}}; + int8_t val_tinyint[2][3] = {{9, 27, 81}, {3, 3, 3}}; type = TSDB_DATA_TYPE_TINYINT; for (int32_t i = 0; i < 2; ++i) { scltMakeDataBlock(&input[i], type, 0, rowNum, false); @@ -2863,7 +2863,7 @@ TEST(ScalarFunctionTest, logFunction_column) { scltDestroyDataBlock(pOutput); //FLOAT - float val_float[2][3] = {{25.0, 81.0, 64.0}, {5.0, 3.0, 4.0}}; + float val_float[2][3] = {{9.0, 27.0, 81.0}, {3.0, 3.0, 3.0}}; type = TSDB_DATA_TYPE_FLOAT; for (int32_t i = 0; i < 2; ++i) { scltMakeDataBlock(&input[i], type, 0, rowNum, false); @@ -2888,8 +2888,8 @@ TEST(ScalarFunctionTest, logFunction_column) { scltDestroyDataBlock(pOutput); //TINYINT AND FLOAT - int8_t param0[] = {25, 81, 64}; - float param1[] = {5.0, 3.0, 4.0}; + int8_t param0[] = {9, 27, 81}; + float param1[] = {3.0, 3.0, 3.0}; scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); pInput[0] = *input[0]; for (int32_t i = 0; i < rowNum; ++i) { @@ -3003,17 +3003,17 @@ TEST(ScalarFunctionTest, powFunction_column) { int32_t rowNum = 3; int32_t type; int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {32.0, 27.0, 16.0}; + double result[] = {8.0, 27.0, 64.0}; pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); //TINYINT - int8_t val_tinyint[2][3] = {{2, 3, 4}, {5, 3, 2}}; + int8_t val_tinyint[2][3] = {{2, 3, 4}, {3, 3, 3}}; type = TSDB_DATA_TYPE_TINYINT; for (int32_t i = 0; i < 2; ++i) { scltMakeDataBlock(&input[i], type, 0, rowNum, false); pInput[i] = *input[i]; for (int32_t j = 0; j < rowNum; ++j) { - colDataAppend(pInput[i].columnData, i, (const char*) &val_tinyint[i][j], false); + colDataAppend(pInput[i].columnData, j, (const char*) &val_tinyint[i][j], false); } PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), @@ -3034,7 +3034,7 @@ TEST(ScalarFunctionTest, powFunction_column) { scltDestroyDataBlock(pOutput); //FLOAT - float val_float[2][3] = {{2.0, 3.0, 4.0}, {5.0, 3.0, 2.0}}; + float val_float[2][3] = {{2.0, 3.0, 4.0}, {3.0, 3.0, 3.0}}; type = TSDB_DATA_TYPE_FLOAT; for (int32_t i = 0; i < 2; ++i) { scltMakeDataBlock(&input[i], type, 0, rowNum, false); @@ -3060,7 +3060,7 @@ TEST(ScalarFunctionTest, powFunction_column) { //TINYINT AND FLOAT int8_t param0[] = {2, 3, 4}; - float param1[] = {5.0, 3.0, 2.0}; + float param1[] = {3.0, 3.0, 2.0}; scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); pInput[0] = *input[0]; for (int32_t i = 0; i < rowNum; ++i) { diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 220f83bb3e..fb6c0f6c12 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -31,12 +31,13 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { ((SMsgHead*)buf)->vgId = 0; req.taskId = pTask->inplaceDispatcher.taskId; + } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { ((SMsgHead*)buf)->vgId = htonl(pTask->fixedEpDispatcher.nodeId); *ppEpSet = &pTask->fixedEpDispatcher.epSet; req.taskId = pTask->fixedEpDispatcher.taskId; + } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - int32_t nodeId = 0; // TODO fix tbname issue char ctbName[TSDB_TABLE_FNAME_LEN + 22]; // all groupId must be the same in an array @@ -52,10 +53,12 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* // TODO: optimize search process SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; int32_t sz = taosArrayGetSize(vgInfo); + int32_t nodeId = 0; for (int32_t i = 0; i < sz; i++) { SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); if (hashValue >= pVgInfo->hashBegin && hashValue <= pVgInfo->hashEnd) { nodeId = pVgInfo->vgId; + req.taskId = pVgInfo->taskId; *ppEpSet = &pVgInfo->epSet; break; } @@ -71,6 +74,7 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* pMsg->contLen = tlen; pMsg->code = 0; pMsg->msgType = pTask->dispatchMsgType; + pMsg->noResp = 1; return 0; } @@ -80,7 +84,7 @@ static int32_t streamShuffleDispatch(SStreamTask* pTask, SMsgCb* pMsgCb, SHashOb while (1) { pIter = taosHashIterate(data, pIter); if (pIter == NULL) return 0; - SArray* pData = (SArray*)pIter; + SArray* pData = *(SArray**)pIter; SRpcMsg dispatchMsg = {0}; SEpSet* pEpSet; if (streamBuildDispatchMsg(pTask, pData, &dispatchMsg, &pEpSet) < 0) { @@ -98,7 +102,6 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK && pTask->sourceType != TASK_SOURCE__SCAN) return 0; // exec - // TODO: for shuffle dispatcher, merge data by groupId if (pTask->execType != TASK_EXEC__NONE) { ASSERT(workId < pTask->exec.numOfRunners); void* exec = pTask->exec.runners[workId].executor; @@ -121,22 +124,23 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in } } else if (inputType == STREAM_DATA_TYPE_SSDATA_BLOCK) { const SArray* blocks = (const SArray*)input; - int32_t sz = taosArrayGetSize(blocks); - for (int32_t i = 0; i < sz; i++) { - SSDataBlock* pBlock = taosArrayGet(blocks, i); - qSetStreamInput(exec, pBlock, inputType); - while (1) { - SSDataBlock* output; - uint64_t ts; - if (qExecTask(exec, &output, &ts) < 0) { - ASSERT(false); - } - if (output == NULL) { - break; - } - taosArrayPush(pRes, output); + /*int32_t sz = taosArrayGetSize(blocks);*/ + /*for (int32_t i = 0; i < sz; i++) {*/ + /*SSDataBlock* pBlock = taosArrayGet(blocks, i);*/ + /*qSetStreamInput(exec, pBlock, inputType);*/ + qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_DATA_TYPE_SSDATA_BLOCK); + while (1) { + SSDataBlock* output; + uint64_t ts; + if (qExecTask(exec, &output, &ts) < 0) { + ASSERT(false); } + if (output == NULL) { + break; + } + taosArrayPush(pRes, output); } + /*}*/ } else { ASSERT(0); } diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index 0b1378dc5a..3a62b19c10 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 faced8e839..b133e1fcbc 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -30,7 +30,6 @@ struct SBTree { int valLen; SPager *pPager; FKeyComparator kcmpr; - u8 fanout; int pageSize; int maxLocal; int minLocal; @@ -85,6 +84,8 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S SBTree *pBt; int ret; + ASSERT(keyLen != 0); + *ppBt = NULL; pBt = (SBTree *)tdbOsCalloc(1, sizeof(*pBt)); @@ -100,21 +101,14 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S 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->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; @@ -226,6 +220,43 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen return 0; } +int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen) { + SBTC btc; + SCell *pCell; + int cret; + void *pTKey; + void *pTVal; + SCellDecoder cd; + + tdbBtcOpen(&btc, pBt); + + tdbBtCursorMoveTo(&btc, pKey, kLen, &cret); + if (cret) { + return cret; + } + + pCell = tdbPageGetCell(btc.pPage, btc.idx); + tdbBtreeDecodeCell(btc.pPage, pCell, &cd); + + pTKey = TDB_REALLOC(*ppKey, cd.kLen); + pTVal = TDB_REALLOC(*ppVal, cd.vLen); + + if (pTKey == NULL || pTVal == NULL) { + TDB_FREE(pTKey); + TDB_FREE(pTVal); + } + + *ppKey = pTKey; + *ppVal = pTVal; + *pkLen = cd.kLen; + *vLen = cd.vLen; + + memcpy(*ppKey, cd.pKey, cd.kLen); + memcpy(*ppVal, cd.pVal, cd.vLen); + + return 0; +} + static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { int ret; SBTree *pBt; @@ -929,7 +960,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo } // 2. Encode payload part - if (leaf) { + if (leaf && vLen > 0) { ret = tdbBtreeEncodePayload(pPage, pCell + nHeader, pKey, kLen, pVal, vLen, &nPayload); } else { ret = tdbBtreeEncodePayload(pPage, pCell + nHeader, pKey, kLen, NULL, 0, &nPayload); @@ -968,6 +999,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder return 0; } +// TODO: here has problem static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder) { u8 flags; u8 leaf; diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 68adb7ccfc..e41e41f72a 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -96,6 +96,10 @@ 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 +133,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/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 981dd63593..07c267a15c 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -122,7 +122,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); 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 3301202a33..cc4ce20802 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/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h index e46e8bb78b..0e8ca0c803 100644 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ b/source/libs/tdb/src/inc/tdbBtree.h @@ -43,6 +43,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SB int tdbBtreeClose(SBTree *pBt); int tdbBtCursorInsert(SBTC *pCur, 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); diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index 4fbf65829d..e60371c734 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/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 49aa9f4398..563fb53e98 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -111,6 +111,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/tdbTxn.h b/source/libs/tdb/src/inc/tdbTxn.h index 4300dc8324..cc11369785 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; diff --git a/source/libs/tdb/src/page/tdbPageL.c b/source/libs/tdb/src/page/tdbPageL.c deleted file mode 100644 index c5d4a6047f..0000000000 --- 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/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index c137657a99..dfb5eb35d6 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -214,9 +214,11 @@ static void uvHandleReq(SSrvConn* pConn) { // no ref here } - if (pHead->noResp == 0) { - transMsg.handle = pConn; - } + // if pHead->noResp = 1, + // 1. server application should not send resp on handle + // 2. once send out data, cli conn released to conn pool immediately + // 3. not mixed with persist + transMsg.handle = pConn; STrans* pTransInst = pConn->pTransInst; (*pTransInst->cfp)(pTransInst->parent, &transMsg, NULL); diff --git a/source/os/src/osShm.c b/source/os/src/osShm.c new file mode 100644 index 0000000000..e7a22c3da1 --- /dev/null +++ b/source/os/src/osShm.c @@ -0,0 +1,71 @@ +/* + * 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) { + int32_t shmid = shmget(IPC_PRIVATE, 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 = 0; + pShm->size = 0; + pShm->ptr = NULL; +} + +int32_t taosAttachShm(SShm* pShm) { + if (pShm->id > 0 && pShm->size > 0) { + pShm->ptr = shmat(pShm->id, NULL, 0); + if (pShm->ptr != NULL) { + return 0; + } + } + + return -1; +} + +void taosDetachShm(SShm* pShm) { + if (pShm->id > 0) { + if (pShm->ptr != NULL) { + shmdt(pShm->ptr); + pShm->ptr = NULL; + } + } + + pShm->id = 0; + pShm->size = 0; + pShm->ptr = NULL; +} diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index d06aab6fda..86cec2d271 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -19,12 +19,7 @@ #include "tlog.h" #include "tqueue.h" -// todo -#include -#include - #define SHM_DEFAULT_SIZE (20 * 1024 * 1024) -#define CEIL8(n) (ceil((float)(n) / 8) * 8) typedef void *(*ProcThreadFp)(void *param); typedef struct SProcQueue { @@ -58,6 +53,11 @@ typedef struct SProcObj { bool stopFlag; } SProcObj; +static inline int32_t CEIL8(int32_t v) { + const int32_t c = ceil((float)(v) / 8) * 8; + return c < 8 ? 8 : c; +} + static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { TdThreadMutex *pMutex = NULL; TdThreadMutexAttr mattr = {0}; @@ -203,16 +203,12 @@ static void taosProcCleanupQueue(SProcQueue *pQueue) { } } -static int32_t taosProcQueuePush(SProcQueue *pQueue, char *pHead, int32_t rawHeadLen, char *pBody, int32_t rawBodyLen) { +static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, const char *pBody, + int32_t rawBodyLen, ProcFuncType ftype) { const int32_t headLen = CEIL8(rawHeadLen); const int32_t bodyLen = CEIL8(rawBodyLen); const int32_t fullLen = headLen + bodyLen + 8; - if (headLen <= 0 || bodyLen <= 0) { - terrno = TSDB_CODE_INVALID_PARA; - return -1; - } - taosThreadMutexLock(pQueue->mutex); if (fullLen > pQueue->avail) { taosThreadMutexUnlock(pQueue->mutex); @@ -220,11 +216,14 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, char *pHead, int32_t rawHea return -1; } + const int32_t pos = pQueue->tail; if (pQueue->tail < pQueue->total) { - *(int32_t *)(pQueue->pBuffer + pQueue->head) = headLen; - *(int32_t *)(pQueue->pBuffer + pQueue->head + 4) = bodyLen; + *(int16_t *)(pQueue->pBuffer + pQueue->tail) = headLen; + *(int8_t *)(pQueue->pBuffer + pQueue->tail + 2) = (int8_t)ftype; + *(int32_t *)(pQueue->pBuffer + pQueue->tail + 4) = bodyLen; } else { - *(int32_t *)(pQueue->pBuffer) = headLen; + *(int16_t *)(pQueue->pBuffer) = headLen; + *(int8_t *)(pQueue->pBuffer + 2) = (int8_t)ftype; *(int32_t *)(pQueue->pBuffer + 4) = bodyLen; } @@ -243,19 +242,19 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, char *pHead, int32_t rawHea memcpy(pQueue->pBuffer + headLen, pBody, rawBodyLen); pQueue->tail = headLen + bodyLen; } else if (remain < 8 + headLen) { - memcpy(pQueue->pBuffer + pQueue->head + 8, pHead, remain - 8); + memcpy(pQueue->pBuffer + pQueue->tail + 8, pHead, remain - 8); memcpy(pQueue->pBuffer, pHead + remain - 8, rawHeadLen - (remain - 8)); memcpy(pQueue->pBuffer + headLen - (remain - 8), pBody, rawBodyLen); pQueue->tail = headLen - (remain - 8) + bodyLen; - } else if (remain < 8 + bodyLen) { - memcpy(pQueue->pBuffer + pQueue->head + 8, pHead, rawHeadLen); - memcpy(pQueue->pBuffer + pQueue->head + 8 + headLen, pBody, remain - 8 - headLen); + } else if (remain < 8 + headLen + bodyLen) { + memcpy(pQueue->pBuffer + pQueue->tail + 8, pHead, rawHeadLen); + memcpy(pQueue->pBuffer + pQueue->tail + 8 + headLen, pBody, remain - 8 - headLen); memcpy(pQueue->pBuffer, pBody + remain - 8 - headLen, rawBodyLen - (remain - 8 - headLen)); pQueue->tail = bodyLen - (remain - 8 - headLen); } else { - memcpy(pQueue->pBuffer + pQueue->head + 8, pHead, rawHeadLen); - memcpy(pQueue->pBuffer + pQueue->head + headLen + 8, pBody, rawBodyLen); - pQueue->tail = pQueue->head + headLen + bodyLen + 8; + memcpy(pQueue->pBuffer + pQueue->tail + 8, pHead, rawHeadLen); + memcpy(pQueue->pBuffer + pQueue->tail + headLen + 8, pBody, rawBodyLen); + pQueue->tail = pQueue->tail + headLen + bodyLen + 8; } } @@ -264,13 +263,13 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, char *pHead, int32_t rawHea taosThreadMutexUnlock(pQueue->mutex); tsem_post(&pQueue->sem); - uTrace("proc:%s, push msg to queue:%p remains:%d, head:%d:%p body:%d:%p", pQueue->name, pQueue, pQueue->items, - headLen, pHead, bodyLen, pBody); + uTrace("proc:%s, push msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype, + pQueue->items, headLen, pHead, bodyLen, pBody); return 0; } -static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHeadLen, void **ppBody, - int32_t *pBodyLen) { +static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, + int32_t *pBodyLen, ProcFuncType *pFuncType) { tsem_wait(&pQueue->sem); taosThreadMutexLock(pQueue->mutex); @@ -281,13 +280,16 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea return 0; } - int32_t headLen = 0; + int16_t headLen = 0; + int8_t ftype = 0; int32_t bodyLen = 0; if (pQueue->head < pQueue->total) { - headLen = *(int32_t *)(pQueue->pBuffer + pQueue->head); + headLen = *(int16_t *)(pQueue->pBuffer + pQueue->head); + ftype = *(int8_t *)(pQueue->pBuffer + pQueue->head + 2); bodyLen = *(int32_t *)(pQueue->pBuffer + pQueue->head + 4); } else { - headLen = *(int32_t *)(pQueue->pBuffer); + headLen = *(int16_t *)(pQueue->pBuffer); + ftype = *(int8_t *)(pQueue->pBuffer + 2); bodyLen = *(int32_t *)(pQueue->pBuffer + 4); } @@ -302,6 +304,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea return -1; } + const int32_t pos = pQueue->head; if (pQueue->head < pQueue->tail) { memcpy(pHead, pQueue->pBuffer + pQueue->head + 8, headLen); memcpy(pBody, pQueue->pBuffer + pQueue->head + 8 + headLen, bodyLen); @@ -321,7 +324,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea memcpy(pHead + remain - 8, pQueue->pBuffer, headLen - (remain - 8)); memcpy(pBody, pQueue->pBuffer + headLen - (remain - 8), bodyLen); pQueue->head = headLen - (remain - 8) + bodyLen; - } else if (remain < 8 + bodyLen) { + } else if (remain < 8 + headLen + bodyLen) { memcpy(pHead, pQueue->pBuffer + pQueue->head + 8, headLen); memcpy(pBody, pQueue->pBuffer + pQueue->head + 8 + headLen, remain - 8 - headLen); memcpy(pBody + remain - 8 - headLen, pQueue->pBuffer, bodyLen - (remain - 8 - headLen)); @@ -341,9 +344,10 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea *ppBody = pBody; *pHeadLen = headLen; *pBodyLen = bodyLen; + *pFuncType = (ProcFuncType)ftype; - uTrace("proc:%s, pop msg from queue:%p remains:%d, head:%d:%p body:%d:%p", pQueue->name, pQueue, pQueue->items, - headLen, pHead, bodyLen, pBody); + uTrace("proc:%s, pop msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype, + pQueue->items, headLen, pHead, bodyLen, pBody); return 1; } @@ -396,12 +400,14 @@ static void taosProcThreadLoop(SProcQueue *pQueue) { ProcConsumeFp consumeFp = pQueue->consumeFp; void *pParent = pQueue->pParent; void *pHead, *pBody; - int32_t headLen, bodyLen; + int16_t headLen; + ProcFuncType ftype; + int32_t bodyLen; uDebug("proc:%s, start to get msg from queue:%p", pQueue->name, pQueue); while (1) { - int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen); + int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype); if (numOfMsgs == 0) { uDebug("proc:%s, get no msg from queue:%p and exit the proc thread", pQueue->name, pQueue); break; @@ -410,7 +416,7 @@ static void taosProcThreadLoop(SProcQueue *pQueue) { taosMsleep(1); continue; } else { - (*consumeFp)(pParent, pHead, headLen, pBody, bodyLen); + (*consumeFp)(pParent, pHead, headLen, pBody, bodyLen, ftype); } } } @@ -458,10 +464,12 @@ void taosProcCleanup(SProcObj *pProc) { } } -int32_t taosProcPutToChildQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen) { - return taosProcQueuePush(pProc->pChildQueue, pHead, headLen, pBody, bodyLen); +int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, + ProcFuncType ftype) { + return taosProcQueuePush(pProc->pChildQueue, pHead, headLen, pBody, bodyLen, ftype); } -int32_t taosProcPutToParentQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen) { - return taosProcQueuePush(pProc->pParentQueue, pHead, headLen, pBody, bodyLen); +int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, + ProcFuncType ftype) { + return taosProcQueuePush(pProc->pParentQueue, pHead, headLen, pBody, bodyLen, ftype); } diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 1b79851c4d..2cad518128 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -21,6 +21,10 @@ ./test.sh -f tsim/insert/backquote.sim ./test.sh -f tsim/insert/null.sim +# ---- parser +#./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 @@ -33,5 +37,6 @@ # ---- tmq ./test.sh -f tsim/tmq/basic.sim +./test.sh -f tsim/tmq/basic1.sim #======================b1-end=============== diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index ea1ad65a5b..1bbfccf989 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 8d7dba2de2..1a9a6a2c52 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 dd6382992a..68c049cad7 100755 --- a/tests/script/sh/massiveTable/compileVersion.sh +++ b/tests/script/sh/massiveTable/compileVersion.sh @@ -68,17 +68,19 @@ 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 rm -f /usr/bin/taosd rm -f /usr/bin/create_table rm -f /usr/bin/tmq_demo +rm -f /usr/bin/tmq_sim ln -s $taos_dir/taos /usr/bin/taos ln -s $taosd_dir/taosd /usr/bin/taosd ln -s $exec_process_dir/create_table /usr/bin/create_table ln -s $exec_process_dir/tmq_demo /usr/bin/tmq_demo +ln -s $exec_process_dir/tmq_sim /usr/bin/tmq_sim diff --git a/tests/script/tsim/insert/basic1.sim b/tests/script/tsim/insert/basic1.sim index 653a44a18a..3a3f8d000e 100644 --- a/tests/script/tsim/insert/basic1.sim +++ b/tests/script/tsim/insert/basic1.sim @@ -41,7 +41,7 @@ print =============== insert data, mode1: one row one table in sql print =============== insert data, mode1: mulit rows one table in sql print =============== insert data, mode1: one rows mulit table in sql print =============== insert data, mode1: mulit rows mulit table in sql -sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c1 values(now-1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+2s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) print =============== query data diff --git a/tests/script/tsim/parser/fourArithmetic-basic.sim b/tests/script/tsim/parser/fourArithmetic-basic.sim new file mode 100644 index 0000000000..2ade01522e --- /dev/null +++ b/tests/script/tsim/parser/fourArithmetic-basic.sim @@ -0,0 +1,110 @@ +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 + +$dbNamme = d0 +print =============== create database +sql create database $dbNamme vgroups 1 +sql show databases +print $data00 $data01 $data02 +if $rows != 2 then + return -1 +endi + +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +sql create table ct0 using stb tags(1000) +#sql create table ct1 using stb tags(2000) +#sql create table ct3 using stb tags(3000) + +sql show tables +if $rows != 1 then + return -1 +endi + +print =============== insert data + +$tbPrefix = ct +$tbNum = 1 +$rowNum = 10 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $c2 = $x + 10 + $c3 = $x * 10 + $c4 = $x - 10 + + sql insert into $tb values ($tstart , $x , $c2 , $c3 , $c4 ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + $i = $i + 1 + $tstart = 1640966400000 +endw + +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 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 +print ===> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 10 then + return -1 +endi + +if $data01 != 10.000000000 then + return -1 +endi +if $data02 != -nan then + return -1 +endi +if $data03 != -10.000000000 then + return -1 +endi + +if $data91 != 10.000000000 then + return -1 +endi +if $data92 != 10.000000000 then + return -1 +endi +if $data93 != 8.000000000 then + return -1 +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 new file mode 100644 index 0000000000..c0cbfa8aeb --- /dev/null +++ b/tests/script/tsim/parser/groupby-basic.sim @@ -0,0 +1,786 @@ +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 + +$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 + +$dbPrefix = group_db +$tbPrefix = group_tb +$mtPrefix = group_mt +$tbNum = 8 +$rowNum = 100 +$totalNum = $tbNum * $rowNum + +print =============== groupby.sim +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +$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 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)) + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + $tg2 = ' . abc + $tg2 = $tg2 . ' + + sql create table $tb using $mt tags( $i , $tg2 ) + + $x = 0 + while $x < $rowNum + $c = $x / 10 + $c = $c * 10 + $c = $x - $c + + $binary = ' . binary + $binary = $binary . $c + $binary = $binary . ' + + $nchar = ' . nchar + $nchar = $nchar . $c + $nchar = $nchar . ' + + sql insert into $tb values ($tstart , $c , $c , $x , $x , $c , $c , $c , $binary , $nchar ) + #print ==== insert into $tb values ($tstart , $c , $c , $x , $x , $c , $c , $c , $binary , $nchar ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + $i = $i + 1 + $tstart = 1640966400000 +endw + +sleep 100 + +$i1 = 1 +$i2 = 0 + +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +$dbPrefix = group_db +$tbPrefix = group_tb +$mtPrefix = group_mt + +$tb1 = $tbPrefix . $i1 +$tb2 = $tbPrefix . $i2 +$ts1 = $tb1 . .ts +$ts2 = $tb2 . .ts + +print ===============================groupby_operation +print +print ==== select count(*), c1 from group_tb0 group by c1 +sql select count(*), 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 +if $rows != 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 $data11 != 1 then + return -1 +endi +#if $data90 != 10 then +# return -1 +#endi +if $data91 != 9 then + return -1 +endi + +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 +if $row != 10 then + return -1 +endi + +if $data00 != @2022-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 + return -1 +endi +if $data91 != 9 then + return -1 +endi + + +sql select sum(c1), c1, avg(c1), min(c1), max(c2) from group_tb0 where c1 < 20 group by c1; +if $row != 20 then + return -1 +endi + +if $data00 != 0 then + return -1 +endi + +if $data01 != 0 then + return -1 +endi + +print $data02 +if $data02 != 0.000000000 then + return -1 +endi + +if $data03 != 0 then + return -1 +endi + +print $data04 +if $data04 != 0.00000 then + return -1 +endi + +if $data10 != 100 then + return -1 +endi + +if $data11 != 1 then + return -1 +endi + +print $data12 +if $data12 != 1.000000000 then + return -1 +endi + +if $data13 != 1 then + return -1 +endi + +if $data14 != 1.00000 then + print expect 1.00000, actual:$data14 + return -1 +endi + +sql_error select sum(c1), ts, c1 from group_tb0 where c1<20 group by c1; +sql_error select first(ts), ts, c2 from group_tb0 where c1 < 20 group by c1; +sql_error select sum(c3), ts, c2 from group_tb0 where c1 < 20 group by c1; +sql_error select sum(c3), first(ts), c2 from group_tb0 where c1 < 20 group by c1; +sql_error select first(c3), ts, c1, c2 from group_tb0 where c1 < 20 group by c1; +sql_error select first(c3), last(c3), ts, c1 from group_tb0 where c1 < 20 group by c1; +sql_error select ts from group_tb0 group by c1; + +#===========================interval=====not support====================== +sql_error select count(*), c1 from group_tb0 where c1<20 interval(1y) group by c1; +#=====tbname must be the first in the group by clause===================== +sql_error select count(*) from group_tb0 where c1 < 20 group by c1, tbname; + +#super table group by normal columns +sql select count(*), c1 from group_mt0 where c1< 20 group by c1; +if $row != 20 then + return -1 +endi + +if $data00 != 800 then + return -1 +endi + +if $data01 != 0 then + return -1 +endi + +if $data10 != 800 then + return -1 +endi + +if $data11 != 1 then + return -1 +endi + +if $data90 != 800 then + return -1 +endi + +if $data91 != 9 then + return -1 +endi + +sql select first(c1), c1, ts from group_mt0 where c1<20 group by c1; +if $row != 20 then + return -1 +endi + +if $data00 != $data01 then + return -1 +endi + +if $data02 != @70-01-01 08:01:40.000@ then + return -1 +endi + +if $data10 != $data11 then + return -1 +endi + +if $data12 != @70-01-01 08:01:40.001@ then + return -1 +endi + +if $data20 != $data21 then + return -1 +endi + +if $data22 != @70-01-01 08:01:40.002@ then + return -1 +endi + +if $data90 != $data91 then + return -1 +endi + +if $data92 != @70-01-01 08:01:40.009@ then + return -1 +endi + +sql select first(c1), last(ts), first(ts), last(c1),c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by c1; +if $row != 20 then + return -1 +endi + +if $data00 != $data03 then + return -1 +endi + +if $data01 != @70-01-01 08:01:49.900@ then + return -1 +endi + +if $data02 != @70-01-01 08:01:40.000@ then + return -1 +endi + +if $data07 != 800 then + return -1 +endi + +if $data10 != $data13 then + return -1 +endi + +if $data11 != @70-01-01 08:01:49.901@ then + return -1 +endi + +if $data12 != @70-01-01 08:01:40.001@ then + return -1 +endi + +if $data17 != 800 then + return -1 +endi + +if $data90 != $data93 then + return -1 +endi + +if $data91 != @70-01-01 08:01:49.909@ then + return -1 +endi + +if $data92 != @70-01-01 08:01:40.009@ then + return -1 +endi + +if $data97 != 800 then + return -1 +endi + +if $data95 != 7200 then + return -1 +endi + +if $data94 != 9 then + return -1 +endi + +sql select c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<5 group by c1; +if $row != 5 then + return -1 +endi + +if $data00 != 0 then + return -1 +endi + +if $data11 != 800 then + return -1 +endi + +sql select first(c1), last(ts), first(ts), last(c1),sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by tbname,c1; +if $row != 160 then + return -1 +endi + +print $data00 +if $data00 != 0 then + return -1 +endi + +if $data01 != @70-01-01 08:01:49.900@ then + return -1 +endi + +print $data01 +if $data02 != @70-01-01 08:01:40.000@ then + return -1 +endi + +if $data03 != 0 then + return -1 +endi + +if $data04 != 0 then + return -1 +endi + +if $data06 != 100 then + return -1 +endi + +if $data07 != @group_tb0@ then + return -1 +endi + +if $data90 != 9 then + return -1 +endi + +if $data91 != @70-01-01 08:01:49.909@ then + return -1 +endi + +if $data92 != @70-01-01 08:01:40.009@ then + return -1 +endi + +if $data93 != 9 then + return -1 +endi + +if $data94 != 900 then + return -1 +endi + +if $data96 != 100 then + return -1 +endi + +if $data97 != @group_tb0@ then + return -1 +endi + +sql select count(*),first(ts),last(ts),min(c3) from group_tb1 group by c4; +if $rows != 10000 then + return -1 +endi + +if $data00 != 1 then + return -1 +endi + +if $data01 != @70-01-01 08:01:40.000@ then + return -1 +endi + +if $data02 != @70-01-01 08:01:40.000@ then + return -1 +endi + +if $data03 != 0 then + return -1 +endi + +sql select count(*),first(ts),last(ts),min(c3) from group_tb1 group by c4 limit 1; +if $rows != 1 then + return -1 +endi + +sql select count(*),first(ts),last(ts),min(c3) from group_tb1 group by c4 limit 20 offset 9990; +if $rows != 10 then + return -1 +endi + +sql select count(*),first(ts),last(ts),min(c3),max(c3),sum(c3),avg(c3),sum(c4)/count(c4) from group_tb1 group by c4; +if $rows != 10000 then + return -1 +endi + +print ---------------------------------> group by binary|nchar data add cases +sql select count(*) from group_tb1 group by c8; +if $rows != 100 then + return -1 +endi + +sql select count(*),sum(c4), count(c4), sum(c4)/count(c4) from group_tb1 group by c8 +if $rows != 100 then + return -1 +endi + +if $data00 != 100 then + return -1 +endi + +if $data01 != 495000 then + return -1 +endi + +if $data02 != 100 then + return -1 +endi + +if $data03 != 4950.000000000 then + print expect 4950.000000000 , acutal $data03 + return -1 +endi + +if $data10 != 100 then + return -1 +endi + +if $data11 != 495100 then + return -1 +endi + +if $data13 != 4951.000000000 then + return -1 +endi + +print ====================> group by normal column + slimit + soffset +sql select count(*), c8 from group_mt0 group by c8 limit 1 offset 0; +if $rows != 100 then + return -1 +endi + +sql select sum(c2),c8,avg(c2), sum(c2)/count(*) from group_mt0 group by c8 slimit 2 soffset 99 +if $rows != 1 then + return -1 +endi + +if $data00 != 79200.000000000 then + return -1 +endi + +if $data01 != @binary99@ then + return -1 +endi + +if $data02 != 99.000000000 then + return -1 +endi + +if $data03 != 99.000000000 then + return -1 +endi + +print ============>td-1765 +sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0 group by c8; +if $rows != 100 then + return -1 +endi + +if $data00 != 4851.000000000 then + return -1 +endi + +if $data01 != 0 then + return -1 +endi + +if $data02 != 9900 then + return -1 +endi + +if $data03 != 4950.000000000 then + return -1 +endi + +if $data04 != 2886.607004772 then + return -1 +endi + +if $data10 != 4852.000000000 then + return -1 +endi + +if $data11 != 1 then + return -1 +endi + +if $data12 != 9901 then + return -1 +endi + +if $data13 != 4951.000000000 then + return -1 +endi + +if $data14 != 2886.607004772 then + return -1 +endi + +print ================>td-2090 +sql select leastsquares(c2, 1, 1) from group_tb1 group by c8; +if $rows != 100 then + return -1 +endi + +if $data00 != @{slop:0.000000, intercept:0.000000}@ then + return -1 +endi + +if $data10 != @{slop:0.000000, intercept:1.000000}@ then + return -1 +endi + +if $data90 != @{slop:0.000000, intercept:9.000000}@ then + return -1 +endi + +#=========================== group by multi tags ====================== +sql create table st (ts timestamp, c int) tags (t1 int, t2 int, t3 int, t4 int); +sql create table t1 using st tags(1, 1, 1, 1); +sql create table t2 using st tags(1, 2, 2, 2); +sql insert into t1 values ('2020-03-27 04:11:16.000', 1)('2020-03-27 04:11:17.000', 2) ('2020-03-27 04:11:18.000', 3) ('2020-03-27 04:11:19.000', 4) ; +sql insert into t1 values ('2020-03-27 04:21:16.000', 1)('2020-03-27 04:31:17.000', 2) ('2020-03-27 04:51:18.000', 3) ('2020-03-27 05:10:19.000', 4) ; +sql insert into t2 values ('2020-03-27 04:11:16.000', 1)('2020-03-27 04:11:17.000', 2) ('2020-03-27 04:11:18.000', 3) ('2020-03-27 04:11:19.000', 4) ; +sql insert into t2 values ('2020-03-27 04:21:16.000', 1)('2020-03-27 04:31:17.000', 2) ('2020-03-27 04:51:18.000', 3) ('2020-03-27 05:10:19.000', 4) ; + +print =================>TD-2665 +sql_error create table txx as select avg(c) as t from st; +sql_error create table txx1 as select avg(c) as t from t1; + +sql select stddev(c),stddev(c) from st group by c; +if $rows != 4 then + return -1 +endi + +print =================>TD-2236 +sql select first(ts),last(ts) from t1 group by c; +if $rows != 4 then + return -1 +endi + +if $data00 != @20-03-27 04:11:16.000@ then + return -1 +endi + +if $data01 != @20-03-27 04:21:16.000@ then + return -1 +endi + +if $data10 != @20-03-27 04:11:17.000@ then + return -1 +endi + +if $data11 != @20-03-27 04:31:17.000@ then + return -1 +endi + +if $data20 != @20-03-27 04:11:18.000@ then + return -1 +endi + +if $data21 != @20-03-27 04:51:18.000@ then + return -1 +endi + +if $data30 != @20-03-27 04:11:19.000@ then + return -1 +endi + +if $data31 != @20-03-27 05:10:19.000@ then + return -1 +endi + +print ===============> +sql select stddev(c),c from st where t2=1 or t2=2 group by c; +if $rows != 4 then + return -1 +endi + +if $data00 != 0.000000000 then + return -1 +endi + +if $data01 != 1 then + return -1 +endi + +if $data10 != 0.000000000 then + return -1 +endi + +if $data11 != 2 then + return -1 +endi + +if $data20 != 0.000000000 then + return -1 +endi + +if $data21 != 3 then + return -1 +endi + +if $data30 != 0.000000000 then + return -1 +endi + +if $data31 != 4 then + return -1 +endi + +sql_error select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,c; +sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2; +if $rows != 40 then + return -1 +endi + +if $data01 != 1.000000000 then + return -1 +endi +if $data02 != t1 then + return -1 +endi +if $data03 != 1 then + return -1 +endi +if $data04 != 1 then + return -1 +endi + +if $data11 != 1.000000000 then + return -1 +endi +if $data12 != t1 then + return -1 +endi +if $data13 != 1 then + return -1 +endi +if $data14 != 1 then + return -1 +endi + +sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2 limit 1; +if $rows != 2 then + return -1 +endi + +if $data11 != 1.000000000 then + return -1 +endi +if $data12 != t2 then + return -1 +endi +if $data13 != 1 then + return -1 +endi +if $data14 != 2 then + return -1 +endi + +sql create table m1 (ts timestamp, k int, f1 int) tags(a int); +sql create table tm0 using m1 tags(0); +sql create table tm1 using m1 tags(1); + +sql insert into tm0 values('2020-1-1 1:1:1', 1, 10); +sql insert into tm0 values('2020-1-1 1:1:2', 1, 20); +sql insert into tm1 values('2020-2-1 1:1:1', 2, 10); +sql insert into tm1 values('2020-2-1 1:1:2', 2, 20); + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 100 +system sh/exec.sh -n dnode1 -s start +sleep 100 + +sql connect +sleep 100 +sql use group_db0; + +print =========================>TD-4894 +sql select count(*),k from m1 group by k; +if $rows != 2 then + return -1 +endi + +if $data00 != 2 then + return -1 +endi + +if $data01 != 1 then + return -1 +endi + +if $data10 != 2 then + return -1 +endi + +if $data11 != 2 then + return -1 +endi + +sql_error select count(*) from m1 group by tbname,k,f1; +sql_error select count(*) from m1 group by tbname,k,a; +sql_error select count(*) from m1 group by k, tbname; +sql_error select count(*) from m1 group by k,f1; +sql_error select count(*) from tm0 group by tbname; +sql_error select count(*) from tm0 group by a; +sql_error select count(*) from tm0 group by k,f1; + +sql_error select count(*),f1 from m1 group by tbname,k; + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/query/interval-offset.sim b/tests/script/tsim/query/interval-offset.sim index f188dff1ba..4c4ebc6670 100644 --- a/tests/script/tsim/query/interval-offset.sim +++ b/tests/script/tsim/query/interval-offset.sim @@ -41,6 +41,38 @@ sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6 ) sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7 ) sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8 ) +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1 ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2 ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3 ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4 ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5 ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 6 ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 7 ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1 ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2 ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3 ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4 ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5 ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6 ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7 ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8 ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1 ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2 ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3 ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4 ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5 ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6 ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7 ) +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) print ===> rows: $rows @@ -102,15 +134,6 @@ if $data80 != 1 then return -1 endi -print =============== insert data into child table ct2 (d) -sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1 ) -sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2 ) -sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3 ) -sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4 ) -sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5 ) -sql insert into ct2 values ( '2022-01-03 10:00:01.000', 6 ) -sql insert into ct2 values ( '2022-01-03 20:00:01.000', 7 ) - 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) print ===> rows: $rows @@ -140,45 +163,19 @@ 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 -#if $data00 != 1 then -# return -1 -#endi -#if $data10 != 2 then -# return -1 -#endi -#if $data20 != 2 then -# return -1 -#endi -#if $data30 != 2 then -# return -1 -#endi -#if $data40 != 2 then -# return -1 -#endi -#if $data50 != 2 then -# return -1 -#endi -#if $data60 != 2 then -# return -1 -#endi -#if $data70 != 1 then -# return -1 -#endi - -print =============== insert data into child table ct3 (n) -sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL ); -sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1 ); -sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2 ); -sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3 ); -sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4 ); -sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5 ); -sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6 ); -sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7 ); -sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8 ); - +if $rows != 8 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 2 then + return -1 +endi +if $data70 != 1 then + return -1 +endi + sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), 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 @@ -236,18 +233,6 @@ print ===> rows7: $data70 $data71 $data72 $data73 $data74 # return -1 #endi - -print =============== insert data into child table ct4 (y) -sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1 ) -sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2 ) -sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3 ) -sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4 ) -sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5 ) -sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6 ) -sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7 ) -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 ) - 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) print ===> rows: $rows @@ -305,6 +290,27 @@ print ===> rows7: $data70 $data71 $data72 $data73 $data74 # return -1 #endi +#================================================= +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: + $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 diff --git a/tests/script/tsim/testCaseSuite.sim b/tests/script/tsim/testCaseSuite.sim index 4b700d2ca4..bf184f8794 100644 --- a/tests/script/tsim/testCaseSuite.sim +++ b/tests/script/tsim/testCaseSuite.sim @@ -2,6 +2,8 @@ run tsim/user/basic1.sim run tsim/db/basic1.sim +run tsim/db/basic2.sim +run tsim/db/basic3.sim run tsim/db/basic6.sim run tsim/db/basic7.sim run tsim/db/error1.sim @@ -13,12 +15,15 @@ run tsim/insert/basic1.sim run tsim/insert/backquote.sim run tsim/insert/null.sim +#run tsim/parser/groupby-basic.sim +#run tsim/parser/fourArithmetic-basic.sim + run tsim/query/interval.sim -#run tsim/query/interval-offset.sim # TD-14266 +run tsim/query/interval-offset.sim run tsim/show/basic.sim run tsim/table/basic1.sim run tsim/tmq/basic.sim - +run tsim/tmq/basic1.sim diff --git a/tests/script/tsim/tmq/basic1.sim b/tests/script/tsim/tmq/basic1.sim new file mode 100644 index 0000000000..fe6a7a0660 --- /dev/null +++ b/tests/script/tsim/tmq/basic1.sim @@ -0,0 +1,183 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# vgroups=1, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# vgroups=1, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# vgroups=4, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# 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). +# +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 + +$dbNamme = d0 +print =============== create database , vgroup 1 +sql create database $dbNamme vgroups 1 +sql show databases +print $data00 $data01 $data02 +if $rows != 2 then + return -1 +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 +sql create table ct0 using stb tags(1000) +sql create table ct1 using stb tags(2000) +#sql create table ct3 using stb tags(3000) + +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; 2. * from ctb; 3. columns from ctb +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_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_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 show tables +if $rows != 3 then + return -1 +endi + +print =============== insert data + +$tbPrefix = ct +$tbNum = 2 +$rowNum = 10 +$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 + +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: 20, 0}@ 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: 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 +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_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: 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 +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_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: 20, 0}@ then + return -1 +endi + +print =============== create database , vgroup 4 +$dbNamme = d1 +sql create database $dbNamme vgroups 4 + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/test/c/CMakeLists.txt b/tests/test/c/CMakeLists.txt index e186491bd4..804894a69d 100644 --- a/tests/test/c/CMakeLists.txt +++ b/tests/test/c/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(create_table create_table.c) add_executable(tmq_demo tmqDemo.c) +add_executable(tmq_sim tmqSim.c) target_link_libraries( create_table PUBLIC taos @@ -14,3 +15,10 @@ target_link_libraries( PUBLIC common PUBLIC os ) +target_link_libraries( + tmq_sim + PUBLIC taos + PUBLIC util + PUBLIC common + PUBLIC os +) diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 2618984f51..d339166d74 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -67,7 +67,7 @@ static SConfInfo g_stConfInfo = { "tmqdb", "stb", "./tmqResult.txt", // output_file - "/data2/dnode/data/vnode/vnode2/wal", + "", // /data2/dnode/data/vnode/vnode2/wal", 1, // threads 1, // tables 1, // vgroups @@ -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); @@ -662,7 +663,7 @@ int main(int32_t argc, char *argv[]) { float msgsSpeed = totalMsgs / seconds; - if (0 == g_stConfInfo.simCase) { + if ((0 == g_stConfInfo.simCase) && (strlen(g_stConfInfo.vnodeWalPath))) { walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath); if (walLogSize <= 0) { printf("%s size incorrect!", g_stConfInfo.vnodeWalPath); diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c new file mode 100644 index 0000000000..4d3108500e --- /dev/null +++ b/tests/test/c/tmqSim.c @@ -0,0 +1,287 @@ +/* + * 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 . + */ + +// clang-format off + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taos.h" +#include "taoserror.h" +#include "tlog.h" + +#define GREEN "\033[1;32m" +#define NC "\033[0m" +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +#define MAX_SQL_STR_LEN (1024 * 1024) +#define MAX_ROW_STR_LEN (16 * 1024) + +typedef struct { + // input from argvs + char dbName[32]; + char topicString[256]; + char keyString[1024]; + int32_t showMsgFlag; + + // save result after parse agrvs + int32_t numOfTopic; + char topics[32][64]; + + int32_t numOfKey; + char key[32][64]; + char value[32][64]; +} SConfInfo; + +static SConfInfo g_stConfInfo; + +//char* g_pRowValue = NULL; +//TdFilePtr g_fp = NULL; + +static void printHelp() { + char indent[10] = " "; + printf("Used to test the tmq feature with sim cases\n"); + + printf("%s%s\n", indent, "-c"); + printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); + printf("%s%s\n", indent, "-d"); + printf("%s%s%s\n", indent, indent, "The name of the database for cosumer, no default "); + printf("%s%s\n", indent, "-t"); + printf("%s%s%s\n", indent, indent, "The topic string for cosumer, no default "); + printf("%s%s\n", indent, "-k"); + printf("%s%s%s\n", indent, indent, "The key-value string for cosumer, no default "); + printf("%s%s\n", indent, "-g"); + printf("%s%s%s%d\n", indent, indent, "showMsgFlag, default is ", g_stConfInfo.showMsgFlag); + exit(EXIT_SUCCESS); +} + +void parseArgument(int32_t argc, char *argv[]) { + + memset(&g_stConfInfo, 0, sizeof(SConfInfo)); + + for (int32_t i = 1; i < argc; i++) { + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { + printHelp(); + exit(0); + } else if (strcmp(argv[i], "-d") == 0) { + strcpy(g_stConfInfo.dbName, argv[++i]); + } else if (strcmp(argv[i], "-c") == 0) { + strcpy(configDir, argv[++i]); + } else if (strcmp(argv[i], "-t") == 0) { + strcpy(g_stConfInfo.topicString, argv[++i]); + } else if (strcmp(argv[i], "-k") == 0) { + strcpy(g_stConfInfo.keyString, argv[++i]); + } else if (strcmp(argv[i], "-g") == 0) { + g_stConfInfo.showMsgFlag = atol(argv[++i]); + } else { + printf("%s unknow para: %s %s", GREEN, argv[++i], NC); + exit(-1); + } + } + +#if 0 + pPrint("%s configDir:%s %s", GREEN, configDir, NC); + pPrint("%s dbName:%s %s", GREEN, g_stConfInfo.dbName, NC); + pPrint("%s topicString:%s %s", GREEN, g_stConfInfo.topicString, NC); + pPrint("%s keyString:%s %s", GREEN, g_stConfInfo.keyString, NC); + pPrint("%s showMsgFlag:%d %s", GREEN, g_stConfInfo.showMsgFlag, NC); +#endif +} + +void splitStr(char **arr, char *str, const char *del) { + char *s = strtok(str, del); + while(s != NULL) { + *arr++ = s; + s = strtok(NULL, del); + } +} + +void ltrim(char *str) +{ + if (str == NULL || *str == '\0') + { + return; + } + int len = 0; + char *p = str; + while (*p != '\0' && isspace(*p)) + { + ++p; ++len; + } + memmove(str, p, strlen(str) - len + 1); + //return str; +} + + +void parseInputString() { + //printf("topicString: %s\n", g_stConfInfo.topicString); + //printf("keyString: %s\n\n", g_stConfInfo.keyString); + + char *token; + const char delim[2] = ","; + const char ch = ':'; + + token = strtok(g_stConfInfo.topicString, delim); + while(token != NULL) { + //printf("%s\n", token ); + strcpy(g_stConfInfo.topics[g_stConfInfo.numOfTopic], token); + ltrim(g_stConfInfo.topics[g_stConfInfo.numOfTopic]); + //printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]); + g_stConfInfo.numOfTopic++; + + token = strtok(NULL, delim); + } + + token = strtok(g_stConfInfo.keyString, delim); + while(token != NULL) { + //printf("%s\n", token ); + { + char* pstr = token; + ltrim(pstr); + char *ret = strchr(pstr, ch); + memcpy(g_stConfInfo.key[g_stConfInfo.numOfKey], pstr, ret-pstr); + strcpy(g_stConfInfo.value[g_stConfInfo.numOfKey], ret+1); + //printf("key: %s, value: %s\n", g_stConfInfo.key[g_stConfInfo.numOfKey], g_stConfInfo.value[g_stConfInfo.numOfKey]); + g_stConfInfo.numOfKey++; + } + + token = strtok(NULL, delim); + } +} + + +static int running = 1; +static void msg_process(tmq_message_t* message) { tmqShowMsg(message); } + + +int queryDB(TAOS *taos, char *command) { + TAOS_RES *pRes = taos_query(taos, command); + int code = taos_errno(pRes); + //if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) { + if (code != 0) { + pError("failed to reason:%s, sql: %s", tstrerror(code), command); + taos_free_result(pRes); + return -1; + } + taos_free_result(pRes); + return 0 ; +} + +tmq_t* build_consumer() { + char sqlStr[1024] = {0}; + + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + sprintf(sqlStr, "use %s", g_stConfInfo.dbName); + TAOS_RES* pRes = taos_query(pConn, sqlStr); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + exit(-1); + } + taos_free_result(pRes); + + tmq_conf_t* conf = tmq_conf_new(); + //tmq_conf_set(conf, "group.id", "tg2"); + for (int32_t i = 0; i < g_stConfInfo.numOfKey; i++) { + tmq_conf_set(conf, g_stConfInfo.key[i], g_stConfInfo.value[i]); + } + tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0); + return tmq; +} + +tmq_list_t* build_topic_list() { + tmq_list_t* topic_list = tmq_list_new(); + //tmq_list_append(topic_list, "test_stb_topic_1"); + for (int32_t i = 0; i < g_stConfInfo.numOfTopic; i++) { + tmq_list_append(topic_list, g_stConfInfo.topics[i]); + } + return topic_list; +} + +void loop_consume(tmq_t* tmq) { + tmq_resp_err_t err; + + int32_t totalMsgs = 0; + int32_t totalRows = 0; + int32_t skipLogNum = 0; + while (running) { + tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 1); + if (tmqMsg) { + totalMsgs++; + + #if 0 + TAOS_ROW row; + while (NULL != (row = tmq_get_row(tmqMsg))) { + totalRows++; + } + #endif + + skipLogNum += tmqGetSkipLogNum(tmqMsg); + if (0 != g_stConfInfo.showMsgFlag) { + msg_process(tmqMsg); + } + tmq_message_destroy(tmqMsg); + } else { + break; + } + } + + err = tmq_consumer_close(tmq); + if (err) { + printf("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); + exit(-1); + } + + printf("{consume success: %d, %d}", totalMsgs, totalRows); +} + +int main(int32_t argc, char *argv[]) { + parseArgument(argc, argv); + parseInputString(); + + tmq_t* tmq = build_consumer(); + tmq_list_t* topic_list = build_topic_list(); + if ((NULL == tmq) || (NULL == topic_list)){ + return -1; + } + + tmq_resp_err_t err = tmq_subscribe(tmq, topic_list); + if (err) { + printf("tmq_subscribe() fail, reason: %s\n", tmq_err2str(err)); + exit(-1); + } + + loop_consume(tmq); + + #if 0 + err = tmq_unsubscribe(tmq); + if (err) { + printf("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); + exit(-1); + } + #endif + + return 0; +} +