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..0260316618 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 @@ -149,6 +151,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); @@ -179,15 +182,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 +223,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 +267,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 67611d9563..51eabb7d61 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -54,16 +54,13 @@ typedef struct SColumnDataAgg { } SColumnDataAgg; typedef struct SDataBlockInfo { - STimeWindow window; - int32_t rows; - int32_t rowSize; - int16_t numOfCols; - int16_t hasVarCol; - union { - int64_t uid; - int64_t blockId; - }; - int64_t groupId; // no need to serialize + STimeWindow window; + int32_t rows; + int32_t rowSize; + int16_t numOfCols; + int16_t hasVarCol; + union {int64_t uid; int64_t blockId;}; + int64_t groupId; // no need to serialize } SDataBlockInfo; typedef struct SSDataBlock { @@ -96,6 +93,7 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock); int32_t tEncodeDataBlocks(void** buf, const SArray* blocks); void* tDecodeDataBlocks(const void* buf, SArray** blocks); +void colDataDestroy(SColumnInfoData* pColData) ; static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { // WARNING: do not use info.numOfCols, @@ -103,13 +101,7 @@ static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { int32_t numOfOutput = taosArrayGetSize(pBlock->pDataBlock); for (int32_t i = 0; i < numOfOutput; ++i) { SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i); - if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - taosMemoryFreeClear(pColInfoData->varmeta.offset); - } else { - taosMemoryFreeClear(pColInfoData->nullbitmap); - } - - taosMemoryFreeClear(pColInfoData->pData); + colDataDestroy(pColInfoData); } taosArrayDestroy(pBlock->pDataBlock); @@ -205,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 20d743046f..4a47acfa50 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; @@ -101,6 +102,54 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \ : ((p1_)->pData + ((r_) * (p1_)->info.bytes))) +static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uint32_t currentRow) { + // There is a placehold for each NULL value of binary or nchar type. + if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { + pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type. + } else { + colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow); + } + + pColumnInfoData->hasNull = true; +} + +static FORCE_INLINE int32_t colDataAppendInt8(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int8_t* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT || + pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; + *(int8_t*)p = *(int8_t*)v; +} + +static FORCE_INLINE int32_t colDataAppendInt16(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int16_t* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; + *(int16_t*)p = *(int16_t*)v; +} + +static FORCE_INLINE int32_t colDataAppendInt32(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int32_t* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_INT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UINT); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; + *(int32_t*)p = *(int32_t*)v; +} + +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); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; + *(int64_t*)p = *(int64_t*)v; +} + +static FORCE_INLINE int32_t colDataAppendFloat(SColumnInfoData* pColumnInfoData, uint32_t currentRow, float* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_FLOAT); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; + *(float*)p = *(float*)v; +} + +static FORCE_INLINE int32_t colDataAppendDouble(SColumnInfoData* pColumnInfoData, uint32_t currentRow, double* v) { + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_DOUBLE); + char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; + *(double*)p = *(double*)v; +} + int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull); int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource, uint32_t numOfRow2); @@ -128,7 +177,7 @@ 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); diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index a2899ead8e..4a3ce2db86 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -63,7 +63,7 @@ extern "C" { typedef struct { col_id_t colId; // column ID(start from PRIMARYKEY_TIMESTAMP_COL_ID(1)) int32_t type : 8; // column type - int32_t bytes : 24; // column bytes (restore to int32_t in case of misuse) + int32_t bytes : 24; // column bytes (0~16M) int32_t sma : 8; // block SMA: 0, no SMA, 1, sum/min/max, 2, ... int32_t offset : 24; // point offset in STpRow after the header part. } STColumn; @@ -81,12 +81,12 @@ typedef struct { // ----------------- TSDB SCHEMA DEFINITION typedef struct { - int32_t version; // version - int32_t numOfCols; // Number of columns appended - int32_t tlen; // maximum length of a STpRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + - // (bytes)) - uint16_t flen; // First part length in a STpRow after the header part - uint16_t vlen; // pure value part length, excluded the overhead (bytes only) + int32_t numOfCols; // Number of columns appended + schema_ver_t version; // schema version + uint16_t flen; // First part length in a STpRow after the header part + int32_t vlen; // pure value part length, excluded the overhead (bytes only) + int32_t tlen; // maximum length of a STpRow without the header part + // (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + (bytes)) STColumn columns[]; } STSchema; @@ -120,13 +120,13 @@ static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { // ----------------- SCHEMA BUILDER DEFINITION typedef struct { - int32_t tCols; - int32_t nCols; - int32_t tlen; - uint16_t flen; - uint16_t vlen; - int32_t version; - STColumn *columns; + int32_t tCols; + int32_t nCols; + schema_ver_t version; + uint16_t flen; + int32_t vlen; + int32_t tlen; + STColumn *columns; } STSchemaBuilder; #define TD_VTYPE_BITS 2 // val type @@ -136,9 +136,9 @@ typedef struct { #define TD_BITMAP_BYTES(cnt) (ceil((double)cnt / TD_VTYPE_PARTS)) #define TD_BIT_TO_BYTES(cnt) (ceil((double)cnt / 8)) -int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); +int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); -void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); +void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col_bytes_t bytes); STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index bdb6181884..de21638179 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -363,7 +363,7 @@ typedef struct { int8_t createType; int8_t superUser; // denote if it is a super user or not char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; + char pass[TSDB_USET_PASSWORD_LEN]; } SCreateUserReq; int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq); @@ -373,7 +373,7 @@ typedef struct { int8_t alterType; int8_t superUser; char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; + char pass[TSDB_USET_PASSWORD_LEN]; char dbname[TSDB_DB_FNAME_LEN]; } SAlterUserReq; @@ -565,8 +565,10 @@ typedef struct { SArray* pVgroupInfos; // Array of SVgroupInfo } SUseDbRsp; -int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp); +int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp); int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp); +int32_t tSerializeSUseDbRspImp(SCoder* pEncoder, const SUseDbRsp* pRsp); +int32_t tDeserializeSUseDbRspImp(SCoder* pDecoder, SUseDbRsp* pRsp); void tFreeSUsedbRsp(SUseDbRsp* pRsp); typedef struct { @@ -799,7 +801,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 { @@ -2210,23 +2215,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; @@ -2254,8 +2242,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 { @@ -2276,32 +2267,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) { @@ -2326,17 +2291,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)); @@ -2348,6 +2317,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 da34ca6253..83de5b6918 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -82,102 +82,111 @@ #define TK_SINGLE_STABLE 64 #define TK_STREAM_MODE 65 #define TK_RETENTIONS 66 -#define TK_FILE_FACTOR 67 -#define TK_NK_FLOAT 68 -#define TK_TABLE 69 -#define TK_NK_LP 70 -#define TK_NK_RP 71 -#define TK_STABLE 72 -#define TK_ADD 73 -#define TK_COLUMN 74 -#define TK_MODIFY 75 -#define TK_RENAME 76 -#define TK_TAG 77 -#define TK_SET 78 -#define TK_NK_EQ 79 -#define TK_USING 80 -#define TK_TAGS 81 -#define TK_NK_DOT 82 -#define TK_NK_COMMA 83 -#define TK_COMMENT 84 -#define TK_BOOL 85 -#define TK_TINYINT 86 -#define TK_SMALLINT 87 -#define TK_INT 88 -#define TK_INTEGER 89 -#define TK_BIGINT 90 -#define TK_FLOAT 91 -#define TK_DOUBLE 92 -#define TK_BINARY 93 -#define TK_TIMESTAMP 94 -#define TK_NCHAR 95 -#define TK_UNSIGNED 96 -#define TK_JSON 97 -#define TK_VARCHAR 98 -#define TK_MEDIUMBLOB 99 -#define TK_BLOB 100 -#define TK_VARBINARY 101 -#define TK_DECIMAL 102 -#define TK_SMA 103 -#define TK_ROLLUP 104 -#define TK_SHOW 105 -#define TK_DATABASES 106 -#define TK_TABLES 107 -#define TK_STABLES 108 -#define TK_MNODES 109 -#define TK_MODULES 110 -#define TK_QNODES 111 -#define TK_FUNCTIONS 112 -#define TK_INDEXES 113 -#define TK_FROM 114 -#define TK_LIKE 115 -#define TK_INDEX 116 -#define TK_FULLTEXT 117 -#define TK_FUNCTION 118 -#define TK_INTERVAL 119 -#define TK_TOPIC 120 -#define TK_AS 121 -#define TK_NK_BOOL 122 -#define TK_NK_VARIABLE 123 -#define TK_BETWEEN 124 -#define TK_IS 125 -#define TK_NULL 126 -#define TK_NK_LT 127 -#define TK_NK_GT 128 -#define TK_NK_LE 129 -#define TK_NK_GE 130 -#define TK_NK_NE 131 -#define TK_MATCH 132 -#define TK_NMATCH 133 -#define TK_IN 134 -#define TK_JOIN 135 -#define TK_INNER 136 -#define TK_SELECT 137 -#define TK_DISTINCT 138 -#define TK_WHERE 139 -#define TK_PARTITION 140 -#define TK_BY 141 -#define TK_SESSION 142 -#define TK_STATE_WINDOW 143 -#define TK_SLIDING 144 -#define TK_FILL 145 -#define TK_VALUE 146 -#define TK_NONE 147 -#define TK_PREV 148 -#define TK_LINEAR 149 -#define TK_NEXT 150 -#define TK_GROUP 151 -#define TK_HAVING 152 -#define TK_ORDER 153 -#define TK_SLIMIT 154 -#define TK_SOFFSET 155 -#define TK_LIMIT 156 -#define TK_OFFSET 157 -#define TK_ASC 158 -#define TK_DESC 159 -#define TK_NULLS 160 -#define TK_FIRST 161 -#define TK_LAST 162 +#define TK_TABLE 67 +#define TK_NK_LP 68 +#define TK_NK_RP 69 +#define TK_STABLE 70 +#define TK_ADD 71 +#define TK_COLUMN 72 +#define TK_MODIFY 73 +#define TK_RENAME 74 +#define TK_TAG 75 +#define TK_SET 76 +#define TK_NK_EQ 77 +#define TK_USING 78 +#define TK_TAGS 79 +#define TK_NK_DOT 80 +#define TK_NK_COMMA 81 +#define TK_COMMENT 82 +#define TK_BOOL 83 +#define TK_TINYINT 84 +#define TK_SMALLINT 85 +#define TK_INT 86 +#define TK_INTEGER 87 +#define TK_BIGINT 88 +#define TK_FLOAT 89 +#define TK_DOUBLE 90 +#define TK_BINARY 91 +#define TK_TIMESTAMP 92 +#define TK_NCHAR 93 +#define TK_UNSIGNED 94 +#define TK_JSON 95 +#define TK_VARCHAR 96 +#define TK_MEDIUMBLOB 97 +#define TK_BLOB 98 +#define TK_VARBINARY 99 +#define TK_DECIMAL 100 +#define TK_SMA 101 +#define TK_ROLLUP 102 +#define TK_FILE_FACTOR 103 +#define TK_NK_FLOAT 104 +#define TK_DELAY 105 +#define TK_SHOW 106 +#define TK_DATABASES 107 +#define TK_TABLES 108 +#define TK_STABLES 109 +#define TK_MNODES 110 +#define TK_MODULES 111 +#define TK_QNODES 112 +#define TK_FUNCTIONS 113 +#define TK_INDEXES 114 +#define TK_FROM 115 +#define TK_LIKE 116 +#define TK_INDEX 117 +#define TK_FULLTEXT 118 +#define TK_FUNCTION 119 +#define TK_INTERVAL 120 +#define TK_TOPIC 121 +#define TK_AS 122 +#define TK_NK_BOOL 123 +#define TK_NULL 124 +#define TK_NK_VARIABLE 125 +#define TK_NK_UNDERLINE 126 +#define TK_ROWTS 127 +#define TK_TBNAME 128 +#define TK_QSTARTTS 129 +#define TK_QENDTS 130 +#define TK_WSTARTTS 131 +#define TK_WENDTS 132 +#define TK_WDURATION 133 +#define TK_BETWEEN 134 +#define TK_IS 135 +#define TK_NK_LT 136 +#define TK_NK_GT 137 +#define TK_NK_LE 138 +#define TK_NK_GE 139 +#define TK_NK_NE 140 +#define TK_MATCH 141 +#define TK_NMATCH 142 +#define TK_IN 143 +#define TK_JOIN 144 +#define TK_INNER 145 +#define TK_SELECT 146 +#define TK_DISTINCT 147 +#define TK_WHERE 148 +#define TK_PARTITION 149 +#define TK_BY 150 +#define TK_SESSION 151 +#define TK_STATE_WINDOW 152 +#define TK_SLIDING 153 +#define TK_FILL 154 +#define TK_VALUE 155 +#define TK_NONE 156 +#define TK_PREV 157 +#define TK_LINEAR 158 +#define TK_NEXT 159 +#define TK_GROUP 160 +#define TK_HAVING 161 +#define TK_ORDER 162 +#define TK_SLIMIT 163 +#define TK_SOFFSET 164 +#define TK_LIMIT 165 +#define TK_OFFSET 166 +#define TK_ASC 167 +#define TK_DESC 168 +#define TK_NULLS 169 +#define TK_FIRST 170 +#define TK_LAST 171 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 87dc752703..19442af206 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -30,6 +30,7 @@ typedef uint8_t TDRowValT; typedef int16_t col_id_t; typedef int8_t col_type_t; typedef int32_t col_bytes_t; +typedef uint16_t schema_ver_t; #pragma pack(push, 1) typedef struct { diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 4ad7e2dfc2..fbdb1d66b4 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,7 @@ typedef struct SReadHandle { #define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1 #define STREAM_DATA_TYPE_SSDATA_BLOCK 0x2 - + /** * Create the exec task for streaming mode * @param pMsg @@ -54,6 +54,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. * @@ -86,16 +96,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 +158,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 +167,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 6c4774c3be..e7895bd972 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -27,16 +27,22 @@ extern "C" { struct SqlFunctionCtx; struct SResultRowEntryInfo; -typedef struct SFunctionNode SFunctionNode; +struct SFunctionNode; +typedef struct SScalarParam SScalarParam; typedef struct SFuncExecEnv { int32_t calcMemSize; } SFuncExecEnv; -typedef bool (*FExecGetEnv)(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +typedef bool (*FExecGetEnv)(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); typedef void (*FExecProcess)(struct SqlFunctionCtx *pCtx); typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx); +typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); + +typedef struct SScalarFuncExecFuncs { + FScalarExecProcess process; +} SScalarFuncExecFuncs; typedef struct SFuncExecFuncs { FExecGetEnv getEnv; @@ -191,6 +197,7 @@ typedef struct SqlFunctionCtx { SPoint1 start; SPoint1 end; SFuncExecFuncs fpSet; + SScalarFuncExecFuncs sfp; } SqlFunctionCtx; enum { @@ -203,7 +210,7 @@ enum { }; typedef struct tExprNode { - uint8_t nodeType; + int32_t nodeType; union { struct { int32_t optr; // binary operator @@ -219,7 +226,7 @@ typedef struct tExprNode { char functionName[FUNCTIONS_NAME_MAX_LENGTH]; // todo refactor int32_t functionId; int32_t num; - SFunctionNode *pFunctNode; + struct SFunctionNode *pFunctNode; // Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the // calculation instead. // E.g., Cov(col1, col2), the column information, w.r.t. the col1 and col2, is kept in pChild nodes. @@ -227,6 +234,10 @@ typedef struct tExprNode { // operator and is kept in the attribute of _node. struct tExprNode **pChild; } _function; + + struct { + struct SNode* pRootNode; + } _optrRoot; }; } tExprNode; @@ -250,25 +261,11 @@ typedef struct SAggFunctionInfo { int32_t (*dataReqFunc)(SqlFunctionCtx *pCtx, STimeWindow* w, int32_t colId); } SAggFunctionInfo; -typedef struct SScalarParam { - void *data; - union { - SColumnInfoData *columnData; - void *data; - } orig; - char *bitmap; - bool dataInBlock; - int32_t num; - int32_t type; - int32_t bytes; -} SScalarParam; - -typedef struct SScalarFunctionInfo { - char name[FUNCTIONS_NAME_MAX_LENGTH]; - int8_t type; // scalar function or aggregation function - uint32_t functionId; // index of scalar function - void (*process)(struct SScalarParam* pOutput, size_t numOfInput, const struct SScalarParam *pInput); -} SScalarFunctionInfo; +struct SScalarParam { + SColumnInfoData *columnData; + SHashObj *pHashFilter; + int32_t numOfRows; +}; typedef struct SMultiFunctionsDesc { bool stableQuery; diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 85a9cd0b23..7d46b543cb 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -96,20 +96,22 @@ 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; struct SResultRowEntryInfo; struct STimeWindow; -typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); - -typedef struct SScalarFuncExecFuncs { - FScalarExecProcess process; -} SScalarFuncExecFuncs; - - int32_t fmFuncMgtInit(); void fmFuncMgtDestroy(); @@ -125,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/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 48a3a9bda8..a03c496b4f 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -41,6 +41,7 @@ typedef struct SDatabaseOptions { int32_t numOfVgroups; int8_t singleStable; int8_t streamMode; + SNodeList* pRetentions; } SDatabaseOptions; typedef struct SCreateDatabaseStmt { @@ -73,6 +74,9 @@ typedef struct STableOptions { int32_t ttl; char comments[TSDB_STB_COMMENT_LEN]; SNodeList* pSma; + SNodeList* pFuncs; + float filesFactor; + int32_t delay; } STableOptions; typedef struct SColumnDefNode { diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 9b8739a4f3..411d34063c 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -121,6 +121,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..68e081cd15 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -66,7 +66,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 +110,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 +159,8 @@ typedef struct SDataBlockDescNode { ENodeType type; int16_t dataBlockId; SNodeList* pSlots; - int32_t resultRowSize; + int32_t totalRowSize; + int32_t outputRowSize; int16_t precision; } SDataBlockDescNode; @@ -195,6 +205,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 { @@ -283,10 +297,17 @@ typedef struct SSubplan { SDataSinkNode* pDataSink; // data of the subplan flow into the datasink } SSubplan; +typedef enum EQueryMode { + QUERY_MODE_NORMAL = 1, + QUERY_MODE_EXPLAIN, + QUERY_MODE_EXPLAIN_AN +} EQueryMode; + typedef struct SQueryPlan { ENodeType type; uint64_t queryId; int32_t numOfSubplans; + SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0. } SQueryPlan; diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 66f60bde98..5dc2cd35b7 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -180,8 +180,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 { diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index 12c03afcb6..c6d17ef65c 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -40,7 +40,7 @@ int32_t scalarGetOperatorParamNum(EOperatorType type); int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type); int32_t vectorGetConvertType(int32_t type1, int32_t type2); -int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut); +int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut); int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 8be9bbbebd..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 @@ -72,8 +77,9 @@ typedef struct { } STaskDispatcherFixedEp; typedef struct { - int8_t hashMethod; - SArray* info; + // int8_t hashMethod; + char stbFullName[TSDB_TABLE_FNAME_LEN]; + SUseDbRsp dbInfo; } STaskDispatcherShuffle; typedef struct { @@ -135,7 +141,6 @@ typedef struct { int8_t sinkType; int8_t dispatchType; int16_t dispatchMsgType; - int32_t downstreamTaskId; int32_t nodeId; SEpSet epSet; 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..fa9d61b997 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 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 6c5208ec00..193be4a3e6 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -369,6 +369,18 @@ typedef enum ELogicConditionType { #define TSDB_MAX_DB_CACHE_LAST_ROW 3 #define TSDB_DEFAULT_CACHE_LAST_ROW 0 +#define TSDB_MIN_DB_STREAM_MODE 0 +#define TSDB_MAX_DB_STREAM_MODE 1 +#define TSDB_DEFAULT_DB_STREAM_MODE 0 + +#define TSDB_MIN_DB_FILE_FACTOR 0 +#define TSDB_MAX_DB_FILE_FACTOR 1 +#define TSDB_DEFAULT_DB_FILE_FACTOR 0.1 + +#define TSDB_MIN_DB_DELAY 1 +#define TSDB_MAX_DB_DELAY 10 +#define TSDB_DEFAULT_DB_DELAY 2 + #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/include/util/tqueue.h b/include/util/tqueue.h index 3bccc7404b..70db65d50f 100644 --- a/include/util/tqueue.h +++ b/include/util/tqueue.h @@ -56,7 +56,7 @@ void taosCloseQueue(STaosQueue *queue); void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp); void *taosAllocateQitem(int32_t size); void taosFreeQitem(void *pItem); -int32_t taosWriteQitem(STaosQueue *queue, void *pItem); +void taosWriteQitem(STaosQueue *queue, void *pItem); int32_t taosReadQitem(STaosQueue *queue, void **ppItem); bool taosQueueEmpty(STaosQueue *queue); int32_t taosQueueSize(STaosQueue *queue); diff --git a/include/util/tworker.h b/include/util/tworker.h index 92d474c885..3545aeed89 100644 --- a/include/util/tworker.h +++ b/include/util/tworker.h @@ -70,8 +70,8 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue); typedef struct { const char *name; - int32_t minNum; - int32_t maxNum; + int32_t min; + int32_t max; FItem fp; void *param; } SSingleWorkerCfg; @@ -84,7 +84,7 @@ typedef struct { typedef struct { const char *name; - int32_t maxNum; + int32_t max; FItems fp; void *param; } SMultiWorkerCfg; diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 7d7e51bc27..49cb12cccd 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -235,7 +235,7 @@ void initMsgHandleFp(); TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port); -void* doFetchRow(SRequestObj* pRequest); +void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr); int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 6e65a4267f..d8017a8727 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -545,7 +545,33 @@ TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, c return taos_connect(ipStr, userStr, passStr, dbStr, port); } -void* doFetchRow(SRequestObj* pRequest) { +static void doSetOneRowPtr(SReqResultInfo* pResultInfo) { + for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { + SResultColumn* pCol = &pResultInfo->pCol[i]; + + int32_t type = pResultInfo->fields[i].type; + int32_t bytes = pResultInfo->fields[i].bytes; + + if (IS_VAR_DATA_TYPE(type)) { + if (pCol->offset[pResultInfo->current] != -1) { + char* pStart = pResultInfo->pCol[i].offset[pResultInfo->current] + pResultInfo->pCol[i].pData; + + pResultInfo->length[i] = varDataLen(pStart); + pResultInfo->row[i] = varDataVal(pStart); + } else { + pResultInfo->row[i] = NULL; + } + } else { + if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) { + pResultInfo->row[i] = pResultInfo->pCol[i].pData + bytes * pResultInfo->current; + } else { + pResultInfo->row[i] = NULL; + } + } + } +} + +void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) { assert(pRequest != NULL); SReqResultInfo* pResultInfo = &pRequest->body.resInfo; @@ -555,17 +581,20 @@ void* doFetchRow(SRequestObj* pRequest) { if (pRequest->type == TDMT_VND_QUERY) { // All data has returned to App already, no need to try again if (pResultInfo->completed) { + pResultInfo->numOfRows = 0; return NULL; } SReqResultInfo* pResInfo = &pRequest->body.resInfo; pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData); if (pRequest->code != TSDB_CODE_SUCCESS) { + pResultInfo->numOfRows = 0; return NULL; } pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData); if (pRequest->code != TSDB_CODE_SUCCESS) { + pResultInfo->numOfRows = 0; return NULL; } @@ -633,41 +662,11 @@ void* doFetchRow(SRequestObj* pRequest) { } _return: - - for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { - SResultColumn* pCol = &pResultInfo->pCol[i]; - - int32_t type = pResultInfo->fields[i].type; - int32_t bytes = pResultInfo->fields[i].bytes; - - if (IS_VAR_DATA_TYPE(type)) { - if (pCol->offset[pResultInfo->current] != -1) { - char* pStart = pResultInfo->pCol[i].offset[pResultInfo->current] + pResultInfo->pCol[i].pData; - - pResultInfo->length[i] = varDataLen(pStart); - pResultInfo->row[i] = varDataVal(pStart); - - if (type == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(pResultInfo->convertBuf[i])); - ASSERT(len <= bytes); - - pResultInfo->row[i] = varDataVal(pResultInfo->convertBuf[i]); - varDataSetLen(pResultInfo->convertBuf[i], len); - pResultInfo->length[i] = len; - } - } else { - pResultInfo->row[i] = NULL; - } - } else { - if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) { - pResultInfo->row[i] = pResultInfo->pCol[i].pData + bytes * pResultInfo->current; - } else { - pResultInfo->row[i] = NULL; - } - } + if (setupOneRowPtr) { + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; } - pResultInfo->current += 1; return pResultInfo->row; } @@ -681,12 +680,6 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { if (pResInfo->row == NULL || pResInfo->pCol == NULL || pResInfo->length == NULL || pResInfo->convertBuf == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - - for(int32_t i = 0; i < pResInfo->numOfCols; ++i) { - if(pResInfo->fields[i].type == TSDB_DATA_TYPE_NCHAR) { - pResInfo->convertBuf[i] = taosMemoryCalloc(1, NCHAR_WIDTH_TO_BYTES(pResInfo->fields[i].bytes)); - } - } } return TSDB_CODE_SUCCESS; @@ -723,6 +716,35 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 pStart += colLength[i]; } + for (int32_t i = 0; i < numOfCols; ++i) { + int32_t type = pResultInfo->fields[i].type; + int32_t bytes = pResultInfo->fields[i].bytes; + + if (type == TSDB_DATA_TYPE_NCHAR) { + char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pResultInfo->convertBuf[i] = p; + + SResultColumn* pCol = &pResultInfo->pCol[i]; + for (int32_t j = 0; j < numOfRows; ++j) { + if (pCol->offset[j] != -1) { + pStart = pCol->offset[j] + pCol->pData; + + int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p)); + ASSERT(len <= bytes); + + varDataSetLen(p, len); + pCol->offset[j] = (p - pResultInfo->convertBuf[i]); + p += (len + VARSTR_HEADER_SIZE); + } + } + + pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; + } + } + return TSDB_CODE_SUCCESS; } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 09a0233e04..40c601f63f 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; } @@ -69,13 +84,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 +100,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,26 +148,24 @@ 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 *pRes) { - if (pRes == NULL) { +TAOS_ROW taos_fetch_row(TAOS_RES *res) { + if (res == NULL) { return NULL; } - SRequestObj *pRequest = (SRequestObj *) pRes; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || - pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || - taos_num_fields(pRes) == 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); + 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 +224,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,28 +249,44 @@ 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; } +// 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_BINARY: return "TSDB_DATA_TYPE_BINARY"; - case TSDB_DATA_TYPE_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP"; - case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR"; - 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"; } } @@ -270,8 +297,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; } @@ -292,8 +319,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; @@ -304,35 +331,57 @@ 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) { - return false; + 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]; + return colDataIsNull_f(pCol->nullbitmap, row); } -int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { - return 0; +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) { + return 0; + } + + doFetchRow(pRequest, false); + + // TODO refactor + 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; } const char *taos_get_server_info(TAOS *taos) { if (taos == NULL) { return NULL; } - STscObj* pTscObj = (STscObj*) taos; + STscObj *pTscObj = (STscObj *)taos; return pTscObj->ver; } @@ -358,52 +407,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; } @@ -413,6 +477,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..f7593595b0 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() { @@ -471,7 +484,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 +633,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 +719,7 @@ _return: return pRequest; } +#endif static char* formatTimestamp(char* buf, int64_t val, int precision) { time_t tt; 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 c624e383fb..7a958136e7 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -647,7 +647,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 +671,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 +906,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 +921,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 +960,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 +1011,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 +1105,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); @@ -1241,6 +1240,16 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) { return pageSize / (blockDataGetSerialRowSize(pBlock) + blockDataGetSerialMetaSize(pBlock)); } +void colDataDestroy(SColumnInfoData* pColData) { + if (IS_VAR_DATA_TYPE(pColData->info.type)) { + taosMemoryFree(pColData->varmeta.offset); + } else { + taosMemoryFree(pColData->nullbitmap); + } + + taosMemoryFree(pColData->pData); +} + int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) { int64_t tbUid = pBlock->info.uid; int16_t numOfCols = pBlock->info.numOfCols; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 1b7157c49c..7fd66e95ad 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -123,7 +123,7 @@ void *tdDecodeSchema(void *buf, STSchema **pRSchema) { return buf; } -int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { +int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) { if (pBuilder == NULL) return -1; pBuilder->tCols = 256; @@ -140,7 +140,7 @@ void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder) { } } -void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { +void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) { pBuilder->nCols = 0; pBuilder->tlen = 0; pBuilder->flen = 0; @@ -168,6 +168,9 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]); } + // TODO: set sma value by user input + pCol->sma = 1; + if (IS_VAR_DATA_TYPE(type)) { colSetBytes(pCol, bytes); pBuilder->tlen += (TYPE_BYTES[type] + bytes); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index f464ce6f50..c85184ffba 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1829,7 +1829,7 @@ int32_t tDeserializeSSyncDbReq(void *buf, int32_t bufLen, SSyncDbReq *pReq) { return 0; } -static int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, SUseDbRsp *pRsp) { +int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, const SUseDbRsp *pRsp) { if (tEncodeCStr(pEncoder, pRsp->db) < 0) return -1; if (tEncodeI64(pEncoder, pRsp->uid) < 0) return -1; if (tEncodeI32(pEncoder, pRsp->vgVersion) < 0) return -1; @@ -1848,7 +1848,7 @@ static int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, SUseDbRsp *pRsp) { return 0; } -int32_t tSerializeSUseDbRsp(void *buf, int32_t bufLen, SUseDbRsp *pRsp) { +int32_t tSerializeSUseDbRsp(void *buf, int32_t bufLen, const SUseDbRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); 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 95% rename from source/dnode/mgmt/bnode/inc/bmInt.h rename to source/dnode/mgmt/bm/inc/bmInt.h index 8cfff0f1f3..f19ba4e034 100644 --- a/source/dnode/mgmt/bnode/inc/bmInt.h +++ b/source/dnode/mgmt/bm/inc/bmInt.h @@ -43,7 +43,7 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); // bmWorker.c int32_t bmStartWorker(SBnodeMgmt *pMgmt); void bmStopWorker(SBnodeMgmt *pMgmt); -int32_t bmProcessWriteMsg(SBnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } 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 90% rename from source/dnode/mgmt/bnode/src/bmWorker.c rename to source/dnode/mgmt/bm/src/bmWorker.c index 7698aa9dbd..932c008e34 100644 --- a/source/dnode/mgmt/bnode/src/bmWorker.c +++ b/source/dnode/mgmt/bm/src/bmWorker.c @@ -63,15 +63,17 @@ static void bmProcessQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs taosArrayDestroy(pArray); } -int32_t bmProcessWriteMsg(SBnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SBnodeMgmt *pMgmt = pWrapper->pMgmt; SMultiWorker *pWorker = &pMgmt->writeWorker; dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } int32_t bmStartWorker(SBnodeMgmt *pMgmt) { - SMultiWorkerCfg cfg = {.maxNum = 1, .name = "bnode-write", .fp = (FItems)bmProcessQueue, .param = pMgmt}; + SMultiWorkerCfg cfg = {.max = 1, .name = "bnode-write", .fp = (FItems)bmProcessQueue, .param = pMgmt}; if (tMultiWorkerInit(&pMgmt->writeWorker, &cfg) != 0) { dError("failed to start bnode write worker since %s", terrstr()); return -1; 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 96% rename from source/dnode/mgmt/dnode/inc/dmInt.h rename to source/dnode/mgmt/dm/inc/dmInt.h index b02b1d2297..3036d1f5ad 100644 --- a/source/dnode/mgmt/dnode/inc/dmInt.h +++ b/source/dnode/mgmt/dm/inc/dmInt.h @@ -54,7 +54,7 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); int32_t dmStartWorker(SDnodeMgmt *pMgmt); void dmStopWorker(SDnodeMgmt *pMgmt); int32_t dmStartThread(SDnodeMgmt *pMgmt); -int32_t dmProcessMgmtMsg(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } 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 78% rename from source/dnode/mgmt/dnode/src/dmMsg.c rename to source/dnode/mgmt/dm/src/dmMsg.c index eb4e843c55..b301ef478b 100644 --- a/source/dnode/mgmt/dnode/src/dmMsg.c +++ b/source/dnode/mgmt/dm/src/dmMsg.c @@ -118,19 +118,19 @@ int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { void dmInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, VND_VGID); // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, VND_VGID); } diff --git a/source/dnode/mgmt/dnode/src/dmWorker.c b/source/dnode/mgmt/dm/src/dmWorker.c similarity index 92% rename from source/dnode/mgmt/dnode/src/dmWorker.c rename to source/dnode/mgmt/dm/src/dmWorker.c index d34a26436c..63b9704b78 100644 --- a/source/dnode/mgmt/dnode/src/dmWorker.c +++ b/source/dnode/mgmt/dm/src/dmWorker.c @@ -101,14 +101,14 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { int32_t dmStartWorker(SDnodeMgmt *pMgmt) { SSingleWorkerCfg mgmtCfg = { - .minNum = 1, .maxNum = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; + .min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) { dError("failed to start dnode mgmt worker since %s", terrstr()); return -1; } SSingleWorkerCfg statusCfg = { - .minNum = 1, .maxNum = 1, .name = "dnode-status", .fp = (FItem)dmProcessQueue, .param = pMgmt}; + .min = 1, .max = 1, .name = "dnode-status", .fp = (FItem)dmProcessQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->statusWorker, &statusCfg) != 0) { dError("failed to start dnode status worker since %s", terrstr()); return -1; @@ -140,12 +140,14 @@ void dmStopWorker(SDnodeMgmt *pMgmt) { dDebug("dnode workers are closed"); } -int32_t dmProcessMgmtMsg(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnodeMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->mgmtWorker; if (pMsg->rpcMsg.msgType == TDMT_MND_STATUS_RSP) { pWorker = &pMgmt->statusWorker; } dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } 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..634e2caa28 --- /dev/null +++ b/source/dnode/mgmt/main/exe/dndMain.c @@ -0,0 +1,199 @@ +/* + * 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 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 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.pDisks = tsDiskCfg; + option.numOfDisks = tsDiskCfgNum; + 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 != 0) { + 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 85% rename from source/dnode/mgmt/container/inc/dnd.h rename to source/dnode/mgmt/main/inc/dnd.h index f6c8897f64..046200510d 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" @@ -63,7 +64,7 @@ typedef struct SQnodeMgmt SQnodeMgmt; typedef struct SSnodeMgmt SSnodeMgmt; typedef struct SBnodeMgmt SBnodeMgmt; -typedef int32_t (*NodeMsgFp)(void *pMgmt, SNodeMsg *pMsg); +typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper); typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper); typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper); @@ -130,15 +131,19 @@ typedef struct SDnode { 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, int32_t msgType, NodeMsgFp nodeMsgFp, int32_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 96% rename from source/dnode/mgmt/container/inc/dndInt.h rename to source/dnode/mgmt/main/inc/dndInt.h index 8ea496b2fb..0f0cc78a1d 100644 --- a/source/dnode/mgmt/container/inc/dndInt.h +++ b/source/dnode/mgmt/main/inc/dndInt.h @@ -56,6 +56,7 @@ 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); #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 82% rename from source/dnode/mgmt/container/src/dndExec.c rename to source/dnode/mgmt/main/src/dndExec.c index a7b8ca288b..5a9077a937 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); @@ -108,23 +110,25 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { } static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) { - dndCleanupServer(pDnode); + // dndCleanupServer(pDnode); for (ENodeType n = 0; n < NODE_MAX; ++n) { if (except == n) continue; SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - dndCloseNode(pWrapper); + pWrapper->required = false; } } -static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t msgLen, void *pCont, int32_t contLen) { - dTrace("msg:%p, get from child queue", pMsg); +static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + ProcFuncType ftype) { SRpcMsg *pRpc = &pMsg->rpcMsg; pRpc->pCont = pCont; + dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle); NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; int32_t code = (*msgFp)(pWrapper, pMsg); if (code != 0) { + dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); if (pRpc->msgType & 1U) { SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; dndSendRsp(pWrapper, &rsp); @@ -136,11 +140,27 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t } } -static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRsp, int32_t msgLen, void *pCont, int32_t contLen) { - dTrace("msg:%p, get from parent queue", pRsp); - pRsp->pCont = pCont; - dndSendRsp(pWrapper, pRsp); - taosMemoryFree(pRsp); +static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + ProcFuncType ftype) { + pMsg->pCont = pCont; + dTrace("msg:%p, get from parent queue, handle:%p app:%p", pMsg, pMsg->handle, pMsg->ahandle); + + switch (ftype) { + case PROC_REG: + rpcRegisterBrokenLinkArg(pMsg); + break; + case PROC_RELEASE: + rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); + rpcFreeCont(pCont); + break; + case PROC_REQ: + // todo send to dnode + dndSendReqToMnode(pWrapper, pMsg); + default: + dndSendRpcRsp(pWrapper, pMsg); + break; + } + taosMemoryFree(pMsg); } static int32_t dndRunInMultiProcess(SDnode *pDnode) { @@ -151,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()); @@ -198,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; + } } } diff --git a/source/dnode/mgmt/container/src/dndFile.c b/source/dnode/mgmt/main/src/dndFile.c similarity index 100% rename from source/dnode/mgmt/container/src/dndFile.c rename to source/dnode/mgmt/main/src/dndFile.c diff --git a/source/dnode/mgmt/container/src/dndInt.c b/source/dnode/mgmt/main/src/dndInt.c similarity index 93% rename from source/dnode/mgmt/container/src/dndInt.c rename to source/dnode/mgmt/main/src/dndInt.c index 33d6bb0ee3..a9b1982138 100644 --- a/source/dnode/mgmt/container/src/dndInt.c +++ b/source/dnode/mgmt/main/src/dndInt.c @@ -80,19 +80,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); 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 b72d085861..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; } @@ -62,11 +64,11 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { if (pWrapper->procType == PROC_SINGLE) { dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); - code = (*msgFp)(pWrapper->pMgmt, pMsg); + code = (*msgFp)(pWrapper, pMsg); } else if (pWrapper->procType == PROC_PARENT) { dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); - 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 100% rename from source/dnode/mgmt/container/src/dndObj.c rename to source/dnode/mgmt/main/src/dndObj.c 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 85% rename from source/dnode/mgmt/mnode/inc/mmInt.h rename to source/dnode/mgmt/mm/inc/mmInt.h index cd4585048b..86cba97a33 100644 --- a/source/dnode/mgmt/mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mm/inc/mmInt.h @@ -55,13 +55,14 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); // mmWorker.c int32_t mmStartWorker(SMnodeMgmt *pMgmt); void mmStopWorker(SMnodeMgmt *pMgmt); -int32_t mmProcessWriteMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmProcessSyncMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmProcessReadMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmProcessQueryMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpcMsg); -int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpcMsg); +int32_t mmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t mmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t mmProcessReadMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t mmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); +int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); +int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); +int32_t mmPutMsgToSyncQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); #ifdef __cplusplus } 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 98% rename from source/dnode/mgmt/mnode/src/mmInt.c rename to source/dnode/mgmt/mm/src/mmInt.c index 61afcb11d1..3d15c9b9ae 100644 --- a/source/dnode/mgmt/mnode/src/mmInt.c +++ b/source/dnode/mgmt/mm/src/mmInt.c @@ -48,9 +48,11 @@ static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue; msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue; + msgCb.queueFps[SYNC_QUEUE] = mmPutMsgToWriteQueue; msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; + msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg; pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/mm/src/mmMsg.c b/source/dnode/mgmt/mm/src/mmMsg.c new file mode 100644 index 0000000000..6afcd249b3 --- /dev/null +++ b/source/dnode/mgmt/mm/src/mmMsg.c @@ -0,0 +1,165 @@ +/* + * 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 "mmInt.h" + +int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnode *pDnode = pWrapper->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDCreateMnodeReq createReq = {0}; + if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (createReq.replica <= 1 || createReq.dnodeId != pDnode->dnodeId) { + terrno = TSDB_CODE_NODE_INVALID_OPTION; + dError("failed to create mnode since %s", terrstr()); + return -1; + } else { + return mmOpenFromMsg(pWrapper, &createReq); + } +} + +int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnode *pDnode = pWrapper->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDDropMnodeReq dropReq = {0}; + if (tDeserializeSMCreateDropMnodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (dropReq.dnodeId != pDnode->dnodeId) { + terrno = TSDB_CODE_NODE_INVALID_OPTION; + dError("failed to drop mnode since %s", terrstr()); + return -1; + } else { + return mmDrop(pWrapper); + } +} + +int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { + SDnode *pDnode = pMgmt->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDAlterMnodeReq alterReq = {0}; + if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (alterReq.dnodeId != pDnode->dnodeId) { + terrno = TSDB_CODE_NODE_INVALID_OPTION; + dError("failed to alter mnode since %s", terrstr()); + return -1; + } else { + return mmAlter(pMgmt, &alterReq); + } +} + +void mmInitMsgHandles(SMgmtWrapper *pWrapper) { + // Requests handled by DNODE + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, VND_VGID); + + // Requests handled by MNODE + dndSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, VND_VGID); + + // Requests handled by VNODE + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, VND_VGID); + + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MND_VGID); + +} diff --git a/source/dnode/mgmt/mnode/src/mmWorker.c b/source/dnode/mgmt/mm/src/mmWorker.c similarity index 57% rename from source/dnode/mgmt/mnode/src/mmWorker.c rename to source/dnode/mgmt/mm/src/mmWorker.c index 27489b45d0..c4aafe05e4 100644 --- a/source/dnode/mgmt/mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mm/src/mmWorker.c @@ -19,7 +19,7 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SMnodeMgmt *pMgmt = pInfo->ahandle; - dTrace("msg:%p, will be processed in mnode queue", pMsg); + dTrace("msg:%p, get from mnode queue", pMsg); SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; @@ -31,9 +31,11 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { } if (pRpc->msgType & 1U) { - if (pRpc->handle == NULL) return; - if (code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - if (code != 0) code = terrno; + if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + if (code != 0) { + code = terrno; + dError("msg:%p, failed to process since %s", pMsg, terrstr()); + } SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; dndSendRsp(pMgmt->pWrapper, &rsp); } @@ -47,7 +49,7 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { static void mmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SMnodeMgmt *pMgmt = pInfo->ahandle; - dTrace("msg:%p, will be processed in mnode queue", pMsg); + dTrace("msg:%p, get from mnode query queue", pMsg); SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; @@ -55,8 +57,8 @@ static void mmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { code = mndProcessMsg(pMsg); if (pRpc->msgType & 1U) { - if (pRpc->handle == NULL) return; - if (code != 0) { + if (pRpc->handle != NULL && code != 0) { + dError("msg:%p, failed to process since %s", pMsg, terrstr()); SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .ahandle = pRpc->ahandle}; dndSendRsp(pMgmt->pWrapper, &rsp); } @@ -67,83 +69,86 @@ static void mmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { taosFreeQitem(pMsg); } - -static int32_t mmPutMsgToWorker(SMnodeMgmt *pMgmt, SSingleWorker *pWorker, SNodeMsg *pMsg) { +static void mmPutMsgToWorker(SSingleWorker *pWorker, SNodeMsg *pMsg) { dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); } -int32_t mmProcessWriteMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->writeWorker, pMsg); +int32_t mmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->writeWorker, pMsg); + return 0; } -int32_t mmProcessSyncMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->syncWorker, pMsg); +int32_t mmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->syncWorker, pMsg); + return 0; } -int32_t mmProcessReadMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->readWorker, pMsg); +int32_t mmProcessReadMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->readWorker, pMsg); + return 0; } -int32_t mmProcessQueryMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->queryWorker, pMsg); +int32_t mmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->queryWorker, pMsg); + return 0; } -static int32_t mmPutRpcMsgToWorker(SMnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) { +static int32_t mmPutRpcMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pRpc) { SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); - if (pMsg == NULL) { - return -1; - } + if (pMsg == NULL) return -1; dTrace("msg:%p, is created and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType)); pMsg->rpcMsg = *pRpc; - - int32_t code = taosWriteQitem(pWorker->queue, pMsg); - if (code != 0) { - dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); - rpcFreeCont(pRpc->pCont); - } - - return code; -} - -int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - return mmPutRpcMsgToWorker(pMgmt, &pMgmt->writeWorker, pRpc); -} - -int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - return mmPutRpcMsgToWorker(pMgmt, &pMgmt->readWorker, pRpc); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { SMnodeMgmt *pMgmt = pWrapper->pMgmt; - return mmPutRpcMsgToWorker(pMgmt, &pMgmt->queryWorker, pRpc); + return mmPutRpcMsgToWorker(&pMgmt->queryWorker, pRpc); } +int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + return mmPutRpcMsgToWorker(&pMgmt->writeWorker, pRpc); +} + +int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + return mmPutRpcMsgToWorker(&pMgmt->readWorker, pRpc); +} + +int32_t mmPutMsgToSyncQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + return mmPutRpcMsgToWorker(&pMgmt->syncWorker, pRpc); +} int32_t mmStartWorker(SMnodeMgmt *pMgmt) { - SSingleWorkerCfg cfg = {.minNum = 0, .maxNum = 1, .name = "mnode-read", .fp = (FItem)mmProcessQueue, .param = pMgmt}; - SSingleWorkerCfg queryCfg = {.minNum = 0, .maxNum = 1, .name = "mnode-query", .fp = (FItem)mmProcessQueryQueue, .param = pMgmt}; - - if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) { + SSingleWorkerCfg qCfg = {.min = 0, .max = 1, .name = "mnode-query", .fp = (FItem)mmProcessQueryQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) { dError("failed to start mnode-query worker since %s", terrstr()); return -1; } - if (tSingleWorkerInit(&pMgmt->readWorker, &cfg) != 0) { + SSingleWorkerCfg rCfg = {.min = 0, .max = 1, .name = "mnode-read", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->readWorker, &rCfg) != 0) { dError("failed to start mnode-read worker since %s", terrstr()); return -1; } - if (tSingleWorkerInit(&pMgmt->writeWorker, &cfg) != 0) { + SSingleWorkerCfg wCfg = {.min = 0, .max = 1, .name = "mnode-write", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->writeWorker, &wCfg) != 0) { dError("failed to start mnode-write worker since %s", terrstr()); return -1; } - if (tSingleWorkerInit(&pMgmt->syncWorker, &cfg) != 0) { + SSingleWorkerCfg sCfg = {.min = 0, .max = 1, .name = "mnode-sync", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->syncWorker, &sCfg) != 0) { dError("failed to start mnode sync-worker since %s", terrstr()); return -1; } @@ -153,8 +158,8 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) { } void mmStopWorker(SMnodeMgmt *pMgmt) { - tSingleWorkerCleanup(&pMgmt->readWorker); tSingleWorkerCleanup(&pMgmt->queryWorker); + tSingleWorkerCleanup(&pMgmt->readWorker); tSingleWorkerCleanup(&pMgmt->writeWorker); tSingleWorkerCleanup(&pMgmt->syncWorker); dDebug("mnode workers are closed"); diff --git a/source/dnode/mgmt/mnode/src/mmMsg.c b/source/dnode/mgmt/mnode/src/mmMsg.c deleted file mode 100644 index d04077baf8..0000000000 --- a/source/dnode/mgmt/mnode/src/mmMsg.c +++ /dev/null @@ -1,165 +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 "mmInt.h" - -int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDCreateMnodeReq createReq = {0}; - if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (createReq.replica <= 1 || createReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_NODE_INVALID_OPTION; - dError("failed to create mnode since %s", terrstr()); - return -1; - } else { - return mmOpenFromMsg(pWrapper, &createReq); - } -} - -int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDDropMnodeReq dropReq = {0}; - if (tDeserializeSMCreateDropMnodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (dropReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_NODE_INVALID_OPTION; - dError("failed to drop mnode since %s", terrstr()); - return -1; - } else { - return mmDrop(pWrapper); - } -} - -int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SDnode *pDnode = pMgmt->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDAlterMnodeReq alterReq = {0}; - if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (alterReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_NODE_INVALID_OPTION; - dError("failed to alter mnode since %s", terrstr()); - return -1; - } else { - return mmAlter(pMgmt, &alterReq); - } -} - -void mmInitMsgHandles(SMgmtWrapper *pWrapper) { - // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - - // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_CONNECT, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_USE_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - - // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - -} 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 92% rename from source/dnode/mgmt/qnode/inc/qmInt.h rename to source/dnode/mgmt/qm/inc/qmInt.h index 52d23a445c..3e975663d3 100644 --- a/source/dnode/mgmt/qnode/inc/qmInt.h +++ b/source/dnode/mgmt/qm/inc/qmInt.h @@ -48,8 +48,8 @@ int32_t qmGetQueueSize(SMgmtWrapper *pWrapper, int32_t vgId, EQueueType qtype); int32_t qmStartWorker(SQnodeMgmt *pMgmt); void qmStopWorker(SQnodeMgmt *pMgmt); -int32_t qmProcessQueryMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t qmProcessFetchMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t qmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t qmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } 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 69% rename from source/dnode/mgmt/qnode/src/qmMsg.c rename to source/dnode/mgmt/qm/src/qmMsg.c index ebe6477e81..da5ba6472a 100644 --- a/source/dnode/mgmt/qnode/src/qmMsg.c +++ b/source/dnode/mgmt/qm/src/qmMsg.c @@ -56,14 +56,14 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { void qmInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)qmProcessQueryMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)qmProcessQueryMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, qmProcessFetchMsg, QND_VGID); } diff --git a/source/dnode/mgmt/qnode/src/qmWorker.c b/source/dnode/mgmt/qm/src/qmWorker.c similarity index 84% rename from source/dnode/mgmt/qnode/src/qmWorker.c rename to source/dnode/mgmt/qm/src/qmWorker.c index aa4da82790..14efb311b1 100644 --- a/source/dnode/mgmt/qnode/src/qmWorker.c +++ b/source/dnode/mgmt/qm/src/qmWorker.c @@ -49,14 +49,22 @@ static void qmProcessFetchQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { taosFreeQitem(pMsg); } -static int32_t qmPutMsgToWorker(SSingleWorker *pWorker, SNodeMsg *pMsg) { +static void qmPutMsgToWorker(SSingleWorker *pWorker, SNodeMsg *pMsg) { dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); } -int32_t qmProcessQueryMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg) { return qmPutMsgToWorker(&pMgmt->queryWorker, pMsg); } +int32_t qmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SQnodeMgmt *pMgmt = pWrapper->pMgmt; + qmPutMsgToWorker(&pMgmt->queryWorker, pMsg); + return 0; +} -int32_t qmProcessFetchMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg) { return qmPutMsgToWorker(&pMgmt->fetchWorker, pMsg); } +int32_t qmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SQnodeMgmt *pMgmt = pWrapper->pMgmt; + qmPutMsgToWorker(&pMgmt->fetchWorker, pMsg); + return 0; +} static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) { SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); @@ -66,15 +74,8 @@ static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SR dTrace("msg:%p, is created and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType)); pMsg->rpcMsg = *pRpc; - - int32_t code = taosWriteQitem(pWorker->queue, pMsg); - if (code != 0) { - dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); - rpcFreeCont(pRpc->pCont); - } - - return code; + taosWriteQitem(pWorker->queue, pMsg); + return 0; } int32_t qmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { @@ -110,8 +111,8 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) { int32_t minQueryThreads = TMAX((int32_t)(tsNumOfCores * tsRatioOfQueryCores), 1); int32_t maxQueryThreads = minQueryThreads; - SSingleWorkerCfg queryCfg = {.minNum = minQueryThreads, - .maxNum = maxQueryThreads, + SSingleWorkerCfg queryCfg = {.min = minQueryThreads, + .max = maxQueryThreads, .name = "qnode-query", .fp = (FItem)qmProcessQueryQueue, .param = pMgmt}; @@ -121,8 +122,8 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) { return -1; } - SSingleWorkerCfg fetchCfg = {.minNum = minFetchThreads, - .maxNum = maxFetchThreads, + SSingleWorkerCfg fetchCfg = {.min = minFetchThreads, + .max = maxFetchThreads, .name = "qnode-fetch", .fp = (FItem)qmProcessFetchQueue, .param = pMgmt}; 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 84% rename from source/dnode/mgmt/snode/inc/smInt.h rename to source/dnode/mgmt/sm/inc/smInt.h index f2b510483c..9290384cab 100644 --- a/source/dnode/mgmt/snode/inc/smInt.h +++ b/source/dnode/mgmt/sm/inc/smInt.h @@ -46,10 +46,10 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); // smWorker.c int32_t smStartWorker(SSnodeMgmt *pMgmt); void smStopWorker(SSnodeMgmt *pMgmt); -int32_t smProcessMgmtMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t smProcessUniqueMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t smProcessSharedMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t smProcessExecMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t smProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessUniqueMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessSharedMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessExecMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } 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 91% rename from source/dnode/mgmt/snode/src/smMsg.c rename to source/dnode/mgmt/sm/src/smMsg.c index aea1dded56..c522ef7fc3 100644 --- a/source/dnode/mgmt/snode/src/smMsg.c +++ b/source/dnode/mgmt/sm/src/smMsg.c @@ -56,6 +56,6 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { void smInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by SNODE - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, (NodeMsgFp)smProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, (NodeMsgFp)smProcessExecMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, VND_VGID); } diff --git a/source/dnode/mgmt/snode/src/smWorker.c b/source/dnode/mgmt/sm/src/smWorker.c similarity index 80% rename from source/dnode/mgmt/snode/src/smWorker.c rename to source/dnode/mgmt/sm/src/smWorker.c index 5913713ff3..0326d7dd9f 100644 --- a/source/dnode/mgmt/snode/src/smWorker.c +++ b/source/dnode/mgmt/sm/src/smWorker.c @@ -57,7 +57,7 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { return -1; } - SMultiWorkerCfg cfg = {.maxNum = 1, .name = "snode-unique", .fp = smProcessUniqueQueue, .param = pMgmt}; + SMultiWorkerCfg cfg = {.max = 1, .name = "snode-unique", .fp = smProcessUniqueQueue, .param = pMgmt}; if (tMultiWorkerInit(pUniqueWorker, &cfg) != 0) { dError("failed to start snode-unique worker since %s", terrstr()); @@ -69,8 +69,8 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { } } - SSingleWorkerCfg cfg = {.minNum = SND_SHARED_THREAD_NUM, - .maxNum = SND_SHARED_THREAD_NUM, + SSingleWorkerCfg cfg = {.min = SND_SHARED_THREAD_NUM, + .max = SND_SHARED_THREAD_NUM, .name = "snode-shared", .fp = (FItem)smProcessSharedQueue, .param = pMgmt}; @@ -107,7 +107,8 @@ static FORCE_INLINE int32_t smGetSWTypeFromMsg(SRpcMsg *pMsg) { return 0; } -int32_t smProcessMgmtMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t smProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, 0); if (pWorker == NULL) { terrno = TSDB_CODE_INVALID_MSG; @@ -115,10 +116,12 @@ int32_t smProcessMgmtMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { } dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } -int32_t smProcessUniqueMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t smProcessUniqueMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; int32_t index = smGetSWIdFromMsg(&pMsg->rpcMsg); SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, index); if (pWorker == NULL) { @@ -127,21 +130,24 @@ int32_t smProcessUniqueMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { } dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } -int32_t smProcessSharedMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t smProcessSharedMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->sharedWorker; dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } -int32_t smProcessExecMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { - int32_t workerType = smGetSWTypeFromMsg(&pMsg->rpcMsg); +int32_t smProcessExecMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + int32_t workerType = smGetSWTypeFromMsg(&pMsg->rpcMsg); if (workerType == SND_WORKER_TYPE__SHARED) { - return smProcessSharedMsg(pMgmt, pMsg); + return smProcessSharedMsg(pWrapper, pMsg); } else { - return smProcessUniqueMsg(pMgmt, pMsg); + return smProcessUniqueMsg(pWrapper, pMsg); } } 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 89% rename from source/dnode/mgmt/vnode/inc/vmInt.h rename to source/dnode/mgmt/vm/inc/vmInt.h index 197c606a0d..6722fe1d65 100644 --- a/source/dnode/mgmt/vnode/inc/vmInt.h +++ b/source/dnode/mgmt/vm/inc/vmInt.h @@ -108,12 +108,12 @@ int32_t vmPutMsgToFetchQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); int32_t vmPutMsgToApplyQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); int32_t vmGetQueueSize(SMgmtWrapper *pWrapper, int32_t vgId, EQueueType qtype); -int32_t vmProcessWriteMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessSyncMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessQueryMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessFetchMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessMergeMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessMgmtMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); +int32_t vmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessMergeMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessMgmtMsg(SMgmtWrapper *pWrappert, SNodeMsg *pMsg); #ifdef __cplusplus } 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..e40c2658e4 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) { diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vm/src/vmMsg.c similarity index 95% rename from source/dnode/mgmt/vnode/src/vmMsg.c rename to source/dnode/mgmt/vm/src/vmMsg.c index 1682c6043d..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; @@ -281,11 +282,12 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { 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, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, VND_VGID); } diff --git a/source/dnode/mgmt/vnode/src/vmWorker.c b/source/dnode/mgmt/vm/src/vmWorker.c similarity index 88% rename from source/dnode/mgmt/vnode/src/vmWorker.c rename to source/dnode/mgmt/vm/src/vmWorker.c index 7b6d78a60c..193807317f 100644 --- a/source/dnode/mgmt/vnode/src/vmWorker.c +++ b/source/dnode/mgmt/vm/src/vmWorker.c @@ -179,9 +179,7 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO } static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueType qtype) { - SRpcMsg *pRpc = &pMsg->rpcMsg; - int32_t code = -1; - + SRpcMsg *pRpc = &pMsg->rpcMsg; SMsgHead *pHead = pRpc->pCont; pHead->contLen = ntohl(pHead->contLen); pHead->vgId = ntohl(pHead->vgId); @@ -192,28 +190,30 @@ static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueTyp return -1; } + int32_t code = 0; switch (qtype) { case QUERY_QUEUE: dTrace("msg:%p, will be written into vnode-query queue", pMsg); - code = taosWriteQitem(pVnode->pQueryQ, pMsg); + taosWriteQitem(pVnode->pQueryQ, pMsg); break; case FETCH_QUEUE: dTrace("msg:%p, will be written into vnode-fetch queue", pMsg); - code = taosWriteQitem(pVnode->pFetchQ, pMsg); + taosWriteQitem(pVnode->pFetchQ, pMsg); break; case WRITE_QUEUE: dTrace("msg:%p, will be written into vnode-write queue", pMsg); - code = taosWriteQitem(pVnode->pWriteQ, pMsg); + taosWriteQitem(pVnode->pWriteQ, pMsg); break; case SYNC_QUEUE: dTrace("msg:%p, will be written into vnode-sync queue", pMsg); - code = taosWriteQitem(pVnode->pSyncQ, pMsg); + taosWriteQitem(pVnode->pSyncQ, pMsg); break; case MERGE_QUEUE: dTrace("msg:%p, will be written into vnode-merge queue", pMsg); - code = taosWriteQitem(pVnode->pMergeQ, pMsg); + taosWriteQitem(pVnode->pMergeQ, pMsg); break; default: + code = -1; terrno = TSDB_CODE_INVALID_PARA; break; } @@ -222,52 +222,73 @@ static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueTyp return code; } -int32_t vmProcessSyncMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); } +int32_t vmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); +} -int32_t vmProcessWriteMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); } +int32_t vmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); +} -int32_t vmProcessQueryMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); } +int32_t vmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); +} -int32_t vmProcessFetchMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); } +int32_t vmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); +} -int32_t vmProcessMergeMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, MERGE_QUEUE); } +int32_t vmProcessMergeMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, MERGE_QUEUE); +} -int32_t vmProcessMgmtMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t vmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->mgmtWorker; dTrace("msg:%p, will be written to vnode-mgmt queue, worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } static int32_t vmPutRpcMsgToQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, EQueueType qtype) { SVnodesMgmt *pMgmt = pWrapper->pMgmt; - int32_t code = -1; SMsgHead *pHead = pRpc->pCont; SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId); if (pVnode == NULL) return -1; SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); - if (pMsg != NULL) { + int32_t code = 0; + + if (pMsg == NULL) { + code = -1; + } else { dTrace("msg:%p, is created, type:%s", pMsg, TMSG_INFO(pRpc->msgType)); pMsg->rpcMsg = *pRpc; switch (qtype) { case QUERY_QUEUE: dTrace("msg:%p, will be put into vnode-query queue", pMsg); - code = taosWriteQitem(pVnode->pQueryQ, pMsg); + taosWriteQitem(pVnode->pQueryQ, pMsg); break; case FETCH_QUEUE: dTrace("msg:%p, will be put into vnode-fetch queue", pMsg); - code = taosWriteQitem(pVnode->pFetchQ, pMsg); + taosWriteQitem(pVnode->pFetchQ, pMsg); break; case APPLY_QUEUE: dTrace("msg:%p, will be put into vnode-apply queue", pMsg); - code = taosWriteQitem(pVnode->pApplyQ, pMsg); + taosWriteQitem(pVnode->pApplyQ, pMsg); break; case MERGE_QUEUE: dTrace("msg:%p, will be put into vnode-merge queue", pMsg); - code = taosWriteQitem(pVnode->pMergeQ, pMsg); + taosWriteQitem(pVnode->pMergeQ, pMsg); break; default: + code = -1; terrno = TSDB_CODE_INVALID_PARA; break; } @@ -394,7 +415,7 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) { if (tWWorkerInit(pWPool) != 0) return -1; SSingleWorkerCfg cfg = { - .minNum = 1, .maxNum = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt}; + .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/mndDb.h b/source/dnode/mnode/impl/inc/mndDb.h index 125b0d3191..c0b25d74d1 100644 --- a/source/dnode/mnode/impl/inc/mndDb.h +++ b/source/dnode/mnode/impl/inc/mndDb.h @@ -28,6 +28,7 @@ SDbObj *mndAcquireDb(SMnode *pMnode, const char *db); void mndReleaseDb(SMnode *pMnode, SDbObj *pDb); int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, void **ppRsp, int32_t *pRspLen); char *mnGetDbStr(char *src); +int32_t mndExtractDbInfo(SMnode *pMnode, SDbObj *pDb, SUseDbRsp *pRsp, const SUseDbReq *pReq); #ifdef __cplusplus } 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/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 05c7d79a1a..bd66bdeae9 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -276,6 +276,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->quorum > pCfg->replications) return -1; if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) return -1; if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1; + if (pCfg->streamMode < TSDB_MIN_DB_STREAM_MODE || pCfg->streamMode > TSDB_MAX_DB_STREAM_MODE) return -1; return TSDB_CODE_SUCCESS; } @@ -285,8 +286,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS; if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; if (pCfg->daysToKeep0 < 0) pCfg->daysToKeep0 = TSDB_DEFAULT_KEEP; - if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = TSDB_DEFAULT_KEEP; - if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = TSDB_DEFAULT_KEEP; + if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep0; + if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep1; if (pCfg->minRows < 0) pCfg->minRows = TSDB_DEFAULT_MIN_ROW_FBLOCK; if (pCfg->maxRows < 0) pCfg->maxRows = TSDB_DEFAULT_MAX_ROW_FBLOCK; if (pCfg->commitTime < 0) pCfg->commitTime = TSDB_DEFAULT_COMMIT_TIME; @@ -298,6 +299,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->quorum < 0) pCfg->quorum = TSDB_DEFAULT_DB_QUORUM_OPTION; if (pCfg->update < 0) pCfg->update = TSDB_DEFAULT_DB_UPDATE_OPTION; if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; + if (pCfg->streamMode < 0) pCfg->streamMode = TSDB_DEFAULT_DB_STREAM_MODE; + if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0; } static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) { @@ -431,11 +434,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate .daysToKeep2 = pCreate->daysToKeep2, .minRows = pCreate->minRows, .maxRows = pCreate->maxRows, - .fsyncPeriod = pCreate->fsyncPeriod, .commitTime = pCreate->commitTime, + .fsyncPeriod = pCreate->fsyncPeriod, + .walLevel = pCreate->walLevel, .precision = pCreate->precision, .compression = pCreate->compression, - .walLevel = pCreate->walLevel, .replications = pCreate->replications, .quorum = pCreate->quorum, .update = pCreate->update, @@ -445,7 +448,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate dbObj.cfg.numOfRetensions = pCreate->numOfRetensions; dbObj.cfg.pRetensions = pCreate->pRetensions; - pCreate = NULL; + pCreate->pRetensions = NULL; mndSetDefaultDbCfg(&dbObj.cfg); @@ -955,7 +958,6 @@ void mndGetDBTableNum(SDbObj *pDb, SMnode *pMnode, int32_t *num) { sdbCancelFetch(pSdb, pIter); } - static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { int32_t vindex = 0; SSdb *pSdb = pMnode->pSdb; @@ -991,7 +993,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { } sdbRelease(pSdb, pVgroup); - + if (pDb && (vindex >= pDb->cfg.numOfVgroups)) { break; } @@ -1000,6 +1002,28 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { sdbCancelFetch(pSdb, pIter); } +int32_t mndExtractDbInfo(SMnode *pMnode, SDbObj *pDb, SUseDbRsp *pRsp, const SUseDbReq *pReq) { + pRsp->pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); + if (pRsp->pVgroupInfos == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + int32_t numOfTable = 0; + mndGetDBTableNum(pDb, pMnode, &numOfTable); + + if (pReq == NULL || pReq->vgVersion < pDb->vgVersion || pReq->dbId != pDb->uid || numOfTable != pReq->numOfTable) { + mndBuildDBVgroupInfo(pDb, pMnode, pRsp->pVgroupInfos); + } + + memcpy(pRsp->db, pDb->name, TSDB_DB_FNAME_LEN); + pRsp->uid = pDb->uid; + pRsp->vgVersion = pDb->vgVersion; + pRsp->vgNum = taosArrayGetSize(pRsp->pVgroupInfos); + pRsp->hashMethod = pDb->hashMethod; + return 0; +} + static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { SMnode *pMnode = pReq->pNode; int32_t code = -1; @@ -1023,10 +1047,10 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto USE_DB_OVER; } - + mndBuildDBVgroupInfo(NULL, pMnode, usedbRsp.pVgroupInfos); usedbRsp.vgVersion = vgVersion++; - + if (taosArrayGetSize(usedbRsp.pVgroupInfos) <= 0) { terrno = TSDB_CODE_MND_DB_NOT_EXIST; } @@ -1034,7 +1058,7 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { usedbRsp.vgVersion = usedbReq.vgVersion; code = 0; } - usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos); + usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos); // no jump, need to construct rsp } else { @@ -1057,24 +1081,10 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { goto USE_DB_OVER; } - usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); - if (usedbRsp.pVgroupInfos == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + if (mndExtractDbInfo(pMnode, pDb, &usedbRsp, &usedbReq) < 0) { goto USE_DB_OVER; } - int32_t numOfTable = 0; - mndGetDBTableNum(pDb, pMnode, &numOfTable); - - if (usedbReq.vgVersion < pDb->vgVersion || usedbReq.dbId != pDb->uid || numOfTable != usedbReq.numOfTable) { - mndBuildDBVgroupInfo(pDb, pMnode, usedbRsp.pVgroupInfos); - } - - memcpy(usedbRsp.db, pDb->name, TSDB_DB_FNAME_LEN); - usedbRsp.uid = pDb->uid; - usedbRsp.vgVersion = pDb->vgVersion; - usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos); - usedbRsp.hashMethod = pDb->hashMethod; code = 0; } } @@ -1138,7 +1148,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, mndReleaseDb(pMnode, pDb); continue; } - + usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); if (usedbRsp.pVgroupInfos == NULL) { mndReleaseDb(pMnode, pDb); @@ -1364,11 +1374,11 @@ static int32_t mndGetDbMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMet pSchema[cols].bytes = pShow->bytes[cols]; cols++; -// pShow->bytes[cols] = 1; -// pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; -// strcpy(pSchema[cols].name, "update"); -// pSchema[cols].bytes = pShow->bytes[cols]; -// cols++; + // pShow->bytes[cols] = 1; + // pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; + // strcpy(pSchema[cols].name, "update"); + // pSchema[cols].bytes = pShow->bytes[cols]; + // cols++; pMeta->numOfColumns = cols; pShow->numOfColumns = cols; @@ -1396,14 +1406,15 @@ char *mnGetDbStr(char *src) { return pos; } -static char* getDataPosition(char* pData, SShowObj* pShow, int32_t cols, int32_t rows, int32_t capacityOfRow) { +static char *getDataPosition(char *pData, SShowObj *pShow, int32_t cols, int32_t rows, int32_t capacityOfRow) { return pData + pShow->offset[cols] * capacityOfRow + pShow->bytes[cols] * rows; } -static void dumpDbInfoToPayload(char* data, SDbObj* pDb, SShowObj* pShow, int32_t rows, int32_t rowCapacity, int64_t numOfTables) { +static void dumpDbInfoToPayload(char *data, SDbObj *pDb, SShowObj *pShow, int32_t rows, int32_t rowCapacity, + int64_t numOfTables) { int32_t cols = 0; - char* pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + char *pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); char *name = mnGetDbStr(pDb->name); if (name != NULL) { STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); @@ -1497,20 +1508,28 @@ static void dumpDbInfoToPayload(char* data, SDbObj* pDb, SShowObj* pShow, int32_ STR_WITH_SIZE_TO_VARSTR(pWrite, prec, 2); cols++; -// pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); -// *(int8_t *)pWrite = pDb->cfg.update; + // pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + // *(int8_t *)pWrite = pDb->cfg.update; } -static void setInformationSchemaDbCfg(SDbObj* pDbObj) { +static void setInformationSchemaDbCfg(SDbObj *pDbObj) { ASSERT(pDbObj != NULL); strncpy(pDbObj->name, TSDB_INFORMATION_SCHEMA_DB, tListLen(pDbObj->name)); - pDbObj->createdTime = 0; + pDbObj->createdTime = 0; pDbObj->cfg.numOfVgroups = 0; - pDbObj->cfg.quorum = 1; + pDbObj->cfg.quorum = 1; pDbObj->cfg.replications = 1; - pDbObj->cfg.update = 1; - pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; + pDbObj->cfg.update = 1; + pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; +} + +static bool mndGetTablesOfDbFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) { + SVgObj *pVgroup = pObj; + int32_t *numOfTables = p1; + + *numOfTables += pVgroup->numOfTables; + return true; } static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rowsCapacity) { @@ -1525,7 +1544,10 @@ static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 break; } - dumpDbInfoToPayload(data, pDb, pShow, numOfRows, rowsCapacity, 0); + int32_t numOfTables = 0; + sdbTraverse(pSdb, SDB_VGROUP, mndGetTablesOfDbFp, &numOfTables, NULL, NULL); + + dumpDbInfoToPayload(data, pDb, pShow, numOfRows, rowsCapacity, numOfTables); numOfRows++; sdbRelease(pSdb, pDb); } 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 697811cd04..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,8 +324,56 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i /*pTask->sinkType = TASK_SINK__NONE;*/ // dispatch part - pTask->dispatchType = TASK_DISPATCH__SHUFFLE; - pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; + 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; + } + } +#endif // exec part pTask->execType = TASK_EXEC__MERGE; 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..c0f591d1f2 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -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/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 7d3f755cd7..469805387f 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -87,12 +87,6 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) { return -1; } -#if 0 - if (mndCreateDefaultUser(pMnode, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { - return -1; - } -#endif - return 0; } diff --git a/source/dnode/vnode/src/inc/tsdbReadImpl.h b/source/dnode/vnode/src/inc/tsdbReadImpl.h index cd24358b27..17c220a35a 100644 --- a/source/dnode/vnode/src/inc/tsdbReadImpl.h +++ b/source/dnode/vnode/src/inc/tsdbReadImpl.h @@ -67,12 +67,13 @@ typedef struct { uint8_t last : 1; uint8_t blkVer : 7; uint8_t numOfSubBlocks; - int16_t numOfCols; // not including timestamp column + col_id_t numOfCols; // not including timestamp column uint32_t len; // data block length - uint32_t keyLen : 24; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols + uint32_t keyLen : 20; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols + uint32_t algorithm : 4; uint32_t reserve : 8; - int32_t algorithm : 8; - int32_t numOfRows : 24; + col_id_t numOfBSma; + uint16_t numOfRows; int64_t offset; uint64_t aggrStat : 1; uint64_t aggrOffset : 63; @@ -80,7 +81,7 @@ typedef struct { TSKEY keyLast; } SBlockV0; -#define SBlock SBlockV0 // latest SBlock definition +#define SBlock SBlockV0 // latest SBlock definition #endif diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 7b0606512c..5ec5b1d58f 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -19,15 +19,14 @@ #include "tmallocator.h" // #include "sync.h" #include "tcoding.h" +#include "tdatablock.h" #include "tfs.h" #include "tlist.h" #include "tlockfree.h" #include "tmacro.h" -#include "wal.h" - #include "vnode.h" - #include "vnodeQuery.h" +#include "wal.h" #ifdef __cplusplus extern "C" { @@ -203,7 +202,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); // sma -void smaHandleRes(SVnode* pVnode, int64_t smaId, const SArray* data); +void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 55202335e0..fce423d811 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 { @@ -356,6 +356,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { void* buf = rpcMallocCont(tlen); if (buf == NULL) { pMsg->code = -1; + ASSERT(0); return -1; } ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; @@ -367,7 +368,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { pMsg->pCont = buf; pMsg->contLen = tlen; pMsg->code = 0; - rpcSendResponse(pMsg); + tmsgSendRsp(pMsg); /*}*/ return 0; @@ -473,10 +474,16 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { } tCoderClear(&decoder); + // exec if (tqExpandTask(pTq, pTask, 4) < 0) { ASSERT(0); } + + // sink pTask->ahandle = pTq->pVnode; + if (pTask->sinkType == TASK_SINK__SMA) { + pTask->smaSink.smaHandle = smaHandleRes; + } taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask)); @@ -502,7 +509,9 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) { 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); diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 8c161e4c8b..3d9d9a90dd 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,9 @@ 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); + // TODO handle null + colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL); } -#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; - } - // 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/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index eb8df61051..3e0b03f331 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -43,20 +43,20 @@ typedef struct { #define TSDB_DEFAULT_BLOCK_ROWS(maxRows) ((maxRows)*4 / 5) -#define TSDB_COMMIT_REPO(ch) TSDB_READ_REPO(&(ch->readh)) -#define TSDB_COMMIT_REPO_ID(ch) REPO_ID(TSDB_READ_REPO(&(ch->readh))) -#define TSDB_COMMIT_WRITE_FSET(ch) (&((ch)->wSet)) -#define TSDB_COMMIT_TABLE(ch) ((ch)->pTable) -#define TSDB_COMMIT_HEAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_HEAD) -#define TSDB_COMMIT_DATA_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_DATA) -#define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST) -#define TSDB_COMMIT_SMAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAD) -#define TSDB_COMMIT_SMAL_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAL) -#define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh)) -#define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh)) -#define TSDB_COMMIT_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh)) +#define TSDB_COMMIT_REPO(ch) TSDB_READ_REPO(&(ch->readh)) +#define TSDB_COMMIT_REPO_ID(ch) REPO_ID(TSDB_READ_REPO(&(ch->readh))) +#define TSDB_COMMIT_WRITE_FSET(ch) (&((ch)->wSet)) +#define TSDB_COMMIT_TABLE(ch) ((ch)->pTable) +#define TSDB_COMMIT_HEAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_HEAD) +#define TSDB_COMMIT_DATA_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_DATA) +#define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST) +#define TSDB_COMMIT_SMAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAD) +#define TSDB_COMMIT_SMAL_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAL) +#define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh)) +#define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh)) +#define TSDB_COMMIT_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh)) #define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->config.maxRowsPerFileBlock) -#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) +#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) static void tsdbStartCommit(STsdb *pRepo); static void tsdbEndCommit(STsdb *pTsdb, int eno); @@ -1204,9 +1204,10 @@ static int tsdbComparKeyBlock(const void *arg1, const void *arg2) { int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDFileAggr, SDataCols *pDataCols, SBlock *pBlock, bool isLast, bool isSuper, void **ppBuf, void **ppCBuf, void **ppExBuf) { - STsdbCfg * pCfg = REPO_CFG(pRepo); - SBlockData * pBlockData = NULL; + STsdbCfg *pCfg = REPO_CFG(pRepo); + SBlockData *pBlockData = NULL; SAggrBlkData *pAggrBlkData = NULL; + STSchema *pSchema = pTable->pSchema; int64_t offset = 0, offsetAggr = 0; int rowsToWrite = pDataCols->numOfRows; @@ -1225,10 +1226,12 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF pAggrBlkData = (SAggrBlkData *)(*ppExBuf); // Get # of cols not all NULL(not including key column) - int nColsNotAllNull = 0; + col_id_t nColsNotAllNull = 0; + col_id_t nColsOfBlockSma = 0; for (int ncol = 1; ncol < pDataCols->numOfCols; ++ncol) { // ncol from 1, we skip the timestamp column - SDataCol * pDataCol = pDataCols->cols + ncol; - SBlockCol * pBlockCol = pBlockData->cols + nColsNotAllNull; + STColumn *pColumn = pSchema->columns + ncol; + SDataCol *pDataCol = pDataCols->cols + ncol; + SBlockCol *pBlockCol = pBlockData->cols + nColsNotAllNull; SAggrBlkCol *pAggrBlkCol = (SAggrBlkCol *)pAggrBlkData + nColsNotAllNull; if (isAllRowsNull(pDataCol)) { // all data to commit are NULL, just ignore it @@ -1260,7 +1263,12 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF } else { TD_SET_COL_ROWS_MISC(pBlockCol); } - nColsNotAllNull++; + + ++nColsNotAllNull; + + if (pColumn->sma) { + ++nColsOfBlockSma; + } } ASSERT(nColsNotAllNull >= 0 && nColsNotAllNull <= pDataCols->numOfCols); @@ -1357,9 +1365,8 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF return -1; } - uint32_t aggrStatus = nColsNotAllNull > 0 ? 1 : 0; + uint32_t aggrStatus = nColsOfBlockSma > 0 ? 1 : 0; if (aggrStatus > 0) { - taosCalcChecksumAppend(0, (uint8_t *)pAggrBlkData, tsizeAggr); tsdbUpdateDFileMagic(pDFileAggr, POINTER_SHIFT(pAggrBlkData, tsizeAggr - sizeof(TSCKSUM))); @@ -1378,6 +1385,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF pBlock->keyLen = keyLen; pBlock->numOfSubBlocks = isSuper ? 1 : 0; pBlock->numOfCols = nColsNotAllNull; + pBlock->numOfBSma = nColsOfBlockSma; pBlock->keyFirst = dataColsKeyFirst(pDataCols); pBlock->keyLast = dataColsKeyLast(pDataCols); pBlock->aggrStat = aggrStatus; diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index 9619ac036e..304b3286fe 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -321,7 +321,7 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) { return -1; } - size_t sizeAggr = tsdbBlockAggrSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer); + size_t sizeAggr = tsdbBlockAggrSize(pBlock->numOfBSma, (uint32_t)pBlock->blkVer); if (tsdbMakeRoom((void **)(&(pReadh->pAggrBlkData)), sizeAggr) < 0) return -1; int64_t nreadAggr = tsdbReadDFile(pDFileAggr, (void *)(pReadh->pAggrBlkData), sizeAggr); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 74d7558e0d..8ebdad48f7 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -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 98256e6b24..c220e6001f 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -15,6 +15,11 @@ #include "vnd.h" +void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { + // TODO + blockDebugShowData(data); +} + void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { SNodeMsg *pMsg; SRpcMsg *pRpc; @@ -184,12 +189,16 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } } break; case TDMT_VND_CREATE_SMA: { // timeRangeSMA -#if 0 +#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)); return -1; } + vWarn("vgId%d: TDMT_VND_CREATE_SMA received for %s:%" PRIi64, pVnode->config.vgId, vCreateSmaReq.tSma.indexName, + vCreateSmaReq.tSma.indexUid); // record current timezone of server side tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 29a4b7f552..d010ea4437 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -330,7 +330,6 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); // step 2: insert data - STSmaDataWrapper *pSmaData = NULL; STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb)); STsdbCfg *pCfg = &pTsdb->config; @@ -416,6 +415,8 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { col_id_t numOfCols = 4096; ASSERT_GT(numOfCols, 0); +#if 0 + STSmaDataWrapper *pSmaData = NULL; pSmaData = (STSmaDataWrapper *)buf; printf(">> allocate [%d] time to %d and addr is %p\n", ++allocCnt, bufSize, pSmaData); pSmaData->skey = skey1; @@ -459,9 +460,13 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { pSmaData->dataLen = (len - sizeof(STSmaDataWrapper)); ASSERT_GE(bufSize, pSmaData->dataLen); - // execute ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); +#endif + + SSDataBlock *pSmaData = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); + + // step 3: query uint32_t checkDataCnt = 0; diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 468e2c5431..2bbd16fbd0 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -430,9 +430,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 @@ -469,7 +470,7 @@ typedef struct SOptrBasicInfo { int32_t* rowCellInfoOffset; // offset value for each row result cell info SqlFunctionCtx* pCtx; SSDataBlock* pRes; - int32_t capacity; + int32_t capacity; // TODO remove it } SOptrBasicInfo; //TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset @@ -572,11 +573,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 +596,7 @@ typedef struct SSortedMergeOperatorInfo { SOptrBasicInfo binfo; bool hasVarCol; - SArray *orderInfo; // SArray - bool nullFirst; + SArray* pSortInfo; int32_t numOfSources; SSortHandle *pSortHandle; @@ -613,12 +615,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 +629,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 +655,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, 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..615bcdcdbb 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 { diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index f5124665d5..09cf147335 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) { @@ -1008,9 +1020,9 @@ static void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, int32_t of 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; @@ -1040,7 +1052,7 @@ 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; getNextTimeWindow(pInterval, precision, order, pNext); @@ -1051,7 +1063,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 +1076,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 +1102,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 +1120,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 +1155,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 +1163,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 +1174,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 +1196,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 +1229,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,29 +1263,55 @@ 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(SSDataBlock* pResult, 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 (pCtx[k].fpSet.init == NULL) { // 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); - } else { // TODO: arithmetic and other process. + + pResult->info.rows = pCtx[0].input.numOfRows; + } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_OPERATOR) { + SArray* pBlockList = taosArrayInit(4, POINTER_BYTES); + taosArrayPush(pBlockList, &pSrcBlock); + + SScalarParam dest = {0}; + dest.columnData = taosArrayGet(pResult->pDataBlock, k); + + scalarCalculate(pExpr[k].pExpr->_optrRoot.pRootNode, pBlockList, &dest); + pResult->info.rows = dest.numOfRows; + + taosArrayDestroy(pBlockList); + } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_FUNCTION) { + ASSERT(!fmIsAggFunc(pCtx->functionId)); + + SArray* pBlockList = taosArrayInit(4, POINTER_BYTES); + taosArrayPush(pBlockList, &pSrcBlock); + + SScalarParam dest = {0}; + dest.columnData = taosArrayGet(pResult->pDataBlock, k); + + scalarCalculate((SNode *)pExpr[k].pExpr->_function.pFunctNode, pBlockList, &dest); + pResult->info.rows = dest.numOfRows; + + taosArrayDestroy(pBlockList); + + } else { ASSERT(0); } } - - pResult->info.rows = pCtx[0].input.numOfRows; } 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; @@ -1273,20 +1322,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) { @@ -1298,18 +1347,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); @@ -1325,18 +1374,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; @@ -1348,22 +1398,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))) { @@ -1383,12 +1434,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; } @@ -1396,19 +1448,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); } @@ -1417,17 +1469,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); } @@ -1436,33 +1489,36 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc } } -static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, int32_t tableGroupId) { - STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*) pOperatorInfo->info; +static void 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; int32_t step = 1; - bool ascQuery = true; + bool ascQuery = 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 = ascQuery ? 0 : (pSDataBlock->info.rows - 1); + TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols, pSDataBlock->info.rows, ascQuery); STimeWindow win = getActiveTimeWindow(pResultRowInfo, ts, &pInfo->interval, pInfo->precision, &pInfo->win); - bool masterScan = true; + 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); } @@ -1478,39 +1534,44 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul for (int32_t j = prevIndex; j < curIndex; ++j) { // previous time window may be all closed already. SResultRow* pRes = getResultRow(pResultRowInfo, j); if (pRes->closed) { - assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && resultRowInterpolated(pRes, RESULT_ROW_END_INTERP)); + assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && + resultRowInterpolated(pRes, RESULT_ROW_END_INTERP)); continue; } - 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, 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, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput, + TSDB_ORDER_ASC); STimeWindow nextWin = win; while (1) { @@ -1521,55 +1582,60 @@ 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); + 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, 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 = ascQuery ? (pSDataBlock->info.rows - 1) : 0; saveDataBlockLastRow(pInfo->pRow, pSDataBlock->pDataBlock, rowIndex, pSDataBlock->info.numOfCols); } -// updateResultRowInfoActiveIndex(pResultRowInfo, &pInfo->win, pRuntimeEnv->current->lastKey, true, false); + // 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) { @@ -1580,20 +1646,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); } @@ -1601,8 +1671,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; @@ -1611,14 +1682,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); @@ -1686,9 +1758,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; @@ -1706,13 +1778,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]); @@ -1730,18 +1802,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; @@ -1760,9 +1832,10 @@ 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); } @@ -1777,9 +1850,10 @@ 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); } @@ -1790,25 +1864,27 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { } } -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]; @@ -1825,17 +1901,17 @@ 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, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, + TSDB_ORDER_ASC); pInfo->curWindow.skey = tsList[j]; pInfo->curWindow.ekey = tsList[j]; @@ -1848,15 +1924,15 @@ 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, pInfo->start, pInfo->numOfRows, NULL, pBlock->info.rows, numOfOutput, + TSDB_ORDER_ASC); } static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { @@ -1876,14 +1952,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); @@ -1891,7 +1968,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); @@ -1913,8 +1990,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; @@ -1931,31 +2008,31 @@ static bool functionNeedToExecute(SqlFunctionCtx *pCtx) { } 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; @@ -1965,14 +2042,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; } @@ -1992,7 +2069,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 @@ -2013,109 +2090,8 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) { return TSDB_CODE_SUCCESS; } -static SqlFunctionCtx* createSqlFunctionCtx(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput, - int32_t** rowCellInfoOffset) { - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - - SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); - if (pFuncCtx == NULL) { - return NULL; - } - - *rowCellInfoOffset = taosMemoryCalloc(numOfOutput, sizeof(int32_t)); - if (*rowCellInfoOffset == 0) { - taosMemoryFreeClear(pFuncCtx); - return NULL; - } - - for (int32_t i = 0; i < numOfOutput; ++i) { - SExprBasicInfo *pFunct = &pExpr[i].base; - SqlFunctionCtx* pCtx = &pFuncCtx[i]; -#if 0 - SColIndex *pIndex = &pFunct->colInfo; - - if (TSDB_COL_REQ_NULL(pIndex->flag)) { - pCtx->requireNull = true; - pIndex->flag &= ~(TSDB_COL_NULL); - } else { - pCtx->requireNull = false; - } -#endif -// pCtx->inputBytes = pFunct->colBytes; -// pCtx->inputType = pFunct->colType; - - pCtx->ptsOutputBuf = NULL; - - pCtx->resDataInfo.bytes = pFunct->resSchema.bytes; - pCtx->resDataInfo.type = pFunct->resSchema.type; - - pCtx->order = pQueryAttr->order.order; -// pCtx->functionId = pFunct->functionId; - pCtx->stableQuery = pQueryAttr->stableQuery; -// pCtx->resDataInfo.interBufSize = pFunct->interBytes; - pCtx->start.key = INT64_MIN; - pCtx->end.key = INT64_MIN; - - pCtx->numOfParams = pFunct->numOfParams; - for (int32_t j = 0; j < pCtx->numOfParams; ++j) { - int16_t type = pFunct->pParam[j].param.nType; - int16_t bytes = pFunct->pParam[j].param.nType; - - if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { -// taosVariantCreateFromBinary(&pCtx->param[j], pFunct->param[j].pz, bytes, type); - } else { -// taosVariantCreateFromBinary(&pCtx->param[j], (char *)&pFunct->param[j].i, bytes, type); - } - } - - // set the order information for top/bottom query - int32_t functionId = pCtx->functionId; - - if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) { - int32_t f = getExprFunctionId(&pExpr[0]); - assert(f == FUNCTION_TS || f == FUNCTION_TS_DUMMY); - - pCtx->param[2].i = pQueryAttr->order.order; - pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT; - pCtx->param[3].i = functionId; - pCtx->param[3].nType = TSDB_DATA_TYPE_BIGINT; - - pCtx->param[1].i = pQueryAttr->order.col.colId; - } else if (functionId == FUNCTION_INTERP) { - pCtx->param[2].i = (int8_t)pQueryAttr->fillType; - if (pQueryAttr->fillVal != NULL) { - if (isNull((const char *)&pQueryAttr->fillVal[i], pCtx->inputType)) { - pCtx->param[1].nType = TSDB_DATA_TYPE_NULL; - } else { // todo refactor, taosVariantCreateFromBinary should handle the NULL value - if (pCtx->inputType != TSDB_DATA_TYPE_BINARY && pCtx->inputType != TSDB_DATA_TYPE_NCHAR) { - taosVariantCreateFromBinary(&pCtx->param[1], (char *)&pQueryAttr->fillVal[i], pCtx->inputBytes, pCtx->inputType); - } - } - } - } else if (functionId == FUNCTION_TS_COMP) { - pCtx->param[0].i = pQueryAttr->vgId; //TODO this should be the parameter from client - pCtx->param[0].nType = TSDB_DATA_TYPE_BIGINT; - } else if (functionId == FUNCTION_TWA) { - pCtx->param[1].i = pQueryAttr->window.skey; - pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT; - pCtx->param[2].i = pQueryAttr->window.ekey; - pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT; - } else if (functionId == FUNCTION_ARITHM) { -// pCtx->param[1].pz = (char*) getScalarFuncSupport(pRuntimeEnv->scalarSup, i); - } - } - -// for(int32_t i = 1; i < numOfOutput; ++i) { -// (*rowCellInfoOffset)[i] = (int32_t)((*rowCellInfoOffset)[i - 1] + sizeof(SResultRowEntryInfo) + pExpr[i - 1].base.interBytes); -// } - - setCtxTagColumnInfo(pFuncCtx, numOfOutput); - - return pFuncCtx; -} - 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; } @@ -2129,30 +2105,35 @@ 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]; - if (pExpr->pExpr->_function.pFunctNode != NULL) { + pCtx->functionId = -1; + if (pExpr->pExpr->nodeType == QUERY_NODE_FUNCTION) { SFuncExecEnv env = {0}; pCtx->functionId = pExpr->pExpr->_function.pFunctNode->funcId; - fmGetFuncExecFuncs(pCtx->functionId, &pCtx->fpSet); - pCtx->fpSet.getEnv(pExpr->pExpr->_function.pFunctNode, &env); + if (fmIsAggFunc(pCtx->functionId)) { + fmGetFuncExecFuncs(pCtx->functionId, &pCtx->fpSet); + pCtx->fpSet.getEnv(pExpr->pExpr->_function.pFunctNode, &env); + } else { + fmGetScalarFuncExecFuncs(pCtx->functionId, &pCtx->sfp); + } pCtx->resDataInfo.interBufSize = env.calcMemSize; - } else { - pCtx->functionId = -1; + } 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; @@ -2202,8 +2183,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); @@ -2228,52 +2210,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); @@ -2285,70 +2271,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) { @@ -2359,7 +2346,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) { @@ -2370,7 +2357,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) { @@ -2400,8 +2387,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); @@ -2420,11 +2408,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; } } @@ -2434,7 +2422,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]); @@ -2451,13 +2439,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; @@ -2481,7 +2475,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; @@ -2495,67 +2489,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); @@ -2582,7 +2579,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); @@ -2593,7 +2591,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); @@ -2608,29 +2607,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}; @@ -2639,15 +2640,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; } @@ -2658,15 +2659,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; } @@ -2681,11 +2682,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 @@ -2719,23 +2721,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)) { @@ -2811,7 +2813,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) { @@ -2851,58 +2853,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) { @@ -2914,10 +2917,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; + // } } } @@ -2938,7 +2941,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; @@ -2954,26 +2957,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; @@ -3129,7 +3136,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; @@ -3139,7 +3146,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; @@ -3196,16 +3203,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; @@ -3214,9 +3221,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); } @@ -3225,7 +3232,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]; } @@ -3234,19 +3241,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); @@ -3266,23 +3273,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); } @@ -3302,12 +3309,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)) { @@ -3318,22 +3325,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; @@ -3365,7 +3372,6 @@ static void setupQueryRangeForReverseScan(STableScanInfo* pTableScanInfo) { } } #endif - } void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { @@ -3375,7 +3381,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; } @@ -3390,39 +3396,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) { @@ -3437,16 +3444,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; } } } @@ -3454,16 +3461,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++; } } @@ -3474,18 +3481,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) { @@ -3505,7 +3512,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 { @@ -3515,24 +3522,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; } @@ -3546,11 +3553,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; @@ -3564,7 +3572,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]); } @@ -3578,11 +3586,11 @@ 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) { +static bool hasMainOutput(STaskAttr* pQueryAttr) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]); @@ -3594,19 +3602,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; } @@ -3614,7 +3622,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 @@ -3628,17 +3636,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); @@ -3661,16 +3669,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) { +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 for (int32_t i = 0; i < numOfOutput; ++i) { pCtx[i].resultInfo = getResultCell(pResult, i, rowCellInfoOffset); @@ -3679,13 +3688,13 @@ 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; -// } + // 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); @@ -3693,25 +3702,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; } @@ -3720,7 +3732,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) { @@ -3733,10 +3746,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) { @@ -3744,8 +3757,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; } /* @@ -3760,28 +3774,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); @@ -3824,7 +3840,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; @@ -3859,7 +3876,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; @@ -3894,22 +3912,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}; /** @@ -3922,17 +3940,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; } /** @@ -3944,14 +3962,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) { @@ -3966,7 +3985,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) { @@ -3976,14 +3995,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); @@ -3999,12 +4018,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); @@ -4012,22 +4032,23 @@ 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; //(pQueryAttr->pGroupbyExpr != NULL) ? pQueryAttr->pGroupbyExpr->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; @@ -4041,17 +4062,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; @@ -4062,19 +4083,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(); @@ -4085,7 +4106,7 @@ void publishQueryAbortEvent(SExecTaskInfo * pTaskInfo, int32_t code) { } } -typedef struct { +typedef struct { uint8_t operatorType; int64_t beginTime; int64_t endTime; @@ -4093,7 +4114,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); @@ -4102,7 +4124,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++; @@ -4112,19 +4134,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; } @@ -4133,7 +4154,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) { @@ -4159,280 +4180,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) { @@ -4452,7 +4480,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)) { @@ -4510,10 +4538,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) { @@ -4525,7 +4553,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; @@ -4546,7 +4574,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; @@ -4557,22 +4585,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; } @@ -4590,50 +4618,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); @@ -4648,12 +4676,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; @@ -4666,21 +4694,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); } @@ -4696,9 +4724,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) { @@ -4715,7 +4743,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; @@ -4723,17 +4751,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; } @@ -4742,12 +4770,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); @@ -4762,12 +4790,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}; @@ -4809,11 +4837,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) { @@ -4821,53 +4859,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); @@ -4880,7 +4920,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}; @@ -4900,7 +4940,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)); @@ -4909,11 +4949,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); @@ -4941,13 +4981,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]); @@ -4958,8 +4999,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 { @@ -4974,10 +5015,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); @@ -5006,23 +5046,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); @@ -5041,13 +5083,14 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo *pOperator, SEx 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; @@ -5056,8 +5099,9 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo *pOperator, SEx } 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; } @@ -5065,12 +5109,12 @@ 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); + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pDataInfo->totalRows, + pLoadInfo->totalRows, pLoadInfo->totalSize, i + 1, totalSources); pDataInfo->status = DATA_EXHAUSTED; } else { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 ", totalBytes:%" PRIu64, + qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 + ", totalBytes:%" PRIu64, GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pLoadInfo->totalRows, pLoadInfo->totalSize); } @@ -5096,19 +5140,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; @@ -5116,7 +5160,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); @@ -5124,15 +5169,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; @@ -5141,7 +5186,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; @@ -5149,14 +5195,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); } @@ -5165,14 +5211,15 @@ 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); @@ -5181,35 +5228,37 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo *pOperator) { 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; 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 { @@ -5223,21 +5272,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; } @@ -5265,11 +5315,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) { @@ -5282,7 +5332,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) { @@ -5299,8 +5349,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); } @@ -5309,25 +5359,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; @@ -5336,22 +5386,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); } @@ -5372,12 +5422,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; @@ -5388,12 +5438,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); @@ -5403,26 +5454,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; } @@ -5430,23 +5481,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; } @@ -5454,7 +5505,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}}; @@ -5464,20 +5515,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); @@ -5486,7 +5538,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); @@ -5494,33 +5546,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; } @@ -5528,10 +5587,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; @@ -5546,7 +5604,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); @@ -5566,49 +5624,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) { - return DEAL_RES_CONTINUE; - } - - SColumnNode *node = (SColumnNode *)pNode; - if (TSDB_INS_USER_STABLES_DBNAME_COLID == node->colId) { - *(int32_t *)pContext = 2; + if (1 != *(int32_t*)pContext) { return DEAL_RES_CONTINUE; } - *(int32_t *)pContext = 0; + SColumnNode* node = (SColumnNode*)pNode; + if (TSDB_INS_USER_STABLES_DBNAME_COLID == node->colId) { + *(int32_t*)pContext = 2; + return DEAL_RES_CONTINUE; + } + + *(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); - strncpy(pContext, varDataVal(dbName), varDataLen(dbName)); - *((char *)pContext + varDataLen(dbName)) = 0; + SValueNode* node = (SValueNode*)pNode; + char* dbName = nodesGetValueFromNode(node); + strncpy(pContext, varDataVal(dbName), varDataLen(dbName)); + *((char*)pContext + varDataLen(dbName)) = 0; return DEAL_RES_ERROR; // stop walk } default: @@ -5618,8 +5676,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; } @@ -5627,9 +5684,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 @@ -5640,10 +5697,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}; @@ -5655,19 +5712,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); } } } @@ -5675,9 +5732,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(); @@ -5690,7 +5747,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 @@ -5719,15 +5776,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); } @@ -5736,9 +5794,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); @@ -5746,15 +5805,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; @@ -5771,7 +5830,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) { @@ -5781,7 +5840,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); } @@ -5796,7 +5855,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; @@ -5805,35 +5864,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) { @@ -5852,12 +5911,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)) { @@ -5872,7 +5931,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) { @@ -5881,23 +5940,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); @@ -5906,24 +5965,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); @@ -5938,10 +5997,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) { @@ -5957,7 +6016,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); @@ -5973,10 +6032,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; @@ -5988,17 +6048,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; @@ -6008,7 +6068,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; @@ -6033,27 +6093,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; @@ -6068,10 +6129,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); @@ -6085,11 +6146,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); @@ -6123,13 +6184,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); @@ -6149,7 +6209,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 } @@ -6162,29 +6223,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); @@ -6199,30 +6258,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; } @@ -6235,10 +6272,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); @@ -6258,8 +6295,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; @@ -6270,14 +6307,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) { @@ -6295,25 +6334,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) { @@ -6322,7 +6361,7 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t return pOperator; - _error: +_error: if (pInfo != NULL) { destroySortedMergeOperatorInfo(pInfo, num); } @@ -6333,42 +6372,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); @@ -6376,35 +6415,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; @@ -6412,12 +6435,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; } @@ -6453,15 +6474,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; @@ -6470,38 +6491,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; } } @@ -6520,32 +6541,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; } @@ -6554,7 +6575,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; } @@ -6567,28 +6588,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; @@ -6598,10 +6620,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); @@ -6610,11 +6632,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); @@ -6627,8 +6649,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); } @@ -6637,7 +6660,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); @@ -6646,32 +6670,29 @@ 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); if (pProjectInfo->existDataBlock) { // TODO refactor -// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; SSDataBlock* pBlock = pProjectInfo->existDataBlock; pProjectInfo->existDataBlock = NULL; *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(pInfo->pRes, pInfo->pCtx, pOperator->numOfOutput); - - pRes->info.rows = getNumOfResult(pInfo->pCtx, pOperator->numOfOutput, NULL); - if (pRes->info.rows >= pProjectInfo->binfo.capacity*0.8) { + projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput); + if (pRes->info.rows >= pProjectInfo->binfo.capacity * 0.8) { copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); resetResultRowEntryResult(pInfo->pCtx, pOperator->numOfOutput); return pRes; @@ -6680,7 +6701,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. @@ -6700,7 +6721,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); } } @@ -6713,26 +6734,26 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC); - updateOutputBuf(pInfo, &pInfo->capacity, pBlock->info.rows); + blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); - projectApplyFunctions(pInfo->pRes, pInfo->pCtx, pOperator->numOfOutput); - if (pRes->info.rows >= pProjectInfo->threshold) { + projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput); + if (pRes->info.rows >= pOperator->resultInfo.threshold) { break; } } - 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) { @@ -6749,7 +6770,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; @@ -6778,17 +6799,17 @@ static SSDataBlock* doLimit(SOperatorInfo *pOperator, bool* newgroup) { } static SSDataBlock* doFilter(void* param, bool* newgroup) { - SOperatorInfo *pOperator = (SOperatorInfo *)param; + SOperatorInfo* pOperator = (SOperatorInfo*)param; if (pOperator->status == OP_EXEC_DONE) { return NULL; } SFilterOperatorInfo* pCondInfo = pOperator->info; - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + 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); + SSDataBlock* pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup); publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC); if (pBlock == NULL) { @@ -6808,16 +6829,16 @@ static SSDataBlock* doFilter(void* param, bool* newgroup) { 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; + int32_t order = TSDB_ORDER_ASC; // STimeWindow win = pQueryAttr->window; - bool newgroup = false; + bool newgroup = false; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { @@ -6832,21 +6853,22 @@ 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; @@ -6858,16 +6880,17 @@ static SSDataBlock* doIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { } 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* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { +static SSDataBlock* doAllIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } @@ -6876,7 +6899,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); @@ -6885,13 +6908,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); @@ -6900,7 +6923,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); @@ -6917,27 +6940,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); } @@ -6945,11 +6968,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); @@ -6961,7 +6984,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); @@ -6969,11 +6992,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; } @@ -6981,16 +7004,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; } @@ -6999,11 +7022,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); @@ -7015,7 +7038,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); @@ -7023,35 +7046,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); @@ -7074,7 +7097,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; @@ -7082,49 +7105,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; @@ -7133,9 +7155,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); @@ -7149,7 +7171,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 @@ -7162,36 +7184,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); @@ -7201,42 +7225,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); @@ -7246,23 +7274,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; } @@ -7270,10 +7301,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); @@ -7284,7 +7317,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); @@ -7299,9 +7333,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); @@ -7315,7 +7349,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); @@ -7374,7 +7408,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; @@ -7394,7 +7428,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]); } @@ -7406,13 +7440,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 || @@ -7452,14 +7486,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; } } @@ -7469,17 +7503,19 @@ 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; } //(int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); int32_t numOfRows = 1; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, pTaskInfo->id.str); + int32_t code = + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -7487,18 +7523,18 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, pTaskInfo); - pOperator->name = "TableAggregate"; + pOperator->name = "TableAggregate"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_AGG; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = numOfCols; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; - pOperator->pTaskInfo = pTaskInfo; - pOperator->_openFn = doOpenAggregateOptr; - pOperator->getNextFn = getAggregateResult; - pOperator->closeFn = destroyAggOperatorInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->_openFn = doOpenAggregateOptr; + pOperator->getNextFn = getAggregateResult; + pOperator->closeFn = destroyAggOperatorInfo; pOperator->encodeResultRow = aggEncodeResultRow; pOperator->decodeResultRow = aggDecodeResultRow; @@ -7508,7 +7544,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* } return pOperator; - _error: +_error: destroyAggOperatorInfo(pInfo, numOfCols); taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -7527,41 +7563,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); @@ -7569,29 +7605,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); @@ -7599,7 +7635,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); @@ -7609,7 +7645,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) { @@ -7619,28 +7655,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; @@ -7655,9 +7694,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; } @@ -7668,21 +7708,21 @@ 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->name = "ProjectOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pExpr = pExprInfo; - pOperator->numOfOutput = num; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doProjectOperation; - pOperator->closeFn = destroyProjectOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = num; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doProjectOperation; + pOperator->closeFn = destroyProjectOperatorInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->pTaskInfo = pTaskInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -7690,7 +7730,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p return pOperator; - _error: +_error: pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -7730,68 +7770,70 @@ SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int3 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->name = "LimitOperator"; + // pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LIMIT; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doLimit; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doLimit; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_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->order = TSDB_ORDER_ASC; pInfo->precision = TSDB_TIME_PRECISION_MILLI; - pInfo->win = pTaskInfo->window; - pInfo->interval = *pInterval; + pInfo->win = pTaskInfo->window; + pInfo->interval = *pInterval; pInfo->win.skey = INT64_MIN; 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*/) { + 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; } initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); - pOperator->name = "TimeIntervalAggOperator"; + pOperator->name = "TimeIntervalAggOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INTERVAL; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->numOfOutput = numOfCols; - pOperator->info = pInfo; - pOperator->_openFn = doOpenIntervalAgg; - pOperator->getNextFn = doIntervalAgg; - pOperator->closeFn = destroyIntervalOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->_openFn = doOpenIntervalAgg; + pOperator->getNextFn = doBuildIntervalResult; + pOperator->closeFn = destroyIntervalOperatorInfo; code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -7800,7 +7842,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* return pOperator; - _error: +_error: destroyIntervalOperatorInfo(pInfo, numOfCols); taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -7808,47 +7850,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; @@ -7856,38 +7900,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); } @@ -7898,71 +7946,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; } @@ -7980,10 +8030,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; } @@ -7997,28 +8048,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); @@ -8029,9 +8080,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); @@ -8042,90 +8092,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) { @@ -8259,7 +8311,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); @@ -8268,26 +8320,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)); @@ -8301,20 +8353,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)) { @@ -8329,18 +8381,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); @@ -8353,13 +8405,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 { @@ -8376,53 +8428,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)) { @@ -8430,7 +8482,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; } @@ -8453,16 +8505,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); @@ -8470,12 +8522,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); @@ -8489,10 +8542,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; @@ -8511,7 +8565,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); @@ -8525,46 +8579,88 @@ 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) { - SColumnNode* pColNode = (SColumnNode*) pTargetNode->pExpr; + pExp->pExpr->nodeType = QUERY_NODE_COLUMN; + SColumnNode* pColNode = (SColumnNode*)pTargetNode->pExpr; + + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); + pExp->base.numOfParams = 1; + pExp->base.pParam[0].pCol = taosMemoryCalloc(1, sizeof(SColumn)); + pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; SDataType* pType = &pColNode->node.resType; pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pColNode->colName); - pCol->slotId = pColNode->slotId; + + SColumn* pCol = pExp->base.pParam[0].pCol; + pCol->slotId = pColNode->slotId; // TODO refactor + pCol->bytes = pType->bytes; + pCol->type = pType->type; + pCol->scale = pType->scale; + pCol->precision = pType->precision; + } 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->pExpr->_function.functionId = pFuncNode->funcId; + pExp->pExpr->_function.pFunctNode = pFuncNode; + strncpy(pExp->pExpr->_function.functionName, pFuncNode->functionName, + tListLen(pExp->pExpr->_function.functionName)); + + // TODO: value parameter needs to be handled + int32_t numOfParam = LIST_LENGTH(pFuncNode->pParameterList); + + 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); + if (p1->type == QUERY_NODE_COLUMN) { + SColumnNode* pcn = (SColumnNode*)p1; // TODO refactor + + pExp->base.pParam[j].type = FUNC_PARAM_TYPE_COLUMN; + pExp->base.pParam[j].pCol = taosMemoryCalloc(1, sizeof(SColumn)); + SColumn* pCol = pExp->base.pParam[j].pCol; + + pCol->slotId = pcn->slotId; + pCol->bytes = pcn->node.resType.bytes; + pCol->type = pcn->node.resType.type; + pCol->scale = pcn->node.resType.scale; + pCol->precision = pcn->node.resType.precision; + pCol->dataBlockId = pcn->dataBlockId; + } 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; + + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); + pExp->base.numOfParams = 1; + pExp->base.pParam[0].pCol = taosMemoryCalloc(1, sizeof(SColumn)); + pExp->base.pParam[0].type = FUNC_PARAM_TYPE_COLUMN; + + SDataType* pType = &pNode->node.resType; + pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, + pType->precision, pNode->node.aliasName); + + pExp->pExpr->_optrRoot.pRootNode = pTargetNode->pExpr; + + SColumn* pCol = pExp->base.pParam[0].pCol; + pCol->slotId = pTargetNode->slotId; // TODO refactor pCol->bytes = pType->bytes; pCol->type = pType->type; pCol->scale = pType->scale; pCol->precision = pType->precision; } else { - 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->pExpr->_function.functionId = pFuncNode->funcId; - pExp->pExpr->_function.pFunctNode = pFuncNode; - strncpy(pExp->pExpr->_function.functionName, pFuncNode->functionName, tListLen(pExp->pExpr->_function.functionName)); - - // TODO: value parameter needs to be handled - int32_t numOfParam = LIST_LENGTH(pFuncNode->pParameterList); - for (int32_t j = 0; j < numOfParam; ++j) { - SNode* p1 = nodesListGetNode(pFuncNode->pParameterList, j); - 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; - } + ASSERT(0); } } @@ -8579,56 +8675,65 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId) { pTaskInfo->id.queryId = queryId; 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* doCreateOperatorTreeNode(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); - tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); - SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols); + int32_t numOfCols = 0; + tsdbReaderT pDataReader = + doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); + SArray* pColList = + extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); - return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, pScanPhyNode->reverse, pColList, pTaskInfo); + 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); @@ -8639,15 +8744,13 @@ 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 = doCreateOperatorTreeNode(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); @@ -8659,8 +8762,8 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa 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); @@ -8679,33 +8782,64 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa 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}; 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 = doCreateOperatorTreeNode(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 = doCreateOperatorTreeNode(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 = doCreateOperatorTreeNode(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; @@ -8713,7 +8847,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) { @@ -8723,7 +8857,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; @@ -8734,18 +8868,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; } @@ -8756,24 +8890,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); } @@ -8781,29 +8915,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); @@ -8832,22 +9012,24 @@ 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; } @@ -8865,7 +9047,7 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead STableGroupInfo group = {0}; (*pTaskInfo)->pRoot = doCreateOperatorTreeNode(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &group); if (NULL == (*pTaskInfo)->pRoot) { - code = terrno; + code = terrno; goto _complete; } @@ -8883,7 +9065,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; } @@ -8897,7 +9079,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) { @@ -8909,7 +9091,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; } @@ -8918,7 +9100,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]); @@ -8928,9 +9111,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); } } } @@ -8939,67 +9123,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)); // } // } // @@ -9011,49 +9197,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) { @@ -9095,7 +9281,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; } @@ -9104,29 +9290,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); } @@ -9143,12 +9329,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); @@ -9165,7 +9351,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 { @@ -9178,8 +9364,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) { @@ -9187,8 +9373,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..c9b0b62013 100644 --- a/source/libs/executor/test/executorTests.cpp +++ b/source/libs/executor/test/executorTests.cpp @@ -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/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 214204723f..f7fccb29f7 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -25,23 +25,23 @@ extern "C" { bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); void functionFinalize(SqlFunctionCtx *pCtx); -bool getCountFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); void countFunction(SqlFunctionCtx *pCtx); -bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); void sumFunction(SqlFunctionCtx *pCtx); bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -bool getMinmaxFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getMinmaxFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); void minFunction(SqlFunctionCtx* pCtx); void maxFunction(SqlFunctionCtx *pCtx); -bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); void stddevFunction(SqlFunctionCtx* pCtx); void stddevFinalize(SqlFunctionCtx* pCtx); -bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); void firstFunction(SqlFunctionCtx *pCtx); void lastFunction(SqlFunctionCtx *pCtx); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 70b2a48da7..0a5a90d2d9 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, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_qendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_wstartts", + .type = FUNCTION_TYPE_QSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_wendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_wduration", + .type = FUNCTION_TYPE_WDURATION, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL } }; @@ -329,8 +399,39 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { break; } case FUNCTION_TYPE_CONCAT: + case FUNCTION_TYPE_ROWTS: + case FUNCTION_TYPE_TBNAME: + case FUNCTION_TYPE_QSTARTTS: + case FUNCTION_TYPE_QENDTS: + case FUNCTION_TYPE_WSTARTTS: + case FUNCTION_TYPE_WENDTS: + case FUNCTION_TYPE_WDURATION: // todo 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..3858258374 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; @@ -89,10 +96,19 @@ int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet) { } 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/taggfunction.c b/source/libs/function/src/taggfunction.c index 05ed30c61a..af24906c9e 100644 --- a/source/libs/function/src/taggfunction.c +++ b/source/libs/function/src/taggfunction.c @@ -3078,8 +3078,8 @@ static void arithmetic_function(SqlFunctionCtx *pCtx) { GET_RES_INFO(pCtx)->numOfRes += pCtx->size; //SScalarFunctionSupport *pSup = (SScalarFunctionSupport *)pCtx->param[1].pz; - SScalarParam output = {0}; - output.data = pCtx->pOutput; +// SScalarParam output = {0}; +// output.data = pCtx->pOutput; //evaluateExprNodeTree(pSup->pExprInfo->pExpr, pCtx->size, &output, pSup, getArithColumnData); } 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..01d49cb364 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; } @@ -2057,19 +2113,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 +2142,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..bd8e9a7518 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -582,11 +582,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 358edcb279..0fe5df183d 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -53,7 +53,6 @@ typedef enum EDatabaseOptionType { DB_OPTION_SINGLE_STABLE, DB_OPTION_STREAM_MODE, DB_OPTION_RETENTIONS, - DB_OPTION_FILE_FACTOR, DB_OPTION_MAX } EDatabaseOptionType; @@ -63,6 +62,8 @@ typedef enum ETableOptionType { TABLE_OPTION_TTL, TABLE_OPTION_COMMENT, TABLE_OPTION_SMA, + TABLE_OPTION_FILE_FACTOR, + TABLE_OPTION_DELAY, TABLE_OPTION_MAX } ETableOptionType; diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 529fbb55c8..7556684e8b 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" @@ -146,7 +147,6 @@ db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); } db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAM_MODE, &C); } db_options(A) ::= db_options(B) RETENTIONS NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, &C); } -db_options(A) ::= db_options(B) FILE_FACTOR NK_FLOAT(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FILE_FACTOR, &C); } alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabaseOption(pCxt, A, B.type, &B.val); } alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseOption(pCxt, B, C.type, &C.val); } @@ -263,6 +263,8 @@ table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); } table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); } table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableRollupOption(pCxt, B, C); } +table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { A = setTableOption(pCxt, B, TABLE_OPTION_FILE_FACTOR, &C); } +table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_DELAY, &C); } alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); } alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableOption(pCxt, B, C.type, &C.val); } @@ -347,6 +349,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)); } @@ -370,6 +373,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($$); } @@ -416,7 +420,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)))); } @@ -466,7 +470,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 a958a748e2..fcabd4614c 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -248,12 +248,37 @@ static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptio } static SDatabaseOptions* setDbRetentions(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { - // todo - return pOptions; -} + pOptions->pRetentions = nodesMakeList(); + if (NULL == pOptions->pRetentions) { + pCxt->valid = false; + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); + return pOptions; + } + + char val[20] = {0}; + int32_t len = trimString(pVal->z, pVal->n, val, sizeof(val)); + char* pStart = val; + char* pEnd = val + len; + int32_t sepOrder = 1; + while (1) { + char* pPos = strchr(pStart, (0 == sepOrder % 2) ? ',' : ':'); + SToken t = { .type = TK_NK_VARIABLE, .z = pStart, .n = (NULL == pPos ? pEnd - pStart : pPos - pStart)}; + if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pOptions->pRetentions, createDurationValueNode(pCxt, &t))) { + pCxt->valid = false; + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); + return pOptions; + } + if (NULL == pPos) { + break; + } + pStart = pPos + 1; + } + + if (LIST_LENGTH(pOptions->pRetentions) % 2 != 0) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option retentions: %s", val); + pCxt->valid = false; + } -static SDatabaseOptions* setDbFileFactor(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { - // todo return pOptions; } @@ -276,7 +301,6 @@ static void initSetDatabaseOptionFp() { setDbOptionFuncs[DB_OPTION_SINGLE_STABLE] = setDbSingleStable; setDbOptionFuncs[DB_OPTION_STREAM_MODE] = setDbStreamMode; setDbOptionFuncs[DB_OPTION_RETENTIONS] = setDbRetentions; - setDbOptionFuncs[DB_OPTION_FILE_FACTOR] = setDbFileFactor; } static STableOptions* setTableKeep(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { @@ -314,10 +338,36 @@ static STableOptions* setTableComment(SAstCreateContext* pCxt, STableOptions* pO return pOptions; } +static STableOptions* setTableFileFactor(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { + double val = strtod(pVal->z, NULL); + if (val < TSDB_MIN_DB_FILE_FACTOR || val > TSDB_MAX_DB_FILE_FACTOR) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, + "invalid table option file_factor: %f valid range: [%d, %d]", val, TSDB_MIN_DB_FILE_FACTOR, TSDB_MAX_DB_FILE_FACTOR); + pCxt->valid = false; + return pOptions; + } + pOptions->filesFactor = val; + return pOptions; +} + +static STableOptions* setTableDelay(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { + int64_t val = strtol(pVal->z, NULL, 10); + if (val < TSDB_MIN_DB_DELAY || val > TSDB_MAX_DB_DELAY) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, + "invalid table option delay: %"PRId64" valid range: [%d, %d]", val, TSDB_MIN_DB_DELAY, TSDB_MAX_DB_DELAY); + pCxt->valid = false; + return pOptions; + } + pOptions->delay = val; + return pOptions; +} + static void initSetTableOptionFp() { setTableOptionFuncs[TABLE_OPTION_KEEP] = setTableKeep; setTableOptionFuncs[TABLE_OPTION_TTL] = setTableTtl; setTableOptionFuncs[TABLE_OPTION_COMMENT] = setTableComment; + setTableOptionFuncs[TABLE_OPTION_FILE_FACTOR] = setTableFileFactor; + setTableOptionFuncs[TABLE_OPTION_DELAY] = setTableDelay; } void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { @@ -527,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) { @@ -667,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; } @@ -906,6 +960,8 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { CHECK_OUT_OF_MEM(pOptions); pOptions->keep = TSDB_DEFAULT_KEEP; pOptions->ttl = TSDB_DEFAULT_DB_TTL_OPTION; + pOptions->filesFactor = TSDB_DEFAULT_DB_FILE_FACTOR; + pOptions->delay = TSDB_DEFAULT_DB_DELAY; return (SNode*)pOptions; } @@ -914,6 +970,8 @@ SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt) { CHECK_OUT_OF_MEM(pOptions); pOptions->keep = -1; pOptions->ttl = -1; + pOptions->filesFactor = -1; + pOptions->delay = -1; return (SNode*)pOptions; } @@ -927,7 +985,12 @@ SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pS } SNode* setTableRollupOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pFuncs) { - // todo + if (1 != LIST_LENGTH(pFuncs)) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid table option rollup: only one function is allowed"); + pCxt->valid = false; + return pOptions; + } + ((STableOptions*)pOptions)->pFuncs = pFuncs; return pOptions; } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 79651cd325..3751041ef7 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -48,6 +48,7 @@ static SKeyword keywordTable[] = { {"DATABASE", TK_DATABASE}, {"DATABASES", TK_DATABASES}, {"DAYS", TK_DAYS}, + {"DELAY", TK_DELAY}, {"DESC", TK_DESC}, {"DISTINCT", TK_DISTINCT}, {"DNODE", TK_DNODE}, @@ -55,7 +56,7 @@ static SKeyword keywordTable[] = { {"DOUBLE", TK_DOUBLE}, {"DROP", TK_DROP}, {"EXISTS", TK_EXISTS}, - // {"FILE", TK_FILE}, + {"FILE_FACTOR", TK_FILE_FACTOR}, {"FILL", TK_FILL}, {"FLOAT", TK_FLOAT}, {"FROM", TK_FROM}, @@ -98,15 +99,21 @@ 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}, {"REPLICA", TK_REPLICA}, + {"RETENTIONS", TK_RETENTIONS}, + {"ROLLUP", TK_ROLLUP}, + {"ROWTS", TK_ROWTS}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, {"SHOW", TK_SHOW}, @@ -124,6 +131,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}, @@ -138,7 +146,10 @@ static SKeyword keywordTable[] = { {"VARCHAR", TK_VARCHAR}, {"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}, @@ -230,7 +241,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}, @@ -424,6 +434,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 60ee8be76d..0f26bec9b2 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -235,6 +235,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 +619,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 +632,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); @@ -920,7 +916,35 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } -static void buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt, SCreateDbReq* pReq) { +static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbReq* pReq) { + if (NULL != pRetentions) { + pReq->pRetensions = taosArrayInit(LIST_LENGTH(pRetentions) / 2, sizeof(SRetention)); + if (NULL == pReq->pRetensions) { + return TSDB_CODE_OUT_OF_MEMORY; + } + SValueNode* pFreq = NULL; + SValueNode* pKeep = NULL; + SNode* pNode = NULL; + int32_t index = 0; + FOREACH(pNode, pRetentions) { + if (0 == index % 2) { + pFreq = (SValueNode*)pNode; + } else { + pKeep = (SValueNode*)pNode; + SRetention retention = { + .freq = pFreq->datum.i, + .freqUnit = pFreq->unit, + .keep = pKeep->datum.i, + .keepUnit = pKeep->unit + }; + taosArrayPush(pReq->pRetensions, &retention); + } + } + } + return TSDB_CODE_SUCCESS; +} + +static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt, SCreateDbReq* pReq) { SName name = {0}; tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameGetFullDbName(&name, pReq->db); @@ -944,27 +968,45 @@ static void buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt pReq->cacheLastRow = pStmt->pOptions->cachelast; pReq->ignoreExist = pStmt->ignoreExists; pReq->streamMode = pStmt->pOptions->streamMode; - return; + return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq); +} + +static int32_t checkCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { + if (NULL != pStmt->pOptions->pRetentions) { + SNode* pNode = NULL; + FOREACH(pNode, pStmt->pOptions->pRetentions) { + if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode)) { + return pCxt->errCode; + } + } + } + return TSDB_CODE_SUCCESS; } static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { SCreateDbReq createReq = {0}; - buildCreateDbReq(pCxt, pStmt, &createReq); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + int32_t code = checkCreateDatabase(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = buildCreateDbReq(pCxt, pStmt, &createReq); } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB; - pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS == code) { + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB; + pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + } + + return code; } static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* pStmt) { @@ -1035,7 +1077,7 @@ static int32_t calcTypeBytes(SDataType dt) { } } -static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { +static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); SNode* pNode; FOREACH(pNode, pList) { @@ -1047,13 +1089,77 @@ static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { return TSDB_CODE_SUCCESS; } +static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { + if (NULL == pList) { + return TSDB_CODE_SUCCESS; + } + + *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); + SNode* pNode; + FOREACH(pNode, pList) { + SColumnNode* pCol = (SColumnNode*)pNode; + SField field = { .type = pCol->node.resType.type, .bytes = calcTypeBytes(pCol->node.resType) }; + strcpy(field.name, pCol->colName); + taosArrayPush(*pArray, &field); + } + return TSDB_CODE_SUCCESS; +} + +static const SColumnDefNode* findColDef(const SNodeList* pCols, const SColumnNode* pCol) { + SNode* pColDef = NULL; + FOREACH(pColDef, pCols) { + if (0 == strcmp(pCol->colName, ((SColumnDefNode*)pColDef)->colName)) { + return (SColumnDefNode*)pColDef; + } + } + return NULL; +} + +static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { + if (NULL != pStmt->pOptions->pSma) { + SNode* pNode = NULL; + FOREACH(pNode, pStmt->pOptions->pSma) { + SColumnNode* pSmaCol = (SColumnNode*)pNode; + const SColumnDefNode* pColDef = findColDef(pStmt->pCols, pSmaCol); + if (NULL == pColDef) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMN, pSmaCol->colName); + } + pSmaCol->node.resType = pColDef->dataType; + } + } + if (NULL != pStmt->pOptions->pFuncs) { + SFunctionNode* pFunc = nodesListGetNode(pStmt->pOptions->pFuncs, 0); + if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName); + } + } + return TSDB_CODE_SUCCESS; +} + +static int32_t getAggregationMethod(SNodeList* pFuncs) { + if (NULL == pFuncs) { + return -1; + } + return ((SFunctionNode*)nodesListGetNode(pFuncs, 0))->funcId; +} + static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { + int32_t code = checkCreateTable(pCxt, pStmt); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + SMCreateStbReq createReq = {0}; createReq.igExists = pStmt->ignoreExists; - columnNodeToField(pStmt->pCols, &createReq.pColumns); - columnNodeToField(pStmt->pTags, &createReq.pTags); + createReq.aggregationMethod = getAggregationMethod(pStmt->pOptions->pFuncs); + createReq.xFilesFactor = pStmt->pOptions->filesFactor; + createReq.delay = pStmt->pOptions->delay; + columnDefNodeToField(pStmt->pCols, &createReq.pColumns); + columnDefNodeToField(pStmt->pTags, &createReq.pTags); + columnNodeToField(pStmt->pOptions->pSma, &createReq.pSmas); createReq.numOfColumns = LIST_LENGTH(pStmt->pCols); createReq.numOfTags = LIST_LENGTH(pStmt->pTags); + createReq.numOfSmas = LIST_LENGTH(pStmt->pOptions->pSma); SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; strcpy(tableName.dbname, pStmt->dbName); @@ -1378,12 +1484,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) { diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 451587c8bf..ef2c547e44 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" @@ -73,7 +74,7 @@ ** which is ParseTOKENTYPE. The entry in the union ** for terminal symbols is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If -** zero the stack is dynamically sized using taosMemoryRealloc() +** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument ** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter @@ -99,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 258 +#define YYNOCODE 268 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - ENullOrder yy73; - SNodeList* yy136; - SNode* yy140; - EJoinType yy144; - SToken yy149; - EOrder yy158; - int32_t yy160; - SAlterOption yy233; - SDataType yy256; - EFillMode yy306; - EOperatorType yy320; - bool yy497; + EOrder yy106; + EFillMode yy142; + SNode* yy176; + SToken yy225; + EJoinType yy236; + SAlterOption yy325; + EOperatorType yy404; + SDataType yy448; + ENullOrder yy465; + bool yy505; + int32_t yy508; + SNodeList* yy512; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -131,17 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 430 -#define YYNRULE 337 -#define YYNTOKEN 163 -#define YY_MAX_SHIFT 429 -#define YY_MIN_SHIFTREDUCE 662 -#define YY_MAX_SHIFTREDUCE 998 -#define YY_ERROR_ACTION 999 -#define YY_ACCEPT_ACTION 1000 -#define YY_NO_ACTION 1001 -#define YY_MIN_REDUCE 1002 -#define YY_MAX_REDUCE 1338 +#define YYNSTATE 432 +#define YYNRULE 348 +#define YYNTOKEN 172 +#define YY_MAX_SHIFT 431 +#define YY_MIN_SHIFTREDUCE 675 +#define YY_MAX_SHIFTREDUCE 1022 +#define YY_ERROR_ACTION 1023 +#define YY_ACCEPT_ACTION 1024 +#define YY_NO_ACTION 1025 +#define YY_MIN_REDUCE 1026 +#define YY_MAX_REDUCE 1373 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -208,398 +209,405 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1263) +#define YY_ACTTAB_COUNT (1282) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1045, 1204, 225, 43, 24, 170, 362, 1200, 1206, 1095, - /* 10 */ 250, 269, 89, 31, 29, 27, 26, 25, 20, 1204, - /* 20 */ 1101, 27, 26, 25, 1084, 1200, 1205, 1106, 31, 29, - /* 30 */ 27, 26, 25, 361, 1000, 78, 209, 869, 77, 76, - /* 40 */ 75, 74, 73, 72, 71, 70, 69, 1091, 211, 414, - /* 50 */ 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, - /* 60 */ 403, 402, 401, 400, 399, 398, 397, 396, 1003, 105, - /* 70 */ 270, 1014, 881, 31, 29, 27, 26, 25, 1231, 132, - /* 80 */ 904, 349, 111, 249, 237, 346, 1216, 1180, 275, 78, - /* 90 */ 131, 22, 77, 76, 75, 74, 73, 72, 71, 70, - /* 100 */ 69, 31, 29, 27, 26, 25, 1231, 1317, 211, 291, - /* 110 */ 320, 286, 270, 346, 290, 44, 905, 289, 129, 287, - /* 120 */ 117, 345, 288, 348, 1315, 23, 232, 1192, 899, 900, - /* 130 */ 901, 902, 903, 907, 908, 909, 1082, 204, 1217, 1220, - /* 140 */ 904, 772, 385, 384, 383, 776, 382, 778, 779, 381, - /* 150 */ 781, 378, 109, 787, 375, 789, 790, 372, 369, 1151, - /* 160 */ 1216, 849, 128, 1144, 305, 224, 125, 43, 326, 189, - /* 170 */ 1149, 361, 1136, 30, 28, 941, 905, 847, 258, 242, - /* 180 */ 1231, 234, 395, 849, 1102, 23, 232, 346, 899, 900, - /* 190 */ 901, 902, 903, 907, 908, 909, 1204, 348, 361, 847, - /* 200 */ 896, 1192, 1200, 1205, 306, 362, 334, 848, 12, 118, - /* 210 */ 66, 61, 1217, 1220, 1256, 1216, 965, 279, 210, 1252, - /* 220 */ 1168, 10, 122, 121, 30, 28, 1106, 120, 1317, 848, - /* 230 */ 1317, 1, 234, 426, 849, 1231, 316, 963, 964, 966, - /* 240 */ 967, 117, 333, 117, 1216, 1315, 245, 1315, 10, 324, - /* 250 */ 847, 337, 348, 1171, 1173, 426, 1192, 349, 699, 12, - /* 260 */ 698, 850, 853, 1181, 1231, 362, 62, 1217, 1220, 1256, - /* 270 */ 66, 333, 283, 227, 1252, 112, 282, 285, 700, 330, - /* 280 */ 848, 348, 1, 850, 853, 1192, 1106, 166, 118, 9, - /* 290 */ 8, 59, 1216, 312, 1283, 62, 1217, 1220, 1256, 284, - /* 300 */ 92, 93, 227, 1252, 112, 1317, 426, 330, 1098, 106, - /* 310 */ 1073, 906, 1231, 31, 29, 27, 26, 25, 1316, 346, - /* 320 */ 21, 1216, 1315, 1284, 395, 1270, 90, 871, 92, 348, - /* 330 */ 910, 422, 421, 1192, 850, 853, 114, 1263, 1264, 870, - /* 340 */ 1268, 1231, 1267, 62, 1217, 1220, 1256, 334, 346, 118, - /* 350 */ 227, 1252, 1329, 698, 90, 1097, 1216, 867, 348, 917, - /* 360 */ 1231, 1290, 1192, 868, 163, 1263, 329, 346, 328, 277, - /* 370 */ 238, 1317, 62, 1217, 1220, 1256, 1231, 362, 104, 227, - /* 380 */ 1252, 1329, 1103, 346, 117, 1216, 1108, 388, 1315, 1025, - /* 390 */ 1313, 1093, 323, 348, 30, 28, 1192, 1192, 1106, 1024, - /* 400 */ 1270, 336, 234, 104, 849, 1231, 1083, 62, 1217, 1220, - /* 410 */ 1256, 1109, 346, 1151, 227, 1252, 1329, 1266, 362, 239, - /* 420 */ 847, 1151, 348, 359, 1149, 1274, 1192, 246, 165, 12, - /* 430 */ 1192, 334, 1149, 30, 28, 1015, 199, 1217, 1220, 1106, - /* 440 */ 1192, 234, 1216, 849, 194, 1023, 1022, 1021, 137, 196, - /* 450 */ 848, 135, 1, 1041, 319, 1317, 30, 28, 347, 847, - /* 460 */ 6, 195, 1231, 392, 234, 1216, 849, 391, 117, 346, - /* 470 */ 1020, 123, 1315, 1151, 118, 292, 426, 325, 321, 348, - /* 480 */ 1019, 1018, 847, 1192, 1172, 1231, 1192, 1192, 1192, 848, - /* 490 */ 393, 7, 346, 63, 1217, 1220, 1256, 1151, 872, 1089, - /* 500 */ 1255, 1252, 348, 1048, 850, 853, 1192, 948, 1150, 390, - /* 510 */ 389, 1192, 848, 869, 7, 426, 63, 1217, 1220, 1256, - /* 520 */ 244, 1192, 1192, 344, 1252, 30, 28, 303, 104, 30, - /* 530 */ 28, 64, 387, 234, 341, 849, 1108, 234, 426, 849, - /* 540 */ 301, 1216, 1270, 850, 853, 1002, 31, 29, 27, 26, - /* 550 */ 25, 847, 291, 936, 286, 847, 1017, 290, 118, 1265, - /* 560 */ 289, 1231, 287, 118, 1216, 288, 850, 853, 346, 87, - /* 570 */ 86, 85, 84, 83, 82, 81, 80, 79, 348, 867, - /* 580 */ 1036, 848, 1192, 7, 1231, 848, 251, 1, 1074, 263, - /* 590 */ 1016, 346, 107, 1217, 1220, 940, 429, 1192, 264, 151, - /* 600 */ 1216, 348, 294, 167, 362, 1192, 247, 426, 342, 360, - /* 610 */ 187, 426, 308, 88, 104, 63, 1217, 1220, 1256, 418, - /* 620 */ 1231, 186, 1108, 1253, 98, 1106, 1013, 346, 317, 335, - /* 630 */ 1330, 1192, 1034, 1012, 1011, 850, 853, 348, 362, 850, - /* 640 */ 853, 1192, 1145, 184, 233, 362, 60, 1010, 1009, 182, - /* 650 */ 248, 205, 1217, 1220, 297, 1008, 160, 1007, 1216, 1106, - /* 660 */ 1275, 936, 1232, 1216, 276, 262, 1106, 1192, 257, 256, - /* 670 */ 255, 254, 253, 338, 1192, 1192, 1006, 856, 1231, 139, - /* 680 */ 358, 1216, 138, 1231, 141, 346, 1216, 140, 1192, 1192, - /* 690 */ 346, 855, 994, 995, 311, 348, 1192, 147, 1192, 1192, - /* 700 */ 348, 1231, 313, 330, 1192, 331, 1231, 859, 346, 205, - /* 710 */ 1217, 1220, 1005, 346, 107, 1217, 1220, 1192, 348, 9, - /* 720 */ 8, 858, 1192, 348, 92, 231, 867, 1192, 1216, 939, - /* 730 */ 235, 1216, 205, 1217, 1220, 1286, 1216, 205, 1217, 1220, - /* 740 */ 31, 29, 27, 26, 25, 339, 330, 1170, 1231, 52, - /* 750 */ 90, 1231, 1331, 1192, 169, 346, 1231, 1081, 346, 332, - /* 760 */ 113, 1263, 1264, 346, 1268, 348, 1099, 92, 348, 1192, - /* 770 */ 2, 119, 1192, 348, 1216, 143, 260, 1192, 142, 203, - /* 780 */ 1217, 1220, 206, 1217, 1220, 962, 156, 197, 1217, 1220, - /* 790 */ 252, 259, 261, 90, 1231, 265, 1216, 41, 154, 881, - /* 800 */ 911, 346, 1216, 115, 1263, 1264, 875, 1268, 997, 998, - /* 810 */ 266, 348, 32, 267, 392, 1192, 1231, 124, 391, 874, - /* 820 */ 878, 58, 1231, 346, 127, 207, 1217, 1220, 1210, 346, - /* 830 */ 1216, 54, 32, 348, 842, 268, 1216, 1192, 271, 348, - /* 840 */ 1208, 393, 42, 1192, 278, 130, 32, 198, 1217, 1220, - /* 850 */ 1231, 873, 68, 208, 1217, 1220, 1231, 346, 175, 280, - /* 860 */ 390, 389, 223, 346, 1216, 1096, 354, 348, 181, 134, - /* 870 */ 173, 1192, 1092, 348, 765, 136, 100, 1192, 95, 101, - /* 880 */ 96, 1228, 1217, 1220, 1231, 1094, 98, 1227, 1217, 1220, - /* 890 */ 760, 346, 1216, 1090, 793, 797, 102, 803, 1216, 802, - /* 900 */ 310, 348, 41, 103, 146, 1192, 367, 96, 99, 97, - /* 910 */ 149, 98, 1231, 307, 309, 1226, 1217, 1220, 1231, 346, - /* 920 */ 96, 872, 318, 1297, 1287, 346, 352, 152, 853, 348, - /* 930 */ 315, 1296, 1216, 1192, 226, 348, 5, 159, 155, 1192, - /* 940 */ 1216, 322, 327, 214, 1217, 1220, 241, 240, 1277, 213, - /* 950 */ 1217, 1220, 1231, 314, 4, 161, 861, 936, 91, 346, - /* 960 */ 1231, 871, 110, 1271, 33, 162, 228, 346, 1216, 348, - /* 970 */ 1332, 340, 854, 1192, 296, 218, 343, 348, 17, 1238, - /* 980 */ 1179, 1192, 168, 215, 1217, 1220, 350, 1314, 1231, 304, - /* 990 */ 351, 212, 1217, 1220, 355, 346, 1178, 283, 356, 236, - /* 1000 */ 177, 282, 857, 145, 357, 348, 299, 179, 53, 1192, - /* 1010 */ 51, 293, 188, 219, 144, 217, 216, 190, 281, 202, - /* 1020 */ 1217, 1220, 1107, 365, 284, 185, 425, 200, 363, 201, - /* 1030 */ 192, 193, 1186, 825, 1163, 1162, 94, 1161, 1160, 40, - /* 1040 */ 1159, 1158, 39, 1157, 1156, 827, 1155, 1154, 1153, 1152, - /* 1050 */ 1047, 1185, 1176, 126, 1085, 711, 862, 853, 1046, 1044, - /* 1060 */ 272, 273, 274, 1033, 1032, 1029, 1087, 67, 133, 808, - /* 1070 */ 1086, 807, 1042, 1037, 740, 806, 1035, 739, 1028, 220, - /* 1080 */ 738, 1027, 221, 737, 222, 1184, 1183, 36, 1175, 150, - /* 1090 */ 300, 302, 3, 736, 735, 65, 45, 32, 14, 153, - /* 1100 */ 295, 37, 15, 158, 19, 298, 1208, 34, 11, 164, - /* 1110 */ 48, 8, 35, 16, 148, 897, 353, 1174, 180, 1001, - /* 1120 */ 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, - /* 1130 */ 983, 982, 229, 987, 986, 230, 863, 1001, 1001, 1001, - /* 1140 */ 1001, 1001, 1001, 178, 1001, 961, 1001, 108, 1001, 157, - /* 1150 */ 1001, 955, 46, 1001, 954, 933, 1001, 47, 1001, 1001, - /* 1160 */ 932, 1001, 988, 1001, 1001, 1001, 1001, 1001, 1001, 366, - /* 1170 */ 879, 13, 116, 18, 243, 172, 959, 174, 176, 1001, - /* 1180 */ 171, 49, 50, 1001, 1207, 38, 370, 1001, 373, 794, - /* 1190 */ 54, 376, 771, 1001, 379, 183, 1001, 364, 799, 1001, - /* 1200 */ 1001, 1001, 368, 731, 791, 371, 1043, 1001, 788, 723, - /* 1210 */ 1001, 428, 423, 801, 374, 786, 800, 782, 1001, 1001, - /* 1220 */ 1001, 730, 377, 729, 728, 709, 780, 727, 380, 394, - /* 1230 */ 785, 726, 1031, 725, 724, 417, 722, 721, 1030, 1026, - /* 1240 */ 416, 720, 55, 56, 57, 415, 420, 732, 719, 424, - /* 1250 */ 1001, 851, 718, 717, 716, 386, 715, 784, 191, 783, - /* 1260 */ 714, 419, 427, + /* 0 */ 1230, 43, 306, 1243, 1118, 350, 1226, 1233, 238, 1114, + /* 10 */ 89, 1205, 31, 29, 27, 26, 25, 1259, 1124, 24, + /* 20 */ 170, 1352, 226, 1259, 347, 31, 29, 27, 26, 25, + /* 30 */ 347, 363, 363, 251, 1351, 362, 66, 270, 1350, 1230, + /* 40 */ 349, 1243, 307, 280, 1217, 1226, 1232, 212, 1069, 335, + /* 50 */ 321, 362, 1129, 1129, 61, 1244, 1245, 1248, 1291, 210, + /* 60 */ 212, 1259, 211, 1287, 246, 363, 1065, 1352, 347, 898, + /* 70 */ 1126, 1196, 1198, 239, 1352, 106, 1096, 928, 349, 350, + /* 80 */ 117, 104, 1217, 12, 1350, 1206, 1129, 117, 293, 1131, + /* 90 */ 928, 1350, 107, 1244, 1245, 1248, 1027, 416, 415, 414, + /* 100 */ 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, + /* 110 */ 403, 402, 401, 400, 399, 189, 929, 77, 1159, 1120, + /* 120 */ 76, 75, 74, 73, 72, 71, 70, 69, 68, 929, + /* 130 */ 336, 1365, 424, 423, 23, 233, 923, 924, 925, 926, + /* 140 */ 927, 931, 932, 933, 27, 26, 25, 23, 233, 923, + /* 150 */ 924, 925, 926, 927, 931, 932, 933, 9, 8, 1243, + /* 160 */ 1217, 784, 386, 385, 384, 788, 383, 790, 791, 382, + /* 170 */ 793, 379, 883, 799, 376, 801, 802, 373, 370, 1259, + /* 180 */ 30, 28, 105, 1176, 1038, 243, 334, 1049, 235, 225, + /* 190 */ 863, 30, 28, 965, 1174, 271, 349, 362, 1259, 235, + /* 200 */ 1217, 863, 1230, 1243, 885, 347, 861, 1107, 1226, 1232, + /* 210 */ 62, 1244, 1245, 1248, 1291, 11, 363, 861, 228, 1287, + /* 220 */ 112, 360, 712, 1259, 711, 941, 11, 339, 1217, 1105, + /* 230 */ 347, 324, 166, 30, 28, 1024, 1, 1129, 313, 1318, + /* 240 */ 349, 235, 713, 863, 1217, 12, 320, 1, 31, 29, + /* 250 */ 27, 26, 25, 271, 62, 1244, 1245, 1248, 1291, 861, + /* 260 */ 428, 338, 228, 1287, 1364, 1310, 960, 1048, 11, 363, + /* 270 */ 930, 428, 862, 1325, 66, 398, 1176, 326, 322, 1243, + /* 280 */ 1047, 286, 240, 862, 250, 242, 241, 1174, 21, 1, + /* 290 */ 1129, 864, 867, 868, 201, 876, 911, 934, 118, 1259, + /* 300 */ 325, 109, 864, 867, 868, 201, 334, 911, 1217, 1352, + /* 310 */ 340, 869, 1169, 428, 118, 1243, 349, 1046, 1176, 1045, + /* 320 */ 1217, 1217, 117, 118, 247, 862, 1350, 259, 1060, 1174, + /* 330 */ 62, 1244, 1245, 1248, 1291, 1259, 363, 1305, 228, 1287, + /* 340 */ 112, 361, 347, 363, 864, 867, 868, 201, 184, 911, + /* 350 */ 295, 1243, 349, 30, 28, 1302, 1217, 1129, 1217, 1319, + /* 360 */ 1217, 235, 1305, 863, 1129, 364, 62, 1244, 1245, 1248, + /* 370 */ 1291, 1259, 122, 121, 228, 1287, 1364, 872, 347, 861, + /* 380 */ 1301, 30, 28, 348, 972, 1348, 1044, 389, 349, 235, + /* 390 */ 885, 863, 1217, 118, 363, 331, 877, 880, 868, 249, + /* 400 */ 1043, 1042, 62, 1244, 1245, 1248, 1291, 861, 1041, 7, + /* 410 */ 228, 1287, 1364, 964, 245, 1129, 92, 886, 30, 28, + /* 420 */ 337, 1309, 104, 398, 30, 28, 235, 1217, 863, 59, + /* 430 */ 1131, 1243, 235, 428, 863, 1040, 1176, 7, 1037, 93, + /* 440 */ 248, 1217, 1217, 90, 861, 862, 1121, 1197, 104, 1217, + /* 450 */ 861, 1259, 333, 113, 1298, 1299, 1131, 1303, 347, 1036, + /* 460 */ 1035, 428, 884, 1193, 864, 867, 868, 201, 349, 911, + /* 470 */ 120, 1034, 1217, 862, 7, 887, 1217, 335, 1176, 1217, + /* 480 */ 1, 1033, 202, 1244, 1245, 1248, 284, 118, 297, 1175, + /* 490 */ 283, 1116, 864, 867, 868, 201, 43, 911, 428, 1112, + /* 500 */ 1217, 1217, 1352, 305, 428, 1032, 1243, 1106, 1031, 1030, + /* 510 */ 862, 285, 1217, 1125, 1029, 117, 862, 145, 888, 1350, + /* 520 */ 300, 1305, 1217, 9, 8, 294, 1259, 52, 144, 864, + /* 530 */ 867, 868, 201, 347, 911, 864, 867, 868, 201, 1300, + /* 540 */ 911, 989, 1243, 349, 1122, 104, 1217, 1217, 6, 1217, + /* 550 */ 1217, 40, 342, 1132, 39, 1217, 963, 63, 1244, 1245, + /* 560 */ 1248, 1291, 1259, 331, 395, 1290, 1287, 304, 394, 347, + /* 570 */ 863, 388, 317, 987, 988, 990, 991, 165, 1243, 349, + /* 580 */ 302, 871, 137, 1217, 92, 135, 861, 194, 139, 396, + /* 590 */ 1039, 138, 196, 63, 1244, 1245, 1248, 1291, 1259, 318, + /* 600 */ 711, 345, 1287, 335, 195, 347, 309, 1243, 393, 392, + /* 610 */ 391, 90, 390, 1058, 123, 349, 278, 346, 98, 1217, + /* 620 */ 151, 163, 1298, 330, 1104, 329, 1243, 1259, 1352, 63, + /* 630 */ 1244, 1245, 1248, 1291, 347, 298, 141, 343, 1288, 140, + /* 640 */ 428, 117, 986, 156, 349, 1350, 1259, 874, 1217, 1243, + /* 650 */ 960, 234, 862, 347, 41, 154, 1021, 1022, 206, 1244, + /* 660 */ 1245, 1248, 143, 349, 58, 142, 1097, 1217, 1243, 1259, + /* 670 */ 314, 864, 867, 868, 54, 64, 347, 206, 1244, 1245, + /* 680 */ 1248, 395, 870, 1170, 935, 394, 349, 895, 1259, 167, + /* 690 */ 1217, 160, 277, 1321, 920, 347, 32, 883, 1237, 32, + /* 700 */ 205, 1244, 1245, 1248, 252, 349, 396, 264, 1243, 1217, + /* 710 */ 1235, 856, 175, 1243, 332, 118, 265, 169, 355, 107, + /* 720 */ 1244, 1245, 1248, 32, 173, 393, 392, 391, 1259, 390, + /* 730 */ 95, 1260, 327, 1259, 2, 347, 883, 1195, 119, 253, + /* 740 */ 347, 181, 261, 260, 266, 349, 891, 262, 873, 1217, + /* 750 */ 349, 777, 232, 96, 1217, 1072, 268, 236, 1366, 206, + /* 760 */ 1244, 1245, 1248, 98, 206, 1244, 1245, 1248, 1026, 267, + /* 770 */ 124, 77, 890, 772, 76, 75, 74, 73, 72, 71, + /* 780 */ 70, 69, 68, 127, 263, 41, 42, 258, 257, 256, + /* 790 */ 255, 254, 86, 85, 84, 83, 82, 81, 80, 79, + /* 800 */ 78, 431, 1243, 272, 292, 269, 287, 1243, 130, 291, + /* 810 */ 889, 805, 290, 279, 288, 187, 281, 289, 88, 87, + /* 820 */ 809, 308, 1259, 368, 420, 224, 186, 1259, 292, 347, + /* 830 */ 287, 310, 96, 291, 347, 815, 290, 1243, 288, 349, + /* 840 */ 1119, 289, 134, 1217, 349, 1243, 1115, 97, 1217, 60, + /* 850 */ 814, 136, 182, 204, 1244, 1245, 1248, 1259, 207, 1244, + /* 860 */ 1245, 1248, 98, 99, 347, 1259, 31, 29, 27, 26, + /* 870 */ 25, 100, 347, 101, 349, 96, 1117, 146, 1217, 1113, + /* 880 */ 102, 1243, 349, 359, 103, 149, 1217, 311, 199, 1244, + /* 890 */ 1245, 1248, 888, 1322, 319, 1332, 208, 1244, 1245, 1248, + /* 900 */ 312, 1259, 353, 147, 1243, 152, 316, 227, 347, 1243, + /* 910 */ 31, 29, 27, 26, 25, 1331, 868, 155, 349, 323, + /* 920 */ 5, 328, 1217, 898, 1259, 315, 1312, 159, 4, 1259, + /* 930 */ 110, 347, 200, 1244, 1245, 1248, 347, 960, 91, 887, + /* 940 */ 33, 349, 161, 1306, 1243, 1217, 349, 162, 344, 341, + /* 950 */ 1217, 17, 1243, 229, 1367, 209, 1244, 1245, 1248, 331, + /* 960 */ 1256, 1244, 1245, 1248, 1259, 1273, 356, 357, 179, 1349, + /* 970 */ 168, 347, 1259, 1204, 1243, 1203, 351, 177, 352, 347, + /* 980 */ 92, 349, 51, 237, 358, 1217, 188, 1130, 53, 349, + /* 990 */ 190, 366, 185, 1217, 1259, 1255, 1244, 1245, 1248, 427, + /* 1000 */ 197, 347, 1243, 1254, 1244, 1245, 1248, 90, 198, 193, + /* 1010 */ 1243, 349, 192, 1211, 839, 1217, 1188, 114, 1298, 1299, + /* 1020 */ 94, 1303, 1259, 1187, 1186, 215, 1244, 1245, 1248, 347, + /* 1030 */ 1259, 1185, 1243, 1184, 1183, 1182, 1181, 347, 126, 349, + /* 1040 */ 1243, 841, 1180, 1217, 1179, 1178, 1177, 349, 1071, 1210, + /* 1050 */ 1201, 1217, 1259, 214, 1244, 1245, 1248, 1108, 724, 347, + /* 1060 */ 1259, 216, 1244, 1245, 1248, 1018, 1019, 347, 1070, 349, + /* 1070 */ 1068, 132, 275, 1217, 111, 219, 1057, 349, 331, 273, + /* 1080 */ 276, 1217, 131, 213, 1244, 1245, 1248, 274, 1056, 1053, + /* 1090 */ 1110, 203, 1244, 1245, 1248, 67, 133, 284, 822, 92, + /* 1100 */ 821, 283, 820, 1109, 752, 44, 1066, 751, 129, 750, + /* 1110 */ 749, 220, 748, 218, 217, 747, 282, 20, 221, 1061, + /* 1120 */ 222, 296, 285, 1059, 223, 299, 90, 31, 29, 27, + /* 1130 */ 26, 25, 22, 1052, 301, 1051, 115, 1298, 1299, 303, + /* 1140 */ 1303, 65, 31, 29, 27, 26, 25, 910, 1209, 912, + /* 1150 */ 913, 914, 915, 916, 1208, 128, 1200, 148, 14, 125, + /* 1160 */ 45, 36, 3, 153, 150, 32, 37, 158, 985, 108, + /* 1170 */ 34, 1235, 157, 164, 979, 46, 19, 978, 47, 48, + /* 1180 */ 15, 35, 957, 1007, 1006, 956, 8, 1012, 230, 116, + /* 1190 */ 1011, 1010, 16, 10, 896, 231, 13, 921, 172, 18, + /* 1200 */ 171, 983, 174, 354, 176, 49, 1199, 178, 50, 878, + /* 1210 */ 38, 367, 244, 806, 180, 369, 54, 371, 803, 1234, + /* 1220 */ 800, 183, 365, 372, 374, 783, 375, 377, 794, 378, + /* 1230 */ 380, 792, 817, 381, 813, 812, 811, 55, 722, 56, + /* 1240 */ 57, 744, 397, 743, 736, 742, 741, 740, 739, 738, + /* 1250 */ 387, 737, 1067, 735, 798, 734, 733, 797, 732, 731, + /* 1260 */ 796, 795, 730, 729, 728, 727, 417, 418, 1055, 1054, + /* 1270 */ 421, 422, 419, 1050, 816, 425, 426, 1025, 865, 191, + /* 1280 */ 429, 430, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 0, 207, 190, 174, 221, 222, 172, 213, 214, 187, - /* 10 */ 172, 177, 183, 12, 13, 14, 15, 16, 2, 207, - /* 20 */ 191, 14, 15, 16, 0, 213, 214, 193, 12, 13, - /* 30 */ 14, 15, 16, 20, 163, 21, 198, 20, 24, 25, - /* 40 */ 26, 27, 28, 29, 30, 31, 32, 187, 47, 49, - /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - /* 60 */ 60, 61, 62, 63, 64, 65, 66, 67, 0, 165, - /* 70 */ 46, 167, 71, 12, 13, 14, 15, 16, 186, 33, - /* 80 */ 79, 203, 36, 212, 206, 193, 166, 209, 42, 21, - /* 90 */ 44, 2, 24, 25, 26, 27, 28, 29, 30, 31, - /* 100 */ 32, 12, 13, 14, 15, 16, 186, 236, 47, 49, - /* 110 */ 218, 51, 46, 193, 54, 69, 115, 57, 72, 59, - /* 120 */ 249, 47, 62, 203, 253, 124, 125, 207, 127, 128, - /* 130 */ 129, 130, 131, 132, 133, 134, 0, 217, 218, 219, - /* 140 */ 79, 85, 86, 87, 88, 89, 90, 91, 92, 93, - /* 150 */ 94, 95, 185, 97, 98, 99, 100, 101, 102, 186, - /* 160 */ 166, 22, 116, 196, 172, 192, 120, 174, 248, 179, - /* 170 */ 197, 20, 182, 12, 13, 14, 115, 38, 63, 190, - /* 180 */ 186, 20, 46, 22, 191, 124, 125, 193, 127, 128, - /* 190 */ 129, 130, 131, 132, 133, 134, 207, 203, 20, 38, - /* 200 */ 126, 207, 213, 214, 212, 172, 212, 68, 47, 137, - /* 210 */ 177, 217, 218, 219, 220, 166, 126, 184, 224, 225, - /* 220 */ 193, 70, 107, 108, 12, 13, 193, 200, 236, 68, - /* 230 */ 236, 70, 20, 94, 22, 186, 146, 147, 148, 149, - /* 240 */ 150, 249, 193, 249, 166, 253, 195, 253, 70, 20, - /* 250 */ 38, 3, 203, 202, 203, 94, 207, 203, 20, 47, - /* 260 */ 22, 122, 123, 209, 186, 172, 217, 218, 219, 220, - /* 270 */ 177, 193, 57, 224, 225, 226, 61, 184, 40, 172, - /* 280 */ 68, 203, 70, 122, 123, 207, 193, 238, 137, 1, - /* 290 */ 2, 171, 166, 244, 245, 217, 218, 219, 220, 84, - /* 300 */ 193, 181, 224, 225, 226, 236, 94, 172, 188, 175, - /* 310 */ 176, 115, 186, 12, 13, 14, 15, 16, 249, 193, - /* 320 */ 124, 166, 253, 245, 46, 215, 219, 20, 193, 203, - /* 330 */ 134, 169, 170, 207, 122, 123, 229, 230, 231, 20, - /* 340 */ 233, 186, 232, 217, 218, 219, 220, 212, 193, 137, - /* 350 */ 224, 225, 226, 22, 219, 166, 166, 20, 203, 71, - /* 360 */ 186, 235, 207, 20, 229, 230, 231, 193, 233, 38, - /* 370 */ 178, 236, 217, 218, 219, 220, 186, 172, 186, 224, - /* 380 */ 225, 226, 177, 193, 249, 166, 194, 81, 253, 166, - /* 390 */ 235, 187, 218, 203, 12, 13, 207, 207, 193, 166, - /* 400 */ 215, 153, 20, 186, 22, 186, 0, 217, 218, 219, - /* 410 */ 220, 194, 193, 186, 224, 225, 226, 232, 172, 192, - /* 420 */ 38, 186, 203, 177, 197, 235, 207, 192, 121, 47, - /* 430 */ 207, 212, 197, 12, 13, 167, 217, 218, 219, 193, - /* 440 */ 207, 20, 166, 22, 18, 166, 166, 166, 74, 23, - /* 450 */ 68, 77, 70, 0, 119, 236, 12, 13, 14, 38, - /* 460 */ 43, 35, 186, 57, 20, 166, 22, 61, 249, 193, - /* 470 */ 166, 45, 253, 186, 137, 22, 94, 142, 143, 203, - /* 480 */ 166, 166, 38, 207, 197, 186, 207, 207, 207, 68, - /* 490 */ 84, 70, 193, 217, 218, 219, 220, 186, 20, 187, - /* 500 */ 224, 225, 203, 0, 122, 123, 207, 14, 197, 103, - /* 510 */ 104, 207, 68, 20, 70, 94, 217, 218, 219, 220, - /* 520 */ 178, 207, 207, 224, 225, 12, 13, 21, 186, 12, - /* 530 */ 13, 105, 187, 20, 83, 22, 194, 20, 94, 22, - /* 540 */ 34, 166, 215, 122, 123, 0, 12, 13, 14, 15, - /* 550 */ 16, 38, 49, 136, 51, 38, 166, 54, 137, 232, - /* 560 */ 57, 186, 59, 137, 166, 62, 122, 123, 193, 24, - /* 570 */ 25, 26, 27, 28, 29, 30, 31, 32, 203, 20, - /* 580 */ 0, 68, 207, 70, 186, 68, 27, 70, 176, 30, - /* 590 */ 166, 193, 217, 218, 219, 4, 19, 207, 39, 121, - /* 600 */ 166, 203, 22, 256, 172, 207, 178, 94, 157, 177, - /* 610 */ 33, 94, 71, 36, 186, 217, 218, 219, 220, 42, - /* 620 */ 186, 44, 194, 225, 83, 193, 166, 193, 247, 254, - /* 630 */ 255, 207, 0, 166, 166, 122, 123, 203, 172, 122, - /* 640 */ 123, 207, 196, 177, 210, 172, 69, 166, 166, 72, - /* 650 */ 177, 217, 218, 219, 22, 166, 241, 166, 166, 193, - /* 660 */ 135, 136, 186, 166, 169, 106, 193, 207, 109, 110, - /* 670 */ 111, 112, 113, 83, 207, 207, 166, 38, 186, 74, - /* 680 */ 103, 166, 77, 186, 74, 193, 166, 77, 207, 207, - /* 690 */ 193, 38, 158, 159, 117, 203, 207, 120, 207, 207, - /* 700 */ 203, 186, 210, 172, 207, 234, 186, 68, 193, 217, - /* 710 */ 218, 219, 166, 193, 217, 218, 219, 207, 203, 1, - /* 720 */ 2, 68, 207, 203, 193, 210, 20, 207, 166, 138, - /* 730 */ 210, 166, 217, 218, 219, 216, 166, 217, 218, 219, - /* 740 */ 12, 13, 14, 15, 16, 155, 172, 172, 186, 171, - /* 750 */ 219, 186, 255, 207, 250, 193, 186, 0, 193, 228, - /* 760 */ 229, 230, 231, 193, 233, 203, 188, 193, 203, 207, - /* 770 */ 237, 114, 207, 203, 166, 74, 115, 207, 77, 217, - /* 780 */ 218, 219, 217, 218, 219, 71, 71, 217, 218, 219, - /* 790 */ 201, 199, 199, 219, 186, 172, 166, 83, 83, 71, - /* 800 */ 71, 193, 166, 229, 230, 231, 20, 233, 161, 162, - /* 810 */ 211, 203, 83, 193, 57, 207, 186, 174, 61, 20, - /* 820 */ 71, 70, 186, 193, 174, 217, 218, 219, 70, 193, - /* 830 */ 166, 80, 83, 203, 71, 204, 166, 207, 172, 203, - /* 840 */ 82, 84, 174, 207, 168, 174, 83, 217, 218, 219, - /* 850 */ 186, 20, 172, 217, 218, 219, 186, 193, 71, 186, - /* 860 */ 103, 104, 168, 193, 166, 186, 71, 203, 71, 186, - /* 870 */ 83, 207, 186, 203, 71, 186, 186, 207, 83, 186, - /* 880 */ 83, 217, 218, 219, 186, 186, 83, 217, 218, 219, - /* 890 */ 71, 193, 166, 186, 71, 71, 186, 71, 166, 71, - /* 900 */ 204, 203, 83, 186, 171, 207, 83, 83, 71, 83, - /* 910 */ 171, 83, 186, 211, 193, 217, 218, 219, 186, 193, - /* 920 */ 83, 20, 145, 246, 216, 193, 144, 208, 123, 203, - /* 930 */ 207, 246, 166, 207, 207, 203, 152, 242, 208, 207, - /* 940 */ 166, 207, 151, 217, 218, 219, 12, 13, 243, 217, - /* 950 */ 218, 219, 186, 140, 139, 239, 22, 136, 193, 193, - /* 960 */ 186, 20, 240, 215, 114, 227, 160, 193, 166, 203, - /* 970 */ 257, 154, 38, 207, 4, 35, 156, 203, 70, 223, - /* 980 */ 208, 207, 251, 217, 218, 219, 207, 252, 186, 19, - /* 990 */ 207, 217, 218, 219, 118, 193, 208, 57, 205, 207, - /* 1000 */ 193, 61, 68, 33, 204, 203, 36, 171, 70, 207, - /* 1010 */ 171, 41, 182, 73, 44, 75, 76, 172, 78, 217, - /* 1020 */ 218, 219, 193, 189, 84, 171, 168, 180, 94, 180, - /* 1030 */ 173, 164, 0, 82, 0, 0, 114, 0, 0, 69, - /* 1040 */ 0, 0, 72, 0, 0, 22, 0, 0, 0, 0, - /* 1050 */ 0, 0, 0, 43, 0, 48, 122, 123, 0, 0, - /* 1060 */ 38, 36, 43, 0, 0, 0, 0, 79, 77, 38, - /* 1070 */ 0, 38, 0, 0, 38, 22, 0, 38, 0, 22, - /* 1080 */ 38, 0, 22, 38, 22, 0, 0, 121, 0, 116, - /* 1090 */ 22, 22, 83, 38, 38, 20, 70, 83, 141, 71, - /* 1100 */ 39, 83, 141, 83, 83, 38, 82, 135, 141, 82, - /* 1110 */ 4, 2, 83, 83, 43, 126, 119, 0, 116, 258, - /* 1120 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1130 */ 38, 38, 38, 38, 38, 38, 22, 258, 258, 258, - /* 1140 */ 258, 258, 258, 43, 258, 71, 258, 70, 258, 70, - /* 1150 */ 258, 71, 70, 258, 71, 71, 258, 70, 258, 258, - /* 1160 */ 71, 258, 71, 258, 258, 258, 258, 258, 258, 38, - /* 1170 */ 71, 70, 82, 70, 38, 71, 71, 70, 70, 258, - /* 1180 */ 82, 70, 70, 258, 82, 70, 38, 258, 38, 71, - /* 1190 */ 80, 38, 22, 258, 38, 82, 258, 81, 22, 258, - /* 1200 */ 258, 258, 70, 22, 71, 70, 0, 258, 71, 22, - /* 1210 */ 258, 20, 22, 38, 70, 96, 38, 71, 258, 258, - /* 1220 */ 258, 38, 70, 38, 38, 48, 71, 38, 70, 47, - /* 1230 */ 96, 38, 0, 38, 38, 43, 38, 38, 0, 0, - /* 1240 */ 36, 38, 70, 70, 70, 38, 37, 68, 38, 21, - /* 1250 */ 258, 22, 38, 38, 38, 84, 38, 96, 22, 96, - /* 1260 */ 38, 38, 21, 258, 258, 258, 258, 258, 258, 258, - /* 1270 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1280 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1290 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1300 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1310 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1320 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1330 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1340 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1350 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1360 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1370 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1380 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1390 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1400 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1410 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1420 */ 258, 258, 258, 258, 258, 258, + /* 0 */ 216, 183, 181, 175, 196, 212, 222, 223, 215, 196, + /* 10 */ 192, 218, 12, 13, 14, 15, 16, 195, 200, 231, + /* 20 */ 232, 246, 199, 195, 202, 12, 13, 14, 15, 16, + /* 30 */ 202, 181, 181, 181, 259, 20, 186, 186, 263, 216, + /* 40 */ 212, 175, 221, 193, 216, 222, 223, 47, 0, 221, + /* 50 */ 228, 20, 202, 202, 226, 227, 228, 229, 230, 207, + /* 60 */ 47, 195, 234, 235, 204, 181, 0, 246, 202, 69, + /* 70 */ 186, 211, 212, 187, 246, 184, 185, 77, 212, 212, + /* 80 */ 259, 195, 216, 68, 263, 218, 202, 259, 22, 203, + /* 90 */ 77, 263, 226, 227, 228, 229, 0, 49, 50, 51, + /* 100 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + /* 110 */ 62, 63, 64, 65, 66, 188, 116, 21, 191, 175, + /* 120 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 116, + /* 130 */ 264, 265, 178, 179, 134, 135, 136, 137, 138, 139, + /* 140 */ 140, 141, 142, 143, 14, 15, 16, 134, 135, 136, + /* 150 */ 137, 138, 139, 140, 141, 142, 143, 1, 2, 175, + /* 160 */ 216, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 170 */ 92, 93, 20, 95, 96, 97, 98, 99, 100, 195, + /* 180 */ 12, 13, 174, 195, 176, 199, 202, 175, 20, 201, + /* 190 */ 22, 12, 13, 14, 206, 46, 212, 20, 195, 20, + /* 200 */ 216, 22, 216, 175, 20, 202, 38, 0, 222, 223, + /* 210 */ 226, 227, 228, 229, 230, 47, 181, 38, 234, 235, + /* 220 */ 236, 186, 20, 195, 22, 69, 47, 81, 216, 0, + /* 230 */ 202, 228, 248, 12, 13, 172, 68, 202, 254, 255, + /* 240 */ 212, 20, 40, 22, 216, 68, 120, 68, 12, 13, + /* 250 */ 14, 15, 16, 46, 226, 227, 228, 229, 230, 38, + /* 260 */ 92, 3, 234, 235, 236, 144, 145, 175, 47, 181, + /* 270 */ 116, 92, 104, 245, 186, 46, 195, 151, 152, 175, + /* 280 */ 175, 193, 201, 104, 221, 12, 13, 206, 134, 68, + /* 290 */ 202, 123, 124, 125, 126, 22, 128, 143, 146, 195, + /* 300 */ 20, 194, 123, 124, 125, 126, 202, 128, 216, 246, + /* 310 */ 164, 38, 205, 92, 146, 175, 212, 175, 195, 175, + /* 320 */ 216, 216, 259, 146, 201, 104, 263, 63, 0, 206, + /* 330 */ 226, 227, 228, 229, 230, 195, 181, 224, 234, 235, + /* 340 */ 236, 186, 202, 181, 123, 124, 125, 126, 186, 128, + /* 350 */ 22, 175, 212, 12, 13, 242, 216, 202, 216, 255, + /* 360 */ 216, 20, 224, 22, 202, 92, 226, 227, 228, 229, + /* 370 */ 230, 195, 108, 109, 234, 235, 236, 104, 202, 38, + /* 380 */ 242, 12, 13, 14, 14, 245, 175, 79, 212, 20, + /* 390 */ 20, 22, 216, 146, 181, 181, 123, 124, 125, 186, + /* 400 */ 175, 175, 226, 227, 228, 229, 230, 38, 175, 68, + /* 410 */ 234, 235, 236, 4, 187, 202, 202, 20, 12, 13, + /* 420 */ 162, 245, 195, 46, 12, 13, 20, 216, 22, 180, + /* 430 */ 203, 175, 20, 92, 22, 175, 195, 68, 175, 190, + /* 440 */ 187, 216, 216, 229, 38, 104, 197, 206, 195, 216, + /* 450 */ 38, 195, 238, 239, 240, 241, 203, 243, 202, 175, + /* 460 */ 175, 92, 20, 202, 123, 124, 125, 126, 212, 128, + /* 470 */ 209, 175, 216, 104, 68, 20, 216, 221, 195, 216, + /* 480 */ 68, 175, 226, 227, 228, 229, 57, 146, 4, 206, + /* 490 */ 61, 196, 123, 124, 125, 126, 183, 128, 92, 196, + /* 500 */ 216, 216, 246, 19, 92, 175, 175, 0, 175, 175, + /* 510 */ 104, 82, 216, 200, 175, 259, 104, 33, 20, 263, + /* 520 */ 36, 224, 216, 1, 2, 41, 195, 180, 44, 123, + /* 530 */ 124, 125, 126, 202, 128, 123, 124, 125, 126, 242, + /* 540 */ 128, 124, 175, 212, 197, 195, 216, 216, 43, 216, + /* 550 */ 216, 67, 81, 203, 70, 216, 147, 226, 227, 228, + /* 560 */ 229, 230, 195, 181, 57, 234, 235, 21, 61, 202, + /* 570 */ 22, 196, 155, 156, 157, 158, 159, 122, 175, 212, + /* 580 */ 34, 38, 72, 216, 202, 75, 38, 18, 72, 82, + /* 590 */ 176, 75, 23, 226, 227, 228, 229, 230, 195, 257, + /* 600 */ 22, 234, 235, 221, 35, 202, 69, 175, 101, 102, + /* 610 */ 103, 229, 105, 0, 45, 212, 38, 47, 81, 216, + /* 620 */ 122, 239, 240, 241, 0, 243, 175, 195, 246, 226, + /* 630 */ 227, 228, 229, 230, 202, 22, 72, 166, 235, 75, + /* 640 */ 92, 259, 69, 69, 212, 263, 195, 104, 216, 175, + /* 650 */ 145, 219, 104, 202, 81, 81, 170, 171, 226, 227, + /* 660 */ 228, 229, 72, 212, 68, 75, 185, 216, 175, 195, + /* 670 */ 219, 123, 124, 125, 78, 106, 202, 226, 227, 228, + /* 680 */ 229, 57, 38, 205, 69, 61, 212, 69, 195, 266, + /* 690 */ 216, 251, 178, 225, 124, 202, 81, 20, 68, 81, + /* 700 */ 226, 227, 228, 229, 27, 212, 82, 30, 175, 216, + /* 710 */ 80, 69, 69, 175, 244, 146, 39, 260, 69, 226, + /* 720 */ 227, 228, 229, 81, 81, 101, 102, 103, 195, 105, + /* 730 */ 81, 195, 258, 195, 247, 202, 20, 181, 115, 210, + /* 740 */ 202, 69, 116, 208, 181, 212, 20, 208, 104, 216, + /* 750 */ 212, 69, 219, 81, 216, 0, 202, 219, 265, 226, + /* 760 */ 227, 228, 229, 81, 226, 227, 228, 229, 0, 220, + /* 770 */ 183, 21, 20, 69, 24, 25, 26, 27, 28, 29, + /* 780 */ 30, 31, 32, 183, 107, 81, 183, 110, 111, 112, + /* 790 */ 113, 114, 24, 25, 26, 27, 28, 29, 30, 31, + /* 800 */ 32, 19, 175, 181, 49, 213, 51, 175, 183, 54, + /* 810 */ 20, 69, 57, 177, 59, 33, 195, 62, 36, 181, + /* 820 */ 69, 220, 195, 81, 42, 177, 44, 195, 49, 202, + /* 830 */ 51, 202, 81, 54, 202, 69, 57, 175, 59, 212, + /* 840 */ 195, 62, 195, 216, 212, 175, 195, 81, 216, 67, + /* 850 */ 69, 195, 70, 226, 227, 228, 229, 195, 226, 227, + /* 860 */ 228, 229, 81, 69, 202, 195, 12, 13, 14, 15, + /* 870 */ 16, 195, 202, 195, 212, 81, 195, 180, 216, 195, + /* 880 */ 195, 175, 212, 101, 195, 180, 216, 213, 226, 227, + /* 890 */ 228, 229, 20, 225, 154, 256, 226, 227, 228, 229, + /* 900 */ 118, 195, 153, 121, 175, 217, 216, 216, 202, 175, + /* 910 */ 12, 13, 14, 15, 16, 256, 125, 217, 212, 216, + /* 920 */ 161, 160, 216, 69, 195, 149, 253, 252, 148, 195, + /* 930 */ 250, 202, 226, 227, 228, 229, 202, 145, 202, 20, + /* 940 */ 115, 212, 249, 224, 175, 216, 212, 237, 165, 163, + /* 950 */ 216, 68, 175, 169, 267, 226, 227, 228, 229, 181, + /* 960 */ 226, 227, 228, 229, 195, 233, 119, 214, 180, 262, + /* 970 */ 261, 202, 195, 217, 175, 217, 216, 202, 216, 202, + /* 980 */ 202, 212, 180, 216, 213, 216, 191, 202, 68, 212, + /* 990 */ 181, 198, 180, 216, 195, 226, 227, 228, 229, 177, + /* 1000 */ 189, 202, 175, 226, 227, 228, 229, 229, 189, 173, + /* 1010 */ 175, 212, 182, 0, 80, 216, 0, 239, 240, 241, + /* 1020 */ 115, 243, 195, 0, 0, 226, 227, 228, 229, 202, + /* 1030 */ 195, 0, 175, 0, 0, 0, 0, 202, 43, 212, + /* 1040 */ 175, 22, 0, 216, 0, 0, 0, 212, 0, 0, + /* 1050 */ 0, 216, 195, 226, 227, 228, 229, 0, 48, 202, + /* 1060 */ 195, 226, 227, 228, 229, 167, 168, 202, 0, 212, + /* 1070 */ 0, 33, 43, 216, 36, 35, 0, 212, 181, 38, + /* 1080 */ 42, 216, 44, 226, 227, 228, 229, 36, 0, 0, + /* 1090 */ 0, 226, 227, 228, 229, 77, 75, 57, 38, 202, + /* 1100 */ 38, 61, 22, 0, 38, 67, 0, 38, 70, 38, + /* 1110 */ 38, 71, 38, 73, 74, 38, 76, 2, 22, 0, + /* 1120 */ 22, 39, 82, 0, 22, 38, 229, 12, 13, 14, + /* 1130 */ 15, 16, 2, 0, 22, 0, 239, 240, 241, 22, + /* 1140 */ 243, 20, 12, 13, 14, 15, 16, 127, 0, 129, + /* 1150 */ 130, 131, 132, 133, 0, 117, 0, 43, 150, 121, + /* 1160 */ 68, 122, 81, 69, 117, 81, 81, 81, 69, 68, + /* 1170 */ 144, 80, 68, 80, 69, 68, 81, 69, 68, 4, + /* 1180 */ 150, 81, 69, 38, 38, 69, 2, 69, 38, 80, + /* 1190 */ 38, 38, 81, 150, 69, 38, 68, 124, 69, 68, + /* 1200 */ 80, 69, 68, 120, 68, 68, 0, 43, 68, 22, + /* 1210 */ 68, 38, 38, 69, 117, 68, 78, 38, 69, 80, + /* 1220 */ 69, 80, 79, 68, 38, 22, 68, 38, 69, 68, + /* 1230 */ 38, 69, 38, 68, 38, 38, 22, 68, 48, 68, + /* 1240 */ 68, 22, 47, 38, 22, 38, 38, 38, 38, 38, + /* 1250 */ 82, 38, 0, 38, 94, 38, 38, 94, 38, 38, + /* 1260 */ 94, 94, 38, 38, 38, 38, 38, 36, 0, 0, + /* 1270 */ 38, 37, 43, 0, 104, 22, 21, 268, 22, 22, + /* 1280 */ 21, 20, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1290 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1300 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1310 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1320 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1330 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1340 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1350 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1360 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1370 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1380 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1390 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1400 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1410 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1420 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1430 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1440 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1450 */ 268, 268, 268, 268, }; -#define YY_SHIFT_COUNT (429) +#define YY_SHIFT_COUNT (431) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1241) +#define YY_SHIFT_MAX (1273) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 426, 212, 161, 382, 382, 382, 382, 421, 382, 382, - /* 10 */ 151, 513, 517, 444, 513, 513, 513, 513, 513, 513, - /* 20 */ 513, 513, 513, 513, 513, 513, 513, 513, 513, 513, - /* 30 */ 513, 513, 513, 178, 178, 178, 337, 934, 934, 13, - /* 40 */ 13, 934, 13, 13, 66, 17, 229, 229, 72, 319, - /* 50 */ 17, 13, 13, 17, 13, 17, 319, 17, 17, 13, - /* 60 */ 278, 1, 61, 61, 559, 14, 940, 139, 60, 139, - /* 70 */ 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, - /* 80 */ 139, 139, 139, 139, 139, 139, 139, 139, 238, 24, - /* 90 */ 307, 307, 307, 136, 343, 319, 17, 17, 17, 306, - /* 100 */ 56, 56, 56, 56, 56, 68, 503, 534, 90, 215, - /* 110 */ 335, 331, 478, 525, 417, 525, 493, 248, 591, 706, - /* 120 */ 657, 661, 661, 706, 786, 66, 343, 799, 66, 66, - /* 130 */ 706, 66, 831, 17, 17, 17, 17, 17, 17, 17, - /* 140 */ 17, 17, 17, 17, 706, 831, 786, 278, 343, 799, - /* 150 */ 278, 901, 777, 782, 805, 777, 782, 805, 805, 784, - /* 160 */ 791, 813, 815, 821, 343, 941, 850, 806, 820, 817, - /* 170 */ 908, 17, 782, 805, 805, 782, 805, 876, 343, 799, - /* 180 */ 278, 306, 278, 343, 938, 706, 278, 831, 1263, 1263, - /* 190 */ 1263, 1263, 0, 545, 577, 46, 970, 16, 89, 728, - /* 200 */ 406, 757, 301, 301, 301, 301, 301, 301, 301, 115, - /* 210 */ 288, 196, 7, 7, 7, 7, 374, 605, 610, 701, - /* 220 */ 453, 580, 632, 506, 541, 714, 715, 718, 647, 590, - /* 230 */ 451, 729, 74, 749, 758, 763, 787, 795, 797, 803, - /* 240 */ 639, 653, 819, 823, 824, 826, 828, 837, 751, 1032, - /* 250 */ 951, 1034, 1035, 922, 1037, 1038, 1040, 1041, 1043, 1044, - /* 260 */ 1023, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1010, 1054, - /* 270 */ 1007, 1058, 1059, 1022, 1025, 1019, 1063, 1064, 1065, 1066, - /* 280 */ 988, 991, 1031, 1033, 1053, 1070, 1036, 1039, 1042, 1045, - /* 290 */ 1055, 1056, 1072, 1057, 1073, 1060, 1061, 1076, 1062, 1067, - /* 300 */ 1078, 1068, 1081, 1069, 1075, 1085, 1086, 966, 1088, 1026, - /* 310 */ 1071, 973, 1009, 1014, 957, 1028, 1018, 1074, 1077, 1079, - /* 320 */ 1080, 1082, 1083, 1020, 1024, 1087, 1021, 961, 1084, 1089, - /* 330 */ 1027, 972, 1029, 1090, 1091, 1030, 967, 1106, 1092, 1093, - /* 340 */ 1094, 1095, 1096, 1097, 1109, 989, 1098, 1099, 1101, 1103, - /* 350 */ 1104, 1105, 1107, 1108, 997, 1111, 1117, 1100, 1002, 1112, - /* 360 */ 1110, 1102, 1113, 1114, 1115, 1116, 1118, 1131, 1136, 1132, - /* 370 */ 1133, 1148, 1135, 1137, 1150, 1144, 1146, 1153, 1152, 1155, - /* 380 */ 1156, 1158, 1119, 1134, 1161, 1163, 1170, 1171, 1172, 1173, - /* 390 */ 1174, 1175, 1178, 1176, 1177, 1182, 1179, 1181, 1183, 1185, - /* 400 */ 1186, 1189, 1193, 1195, 1196, 1187, 1198, 1199, 1203, 1210, - /* 410 */ 1214, 1215, 1216, 1218, 1222, 1206, 1207, 1204, 1192, 1232, - /* 420 */ 1223, 1209, 1238, 1239, 1190, 1228, 1229, 1236, 1241, 1191, + /* 0 */ 569, 168, 179, 221, 221, 221, 221, 341, 221, 221, + /* 10 */ 406, 412, 177, 369, 406, 406, 406, 406, 406, 406, + /* 20 */ 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, + /* 30 */ 406, 406, 406, 15, 15, 15, 152, 273, 273, 31, + /* 40 */ 31, 273, 31, 31, 149, 184, 280, 280, 247, 397, + /* 50 */ 184, 31, 31, 184, 31, 184, 397, 184, 184, 31, + /* 60 */ 377, 0, 13, 13, 677, 750, 1040, 548, 548, 548, + /* 70 */ 548, 548, 548, 548, 548, 548, 548, 548, 548, 548, + /* 80 */ 548, 548, 548, 548, 548, 548, 548, 779, 202, 207, + /* 90 */ 455, 455, 455, 229, 442, 397, 184, 184, 184, 308, + /* 100 */ 78, 78, 78, 78, 78, 96, 755, 898, 417, 429, + /* 110 */ 126, 578, 498, 121, 505, 121, 370, 258, 409, 716, + /* 120 */ 623, 626, 626, 716, 726, 149, 442, 752, 149, 149, + /* 130 */ 716, 149, 790, 184, 184, 184, 184, 184, 184, 184, + /* 140 */ 184, 184, 184, 184, 716, 790, 726, 377, 442, 752, + /* 150 */ 377, 872, 740, 749, 791, 740, 749, 791, 791, 759, + /* 160 */ 761, 776, 780, 792, 442, 919, 825, 784, 783, 786, + /* 170 */ 883, 184, 749, 791, 791, 749, 791, 847, 442, 752, + /* 180 */ 377, 308, 377, 442, 920, 716, 377, 790, 1282, 1282, + /* 190 */ 1282, 1282, 48, 768, 782, 1038, 484, 507, 624, 1115, + /* 200 */ 1130, 1020, 854, 236, 236, 236, 236, 236, 236, 236, + /* 210 */ 264, 156, 154, 130, 130, 130, 130, 510, 516, 564, + /* 220 */ 590, 66, 328, 613, 546, 537, 573, 574, 522, 486, + /* 230 */ 146, 471, 615, 570, 618, 630, 642, 643, 649, 672, + /* 240 */ 682, 543, 644, 704, 742, 751, 766, 781, 794, 596, + /* 250 */ 1013, 934, 1016, 1023, 905, 1024, 1031, 1033, 1034, 1035, + /* 260 */ 1036, 1019, 1042, 1044, 1045, 1046, 1048, 1049, 1050, 995, + /* 270 */ 1057, 1010, 1068, 1070, 1041, 1051, 1029, 1076, 1088, 1089, + /* 280 */ 1090, 1018, 1021, 1060, 1062, 1080, 1103, 1066, 1069, 1071, + /* 290 */ 1072, 1074, 1077, 1106, 1096, 1119, 1098, 1082, 1123, 1102, + /* 300 */ 1087, 1133, 1112, 1135, 1117, 1121, 1148, 1154, 1039, 1156, + /* 310 */ 1092, 1114, 1047, 1081, 1084, 1008, 1094, 1085, 1099, 1101, + /* 320 */ 1104, 1105, 1107, 1108, 1086, 1091, 1110, 1095, 1030, 1113, + /* 330 */ 1116, 1093, 1026, 1100, 1109, 1118, 1111, 1043, 1175, 1145, + /* 340 */ 1146, 1150, 1152, 1153, 1157, 1184, 1073, 1120, 1125, 1128, + /* 350 */ 1131, 1129, 1132, 1134, 1136, 1083, 1137, 1206, 1164, 1097, + /* 360 */ 1140, 1138, 1139, 1141, 1187, 1142, 1143, 1144, 1173, 1174, + /* 370 */ 1147, 1149, 1179, 1155, 1151, 1186, 1158, 1159, 1189, 1161, + /* 380 */ 1162, 1192, 1165, 1160, 1163, 1166, 1167, 1203, 1168, 1169, + /* 390 */ 1194, 1170, 1171, 1172, 1196, 1197, 1214, 1190, 1195, 1219, + /* 400 */ 1205, 1207, 1208, 1209, 1210, 1211, 1213, 1222, 1215, 1217, + /* 410 */ 1218, 1220, 1221, 1224, 1225, 1226, 1227, 1252, 1228, 1231, + /* 420 */ 1229, 1268, 1232, 1234, 1269, 1273, 1253, 1255, 1256, 1257, + /* 430 */ 1259, 1261, }; #define YY_REDUCE_COUNT (191) -#define YY_REDUCE_MIN (-217) -#define YY_REDUCE_MAX (867) +#define YY_REDUCE_MIN (-225) +#define YY_REDUCE_MAX (897) static const short yy_reduce_ofst[] = { - /* 0 */ -129, -6, 49, 78, 126, 155, 190, 219, 276, 299, - /* 10 */ 135, 375, 398, 434, 492, -80, 497, 515, 520, 562, - /* 20 */ 565, 570, 608, 630, 636, 664, 670, 698, 726, 732, - /* 30 */ 766, 774, 802, 531, 107, 574, -8, -188, -11, 33, - /* 40 */ 93, -206, -166, 205, -171, -27, -108, 174, 69, -122, - /* 50 */ 192, 246, 432, 227, 466, 342, 51, 235, 428, 473, - /* 60 */ 120, -217, -217, -217, -162, -96, -33, 189, 134, 223, - /* 70 */ 233, 279, 280, 281, 304, 314, 315, 390, 424, 460, - /* 80 */ 467, 468, 481, 482, 489, 491, 510, 546, 162, -7, - /* 90 */ 110, 185, 327, 578, 27, 54, 217, 287, 311, -10, - /* 100 */ -178, -140, 204, 312, 345, 268, 412, 347, 381, 446, - /* 110 */ 415, 495, 519, 471, 471, 471, 476, 504, 533, 575, - /* 120 */ 589, 592, 593, 623, 599, 643, 620, 631, 650, 668, - /* 130 */ 666, 671, 676, 673, 679, 683, 686, 689, 690, 693, - /* 140 */ 699, 707, 710, 717, 680, 694, 702, 733, 721, 696, - /* 150 */ 739, 708, 677, 719, 723, 685, 730, 727, 734, 705, - /* 160 */ 695, 722, 716, 471, 765, 748, 738, 713, 735, 731, - /* 170 */ 756, 476, 772, 779, 783, 788, 792, 793, 807, 800, - /* 180 */ 836, 830, 839, 829, 834, 845, 854, 858, 847, 849, - /* 190 */ 857, 867, + /* 0 */ 63, -172, -16, 104, 28, 140, 176, 256, 331, 367, + /* 10 */ -134, 403, 382, 432, 451, 474, 493, 533, 538, 627, + /* 20 */ 632, 662, 670, 706, 729, 734, 769, 777, 799, 827, + /* 30 */ 835, 857, 865, 214, 778, 897, -179, -177, -14, -150, + /* 40 */ 88, -216, -149, -116, -182, -12, -178, 3, -225, -207, + /* 50 */ -114, 35, 155, 81, 162, 227, -140, 123, 253, 213, + /* 60 */ 249, -212, -212, -212, -148, 8, 107, -56, 12, 92, + /* 70 */ 105, 142, 144, 211, 225, 226, 233, 260, 263, 284, + /* 80 */ 285, 296, 306, 330, 333, 334, 339, -109, -46, 313, + /* 90 */ 113, 138, 297, 347, 261, -133, 350, 241, 283, -73, + /* 100 */ -192, -187, 295, 303, 375, 414, 481, 423, 342, 478, + /* 110 */ 440, 514, 468, 470, 470, 470, 536, 457, 487, 556, + /* 120 */ 529, 535, 539, 563, 549, 587, 554, 592, 600, 603, + /* 130 */ 622, 625, 636, 621, 645, 647, 651, 656, 676, 678, + /* 140 */ 681, 684, 685, 689, 638, 648, 601, 697, 629, 674, + /* 150 */ 705, 668, 639, 688, 690, 659, 700, 691, 703, 673, + /* 160 */ 675, 680, 693, 470, 736, 719, 710, 687, 707, 709, + /* 170 */ 732, 536, 756, 760, 762, 758, 767, 753, 775, 771, + /* 180 */ 788, 795, 802, 785, 793, 809, 812, 822, 811, 819, + /* 190 */ 830, 836, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 10 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 20 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 30 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 40 */ 999, 999, 999, 999, 1052, 999, 999, 999, 999, 999, - /* 50 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 60 */ 1050, 999, 1258, 999, 1164, 999, 999, 999, 999, 999, - /* 70 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 80 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 1052, - /* 90 */ 1269, 1269, 1269, 1050, 999, 999, 999, 999, 999, 1135, - /* 100 */ 999, 999, 999, 999, 999, 999, 999, 1333, 999, 1088, - /* 110 */ 1293, 999, 1285, 1261, 1275, 1262, 999, 1318, 1278, 999, - /* 120 */ 1169, 1166, 1166, 999, 999, 1052, 999, 999, 1052, 1052, - /* 130 */ 999, 1052, 999, 999, 999, 999, 999, 999, 999, 999, - /* 140 */ 999, 999, 999, 999, 999, 999, 999, 1050, 999, 999, - /* 150 */ 1050, 999, 1300, 1298, 999, 1300, 1298, 999, 999, 1312, - /* 160 */ 1308, 1291, 1289, 1275, 999, 999, 999, 1336, 1324, 1320, - /* 170 */ 999, 999, 1298, 999, 999, 1298, 999, 1177, 999, 999, - /* 180 */ 1050, 999, 1050, 999, 1104, 999, 1050, 999, 1138, 1138, - /* 190 */ 1053, 1004, 999, 999, 999, 999, 999, 999, 999, 999, - /* 200 */ 999, 999, 1230, 1311, 1310, 1229, 1235, 1234, 1233, 999, - /* 210 */ 999, 999, 1224, 1225, 1223, 1222, 999, 999, 999, 999, - /* 220 */ 999, 999, 999, 999, 999, 999, 999, 1259, 999, 1321, - /* 230 */ 1325, 999, 999, 999, 1209, 999, 999, 999, 999, 999, - /* 240 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 250 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 260 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 270 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 280 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 290 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 300 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 310 */ 999, 999, 1282, 1292, 999, 999, 999, 999, 999, 999, - /* 320 */ 999, 999, 999, 999, 1209, 999, 1309, 999, 1268, 1264, - /* 330 */ 999, 999, 1260, 999, 999, 1319, 999, 999, 999, 999, - /* 340 */ 999, 999, 999, 999, 1254, 999, 999, 999, 999, 999, - /* 350 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 360 */ 999, 1208, 999, 999, 999, 999, 999, 999, 999, 1132, - /* 370 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 380 */ 999, 999, 1117, 1115, 1114, 1113, 999, 1110, 999, 999, - /* 390 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 400 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 410 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 420 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, + /* 0 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 10 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 20 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 30 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 40 */ 1023, 1023, 1023, 1023, 1076, 1023, 1023, 1023, 1023, 1023, + /* 50 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 60 */ 1074, 1023, 1293, 1023, 1189, 1023, 1023, 1023, 1023, 1023, + /* 70 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 80 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1076, + /* 90 */ 1304, 1304, 1304, 1074, 1023, 1023, 1023, 1023, 1023, 1158, + /* 100 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1368, 1023, 1111, + /* 110 */ 1328, 1023, 1320, 1296, 1310, 1297, 1023, 1353, 1313, 1023, + /* 120 */ 1194, 1191, 1191, 1023, 1023, 1076, 1023, 1023, 1076, 1076, + /* 130 */ 1023, 1076, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 140 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1074, 1023, 1023, + /* 150 */ 1074, 1023, 1335, 1333, 1023, 1335, 1333, 1023, 1023, 1347, + /* 160 */ 1343, 1326, 1324, 1310, 1023, 1023, 1023, 1371, 1359, 1355, + /* 170 */ 1023, 1023, 1333, 1023, 1023, 1333, 1023, 1202, 1023, 1023, + /* 180 */ 1074, 1023, 1074, 1023, 1127, 1023, 1074, 1023, 1161, 1161, + /* 190 */ 1077, 1028, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 200 */ 1023, 1023, 1023, 1258, 1346, 1345, 1257, 1270, 1269, 1268, + /* 210 */ 1023, 1023, 1023, 1252, 1253, 1251, 1250, 1023, 1023, 1023, + /* 220 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1294, 1023, + /* 230 */ 1356, 1360, 1023, 1023, 1023, 1236, 1023, 1023, 1023, 1023, + /* 240 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 250 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 260 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 270 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 280 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 290 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 300 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 310 */ 1023, 1023, 1023, 1317, 1327, 1023, 1023, 1023, 1023, 1023, + /* 320 */ 1023, 1023, 1023, 1023, 1023, 1236, 1023, 1344, 1023, 1303, + /* 330 */ 1299, 1023, 1023, 1295, 1023, 1023, 1354, 1023, 1023, 1023, + /* 340 */ 1023, 1023, 1023, 1023, 1023, 1289, 1023, 1023, 1023, 1023, + /* 350 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 360 */ 1023, 1023, 1235, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 370 */ 1155, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 380 */ 1023, 1023, 1023, 1140, 1138, 1137, 1136, 1023, 1133, 1023, + /* 390 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 400 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 410 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 420 */ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + /* 430 */ 1023, 1023, }; /********** End of lemon-generated parsing tables *****************************/ @@ -773,197 +781,207 @@ static const char *const yyTokenName[] = { /* 64 */ "SINGLE_STABLE", /* 65 */ "STREAM_MODE", /* 66 */ "RETENTIONS", - /* 67 */ "FILE_FACTOR", - /* 68 */ "NK_FLOAT", - /* 69 */ "TABLE", - /* 70 */ "NK_LP", - /* 71 */ "NK_RP", - /* 72 */ "STABLE", - /* 73 */ "ADD", - /* 74 */ "COLUMN", - /* 75 */ "MODIFY", - /* 76 */ "RENAME", - /* 77 */ "TAG", - /* 78 */ "SET", - /* 79 */ "NK_EQ", - /* 80 */ "USING", - /* 81 */ "TAGS", - /* 82 */ "NK_DOT", - /* 83 */ "NK_COMMA", - /* 84 */ "COMMENT", - /* 85 */ "BOOL", - /* 86 */ "TINYINT", - /* 87 */ "SMALLINT", - /* 88 */ "INT", - /* 89 */ "INTEGER", - /* 90 */ "BIGINT", - /* 91 */ "FLOAT", - /* 92 */ "DOUBLE", - /* 93 */ "BINARY", - /* 94 */ "TIMESTAMP", - /* 95 */ "NCHAR", - /* 96 */ "UNSIGNED", - /* 97 */ "JSON", - /* 98 */ "VARCHAR", - /* 99 */ "MEDIUMBLOB", - /* 100 */ "BLOB", - /* 101 */ "VARBINARY", - /* 102 */ "DECIMAL", - /* 103 */ "SMA", - /* 104 */ "ROLLUP", - /* 105 */ "SHOW", - /* 106 */ "DATABASES", - /* 107 */ "TABLES", - /* 108 */ "STABLES", - /* 109 */ "MNODES", - /* 110 */ "MODULES", - /* 111 */ "QNODES", - /* 112 */ "FUNCTIONS", - /* 113 */ "INDEXES", - /* 114 */ "FROM", - /* 115 */ "LIKE", - /* 116 */ "INDEX", - /* 117 */ "FULLTEXT", - /* 118 */ "FUNCTION", - /* 119 */ "INTERVAL", - /* 120 */ "TOPIC", - /* 121 */ "AS", - /* 122 */ "NK_BOOL", - /* 123 */ "NK_VARIABLE", - /* 124 */ "BETWEEN", - /* 125 */ "IS", - /* 126 */ "NULL", - /* 127 */ "NK_LT", - /* 128 */ "NK_GT", - /* 129 */ "NK_LE", - /* 130 */ "NK_GE", - /* 131 */ "NK_NE", - /* 132 */ "MATCH", - /* 133 */ "NMATCH", - /* 134 */ "IN", - /* 135 */ "JOIN", - /* 136 */ "INNER", - /* 137 */ "SELECT", - /* 138 */ "DISTINCT", - /* 139 */ "WHERE", - /* 140 */ "PARTITION", - /* 141 */ "BY", - /* 142 */ "SESSION", - /* 143 */ "STATE_WINDOW", - /* 144 */ "SLIDING", - /* 145 */ "FILL", - /* 146 */ "VALUE", - /* 147 */ "NONE", - /* 148 */ "PREV", - /* 149 */ "LINEAR", - /* 150 */ "NEXT", - /* 151 */ "GROUP", - /* 152 */ "HAVING", - /* 153 */ "ORDER", - /* 154 */ "SLIMIT", - /* 155 */ "SOFFSET", - /* 156 */ "LIMIT", - /* 157 */ "OFFSET", - /* 158 */ "ASC", - /* 159 */ "DESC", - /* 160 */ "NULLS", - /* 161 */ "FIRST", - /* 162 */ "LAST", - /* 163 */ "cmd", - /* 164 */ "account_options", - /* 165 */ "alter_account_options", - /* 166 */ "literal", - /* 167 */ "alter_account_option", - /* 168 */ "user_name", - /* 169 */ "dnode_endpoint", - /* 170 */ "dnode_host_name", - /* 171 */ "not_exists_opt", - /* 172 */ "db_name", - /* 173 */ "db_options", - /* 174 */ "exists_opt", - /* 175 */ "alter_db_options", - /* 176 */ "alter_db_option", - /* 177 */ "full_table_name", - /* 178 */ "column_def_list", - /* 179 */ "tags_def_opt", - /* 180 */ "table_options", - /* 181 */ "multi_create_clause", - /* 182 */ "tags_def", - /* 183 */ "multi_drop_clause", - /* 184 */ "alter_table_clause", - /* 185 */ "alter_table_options", - /* 186 */ "column_name", - /* 187 */ "type_name", - /* 188 */ "create_subtable_clause", - /* 189 */ "specific_tags_opt", - /* 190 */ "literal_list", - /* 191 */ "drop_table_clause", - /* 192 */ "col_name_list", - /* 193 */ "table_name", - /* 194 */ "column_def", - /* 195 */ "func_name_list", - /* 196 */ "alter_table_option", - /* 197 */ "col_name", - /* 198 */ "db_name_cond_opt", - /* 199 */ "like_pattern_opt", - /* 200 */ "table_name_cond", - /* 201 */ "from_db_opt", - /* 202 */ "func_name", - /* 203 */ "function_name", - /* 204 */ "index_name", - /* 205 */ "index_options", - /* 206 */ "func_list", - /* 207 */ "duration_literal", - /* 208 */ "sliding_opt", - /* 209 */ "func", - /* 210 */ "expression_list", - /* 211 */ "topic_name", - /* 212 */ "query_expression", - /* 213 */ "signed", - /* 214 */ "signed_literal", - /* 215 */ "table_alias", - /* 216 */ "column_alias", - /* 217 */ "expression", - /* 218 */ "column_reference", - /* 219 */ "subquery", - /* 220 */ "predicate", - /* 221 */ "compare_op", - /* 222 */ "in_op", - /* 223 */ "in_predicate_value", - /* 224 */ "boolean_value_expression", - /* 225 */ "boolean_primary", - /* 226 */ "common_expression", - /* 227 */ "from_clause", - /* 228 */ "table_reference_list", - /* 229 */ "table_reference", - /* 230 */ "table_primary", - /* 231 */ "joined_table", - /* 232 */ "alias_opt", - /* 233 */ "parenthesized_joined_table", - /* 234 */ "join_type", - /* 235 */ "search_condition", - /* 236 */ "query_specification", - /* 237 */ "set_quantifier_opt", - /* 238 */ "select_list", - /* 239 */ "where_clause_opt", - /* 240 */ "partition_by_clause_opt", - /* 241 */ "twindow_clause_opt", - /* 242 */ "group_by_clause_opt", - /* 243 */ "having_clause_opt", - /* 244 */ "select_sublist", - /* 245 */ "select_item", - /* 246 */ "fill_opt", - /* 247 */ "fill_mode", - /* 248 */ "group_by_list", - /* 249 */ "query_expression_body", - /* 250 */ "order_by_clause_opt", - /* 251 */ "slimit_clause_opt", - /* 252 */ "limit_clause_opt", - /* 253 */ "query_primary", - /* 254 */ "sort_specification_list", - /* 255 */ "sort_specification", - /* 256 */ "ordering_specification_opt", - /* 257 */ "null_ordering_opt", + /* 67 */ "TABLE", + /* 68 */ "NK_LP", + /* 69 */ "NK_RP", + /* 70 */ "STABLE", + /* 71 */ "ADD", + /* 72 */ "COLUMN", + /* 73 */ "MODIFY", + /* 74 */ "RENAME", + /* 75 */ "TAG", + /* 76 */ "SET", + /* 77 */ "NK_EQ", + /* 78 */ "USING", + /* 79 */ "TAGS", + /* 80 */ "NK_DOT", + /* 81 */ "NK_COMMA", + /* 82 */ "COMMENT", + /* 83 */ "BOOL", + /* 84 */ "TINYINT", + /* 85 */ "SMALLINT", + /* 86 */ "INT", + /* 87 */ "INTEGER", + /* 88 */ "BIGINT", + /* 89 */ "FLOAT", + /* 90 */ "DOUBLE", + /* 91 */ "BINARY", + /* 92 */ "TIMESTAMP", + /* 93 */ "NCHAR", + /* 94 */ "UNSIGNED", + /* 95 */ "JSON", + /* 96 */ "VARCHAR", + /* 97 */ "MEDIUMBLOB", + /* 98 */ "BLOB", + /* 99 */ "VARBINARY", + /* 100 */ "DECIMAL", + /* 101 */ "SMA", + /* 102 */ "ROLLUP", + /* 103 */ "FILE_FACTOR", + /* 104 */ "NK_FLOAT", + /* 105 */ "DELAY", + /* 106 */ "SHOW", + /* 107 */ "DATABASES", + /* 108 */ "TABLES", + /* 109 */ "STABLES", + /* 110 */ "MNODES", + /* 111 */ "MODULES", + /* 112 */ "QNODES", + /* 113 */ "FUNCTIONS", + /* 114 */ "INDEXES", + /* 115 */ "FROM", + /* 116 */ "LIKE", + /* 117 */ "INDEX", + /* 118 */ "FULLTEXT", + /* 119 */ "FUNCTION", + /* 120 */ "INTERVAL", + /* 121 */ "TOPIC", + /* 122 */ "AS", + /* 123 */ "NK_BOOL", + /* 124 */ "NULL", + /* 125 */ "NK_VARIABLE", + /* 126 */ "NK_UNDERLINE", + /* 127 */ "ROWTS", + /* 128 */ "TBNAME", + /* 129 */ "QSTARTTS", + /* 130 */ "QENDTS", + /* 131 */ "WSTARTTS", + /* 132 */ "WENDTS", + /* 133 */ "WDURATION", + /* 134 */ "BETWEEN", + /* 135 */ "IS", + /* 136 */ "NK_LT", + /* 137 */ "NK_GT", + /* 138 */ "NK_LE", + /* 139 */ "NK_GE", + /* 140 */ "NK_NE", + /* 141 */ "MATCH", + /* 142 */ "NMATCH", + /* 143 */ "IN", + /* 144 */ "JOIN", + /* 145 */ "INNER", + /* 146 */ "SELECT", + /* 147 */ "DISTINCT", + /* 148 */ "WHERE", + /* 149 */ "PARTITION", + /* 150 */ "BY", + /* 151 */ "SESSION", + /* 152 */ "STATE_WINDOW", + /* 153 */ "SLIDING", + /* 154 */ "FILL", + /* 155 */ "VALUE", + /* 156 */ "NONE", + /* 157 */ "PREV", + /* 158 */ "LINEAR", + /* 159 */ "NEXT", + /* 160 */ "GROUP", + /* 161 */ "HAVING", + /* 162 */ "ORDER", + /* 163 */ "SLIMIT", + /* 164 */ "SOFFSET", + /* 165 */ "LIMIT", + /* 166 */ "OFFSET", + /* 167 */ "ASC", + /* 168 */ "DESC", + /* 169 */ "NULLS", + /* 170 */ "FIRST", + /* 171 */ "LAST", + /* 172 */ "cmd", + /* 173 */ "account_options", + /* 174 */ "alter_account_options", + /* 175 */ "literal", + /* 176 */ "alter_account_option", + /* 177 */ "user_name", + /* 178 */ "dnode_endpoint", + /* 179 */ "dnode_host_name", + /* 180 */ "not_exists_opt", + /* 181 */ "db_name", + /* 182 */ "db_options", + /* 183 */ "exists_opt", + /* 184 */ "alter_db_options", + /* 185 */ "alter_db_option", + /* 186 */ "full_table_name", + /* 187 */ "column_def_list", + /* 188 */ "tags_def_opt", + /* 189 */ "table_options", + /* 190 */ "multi_create_clause", + /* 191 */ "tags_def", + /* 192 */ "multi_drop_clause", + /* 193 */ "alter_table_clause", + /* 194 */ "alter_table_options", + /* 195 */ "column_name", + /* 196 */ "type_name", + /* 197 */ "create_subtable_clause", + /* 198 */ "specific_tags_opt", + /* 199 */ "literal_list", + /* 200 */ "drop_table_clause", + /* 201 */ "col_name_list", + /* 202 */ "table_name", + /* 203 */ "column_def", + /* 204 */ "func_name_list", + /* 205 */ "alter_table_option", + /* 206 */ "col_name", + /* 207 */ "db_name_cond_opt", + /* 208 */ "like_pattern_opt", + /* 209 */ "table_name_cond", + /* 210 */ "from_db_opt", + /* 211 */ "func_name", + /* 212 */ "function_name", + /* 213 */ "index_name", + /* 214 */ "index_options", + /* 215 */ "func_list", + /* 216 */ "duration_literal", + /* 217 */ "sliding_opt", + /* 218 */ "func", + /* 219 */ "expression_list", + /* 220 */ "topic_name", + /* 221 */ "query_expression", + /* 222 */ "signed", + /* 223 */ "signed_literal", + /* 224 */ "table_alias", + /* 225 */ "column_alias", + /* 226 */ "expression", + /* 227 */ "pseudo_column", + /* 228 */ "column_reference", + /* 229 */ "subquery", + /* 230 */ "predicate", + /* 231 */ "compare_op", + /* 232 */ "in_op", + /* 233 */ "in_predicate_value", + /* 234 */ "boolean_value_expression", + /* 235 */ "boolean_primary", + /* 236 */ "common_expression", + /* 237 */ "from_clause", + /* 238 */ "table_reference_list", + /* 239 */ "table_reference", + /* 240 */ "table_primary", + /* 241 */ "joined_table", + /* 242 */ "alias_opt", + /* 243 */ "parenthesized_joined_table", + /* 244 */ "join_type", + /* 245 */ "search_condition", + /* 246 */ "query_specification", + /* 247 */ "set_quantifier_opt", + /* 248 */ "select_list", + /* 249 */ "where_clause_opt", + /* 250 */ "partition_by_clause_opt", + /* 251 */ "twindow_clause_opt", + /* 252 */ "group_by_clause_opt", + /* 253 */ "having_clause_opt", + /* 254 */ "select_sublist", + /* 255 */ "select_item", + /* 256 */ "fill_opt", + /* 257 */ "fill_mode", + /* 258 */ "group_by_list", + /* 259 */ "query_expression_body", + /* 260 */ "order_by_clause_opt", + /* 261 */ "slimit_clause_opt", + /* 262 */ "limit_clause_opt", + /* 263 */ "query_primary", + /* 264 */ "sort_specification_list", + /* 265 */ "sort_specification", + /* 266 */ "ordering_specification_opt", + /* 267 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1041,273 +1059,284 @@ static const char *const yyRuleName[] = { /* 67 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", /* 68 */ "db_options ::= db_options STREAM_MODE NK_INTEGER", /* 69 */ "db_options ::= db_options RETENTIONS NK_STRING", - /* 70 */ "db_options ::= db_options FILE_FACTOR NK_FLOAT", - /* 71 */ "alter_db_options ::= alter_db_option", - /* 72 */ "alter_db_options ::= alter_db_options alter_db_option", - /* 73 */ "alter_db_option ::= BLOCKS NK_INTEGER", - /* 74 */ "alter_db_option ::= FSYNC NK_INTEGER", - /* 75 */ "alter_db_option ::= KEEP NK_INTEGER", - /* 76 */ "alter_db_option ::= WAL NK_INTEGER", - /* 77 */ "alter_db_option ::= QUORUM NK_INTEGER", - /* 78 */ "alter_db_option ::= CACHELAST NK_INTEGER", - /* 79 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 80 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 81 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 82 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 83 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 84 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 85 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 86 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 87 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 88 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 89 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 90 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 91 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 92 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 93 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 94 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 95 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", - /* 96 */ "multi_create_clause ::= create_subtable_clause", - /* 97 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 98 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", - /* 99 */ "multi_drop_clause ::= drop_table_clause", - /* 100 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 101 */ "drop_table_clause ::= exists_opt full_table_name", - /* 102 */ "specific_tags_opt ::=", - /* 103 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", - /* 104 */ "full_table_name ::= table_name", - /* 105 */ "full_table_name ::= db_name NK_DOT table_name", - /* 106 */ "column_def_list ::= column_def", - /* 107 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 108 */ "column_def ::= column_name type_name", - /* 109 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 110 */ "type_name ::= BOOL", - /* 111 */ "type_name ::= TINYINT", - /* 112 */ "type_name ::= SMALLINT", - /* 113 */ "type_name ::= INT", - /* 114 */ "type_name ::= INTEGER", - /* 115 */ "type_name ::= BIGINT", - /* 116 */ "type_name ::= FLOAT", - /* 117 */ "type_name ::= DOUBLE", - /* 118 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 119 */ "type_name ::= TIMESTAMP", - /* 120 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 121 */ "type_name ::= TINYINT UNSIGNED", - /* 122 */ "type_name ::= SMALLINT UNSIGNED", - /* 123 */ "type_name ::= INT UNSIGNED", - /* 124 */ "type_name ::= BIGINT UNSIGNED", - /* 125 */ "type_name ::= JSON", - /* 126 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 127 */ "type_name ::= MEDIUMBLOB", - /* 128 */ "type_name ::= BLOB", - /* 129 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 130 */ "type_name ::= DECIMAL", - /* 131 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 132 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 133 */ "tags_def_opt ::=", - /* 134 */ "tags_def_opt ::= tags_def", - /* 135 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 136 */ "table_options ::=", - /* 137 */ "table_options ::= table_options COMMENT NK_STRING", - /* 138 */ "table_options ::= table_options KEEP NK_INTEGER", - /* 139 */ "table_options ::= table_options TTL NK_INTEGER", - /* 140 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 141 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", - /* 142 */ "alter_table_options ::= alter_table_option", - /* 143 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 144 */ "alter_table_option ::= COMMENT NK_STRING", - /* 145 */ "alter_table_option ::= KEEP NK_INTEGER", - /* 146 */ "alter_table_option ::= TTL NK_INTEGER", - /* 147 */ "col_name_list ::= col_name", - /* 148 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 149 */ "col_name ::= column_name", - /* 150 */ "cmd ::= SHOW DNODES", - /* 151 */ "cmd ::= SHOW USERS", - /* 152 */ "cmd ::= SHOW DATABASES", - /* 153 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 154 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 155 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 156 */ "cmd ::= SHOW MNODES", - /* 157 */ "cmd ::= SHOW MODULES", - /* 158 */ "cmd ::= SHOW QNODES", - /* 159 */ "cmd ::= SHOW FUNCTIONS", - /* 160 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 161 */ "cmd ::= SHOW STREAMS", - /* 162 */ "db_name_cond_opt ::=", - /* 163 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 164 */ "like_pattern_opt ::=", - /* 165 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 166 */ "table_name_cond ::= table_name", - /* 167 */ "from_db_opt ::=", - /* 168 */ "from_db_opt ::= FROM db_name", - /* 169 */ "func_name_list ::= func_name", - /* 170 */ "func_name_list ::= func_name_list NK_COMMA col_name", - /* 171 */ "func_name ::= function_name", - /* 172 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 173 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 174 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 175 */ "index_options ::=", - /* 176 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 177 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 178 */ "func_list ::= func", - /* 179 */ "func_list ::= func_list NK_COMMA func", - /* 180 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 181 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 182 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", - /* 183 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 184 */ "cmd ::= query_expression", - /* 185 */ "literal ::= NK_INTEGER", - /* 186 */ "literal ::= NK_FLOAT", - /* 187 */ "literal ::= NK_STRING", - /* 188 */ "literal ::= NK_BOOL", - /* 189 */ "literal ::= TIMESTAMP NK_STRING", - /* 190 */ "literal ::= duration_literal", - /* 191 */ "duration_literal ::= NK_VARIABLE", - /* 192 */ "signed ::= NK_INTEGER", - /* 193 */ "signed ::= NK_PLUS NK_INTEGER", - /* 194 */ "signed ::= NK_MINUS NK_INTEGER", - /* 195 */ "signed ::= NK_FLOAT", - /* 196 */ "signed ::= NK_PLUS NK_FLOAT", - /* 197 */ "signed ::= NK_MINUS NK_FLOAT", - /* 198 */ "signed_literal ::= signed", - /* 199 */ "signed_literal ::= NK_STRING", - /* 200 */ "signed_literal ::= NK_BOOL", - /* 201 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 202 */ "signed_literal ::= duration_literal", - /* 203 */ "literal_list ::= signed_literal", - /* 204 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 205 */ "db_name ::= NK_ID", - /* 206 */ "table_name ::= NK_ID", - /* 207 */ "column_name ::= NK_ID", - /* 208 */ "function_name ::= NK_ID", - /* 209 */ "table_alias ::= NK_ID", - /* 210 */ "column_alias ::= NK_ID", - /* 211 */ "user_name ::= NK_ID", - /* 212 */ "index_name ::= NK_ID", - /* 213 */ "topic_name ::= NK_ID", - /* 214 */ "expression ::= literal", - /* 215 */ "expression ::= column_reference", - /* 216 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 217 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 218 */ "expression ::= subquery", - /* 219 */ "expression ::= NK_LP expression NK_RP", - /* 220 */ "expression ::= NK_PLUS expression", - /* 221 */ "expression ::= NK_MINUS expression", - /* 222 */ "expression ::= expression NK_PLUS expression", - /* 223 */ "expression ::= expression NK_MINUS expression", - /* 224 */ "expression ::= expression NK_STAR expression", - /* 225 */ "expression ::= expression NK_SLASH expression", - /* 226 */ "expression ::= expression NK_REM expression", - /* 227 */ "expression_list ::= expression", - /* 228 */ "expression_list ::= expression_list NK_COMMA expression", - /* 229 */ "column_reference ::= column_name", - /* 230 */ "column_reference ::= table_name NK_DOT column_name", - /* 231 */ "predicate ::= expression compare_op expression", - /* 232 */ "predicate ::= expression BETWEEN expression AND expression", - /* 233 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 234 */ "predicate ::= expression IS NULL", - /* 235 */ "predicate ::= expression IS NOT NULL", - /* 236 */ "predicate ::= expression in_op in_predicate_value", - /* 237 */ "compare_op ::= NK_LT", - /* 238 */ "compare_op ::= NK_GT", - /* 239 */ "compare_op ::= NK_LE", - /* 240 */ "compare_op ::= NK_GE", - /* 241 */ "compare_op ::= NK_NE", - /* 242 */ "compare_op ::= NK_EQ", - /* 243 */ "compare_op ::= LIKE", - /* 244 */ "compare_op ::= NOT LIKE", - /* 245 */ "compare_op ::= MATCH", - /* 246 */ "compare_op ::= NMATCH", - /* 247 */ "in_op ::= IN", - /* 248 */ "in_op ::= NOT IN", - /* 249 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 250 */ "boolean_value_expression ::= boolean_primary", - /* 251 */ "boolean_value_expression ::= NOT boolean_primary", - /* 252 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 253 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 254 */ "boolean_primary ::= predicate", - /* 255 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 256 */ "common_expression ::= expression", - /* 257 */ "common_expression ::= boolean_value_expression", - /* 258 */ "from_clause ::= FROM table_reference_list", - /* 259 */ "table_reference_list ::= table_reference", - /* 260 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 261 */ "table_reference ::= table_primary", - /* 262 */ "table_reference ::= joined_table", - /* 263 */ "table_primary ::= table_name alias_opt", - /* 264 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 265 */ "table_primary ::= subquery alias_opt", - /* 266 */ "table_primary ::= parenthesized_joined_table", - /* 267 */ "alias_opt ::=", - /* 268 */ "alias_opt ::= table_alias", - /* 269 */ "alias_opt ::= AS table_alias", - /* 270 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 271 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 272 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 273 */ "join_type ::=", - /* 274 */ "join_type ::= INNER", - /* 275 */ "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", - /* 276 */ "set_quantifier_opt ::=", - /* 277 */ "set_quantifier_opt ::= DISTINCT", - /* 278 */ "set_quantifier_opt ::= ALL", - /* 279 */ "select_list ::= NK_STAR", - /* 280 */ "select_list ::= select_sublist", - /* 281 */ "select_sublist ::= select_item", - /* 282 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 283 */ "select_item ::= common_expression", - /* 284 */ "select_item ::= common_expression column_alias", - /* 285 */ "select_item ::= common_expression AS column_alias", - /* 286 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 287 */ "where_clause_opt ::=", - /* 288 */ "where_clause_opt ::= WHERE search_condition", - /* 289 */ "partition_by_clause_opt ::=", - /* 290 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 291 */ "twindow_clause_opt ::=", - /* 292 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 293 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 294 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 295 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 296 */ "sliding_opt ::=", - /* 297 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 298 */ "fill_opt ::=", - /* 299 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 300 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 301 */ "fill_mode ::= NONE", - /* 302 */ "fill_mode ::= PREV", - /* 303 */ "fill_mode ::= NULL", - /* 304 */ "fill_mode ::= LINEAR", - /* 305 */ "fill_mode ::= NEXT", - /* 306 */ "group_by_clause_opt ::=", - /* 307 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 308 */ "group_by_list ::= expression", - /* 309 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 310 */ "having_clause_opt ::=", - /* 311 */ "having_clause_opt ::= HAVING search_condition", - /* 312 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 313 */ "query_expression_body ::= query_primary", - /* 314 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 315 */ "query_primary ::= query_specification", - /* 316 */ "order_by_clause_opt ::=", - /* 317 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 318 */ "slimit_clause_opt ::=", - /* 319 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 320 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 321 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 322 */ "limit_clause_opt ::=", - /* 323 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 324 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 325 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 326 */ "subquery ::= NK_LP query_expression NK_RP", - /* 327 */ "search_condition ::= common_expression", - /* 328 */ "sort_specification_list ::= sort_specification", - /* 329 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 330 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 331 */ "ordering_specification_opt ::=", - /* 332 */ "ordering_specification_opt ::= ASC", - /* 333 */ "ordering_specification_opt ::= DESC", - /* 334 */ "null_ordering_opt ::=", - /* 335 */ "null_ordering_opt ::= NULLS FIRST", - /* 336 */ "null_ordering_opt ::= NULLS LAST", + /* 70 */ "alter_db_options ::= alter_db_option", + /* 71 */ "alter_db_options ::= alter_db_options alter_db_option", + /* 72 */ "alter_db_option ::= BLOCKS NK_INTEGER", + /* 73 */ "alter_db_option ::= FSYNC NK_INTEGER", + /* 74 */ "alter_db_option ::= KEEP NK_INTEGER", + /* 75 */ "alter_db_option ::= WAL NK_INTEGER", + /* 76 */ "alter_db_option ::= QUORUM NK_INTEGER", + /* 77 */ "alter_db_option ::= CACHELAST NK_INTEGER", + /* 78 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 79 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 80 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 81 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 82 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 83 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 84 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 85 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 86 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 87 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 88 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 89 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 90 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 91 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 92 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 93 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 94 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", + /* 95 */ "multi_create_clause ::= create_subtable_clause", + /* 96 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 97 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", + /* 98 */ "multi_drop_clause ::= drop_table_clause", + /* 99 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 100 */ "drop_table_clause ::= exists_opt full_table_name", + /* 101 */ "specific_tags_opt ::=", + /* 102 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", + /* 103 */ "full_table_name ::= table_name", + /* 104 */ "full_table_name ::= db_name NK_DOT table_name", + /* 105 */ "column_def_list ::= column_def", + /* 106 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 107 */ "column_def ::= column_name type_name", + /* 108 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 109 */ "type_name ::= BOOL", + /* 110 */ "type_name ::= TINYINT", + /* 111 */ "type_name ::= SMALLINT", + /* 112 */ "type_name ::= INT", + /* 113 */ "type_name ::= INTEGER", + /* 114 */ "type_name ::= BIGINT", + /* 115 */ "type_name ::= FLOAT", + /* 116 */ "type_name ::= DOUBLE", + /* 117 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 118 */ "type_name ::= TIMESTAMP", + /* 119 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 120 */ "type_name ::= TINYINT UNSIGNED", + /* 121 */ "type_name ::= SMALLINT UNSIGNED", + /* 122 */ "type_name ::= INT UNSIGNED", + /* 123 */ "type_name ::= BIGINT UNSIGNED", + /* 124 */ "type_name ::= JSON", + /* 125 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 126 */ "type_name ::= MEDIUMBLOB", + /* 127 */ "type_name ::= BLOB", + /* 128 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 129 */ "type_name ::= DECIMAL", + /* 130 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 131 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 132 */ "tags_def_opt ::=", + /* 133 */ "tags_def_opt ::= tags_def", + /* 134 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 135 */ "table_options ::=", + /* 136 */ "table_options ::= table_options COMMENT NK_STRING", + /* 137 */ "table_options ::= table_options KEEP NK_INTEGER", + /* 138 */ "table_options ::= table_options TTL NK_INTEGER", + /* 139 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 140 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", + /* 141 */ "table_options ::= table_options FILE_FACTOR NK_FLOAT", + /* 142 */ "table_options ::= table_options DELAY NK_INTEGER", + /* 143 */ "alter_table_options ::= alter_table_option", + /* 144 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 145 */ "alter_table_option ::= COMMENT NK_STRING", + /* 146 */ "alter_table_option ::= KEEP NK_INTEGER", + /* 147 */ "alter_table_option ::= TTL NK_INTEGER", + /* 148 */ "col_name_list ::= col_name", + /* 149 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 150 */ "col_name ::= column_name", + /* 151 */ "cmd ::= SHOW DNODES", + /* 152 */ "cmd ::= SHOW USERS", + /* 153 */ "cmd ::= SHOW DATABASES", + /* 154 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 155 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 156 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 157 */ "cmd ::= SHOW MNODES", + /* 158 */ "cmd ::= SHOW MODULES", + /* 159 */ "cmd ::= SHOW QNODES", + /* 160 */ "cmd ::= SHOW FUNCTIONS", + /* 161 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 162 */ "cmd ::= SHOW STREAMS", + /* 163 */ "db_name_cond_opt ::=", + /* 164 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 165 */ "like_pattern_opt ::=", + /* 166 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 167 */ "table_name_cond ::= table_name", + /* 168 */ "from_db_opt ::=", + /* 169 */ "from_db_opt ::= FROM db_name", + /* 170 */ "func_name_list ::= func_name", + /* 171 */ "func_name_list ::= func_name_list NK_COMMA col_name", + /* 172 */ "func_name ::= function_name", + /* 173 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 174 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 175 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 176 */ "index_options ::=", + /* 177 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 178 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 179 */ "func_list ::= func", + /* 180 */ "func_list ::= func_list NK_COMMA func", + /* 181 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 182 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 183 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", + /* 184 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 185 */ "cmd ::= query_expression", + /* 186 */ "literal ::= NK_INTEGER", + /* 187 */ "literal ::= NK_FLOAT", + /* 188 */ "literal ::= NK_STRING", + /* 189 */ "literal ::= NK_BOOL", + /* 190 */ "literal ::= TIMESTAMP NK_STRING", + /* 191 */ "literal ::= duration_literal", + /* 192 */ "literal ::= NULL", + /* 193 */ "duration_literal ::= NK_VARIABLE", + /* 194 */ "signed ::= NK_INTEGER", + /* 195 */ "signed ::= NK_PLUS NK_INTEGER", + /* 196 */ "signed ::= NK_MINUS NK_INTEGER", + /* 197 */ "signed ::= NK_FLOAT", + /* 198 */ "signed ::= NK_PLUS NK_FLOAT", + /* 199 */ "signed ::= NK_MINUS NK_FLOAT", + /* 200 */ "signed_literal ::= signed", + /* 201 */ "signed_literal ::= NK_STRING", + /* 202 */ "signed_literal ::= NK_BOOL", + /* 203 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 204 */ "signed_literal ::= duration_literal", + /* 205 */ "signed_literal ::= NULL", + /* 206 */ "literal_list ::= signed_literal", + /* 207 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 208 */ "db_name ::= NK_ID", + /* 209 */ "table_name ::= NK_ID", + /* 210 */ "column_name ::= NK_ID", + /* 211 */ "function_name ::= NK_ID", + /* 212 */ "table_alias ::= NK_ID", + /* 213 */ "column_alias ::= NK_ID", + /* 214 */ "user_name ::= NK_ID", + /* 215 */ "index_name ::= NK_ID", + /* 216 */ "topic_name ::= NK_ID", + /* 217 */ "expression ::= literal", + /* 218 */ "expression ::= pseudo_column", + /* 219 */ "expression ::= column_reference", + /* 220 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 221 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 222 */ "expression ::= subquery", + /* 223 */ "expression ::= NK_LP expression NK_RP", + /* 224 */ "expression ::= NK_PLUS expression", + /* 225 */ "expression ::= NK_MINUS expression", + /* 226 */ "expression ::= expression NK_PLUS expression", + /* 227 */ "expression ::= expression NK_MINUS expression", + /* 228 */ "expression ::= expression NK_STAR expression", + /* 229 */ "expression ::= expression NK_SLASH expression", + /* 230 */ "expression ::= expression NK_REM expression", + /* 231 */ "expression_list ::= expression", + /* 232 */ "expression_list ::= expression_list NK_COMMA expression", + /* 233 */ "column_reference ::= column_name", + /* 234 */ "column_reference ::= table_name NK_DOT column_name", + /* 235 */ "pseudo_column ::= NK_UNDERLINE ROWTS", + /* 236 */ "pseudo_column ::= TBNAME", + /* 237 */ "pseudo_column ::= NK_UNDERLINE QSTARTTS", + /* 238 */ "pseudo_column ::= NK_UNDERLINE QENDTS", + /* 239 */ "pseudo_column ::= NK_UNDERLINE WSTARTTS", + /* 240 */ "pseudo_column ::= NK_UNDERLINE WENDTS", + /* 241 */ "pseudo_column ::= NK_UNDERLINE WDURATION", + /* 242 */ "predicate ::= expression compare_op expression", + /* 243 */ "predicate ::= expression BETWEEN expression AND expression", + /* 244 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 245 */ "predicate ::= expression IS NULL", + /* 246 */ "predicate ::= expression IS NOT NULL", + /* 247 */ "predicate ::= expression in_op in_predicate_value", + /* 248 */ "compare_op ::= NK_LT", + /* 249 */ "compare_op ::= NK_GT", + /* 250 */ "compare_op ::= NK_LE", + /* 251 */ "compare_op ::= NK_GE", + /* 252 */ "compare_op ::= NK_NE", + /* 253 */ "compare_op ::= NK_EQ", + /* 254 */ "compare_op ::= LIKE", + /* 255 */ "compare_op ::= NOT LIKE", + /* 256 */ "compare_op ::= MATCH", + /* 257 */ "compare_op ::= NMATCH", + /* 258 */ "in_op ::= IN", + /* 259 */ "in_op ::= NOT IN", + /* 260 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 261 */ "boolean_value_expression ::= boolean_primary", + /* 262 */ "boolean_value_expression ::= NOT boolean_primary", + /* 263 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 264 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 265 */ "boolean_primary ::= predicate", + /* 266 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 267 */ "common_expression ::= expression", + /* 268 */ "common_expression ::= boolean_value_expression", + /* 269 */ "from_clause ::= FROM table_reference_list", + /* 270 */ "table_reference_list ::= table_reference", + /* 271 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 272 */ "table_reference ::= table_primary", + /* 273 */ "table_reference ::= joined_table", + /* 274 */ "table_primary ::= table_name alias_opt", + /* 275 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 276 */ "table_primary ::= subquery alias_opt", + /* 277 */ "table_primary ::= parenthesized_joined_table", + /* 278 */ "alias_opt ::=", + /* 279 */ "alias_opt ::= table_alias", + /* 280 */ "alias_opt ::= AS table_alias", + /* 281 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 282 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 283 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 284 */ "join_type ::=", + /* 285 */ "join_type ::= INNER", + /* 286 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 287 */ "set_quantifier_opt ::=", + /* 288 */ "set_quantifier_opt ::= DISTINCT", + /* 289 */ "set_quantifier_opt ::= ALL", + /* 290 */ "select_list ::= NK_STAR", + /* 291 */ "select_list ::= select_sublist", + /* 292 */ "select_sublist ::= select_item", + /* 293 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 294 */ "select_item ::= common_expression", + /* 295 */ "select_item ::= common_expression column_alias", + /* 296 */ "select_item ::= common_expression AS column_alias", + /* 297 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 298 */ "where_clause_opt ::=", + /* 299 */ "where_clause_opt ::= WHERE search_condition", + /* 300 */ "partition_by_clause_opt ::=", + /* 301 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 302 */ "twindow_clause_opt ::=", + /* 303 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 304 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 305 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 306 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 307 */ "sliding_opt ::=", + /* 308 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 309 */ "fill_opt ::=", + /* 310 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 311 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 312 */ "fill_mode ::= NONE", + /* 313 */ "fill_mode ::= PREV", + /* 314 */ "fill_mode ::= NULL", + /* 315 */ "fill_mode ::= LINEAR", + /* 316 */ "fill_mode ::= NEXT", + /* 317 */ "group_by_clause_opt ::=", + /* 318 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 319 */ "group_by_list ::= expression", + /* 320 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 321 */ "having_clause_opt ::=", + /* 322 */ "having_clause_opt ::= HAVING search_condition", + /* 323 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 324 */ "query_expression_body ::= query_primary", + /* 325 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 326 */ "query_primary ::= query_specification", + /* 327 */ "order_by_clause_opt ::=", + /* 328 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 329 */ "slimit_clause_opt ::=", + /* 330 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 331 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 332 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 333 */ "limit_clause_opt ::=", + /* 334 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 335 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 336 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 337 */ "subquery ::= NK_LP query_expression NK_RP", + /* 338 */ "search_condition ::= common_expression", + /* 339 */ "sort_specification_list ::= sort_specification", + /* 340 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 341 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 342 */ "ordering_specification_opt ::=", + /* 343 */ "ordering_specification_opt ::= ASC", + /* 344 */ "ordering_specification_opt ::= DESC", + /* 345 */ "null_ordering_opt ::=", + /* 346 */ "null_ordering_opt ::= NULLS FIRST", + /* 347 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1325,10 +1354,10 @@ static int yyGrowStack(yyParser *p){ newSize = p->yystksz*2 + 100; idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; if( p->yystack==&p->yystk0 ){ - pNew = taosMemoryMalloc(newSize*sizeof(pNew[0])); + pNew = malloc(newSize*sizeof(pNew[0])); if( pNew ) pNew[0] = p->yystk0; }else{ - pNew = taosMemoryRealloc(p->yystack, newSize*sizeof(pNew[0])); + pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); } if( pNew ){ p->yystack = pNew; @@ -1434,145 +1463,146 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 163: /* cmd */ - case 166: /* literal */ - case 173: /* db_options */ - case 175: /* alter_db_options */ - case 177: /* full_table_name */ - case 180: /* table_options */ - case 184: /* alter_table_clause */ - case 185: /* alter_table_options */ - case 188: /* create_subtable_clause */ - case 191: /* drop_table_clause */ - case 194: /* column_def */ - case 197: /* col_name */ - case 198: /* db_name_cond_opt */ - case 199: /* like_pattern_opt */ - case 200: /* table_name_cond */ - case 201: /* from_db_opt */ - case 202: /* func_name */ - case 205: /* index_options */ - case 207: /* duration_literal */ - case 208: /* sliding_opt */ - case 209: /* func */ - case 212: /* query_expression */ - case 213: /* signed */ - case 214: /* signed_literal */ - case 217: /* expression */ - case 218: /* column_reference */ - case 219: /* subquery */ - case 220: /* predicate */ - case 223: /* in_predicate_value */ - case 224: /* boolean_value_expression */ - case 225: /* boolean_primary */ - case 226: /* common_expression */ - case 227: /* from_clause */ - case 228: /* table_reference_list */ - case 229: /* table_reference */ - case 230: /* table_primary */ - case 231: /* joined_table */ - case 233: /* parenthesized_joined_table */ - case 235: /* search_condition */ - case 236: /* query_specification */ - case 239: /* where_clause_opt */ - case 241: /* twindow_clause_opt */ - case 243: /* having_clause_opt */ - case 245: /* select_item */ - case 246: /* fill_opt */ - case 249: /* query_expression_body */ - case 251: /* slimit_clause_opt */ - case 252: /* limit_clause_opt */ - case 253: /* query_primary */ - case 255: /* sort_specification */ + case 172: /* cmd */ + case 175: /* literal */ + case 182: /* db_options */ + case 184: /* alter_db_options */ + case 186: /* full_table_name */ + case 189: /* table_options */ + case 193: /* alter_table_clause */ + case 194: /* alter_table_options */ + case 197: /* create_subtable_clause */ + case 200: /* drop_table_clause */ + case 203: /* column_def */ + case 206: /* col_name */ + case 207: /* db_name_cond_opt */ + case 208: /* like_pattern_opt */ + case 209: /* table_name_cond */ + case 210: /* from_db_opt */ + case 211: /* func_name */ + case 214: /* index_options */ + case 216: /* duration_literal */ + case 217: /* sliding_opt */ + case 218: /* func */ + case 221: /* query_expression */ + case 222: /* signed */ + case 223: /* signed_literal */ + case 226: /* expression */ + case 227: /* pseudo_column */ + case 228: /* column_reference */ + case 229: /* subquery */ + case 230: /* predicate */ + case 233: /* in_predicate_value */ + case 234: /* boolean_value_expression */ + case 235: /* boolean_primary */ + case 236: /* common_expression */ + case 237: /* from_clause */ + case 238: /* table_reference_list */ + case 239: /* table_reference */ + case 240: /* table_primary */ + case 241: /* joined_table */ + case 243: /* parenthesized_joined_table */ + case 245: /* search_condition */ + case 246: /* query_specification */ + case 249: /* where_clause_opt */ + case 251: /* twindow_clause_opt */ + case 253: /* having_clause_opt */ + case 255: /* select_item */ + case 256: /* fill_opt */ + case 259: /* query_expression_body */ + case 261: /* slimit_clause_opt */ + case 262: /* limit_clause_opt */ + case 263: /* query_primary */ + case 265: /* sort_specification */ { - nodesDestroyNode((yypminor->yy140)); + nodesDestroyNode((yypminor->yy176)); } break; - case 164: /* account_options */ - case 165: /* alter_account_options */ - case 167: /* alter_account_option */ + case 173: /* account_options */ + case 174: /* alter_account_options */ + case 176: /* alter_account_option */ { } break; - case 168: /* user_name */ - case 169: /* dnode_endpoint */ - case 170: /* dnode_host_name */ - case 172: /* db_name */ - case 186: /* column_name */ - case 193: /* table_name */ - case 203: /* function_name */ - case 204: /* index_name */ - case 211: /* topic_name */ - case 215: /* table_alias */ - case 216: /* column_alias */ - case 232: /* alias_opt */ + case 177: /* user_name */ + case 178: /* dnode_endpoint */ + case 179: /* dnode_host_name */ + case 181: /* db_name */ + case 195: /* column_name */ + case 202: /* table_name */ + case 212: /* function_name */ + case 213: /* index_name */ + case 220: /* topic_name */ + case 224: /* table_alias */ + case 225: /* column_alias */ + case 242: /* alias_opt */ { } break; - case 171: /* not_exists_opt */ - case 174: /* exists_opt */ - case 237: /* set_quantifier_opt */ + case 180: /* not_exists_opt */ + case 183: /* exists_opt */ + case 247: /* set_quantifier_opt */ { } break; - case 176: /* alter_db_option */ - case 196: /* alter_table_option */ + case 185: /* alter_db_option */ + case 205: /* alter_table_option */ { } break; - case 178: /* column_def_list */ - case 179: /* tags_def_opt */ - case 181: /* multi_create_clause */ - case 182: /* tags_def */ - case 183: /* multi_drop_clause */ - case 189: /* specific_tags_opt */ - case 190: /* literal_list */ - case 192: /* col_name_list */ - case 195: /* func_name_list */ - case 206: /* func_list */ - case 210: /* expression_list */ - case 238: /* select_list */ - case 240: /* partition_by_clause_opt */ - case 242: /* group_by_clause_opt */ - case 244: /* select_sublist */ - case 248: /* group_by_list */ - case 250: /* order_by_clause_opt */ - case 254: /* sort_specification_list */ + case 187: /* column_def_list */ + case 188: /* tags_def_opt */ + case 190: /* multi_create_clause */ + case 191: /* tags_def */ + case 192: /* multi_drop_clause */ + case 198: /* specific_tags_opt */ + case 199: /* literal_list */ + case 201: /* col_name_list */ + case 204: /* func_name_list */ + case 215: /* func_list */ + case 219: /* expression_list */ + case 248: /* select_list */ + case 250: /* partition_by_clause_opt */ + case 252: /* group_by_clause_opt */ + case 254: /* select_sublist */ + case 258: /* group_by_list */ + case 260: /* order_by_clause_opt */ + case 264: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy136)); + nodesDestroyList((yypminor->yy512)); } break; - case 187: /* type_name */ + case 196: /* type_name */ { } break; - case 221: /* compare_op */ - case 222: /* in_op */ + case 231: /* compare_op */ + case 232: /* in_op */ { } break; - case 234: /* join_type */ + case 244: /* join_type */ { } break; - case 247: /* fill_mode */ + case 257: /* fill_mode */ { } break; - case 256: /* ordering_specification_opt */ + case 266: /* ordering_specification_opt */ { } break; - case 257: /* null_ordering_opt */ + case 267: /* null_ordering_opt */ { } @@ -1610,7 +1640,7 @@ void ParseFinalize(void *p){ yyParser *pParser = (yyParser*)p; while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); #if YYSTACKDEPTH<=0 - if( pParser->yystack!=&pParser->yystk0 ) taosMemoryFree(pParser->yystack); + if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); #endif } @@ -1871,343 +1901,354 @@ 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[] = { - { 163, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 163, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 164, 0 }, /* (2) account_options ::= */ - { 164, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 164, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 164, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 164, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 164, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 164, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 164, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 164, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 164, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 165, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 165, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 167, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 167, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 167, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 167, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 167, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 167, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 167, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 167, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 167, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 167, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 163, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 163, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 163, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 163, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 163, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ - { 163, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 163, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ - { 163, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ - { 163, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 163, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 163, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ - { 163, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 169, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ - { 170, -1 }, /* (37) dnode_host_name ::= NK_ID */ - { 170, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ - { 163, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ - { 163, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 163, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 163, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 163, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 163, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ - { 163, -2 }, /* (45) cmd ::= USE db_name */ - { 163, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 171, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ - { 171, 0 }, /* (48) not_exists_opt ::= */ - { 174, -2 }, /* (49) exists_opt ::= IF EXISTS */ - { 174, 0 }, /* (50) exists_opt ::= */ - { 173, 0 }, /* (51) db_options ::= */ - { 173, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ - { 173, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ - { 173, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ - { 173, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ - { 173, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ - { 173, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ - { 173, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ - { 173, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ - { 173, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ - { 173, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ - { 173, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ - { 173, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ - { 173, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ - { 173, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ - { 173, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ - { 173, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 173, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 173, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ - { 173, -3 }, /* (70) db_options ::= db_options FILE_FACTOR NK_FLOAT */ - { 175, -1 }, /* (71) alter_db_options ::= alter_db_option */ - { 175, -2 }, /* (72) alter_db_options ::= alter_db_options alter_db_option */ - { 176, -2 }, /* (73) alter_db_option ::= BLOCKS NK_INTEGER */ - { 176, -2 }, /* (74) alter_db_option ::= FSYNC NK_INTEGER */ - { 176, -2 }, /* (75) alter_db_option ::= KEEP NK_INTEGER */ - { 176, -2 }, /* (76) alter_db_option ::= WAL NK_INTEGER */ - { 176, -2 }, /* (77) alter_db_option ::= QUORUM NK_INTEGER */ - { 176, -2 }, /* (78) alter_db_option ::= CACHELAST NK_INTEGER */ - { 163, -9 }, /* (79) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 163, -3 }, /* (80) cmd ::= CREATE TABLE multi_create_clause */ - { 163, -9 }, /* (81) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 163, -3 }, /* (82) cmd ::= DROP TABLE multi_drop_clause */ - { 163, -4 }, /* (83) cmd ::= DROP STABLE exists_opt full_table_name */ - { 163, -3 }, /* (84) cmd ::= ALTER TABLE alter_table_clause */ - { 163, -3 }, /* (85) cmd ::= ALTER STABLE alter_table_clause */ - { 184, -2 }, /* (86) alter_table_clause ::= full_table_name alter_table_options */ - { 184, -5 }, /* (87) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 184, -4 }, /* (88) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 184, -5 }, /* (89) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 184, -5 }, /* (90) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 184, -5 }, /* (91) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 184, -4 }, /* (92) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 184, -5 }, /* (93) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 184, -5 }, /* (94) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 184, -6 }, /* (95) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 181, -1 }, /* (96) multi_create_clause ::= create_subtable_clause */ - { 181, -2 }, /* (97) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 188, -9 }, /* (98) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 183, -1 }, /* (99) multi_drop_clause ::= drop_table_clause */ - { 183, -2 }, /* (100) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 191, -2 }, /* (101) drop_table_clause ::= exists_opt full_table_name */ - { 189, 0 }, /* (102) specific_tags_opt ::= */ - { 189, -3 }, /* (103) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 177, -1 }, /* (104) full_table_name ::= table_name */ - { 177, -3 }, /* (105) full_table_name ::= db_name NK_DOT table_name */ - { 178, -1 }, /* (106) column_def_list ::= column_def */ - { 178, -3 }, /* (107) column_def_list ::= column_def_list NK_COMMA column_def */ - { 194, -2 }, /* (108) column_def ::= column_name type_name */ - { 194, -4 }, /* (109) column_def ::= column_name type_name COMMENT NK_STRING */ - { 187, -1 }, /* (110) type_name ::= BOOL */ - { 187, -1 }, /* (111) type_name ::= TINYINT */ - { 187, -1 }, /* (112) type_name ::= SMALLINT */ - { 187, -1 }, /* (113) type_name ::= INT */ - { 187, -1 }, /* (114) type_name ::= INTEGER */ - { 187, -1 }, /* (115) type_name ::= BIGINT */ - { 187, -1 }, /* (116) type_name ::= FLOAT */ - { 187, -1 }, /* (117) type_name ::= DOUBLE */ - { 187, -4 }, /* (118) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 187, -1 }, /* (119) type_name ::= TIMESTAMP */ - { 187, -4 }, /* (120) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 187, -2 }, /* (121) type_name ::= TINYINT UNSIGNED */ - { 187, -2 }, /* (122) type_name ::= SMALLINT UNSIGNED */ - { 187, -2 }, /* (123) type_name ::= INT UNSIGNED */ - { 187, -2 }, /* (124) type_name ::= BIGINT UNSIGNED */ - { 187, -1 }, /* (125) type_name ::= JSON */ - { 187, -4 }, /* (126) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 187, -1 }, /* (127) type_name ::= MEDIUMBLOB */ - { 187, -1 }, /* (128) type_name ::= BLOB */ - { 187, -4 }, /* (129) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 187, -1 }, /* (130) type_name ::= DECIMAL */ - { 187, -4 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 187, -6 }, /* (132) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 179, 0 }, /* (133) tags_def_opt ::= */ - { 179, -1 }, /* (134) tags_def_opt ::= tags_def */ - { 182, -4 }, /* (135) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 180, 0 }, /* (136) table_options ::= */ - { 180, -3 }, /* (137) table_options ::= table_options COMMENT NK_STRING */ - { 180, -3 }, /* (138) table_options ::= table_options KEEP NK_INTEGER */ - { 180, -3 }, /* (139) table_options ::= table_options TTL NK_INTEGER */ - { 180, -5 }, /* (140) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 180, -5 }, /* (141) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 185, -1 }, /* (142) alter_table_options ::= alter_table_option */ - { 185, -2 }, /* (143) alter_table_options ::= alter_table_options alter_table_option */ - { 196, -2 }, /* (144) alter_table_option ::= COMMENT NK_STRING */ - { 196, -2 }, /* (145) alter_table_option ::= KEEP NK_INTEGER */ - { 196, -2 }, /* (146) alter_table_option ::= TTL NK_INTEGER */ - { 192, -1 }, /* (147) col_name_list ::= col_name */ - { 192, -3 }, /* (148) col_name_list ::= col_name_list NK_COMMA col_name */ - { 197, -1 }, /* (149) col_name ::= column_name */ - { 163, -2 }, /* (150) cmd ::= SHOW DNODES */ - { 163, -2 }, /* (151) cmd ::= SHOW USERS */ - { 163, -2 }, /* (152) cmd ::= SHOW DATABASES */ - { 163, -4 }, /* (153) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 163, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 163, -3 }, /* (155) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 163, -2 }, /* (156) cmd ::= SHOW MNODES */ - { 163, -2 }, /* (157) cmd ::= SHOW MODULES */ - { 163, -2 }, /* (158) cmd ::= SHOW QNODES */ - { 163, -2 }, /* (159) cmd ::= SHOW FUNCTIONS */ - { 163, -5 }, /* (160) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 163, -2 }, /* (161) cmd ::= SHOW STREAMS */ - { 198, 0 }, /* (162) db_name_cond_opt ::= */ - { 198, -2 }, /* (163) db_name_cond_opt ::= db_name NK_DOT */ - { 199, 0 }, /* (164) like_pattern_opt ::= */ - { 199, -2 }, /* (165) like_pattern_opt ::= LIKE NK_STRING */ - { 200, -1 }, /* (166) table_name_cond ::= table_name */ - { 201, 0 }, /* (167) from_db_opt ::= */ - { 201, -2 }, /* (168) from_db_opt ::= FROM db_name */ - { 195, -1 }, /* (169) func_name_list ::= func_name */ - { 195, -3 }, /* (170) func_name_list ::= func_name_list NK_COMMA col_name */ - { 202, -1 }, /* (171) func_name ::= function_name */ - { 163, -8 }, /* (172) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 163, -10 }, /* (173) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 163, -6 }, /* (174) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 205, 0 }, /* (175) index_options ::= */ - { 205, -9 }, /* (176) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 205, -11 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 206, -1 }, /* (178) func_list ::= func */ - { 206, -3 }, /* (179) func_list ::= func_list NK_COMMA func */ - { 209, -4 }, /* (180) func ::= function_name NK_LP expression_list NK_RP */ - { 163, -6 }, /* (181) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 163, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ - { 163, -4 }, /* (183) cmd ::= DROP TOPIC exists_opt topic_name */ - { 163, -1 }, /* (184) cmd ::= query_expression */ - { 166, -1 }, /* (185) literal ::= NK_INTEGER */ - { 166, -1 }, /* (186) literal ::= NK_FLOAT */ - { 166, -1 }, /* (187) literal ::= NK_STRING */ - { 166, -1 }, /* (188) literal ::= NK_BOOL */ - { 166, -2 }, /* (189) literal ::= TIMESTAMP NK_STRING */ - { 166, -1 }, /* (190) literal ::= duration_literal */ - { 207, -1 }, /* (191) duration_literal ::= NK_VARIABLE */ - { 213, -1 }, /* (192) signed ::= NK_INTEGER */ - { 213, -2 }, /* (193) signed ::= NK_PLUS NK_INTEGER */ - { 213, -2 }, /* (194) signed ::= NK_MINUS NK_INTEGER */ - { 213, -1 }, /* (195) signed ::= NK_FLOAT */ - { 213, -2 }, /* (196) signed ::= NK_PLUS NK_FLOAT */ - { 213, -2 }, /* (197) signed ::= NK_MINUS NK_FLOAT */ - { 214, -1 }, /* (198) signed_literal ::= signed */ - { 214, -1 }, /* (199) signed_literal ::= NK_STRING */ - { 214, -1 }, /* (200) signed_literal ::= NK_BOOL */ - { 214, -2 }, /* (201) signed_literal ::= TIMESTAMP NK_STRING */ - { 214, -1 }, /* (202) signed_literal ::= duration_literal */ - { 190, -1 }, /* (203) literal_list ::= signed_literal */ - { 190, -3 }, /* (204) literal_list ::= literal_list NK_COMMA signed_literal */ - { 172, -1 }, /* (205) db_name ::= NK_ID */ - { 193, -1 }, /* (206) table_name ::= NK_ID */ - { 186, -1 }, /* (207) column_name ::= NK_ID */ - { 203, -1 }, /* (208) function_name ::= NK_ID */ - { 215, -1 }, /* (209) table_alias ::= NK_ID */ - { 216, -1 }, /* (210) column_alias ::= NK_ID */ - { 168, -1 }, /* (211) user_name ::= NK_ID */ - { 204, -1 }, /* (212) index_name ::= NK_ID */ - { 211, -1 }, /* (213) topic_name ::= NK_ID */ - { 217, -1 }, /* (214) expression ::= literal */ - { 217, -1 }, /* (215) expression ::= column_reference */ - { 217, -4 }, /* (216) expression ::= function_name NK_LP expression_list NK_RP */ - { 217, -4 }, /* (217) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 217, -1 }, /* (218) expression ::= subquery */ - { 217, -3 }, /* (219) expression ::= NK_LP expression NK_RP */ - { 217, -2 }, /* (220) expression ::= NK_PLUS expression */ - { 217, -2 }, /* (221) expression ::= NK_MINUS expression */ - { 217, -3 }, /* (222) expression ::= expression NK_PLUS expression */ - { 217, -3 }, /* (223) expression ::= expression NK_MINUS expression */ - { 217, -3 }, /* (224) expression ::= expression NK_STAR expression */ - { 217, -3 }, /* (225) expression ::= expression NK_SLASH expression */ - { 217, -3 }, /* (226) expression ::= expression NK_REM expression */ - { 210, -1 }, /* (227) expression_list ::= expression */ - { 210, -3 }, /* (228) expression_list ::= expression_list NK_COMMA expression */ - { 218, -1 }, /* (229) column_reference ::= column_name */ - { 218, -3 }, /* (230) column_reference ::= table_name NK_DOT column_name */ - { 220, -3 }, /* (231) predicate ::= expression compare_op expression */ - { 220, -5 }, /* (232) predicate ::= expression BETWEEN expression AND expression */ - { 220, -6 }, /* (233) predicate ::= expression NOT BETWEEN expression AND expression */ - { 220, -3 }, /* (234) predicate ::= expression IS NULL */ - { 220, -4 }, /* (235) predicate ::= expression IS NOT NULL */ - { 220, -3 }, /* (236) predicate ::= expression in_op in_predicate_value */ - { 221, -1 }, /* (237) compare_op ::= NK_LT */ - { 221, -1 }, /* (238) compare_op ::= NK_GT */ - { 221, -1 }, /* (239) compare_op ::= NK_LE */ - { 221, -1 }, /* (240) compare_op ::= NK_GE */ - { 221, -1 }, /* (241) compare_op ::= NK_NE */ - { 221, -1 }, /* (242) compare_op ::= NK_EQ */ - { 221, -1 }, /* (243) compare_op ::= LIKE */ - { 221, -2 }, /* (244) compare_op ::= NOT LIKE */ - { 221, -1 }, /* (245) compare_op ::= MATCH */ - { 221, -1 }, /* (246) compare_op ::= NMATCH */ - { 222, -1 }, /* (247) in_op ::= IN */ - { 222, -2 }, /* (248) in_op ::= NOT IN */ - { 223, -3 }, /* (249) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 224, -1 }, /* (250) boolean_value_expression ::= boolean_primary */ - { 224, -2 }, /* (251) boolean_value_expression ::= NOT boolean_primary */ - { 224, -3 }, /* (252) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 224, -3 }, /* (253) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 225, -1 }, /* (254) boolean_primary ::= predicate */ - { 225, -3 }, /* (255) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 226, -1 }, /* (256) common_expression ::= expression */ - { 226, -1 }, /* (257) common_expression ::= boolean_value_expression */ - { 227, -2 }, /* (258) from_clause ::= FROM table_reference_list */ - { 228, -1 }, /* (259) table_reference_list ::= table_reference */ - { 228, -3 }, /* (260) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 229, -1 }, /* (261) table_reference ::= table_primary */ - { 229, -1 }, /* (262) table_reference ::= joined_table */ - { 230, -2 }, /* (263) table_primary ::= table_name alias_opt */ - { 230, -4 }, /* (264) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 230, -2 }, /* (265) table_primary ::= subquery alias_opt */ - { 230, -1 }, /* (266) table_primary ::= parenthesized_joined_table */ - { 232, 0 }, /* (267) alias_opt ::= */ - { 232, -1 }, /* (268) alias_opt ::= table_alias */ - { 232, -2 }, /* (269) alias_opt ::= AS table_alias */ - { 233, -3 }, /* (270) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 233, -3 }, /* (271) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 231, -6 }, /* (272) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 234, 0 }, /* (273) join_type ::= */ - { 234, -1 }, /* (274) join_type ::= INNER */ - { 236, -9 }, /* (275) 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 */ - { 237, 0 }, /* (276) set_quantifier_opt ::= */ - { 237, -1 }, /* (277) set_quantifier_opt ::= DISTINCT */ - { 237, -1 }, /* (278) set_quantifier_opt ::= ALL */ - { 238, -1 }, /* (279) select_list ::= NK_STAR */ - { 238, -1 }, /* (280) select_list ::= select_sublist */ - { 244, -1 }, /* (281) select_sublist ::= select_item */ - { 244, -3 }, /* (282) select_sublist ::= select_sublist NK_COMMA select_item */ - { 245, -1 }, /* (283) select_item ::= common_expression */ - { 245, -2 }, /* (284) select_item ::= common_expression column_alias */ - { 245, -3 }, /* (285) select_item ::= common_expression AS column_alias */ - { 245, -3 }, /* (286) select_item ::= table_name NK_DOT NK_STAR */ - { 239, 0 }, /* (287) where_clause_opt ::= */ - { 239, -2 }, /* (288) where_clause_opt ::= WHERE search_condition */ - { 240, 0 }, /* (289) partition_by_clause_opt ::= */ - { 240, -3 }, /* (290) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 241, 0 }, /* (291) twindow_clause_opt ::= */ - { 241, -6 }, /* (292) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 241, -4 }, /* (293) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 241, -6 }, /* (294) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 241, -8 }, /* (295) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 208, 0 }, /* (296) sliding_opt ::= */ - { 208, -4 }, /* (297) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 246, 0 }, /* (298) fill_opt ::= */ - { 246, -4 }, /* (299) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 246, -6 }, /* (300) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 247, -1 }, /* (301) fill_mode ::= NONE */ - { 247, -1 }, /* (302) fill_mode ::= PREV */ - { 247, -1 }, /* (303) fill_mode ::= NULL */ - { 247, -1 }, /* (304) fill_mode ::= LINEAR */ - { 247, -1 }, /* (305) fill_mode ::= NEXT */ - { 242, 0 }, /* (306) group_by_clause_opt ::= */ - { 242, -3 }, /* (307) group_by_clause_opt ::= GROUP BY group_by_list */ - { 248, -1 }, /* (308) group_by_list ::= expression */ - { 248, -3 }, /* (309) group_by_list ::= group_by_list NK_COMMA expression */ - { 243, 0 }, /* (310) having_clause_opt ::= */ - { 243, -2 }, /* (311) having_clause_opt ::= HAVING search_condition */ - { 212, -4 }, /* (312) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 249, -1 }, /* (313) query_expression_body ::= query_primary */ - { 249, -4 }, /* (314) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 253, -1 }, /* (315) query_primary ::= query_specification */ - { 250, 0 }, /* (316) order_by_clause_opt ::= */ - { 250, -3 }, /* (317) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 251, 0 }, /* (318) slimit_clause_opt ::= */ - { 251, -2 }, /* (319) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 251, -4 }, /* (320) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 251, -4 }, /* (321) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 252, 0 }, /* (322) limit_clause_opt ::= */ - { 252, -2 }, /* (323) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 252, -4 }, /* (324) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 252, -4 }, /* (325) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 219, -3 }, /* (326) subquery ::= NK_LP query_expression NK_RP */ - { 235, -1 }, /* (327) search_condition ::= common_expression */ - { 254, -1 }, /* (328) sort_specification_list ::= sort_specification */ - { 254, -3 }, /* (329) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 255, -3 }, /* (330) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 256, 0 }, /* (331) ordering_specification_opt ::= */ - { 256, -1 }, /* (332) ordering_specification_opt ::= ASC */ - { 256, -1 }, /* (333) ordering_specification_opt ::= DESC */ - { 257, 0 }, /* (334) null_ordering_opt ::= */ - { 257, -2 }, /* (335) null_ordering_opt ::= NULLS FIRST */ - { 257, -2 }, /* (336) null_ordering_opt ::= NULLS LAST */ + { 172, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 172, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 173, 0 }, /* (2) account_options ::= */ + { 173, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 173, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 173, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 173, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 173, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 173, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 173, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 173, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 173, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 174, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 174, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 176, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 176, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 176, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 176, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 176, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 176, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 176, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 176, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 176, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 176, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 172, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 172, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 172, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 172, -3 }, /* (27) cmd ::= DROP USER user_name */ + { 172, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ + { 172, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 172, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ + { 172, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ + { 172, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 172, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 172, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ + { 172, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 178, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ + { 179, -1 }, /* (37) dnode_host_name ::= NK_ID */ + { 179, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ + { 172, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ + { 172, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 172, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 172, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 172, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 172, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ + { 172, -2 }, /* (45) cmd ::= USE db_name */ + { 172, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 180, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ + { 180, 0 }, /* (48) not_exists_opt ::= */ + { 183, -2 }, /* (49) exists_opt ::= IF EXISTS */ + { 183, 0 }, /* (50) exists_opt ::= */ + { 182, 0 }, /* (51) db_options ::= */ + { 182, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ + { 182, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ + { 182, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ + { 182, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ + { 182, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ + { 182, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ + { 182, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ + { 182, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ + { 182, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ + { 182, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ + { 182, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ + { 182, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ + { 182, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ + { 182, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ + { 182, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ + { 182, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 182, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 182, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ + { 184, -1 }, /* (70) alter_db_options ::= alter_db_option */ + { 184, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ + { 185, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ + { 185, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ + { 185, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ + { 185, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ + { 185, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ + { 185, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ + { 172, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 172, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ + { 172, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 172, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ + { 172, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ + { 172, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ + { 172, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ + { 193, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ + { 193, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 193, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 193, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 193, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 193, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 193, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 193, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 193, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 193, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + { 190, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ + { 190, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 197, -9 }, /* (97) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 192, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ + { 192, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 200, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ + { 198, 0 }, /* (101) specific_tags_opt ::= */ + { 198, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 186, -1 }, /* (103) full_table_name ::= table_name */ + { 186, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ + { 187, -1 }, /* (105) column_def_list ::= column_def */ + { 187, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ + { 203, -2 }, /* (107) column_def ::= column_name type_name */ + { 203, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ + { 196, -1 }, /* (109) type_name ::= BOOL */ + { 196, -1 }, /* (110) type_name ::= TINYINT */ + { 196, -1 }, /* (111) type_name ::= SMALLINT */ + { 196, -1 }, /* (112) type_name ::= INT */ + { 196, -1 }, /* (113) type_name ::= INTEGER */ + { 196, -1 }, /* (114) type_name ::= BIGINT */ + { 196, -1 }, /* (115) type_name ::= FLOAT */ + { 196, -1 }, /* (116) type_name ::= DOUBLE */ + { 196, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 196, -1 }, /* (118) type_name ::= TIMESTAMP */ + { 196, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 196, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ + { 196, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ + { 196, -2 }, /* (122) type_name ::= INT UNSIGNED */ + { 196, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ + { 196, -1 }, /* (124) type_name ::= JSON */ + { 196, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 196, -1 }, /* (126) type_name ::= MEDIUMBLOB */ + { 196, -1 }, /* (127) type_name ::= BLOB */ + { 196, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 196, -1 }, /* (129) type_name ::= DECIMAL */ + { 196, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 196, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 188, 0 }, /* (132) tags_def_opt ::= */ + { 188, -1 }, /* (133) tags_def_opt ::= tags_def */ + { 191, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 189, 0 }, /* (135) table_options ::= */ + { 189, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ + { 189, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ + { 189, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ + { 189, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 189, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ + { 189, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ + { 189, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ + { 194, -1 }, /* (143) alter_table_options ::= alter_table_option */ + { 194, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ + { 205, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ + { 205, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ + { 205, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ + { 201, -1 }, /* (148) col_name_list ::= col_name */ + { 201, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ + { 206, -1 }, /* (150) col_name ::= column_name */ + { 172, -2 }, /* (151) cmd ::= SHOW DNODES */ + { 172, -2 }, /* (152) cmd ::= SHOW USERS */ + { 172, -2 }, /* (153) cmd ::= SHOW DATABASES */ + { 172, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 172, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 172, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 172, -2 }, /* (157) cmd ::= SHOW MNODES */ + { 172, -2 }, /* (158) cmd ::= SHOW MODULES */ + { 172, -2 }, /* (159) cmd ::= SHOW QNODES */ + { 172, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ + { 172, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 172, -2 }, /* (162) cmd ::= SHOW STREAMS */ + { 207, 0 }, /* (163) db_name_cond_opt ::= */ + { 207, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ + { 208, 0 }, /* (165) like_pattern_opt ::= */ + { 208, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ + { 209, -1 }, /* (167) table_name_cond ::= table_name */ + { 210, 0 }, /* (168) from_db_opt ::= */ + { 210, -2 }, /* (169) from_db_opt ::= FROM db_name */ + { 204, -1 }, /* (170) func_name_list ::= func_name */ + { 204, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ + { 211, -1 }, /* (172) func_name ::= function_name */ + { 172, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 172, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 172, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 214, 0 }, /* (176) index_options ::= */ + { 214, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 214, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 215, -1 }, /* (179) func_list ::= func */ + { 215, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ + { 218, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ + { 172, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 172, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ + { 172, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ + { 172, -1 }, /* (185) cmd ::= query_expression */ + { 175, -1 }, /* (186) literal ::= NK_INTEGER */ + { 175, -1 }, /* (187) literal ::= NK_FLOAT */ + { 175, -1 }, /* (188) literal ::= NK_STRING */ + { 175, -1 }, /* (189) literal ::= NK_BOOL */ + { 175, -2 }, /* (190) literal ::= TIMESTAMP NK_STRING */ + { 175, -1 }, /* (191) literal ::= duration_literal */ + { 175, -1 }, /* (192) literal ::= NULL */ + { 216, -1 }, /* (193) duration_literal ::= NK_VARIABLE */ + { 222, -1 }, /* (194) signed ::= NK_INTEGER */ + { 222, -2 }, /* (195) signed ::= NK_PLUS NK_INTEGER */ + { 222, -2 }, /* (196) signed ::= NK_MINUS NK_INTEGER */ + { 222, -1 }, /* (197) signed ::= NK_FLOAT */ + { 222, -2 }, /* (198) signed ::= NK_PLUS NK_FLOAT */ + { 222, -2 }, /* (199) signed ::= NK_MINUS NK_FLOAT */ + { 223, -1 }, /* (200) signed_literal ::= signed */ + { 223, -1 }, /* (201) signed_literal ::= NK_STRING */ + { 223, -1 }, /* (202) signed_literal ::= NK_BOOL */ + { 223, -2 }, /* (203) signed_literal ::= TIMESTAMP NK_STRING */ + { 223, -1 }, /* (204) signed_literal ::= duration_literal */ + { 223, -1 }, /* (205) signed_literal ::= NULL */ + { 199, -1 }, /* (206) literal_list ::= signed_literal */ + { 199, -3 }, /* (207) literal_list ::= literal_list NK_COMMA signed_literal */ + { 181, -1 }, /* (208) db_name ::= NK_ID */ + { 202, -1 }, /* (209) table_name ::= NK_ID */ + { 195, -1 }, /* (210) column_name ::= NK_ID */ + { 212, -1 }, /* (211) function_name ::= NK_ID */ + { 224, -1 }, /* (212) table_alias ::= NK_ID */ + { 225, -1 }, /* (213) column_alias ::= NK_ID */ + { 177, -1 }, /* (214) user_name ::= NK_ID */ + { 213, -1 }, /* (215) index_name ::= NK_ID */ + { 220, -1 }, /* (216) topic_name ::= NK_ID */ + { 226, -1 }, /* (217) expression ::= literal */ + { 226, -1 }, /* (218) expression ::= pseudo_column */ + { 226, -1 }, /* (219) expression ::= column_reference */ + { 226, -4 }, /* (220) expression ::= function_name NK_LP expression_list NK_RP */ + { 226, -4 }, /* (221) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 226, -1 }, /* (222) expression ::= subquery */ + { 226, -3 }, /* (223) expression ::= NK_LP expression NK_RP */ + { 226, -2 }, /* (224) expression ::= NK_PLUS expression */ + { 226, -2 }, /* (225) expression ::= NK_MINUS expression */ + { 226, -3 }, /* (226) expression ::= expression NK_PLUS expression */ + { 226, -3 }, /* (227) expression ::= expression NK_MINUS expression */ + { 226, -3 }, /* (228) expression ::= expression NK_STAR expression */ + { 226, -3 }, /* (229) expression ::= expression NK_SLASH expression */ + { 226, -3 }, /* (230) expression ::= expression NK_REM expression */ + { 219, -1 }, /* (231) expression_list ::= expression */ + { 219, -3 }, /* (232) expression_list ::= expression_list NK_COMMA expression */ + { 228, -1 }, /* (233) column_reference ::= column_name */ + { 228, -3 }, /* (234) column_reference ::= table_name NK_DOT column_name */ + { 227, -2 }, /* (235) pseudo_column ::= NK_UNDERLINE ROWTS */ + { 227, -1 }, /* (236) pseudo_column ::= TBNAME */ + { 227, -2 }, /* (237) pseudo_column ::= NK_UNDERLINE QSTARTTS */ + { 227, -2 }, /* (238) pseudo_column ::= NK_UNDERLINE QENDTS */ + { 227, -2 }, /* (239) pseudo_column ::= NK_UNDERLINE WSTARTTS */ + { 227, -2 }, /* (240) pseudo_column ::= NK_UNDERLINE WENDTS */ + { 227, -2 }, /* (241) pseudo_column ::= NK_UNDERLINE WDURATION */ + { 230, -3 }, /* (242) predicate ::= expression compare_op expression */ + { 230, -5 }, /* (243) predicate ::= expression BETWEEN expression AND expression */ + { 230, -6 }, /* (244) predicate ::= expression NOT BETWEEN expression AND expression */ + { 230, -3 }, /* (245) predicate ::= expression IS NULL */ + { 230, -4 }, /* (246) predicate ::= expression IS NOT NULL */ + { 230, -3 }, /* (247) predicate ::= expression in_op in_predicate_value */ + { 231, -1 }, /* (248) compare_op ::= NK_LT */ + { 231, -1 }, /* (249) compare_op ::= NK_GT */ + { 231, -1 }, /* (250) compare_op ::= NK_LE */ + { 231, -1 }, /* (251) compare_op ::= NK_GE */ + { 231, -1 }, /* (252) compare_op ::= NK_NE */ + { 231, -1 }, /* (253) compare_op ::= NK_EQ */ + { 231, -1 }, /* (254) compare_op ::= LIKE */ + { 231, -2 }, /* (255) compare_op ::= NOT LIKE */ + { 231, -1 }, /* (256) compare_op ::= MATCH */ + { 231, -1 }, /* (257) compare_op ::= NMATCH */ + { 232, -1 }, /* (258) in_op ::= IN */ + { 232, -2 }, /* (259) in_op ::= NOT IN */ + { 233, -3 }, /* (260) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 234, -1 }, /* (261) boolean_value_expression ::= boolean_primary */ + { 234, -2 }, /* (262) boolean_value_expression ::= NOT boolean_primary */ + { 234, -3 }, /* (263) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 234, -3 }, /* (264) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 235, -1 }, /* (265) boolean_primary ::= predicate */ + { 235, -3 }, /* (266) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 236, -1 }, /* (267) common_expression ::= expression */ + { 236, -1 }, /* (268) common_expression ::= boolean_value_expression */ + { 237, -2 }, /* (269) from_clause ::= FROM table_reference_list */ + { 238, -1 }, /* (270) table_reference_list ::= table_reference */ + { 238, -3 }, /* (271) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 239, -1 }, /* (272) table_reference ::= table_primary */ + { 239, -1 }, /* (273) table_reference ::= joined_table */ + { 240, -2 }, /* (274) table_primary ::= table_name alias_opt */ + { 240, -4 }, /* (275) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 240, -2 }, /* (276) table_primary ::= subquery alias_opt */ + { 240, -1 }, /* (277) table_primary ::= parenthesized_joined_table */ + { 242, 0 }, /* (278) alias_opt ::= */ + { 242, -1 }, /* (279) alias_opt ::= table_alias */ + { 242, -2 }, /* (280) alias_opt ::= AS table_alias */ + { 243, -3 }, /* (281) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 243, -3 }, /* (282) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 241, -6 }, /* (283) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 244, 0 }, /* (284) join_type ::= */ + { 244, -1 }, /* (285) join_type ::= INNER */ + { 246, -9 }, /* (286) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 247, 0 }, /* (287) set_quantifier_opt ::= */ + { 247, -1 }, /* (288) set_quantifier_opt ::= DISTINCT */ + { 247, -1 }, /* (289) set_quantifier_opt ::= ALL */ + { 248, -1 }, /* (290) select_list ::= NK_STAR */ + { 248, -1 }, /* (291) select_list ::= select_sublist */ + { 254, -1 }, /* (292) select_sublist ::= select_item */ + { 254, -3 }, /* (293) select_sublist ::= select_sublist NK_COMMA select_item */ + { 255, -1 }, /* (294) select_item ::= common_expression */ + { 255, -2 }, /* (295) select_item ::= common_expression column_alias */ + { 255, -3 }, /* (296) select_item ::= common_expression AS column_alias */ + { 255, -3 }, /* (297) select_item ::= table_name NK_DOT NK_STAR */ + { 249, 0 }, /* (298) where_clause_opt ::= */ + { 249, -2 }, /* (299) where_clause_opt ::= WHERE search_condition */ + { 250, 0 }, /* (300) partition_by_clause_opt ::= */ + { 250, -3 }, /* (301) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 251, 0 }, /* (302) twindow_clause_opt ::= */ + { 251, -6 }, /* (303) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 251, -4 }, /* (304) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 251, -6 }, /* (305) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 251, -8 }, /* (306) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 217, 0 }, /* (307) sliding_opt ::= */ + { 217, -4 }, /* (308) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 256, 0 }, /* (309) fill_opt ::= */ + { 256, -4 }, /* (310) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 256, -6 }, /* (311) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 257, -1 }, /* (312) fill_mode ::= NONE */ + { 257, -1 }, /* (313) fill_mode ::= PREV */ + { 257, -1 }, /* (314) fill_mode ::= NULL */ + { 257, -1 }, /* (315) fill_mode ::= LINEAR */ + { 257, -1 }, /* (316) fill_mode ::= NEXT */ + { 252, 0 }, /* (317) group_by_clause_opt ::= */ + { 252, -3 }, /* (318) group_by_clause_opt ::= GROUP BY group_by_list */ + { 258, -1 }, /* (319) group_by_list ::= expression */ + { 258, -3 }, /* (320) group_by_list ::= group_by_list NK_COMMA expression */ + { 253, 0 }, /* (321) having_clause_opt ::= */ + { 253, -2 }, /* (322) having_clause_opt ::= HAVING search_condition */ + { 221, -4 }, /* (323) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 259, -1 }, /* (324) query_expression_body ::= query_primary */ + { 259, -4 }, /* (325) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 263, -1 }, /* (326) query_primary ::= query_specification */ + { 260, 0 }, /* (327) order_by_clause_opt ::= */ + { 260, -3 }, /* (328) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 261, 0 }, /* (329) slimit_clause_opt ::= */ + { 261, -2 }, /* (330) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 261, -4 }, /* (331) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 261, -4 }, /* (332) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 262, 0 }, /* (333) limit_clause_opt ::= */ + { 262, -2 }, /* (334) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 262, -4 }, /* (335) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 262, -4 }, /* (336) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 229, -3 }, /* (337) subquery ::= NK_LP query_expression NK_RP */ + { 245, -1 }, /* (338) search_condition ::= common_expression */ + { 264, -1 }, /* (339) sort_specification_list ::= sort_specification */ + { 264, -3 }, /* (340) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 265, -3 }, /* (341) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 266, 0 }, /* (342) ordering_specification_opt ::= */ + { 266, -1 }, /* (343) ordering_specification_opt ::= ASC */ + { 266, -1 }, /* (344) ordering_specification_opt ::= DESC */ + { 267, 0 }, /* (345) null_ordering_opt ::= */ + { 267, -2 }, /* (346) null_ordering_opt ::= NULLS FIRST */ + { 267, -2 }, /* (347) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2296,11 +2337,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,164,&yymsp[0].minor); + yy_destructor(yypParser,173,&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,165,&yymsp[0].minor); + yy_destructor(yypParser,174,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2314,20 +2355,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,164,&yymsp[-2].minor); +{ yy_destructor(yypParser,173,&yymsp[-2].minor); { } - yy_destructor(yypParser,166,&yymsp[0].minor); + yy_destructor(yypParser,175,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,167,&yymsp[0].minor); +{ yy_destructor(yypParser,176,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,165,&yymsp[-1].minor); +{ yy_destructor(yypParser,174,&yymsp[-1].minor); { } - yy_destructor(yypParser,167,&yymsp[0].minor); + yy_destructor(yypParser,176,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2341,31 +2382,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,166,&yymsp[0].minor); + yy_destructor(yypParser,175,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy149, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy225, 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.yy149, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy225, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy149); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy225); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy149, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy225, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy225, &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.yy149); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy225); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -2382,17 +2423,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 205: /* db_name ::= NK_ID */ yytestcase(yyruleno==205); - case 206: /* table_name ::= NK_ID */ yytestcase(yyruleno==206); - case 207: /* column_name ::= NK_ID */ yytestcase(yyruleno==207); - case 208: /* function_name ::= NK_ID */ yytestcase(yyruleno==208); - case 209: /* table_alias ::= NK_ID */ yytestcase(yyruleno==209); - case 210: /* column_alias ::= NK_ID */ yytestcase(yyruleno==210); - case 211: /* user_name ::= NK_ID */ yytestcase(yyruleno==211); - case 212: /* index_name ::= NK_ID */ yytestcase(yyruleno==212); - case 213: /* topic_name ::= NK_ID */ yytestcase(yyruleno==213); -{ yylhsminor.yy149 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy149 = yylhsminor.yy149; + case 208: /* db_name ::= NK_ID */ yytestcase(yyruleno==208); + case 209: /* table_name ::= NK_ID */ yytestcase(yyruleno==209); + case 210: /* column_name ::= NK_ID */ yytestcase(yyruleno==210); + case 211: /* function_name ::= NK_ID */ yytestcase(yyruleno==211); + case 212: /* table_alias ::= NK_ID */ yytestcase(yyruleno==212); + case 213: /* column_alias ::= NK_ID */ yytestcase(yyruleno==213); + case 214: /* user_name ::= NK_ID */ yytestcase(yyruleno==214); + case 215: /* index_name ::= NK_ID */ yytestcase(yyruleno==215); + case 216: /* topic_name ::= NK_ID */ yytestcase(yyruleno==216); +{ yylhsminor.yy225 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy225 = yylhsminor.yy225; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2407,922 +2448,951 @@ 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.yy497, &yymsp[-1].minor.yy149, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy505, &yymsp[-1].minor.yy225, yymsp[0].minor.yy176); } break; case 44: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy497, &yymsp[0].minor.yy149); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy505, &yymsp[0].minor.yy225); } break; case 45: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy149); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy225); } break; case 46: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy149, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy225, yymsp[0].minor.yy176); } break; case 47: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy497 = true; } +{ yymsp[-2].minor.yy505 = true; } break; case 48: /* not_exists_opt ::= */ case 50: /* exists_opt ::= */ yytestcase(yyruleno==50); - case 276: /* set_quantifier_opt ::= */ yytestcase(yyruleno==276); -{ yymsp[1].minor.yy497 = false; } + case 287: /* set_quantifier_opt ::= */ yytestcase(yyruleno==287); +{ yymsp[1].minor.yy505 = false; } break; case 49: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy497 = true; } +{ yymsp[-1].minor.yy505 = true; } break; case 51: /* db_options ::= */ -{ yymsp[1].minor.yy140 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy176 = createDefaultDatabaseOptions(pCxt); } break; case 52: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 53: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 54: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 55: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 56: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 57: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 58: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 59: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 60: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 61: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 62: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 63: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 64: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 65: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 66: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 67: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 68: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 69: /* db_options ::= db_options RETENTIONS NK_STRING */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 70: /* db_options ::= db_options FILE_FACTOR NK_FLOAT */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 70: /* alter_db_options ::= alter_db_option */ +{ yylhsminor.yy176 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy176 = setDatabaseOption(pCxt, yylhsminor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 71: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy140 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy140 = setDatabaseOption(pCxt, yylhsminor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 71: /* alter_db_options ::= alter_db_options alter_db_option */ +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 72: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 72: /* alter_db_option ::= BLOCKS NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; - case 73: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 73: /* alter_db_option ::= FSYNC NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } + break; + case 74: /* alter_db_option ::= KEEP NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = DB_OPTION_KEEP; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } + break; + case 75: /* alter_db_option ::= WAL NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = DB_OPTION_WAL; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; - case 74: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } - break; - case 75: /* alter_db_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_KEEP; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } - break; - case 76: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_WAL; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 76: /* alter_db_option ::= QUORUM NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; - case 77: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 77: /* alter_db_option ::= CACHELAST NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } + break; + case 78: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 80: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==80); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy505, yymsp[-5].minor.yy176, yymsp[-3].minor.yy512, yymsp[-1].minor.yy512, yymsp[0].minor.yy176); } + break; + case 79: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy512); } + break; + case 81: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy512); } + break; + case 82: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy505, yymsp[0].minor.yy176); } + break; + case 83: /* cmd ::= ALTER TABLE alter_table_clause */ + case 84: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==84); + case 185: /* cmd ::= query_expression */ yytestcase(yyruleno==185); +{ pCxt->pRootNode = yymsp[0].minor.yy176; } + break; + case 85: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy176 = createAlterTableOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; + break; + case 86: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; + break; + case 87: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ +{ yylhsminor.yy176 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy176, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy225); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; + break; + case 88: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; + break; + case 89: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ +{ yylhsminor.yy176 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 78: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } - break; - case 79: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 81: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==81); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy497, yymsp[-5].minor.yy140, yymsp[-3].minor.yy136, yymsp[-1].minor.yy136, yymsp[0].minor.yy140); } - break; - case 80: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy136); } - break; - case 82: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy136); } - break; - case 83: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy497, yymsp[0].minor.yy140); } - break; - case 84: /* cmd ::= ALTER TABLE alter_table_clause */ - case 85: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==85); - case 184: /* cmd ::= query_expression */ yytestcase(yyruleno==184); -{ pCxt->pRootNode = yymsp[0].minor.yy140; } - break; - case 86: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy140 = createAlterTableOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; - break; - case 87: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; - break; - case 88: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy149); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; - break; - case 89: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; - break; - case 90: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 90: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 91: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 91: /* alter_table_clause ::= full_table_name DROP TAG column_name */ +{ yylhsminor.yy176 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy176, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy225); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 92: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy149); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 92: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 93: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 93: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ +{ yylhsminor.yy176 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 94: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 94: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ +{ yylhsminor.yy176 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy176, &yymsp[-2].minor.yy225, yymsp[0].minor.yy176); } + yymsp[-5].minor.yy176 = yylhsminor.yy176; break; - case 95: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy140 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy140, &yymsp[-2].minor.yy149, yymsp[0].minor.yy140); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + case 95: /* multi_create_clause ::= create_subtable_clause */ + case 98: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==98); + case 105: /* column_def_list ::= column_def */ yytestcase(yyruleno==105); + case 148: /* col_name_list ::= col_name */ yytestcase(yyruleno==148); + case 170: /* func_name_list ::= func_name */ yytestcase(yyruleno==170); + case 179: /* func_list ::= func */ yytestcase(yyruleno==179); + case 206: /* literal_list ::= signed_literal */ yytestcase(yyruleno==206); + case 292: /* select_sublist ::= select_item */ yytestcase(yyruleno==292); + case 339: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==339); +{ yylhsminor.yy512 = createNodeList(pCxt, yymsp[0].minor.yy176); } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; - case 96: /* multi_create_clause ::= create_subtable_clause */ - case 99: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==99); - case 106: /* column_def_list ::= column_def */ yytestcase(yyruleno==106); - case 147: /* col_name_list ::= col_name */ yytestcase(yyruleno==147); - case 169: /* func_name_list ::= func_name */ yytestcase(yyruleno==169); - case 178: /* func_list ::= func */ yytestcase(yyruleno==178); - case 203: /* literal_list ::= signed_literal */ yytestcase(yyruleno==203); - case 281: /* select_sublist ::= select_item */ yytestcase(yyruleno==281); - case 328: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==328); -{ yylhsminor.yy136 = createNodeList(pCxt, yymsp[0].minor.yy140); } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 96: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 99: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==99); +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-1].minor.yy512, yymsp[0].minor.yy176); } + yymsp[-1].minor.yy512 = yylhsminor.yy512; break; - case 97: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 100: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==100); -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-1].minor.yy136, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy136 = yylhsminor.yy136; + case 97: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ +{ yylhsminor.yy176 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy505, yymsp[-7].minor.yy176, yymsp[-5].minor.yy176, yymsp[-4].minor.yy512, yymsp[-1].minor.yy512); } + yymsp[-8].minor.yy176 = yylhsminor.yy176; break; - case 98: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy140 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy497, yymsp[-7].minor.yy140, yymsp[-5].minor.yy140, yymsp[-4].minor.yy136, yymsp[-1].minor.yy136); } - yymsp[-8].minor.yy140 = yylhsminor.yy140; + case 100: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy176 = createDropTableClause(pCxt, yymsp[-1].minor.yy505, yymsp[0].minor.yy176); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 101: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy140 = createDropTableClause(pCxt, yymsp[-1].minor.yy497, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 101: /* specific_tags_opt ::= */ + case 132: /* tags_def_opt ::= */ yytestcase(yyruleno==132); + case 300: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==300); + case 317: /* group_by_clause_opt ::= */ yytestcase(yyruleno==317); + case 327: /* order_by_clause_opt ::= */ yytestcase(yyruleno==327); +{ yymsp[1].minor.yy512 = NULL; } break; - case 102: /* specific_tags_opt ::= */ - case 133: /* tags_def_opt ::= */ yytestcase(yyruleno==133); - case 289: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==289); - case 306: /* group_by_clause_opt ::= */ yytestcase(yyruleno==306); - case 316: /* order_by_clause_opt ::= */ yytestcase(yyruleno==316); -{ yymsp[1].minor.yy136 = NULL; } + case 102: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy512 = yymsp[-1].minor.yy512; } break; - case 103: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy136 = yymsp[-1].minor.yy136; } + case 103: /* full_table_name ::= table_name */ +{ yylhsminor.yy176 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy225, NULL); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 104: /* full_table_name ::= table_name */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy149, NULL); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 104: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy176 = createRealTableNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225, NULL); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 105: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149, NULL); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 106: /* column_def_list ::= column_def_list NK_COMMA column_def */ + case 149: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==149); + case 171: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==171); + case 180: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==180); + case 207: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==207); + case 293: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==293); + case 340: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==340); +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, yymsp[0].minor.yy176); } + yymsp[-2].minor.yy512 = yylhsminor.yy512; break; - case 107: /* column_def_list ::= column_def_list NK_COMMA column_def */ - case 148: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==148); - case 170: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==170); - case 179: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==179); - case 204: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==204); - case 282: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==282); - case 329: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==329); -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-2].minor.yy136, yymsp[0].minor.yy140); } - yymsp[-2].minor.yy136 = yylhsminor.yy136; + case 107: /* column_def ::= column_name type_name */ +{ yylhsminor.yy176 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448, NULL); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 108: /* column_def ::= column_name type_name */ -{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256, NULL); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 108: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy176 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-2].minor.yy448, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 109: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy149, yymsp[-2].minor.yy256, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 109: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 110: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 110: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 111: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 111: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 112: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 112: /* type_name ::= INT */ + case 113: /* type_name ::= INTEGER */ yytestcase(yyruleno==113); +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 113: /* type_name ::= INT */ - case 114: /* type_name ::= INTEGER */ yytestcase(yyruleno==114); -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_INT); } + case 114: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 115: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 115: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 116: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 116: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 117: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 117: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 118: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 118: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 119: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 119: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 120: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 120: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 121: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 121: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 122: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 122: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 123: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_UINT); } + case 123: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 124: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 124: /* type_name ::= JSON */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 125: /* type_name ::= JSON */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_JSON); } + case 125: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 126: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 126: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 127: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 127: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 128: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 128: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 129: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 129: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 130: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 130: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 131: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 131: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 132: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy256 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 133: /* tags_def_opt ::= tags_def */ + case 291: /* select_list ::= select_sublist */ yytestcase(yyruleno==291); +{ yylhsminor.yy512 = yymsp[0].minor.yy512; } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; - case 134: /* tags_def_opt ::= tags_def */ - case 280: /* select_list ::= select_sublist */ yytestcase(yyruleno==280); -{ yylhsminor.yy136 = yymsp[0].minor.yy136; } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 134: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy512 = yymsp[-1].minor.yy512; } break; - case 135: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy136 = yymsp[-1].minor.yy136; } + case 135: /* table_options ::= */ +{ yymsp[1].minor.yy176 = createDefaultTableOptions(pCxt); } break; - case 136: /* table_options ::= */ -{ yymsp[1].minor.yy140 = createDefaultTableOptions(pCxt); } + case 136: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 137: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-2].minor.yy140, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 137: /* table_options ::= table_options KEEP NK_INTEGER */ +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 138: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-2].minor.yy140, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 138: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 139: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-2].minor.yy140, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 139: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy176 = setTableSmaOption(pCxt, yymsp[-4].minor.yy176, yymsp[-1].minor.yy512); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 140: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy140 = setTableSmaOption(pCxt, yymsp[-4].minor.yy140, yymsp[-1].minor.yy136); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 140: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ +{ yylhsminor.yy176 = setTableRollupOption(pCxt, yymsp[-4].minor.yy176, yymsp[-1].minor.yy512); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 141: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ yylhsminor.yy140 = setTableRollupOption(pCxt, yymsp[-4].minor.yy140, yymsp[-1].minor.yy136); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 141: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 142: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy140 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy140 = setTableOption(pCxt, yylhsminor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 142: /* table_options ::= table_options DELAY NK_INTEGER */ +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 143: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 143: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy176 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy176 = setTableOption(pCxt, yylhsminor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 144: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy233.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 144: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 145: /* alter_table_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 145: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy325.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; - case 146: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 146: /* alter_table_option ::= KEEP NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; - case 149: /* col_name ::= column_name */ -{ yylhsminor.yy140 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy149); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 147: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy325.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; - case 150: /* cmd ::= SHOW DNODES */ + case 150: /* col_name ::= column_name */ +{ yylhsminor.yy176 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy225); } + yymsp[0].minor.yy176 = yylhsminor.yy176; + break; + case 151: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } break; - case 151: /* cmd ::= SHOW USERS */ + case 152: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL, NULL); } break; - case 152: /* cmd ::= SHOW DATABASES */ + case 153: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; - case 153: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } + case 154: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy176, yymsp[0].minor.yy176); } break; - case 154: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } + case 155: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy176, yymsp[0].minor.yy176); } break; - case 155: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy140, NULL); } + case 156: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy176, NULL); } break; - case 156: /* cmd ::= SHOW MNODES */ + case 157: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } break; - case 157: /* cmd ::= SHOW MODULES */ + case 158: /* cmd ::= SHOW MODULES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT, NULL, NULL); } break; - case 158: /* cmd ::= SHOW QNODES */ + case 159: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL, NULL); } break; - case 159: /* cmd ::= SHOW FUNCTIONS */ + case 160: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; - case 160: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 161: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } break; - case 161: /* cmd ::= SHOW STREAMS */ + case 162: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } break; - case 162: /* db_name_cond_opt ::= */ - case 167: /* from_db_opt ::= */ yytestcase(yyruleno==167); -{ yymsp[1].minor.yy140 = createDefaultDatabaseCondValue(pCxt); } + case 163: /* db_name_cond_opt ::= */ + case 168: /* from_db_opt ::= */ yytestcase(yyruleno==168); +{ yymsp[1].minor.yy176 = createDefaultDatabaseCondValue(pCxt); } break; - case 163: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 164: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 164: /* like_pattern_opt ::= */ - case 175: /* index_options ::= */ yytestcase(yyruleno==175); - case 287: /* where_clause_opt ::= */ yytestcase(yyruleno==287); - case 291: /* twindow_clause_opt ::= */ yytestcase(yyruleno==291); - case 296: /* sliding_opt ::= */ yytestcase(yyruleno==296); - case 298: /* fill_opt ::= */ yytestcase(yyruleno==298); - case 310: /* having_clause_opt ::= */ yytestcase(yyruleno==310); - case 318: /* slimit_clause_opt ::= */ yytestcase(yyruleno==318); - case 322: /* limit_clause_opt ::= */ yytestcase(yyruleno==322); -{ yymsp[1].minor.yy140 = NULL; } + case 165: /* like_pattern_opt ::= */ + case 176: /* index_options ::= */ yytestcase(yyruleno==176); + case 298: /* where_clause_opt ::= */ yytestcase(yyruleno==298); + case 302: /* twindow_clause_opt ::= */ yytestcase(yyruleno==302); + case 307: /* sliding_opt ::= */ yytestcase(yyruleno==307); + case 309: /* fill_opt ::= */ yytestcase(yyruleno==309); + case 321: /* having_clause_opt ::= */ yytestcase(yyruleno==321); + case 329: /* slimit_clause_opt ::= */ yytestcase(yyruleno==329); + case 333: /* limit_clause_opt ::= */ yytestcase(yyruleno==333); +{ yymsp[1].minor.yy176 = NULL; } break; - case 165: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 166: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 166: /* table_name_cond ::= table_name */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy149); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 167: /* table_name_cond ::= table_name */ +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy225); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 168: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy149); } + case 169: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy225); } break; - case 171: /* func_name ::= function_name */ -{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[0].minor.yy149, NULL); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 172: /* func_name ::= function_name */ +{ yylhsminor.yy176 = createFunctionNode(pCxt, &yymsp[0].minor.yy225, NULL); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 172: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy497, &yymsp[-3].minor.yy149, &yymsp[-1].minor.yy149, NULL, yymsp[0].minor.yy140); } + case 173: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy505, &yymsp[-3].minor.yy225, &yymsp[-1].minor.yy225, NULL, yymsp[0].minor.yy176); } break; - case 173: /* 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.yy497, &yymsp[-5].minor.yy149, &yymsp[-3].minor.yy149, yymsp[-1].minor.yy136, NULL); } + case 174: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy505, &yymsp[-5].minor.yy225, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512, NULL); } break; - case 174: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy497, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149); } + case 175: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225); } break; - case 176: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy140 = createIndexOption(pCxt, yymsp[-6].minor.yy136, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL, yymsp[0].minor.yy140); } + case 177: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy176 = createIndexOption(pCxt, yymsp[-6].minor.yy512, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), NULL, yymsp[0].minor.yy176); } break; - case 177: /* 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.yy140 = createIndexOption(pCxt, yymsp[-8].minor.yy136, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[0].minor.yy140); } + case 178: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ +{ yymsp[-10].minor.yy176 = createIndexOption(pCxt, yymsp[-8].minor.yy512, releaseRawExprNode(pCxt, yymsp[-4].minor.yy176), releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), yymsp[0].minor.yy176); } break; - case 180: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[-3].minor.yy149, yymsp[-1].minor.yy136); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 181: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy176 = createFunctionNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 181: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy497, &yymsp[-2].minor.yy149, yymsp[0].minor.yy140, NULL); } + case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, yymsp[0].minor.yy176, NULL); } break; - case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy497, &yymsp[-2].minor.yy149, NULL, &yymsp[0].minor.yy149); } + case 183: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, NULL, &yymsp[0].minor.yy225); } break; - case 183: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy497, &yymsp[0].minor.yy149); } + case 184: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy505, &yymsp[0].minor.yy225); } break; - case 185: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 186: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 186: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 187: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 187: /* literal ::= NK_STRING */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 188: /* literal ::= NK_STRING */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 188: /* literal ::= NK_BOOL */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 189: /* literal ::= NK_BOOL */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 189: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 190: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 190: /* literal ::= duration_literal */ - case 198: /* signed_literal ::= signed */ yytestcase(yyruleno==198); - case 214: /* expression ::= literal */ yytestcase(yyruleno==214); - case 215: /* expression ::= column_reference */ yytestcase(yyruleno==215); - case 218: /* expression ::= subquery */ yytestcase(yyruleno==218); - case 250: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==250); - case 254: /* boolean_primary ::= predicate */ yytestcase(yyruleno==254); - case 256: /* common_expression ::= expression */ yytestcase(yyruleno==256); - case 257: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==257); - case 259: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==259); - case 261: /* table_reference ::= table_primary */ yytestcase(yyruleno==261); - case 262: /* table_reference ::= joined_table */ yytestcase(yyruleno==262); - case 266: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==266); - case 313: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==313); - case 315: /* query_primary ::= query_specification */ yytestcase(yyruleno==315); -{ yylhsminor.yy140 = yymsp[0].minor.yy140; } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 191: /* literal ::= duration_literal */ + case 200: /* signed_literal ::= signed */ yytestcase(yyruleno==200); + case 217: /* expression ::= literal */ yytestcase(yyruleno==217); + case 218: /* expression ::= pseudo_column */ yytestcase(yyruleno==218); + case 219: /* expression ::= column_reference */ yytestcase(yyruleno==219); + case 222: /* expression ::= subquery */ yytestcase(yyruleno==222); + case 261: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==261); + case 265: /* boolean_primary ::= predicate */ yytestcase(yyruleno==265); + case 267: /* common_expression ::= expression */ yytestcase(yyruleno==267); + case 268: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==268); + case 270: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==270); + case 272: /* table_reference ::= table_primary */ yytestcase(yyruleno==272); + case 273: /* table_reference ::= joined_table */ yytestcase(yyruleno==273); + case 277: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==277); + case 324: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==324); + case 326: /* query_primary ::= query_specification */ yytestcase(yyruleno==326); +{ yylhsminor.yy176 = yymsp[0].minor.yy176; } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 191: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 192: /* literal ::= NULL */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 192: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 193: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 193: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 194: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 194: /* signed ::= NK_MINUS NK_INTEGER */ + case 195: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + break; + case 196: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 195: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 197: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 196: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 198: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 197: /* signed ::= NK_MINUS NK_FLOAT */ + case 199: /* 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.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 199: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 201: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 200: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 202: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 201: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 203: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 202: /* signed_literal ::= duration_literal */ - case 327: /* search_condition ::= common_expression */ yytestcase(yyruleno==327); -{ yylhsminor.yy140 = releaseRawExprNode(pCxt, yymsp[0].minor.yy140); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 204: /* signed_literal ::= duration_literal */ + case 338: /* search_condition ::= common_expression */ yytestcase(yyruleno==338); +{ yylhsminor.yy176 = releaseRawExprNode(pCxt, yymsp[0].minor.yy176); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 216: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy149, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy149, yymsp[-1].minor.yy136)); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 205: /* signed_literal ::= NULL */ +{ yymsp[0].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; - case 217: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy149, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy149, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 220: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy225, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512)); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 219: /* expression ::= NK_LP expression NK_RP */ - case 255: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==255); -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 221: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy225, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy225, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 220: /* expression ::= NK_PLUS expression */ + case 223: /* expression ::= NK_LP expression NK_RP */ + case 266: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==266); +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; + break; + case 224: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 221: /* expression ::= NK_MINUS expression */ + case 225: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), NULL)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 222: /* expression ::= expression NK_PLUS expression */ + case 226: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 223: /* expression ::= expression NK_MINUS expression */ + case 227: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 224: /* expression ::= expression NK_STAR expression */ + case 228: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 225: /* expression ::= expression NK_SLASH expression */ + case 229: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 226: /* expression ::= expression NK_REM expression */ + case 230: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 227: /* expression_list ::= expression */ -{ yylhsminor.yy136 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 231: /* expression_list ::= expression */ +{ yylhsminor.yy512 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; - case 228: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-2].minor.yy136, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } - yymsp[-2].minor.yy136 = yylhsminor.yy136; + case 232: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } + yymsp[-2].minor.yy512 = yylhsminor.yy512; break; - case 229: /* column_reference ::= column_name */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy149, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy149)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 233: /* column_reference ::= column_name */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy225, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy225)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 230: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149, createColumnNode(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 234: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225, createColumnNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225)); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 231: /* predicate ::= expression compare_op expression */ - case 236: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==236); + case 235: /* pseudo_column ::= NK_UNDERLINE ROWTS */ + case 237: /* pseudo_column ::= NK_UNDERLINE QSTARTTS */ yytestcase(yyruleno==237); + case 238: /* pseudo_column ::= NK_UNDERLINE QENDTS */ yytestcase(yyruleno==238); + case 239: /* pseudo_column ::= NK_UNDERLINE WSTARTTS */ yytestcase(yyruleno==239); + case 240: /* pseudo_column ::= NK_UNDERLINE WENDTS */ yytestcase(yyruleno==240); + case 241: /* pseudo_column ::= NK_UNDERLINE WDURATION */ yytestcase(yyruleno==241); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy320, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken t = yymsp[-1].minor.yy0; + t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; + yylhsminor.yy176 = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 232: /* predicate ::= expression BETWEEN expression AND expression */ + case 236: /* pseudo_column ::= TBNAME */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; + break; + case 242: /* predicate ::= expression compare_op expression */ + case 247: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==247); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy404, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 233: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 243: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy176), releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 234: /* predicate ::= expression IS NULL */ + case 244: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[-5].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-5].minor.yy176 = yylhsminor.yy176; break; - case 235: /* predicate ::= expression IS NOT NULL */ + case 245: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), NULL)); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 237: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy320 = OP_TYPE_LOWER_THAN; } - break; - case 238: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy320 = OP_TYPE_GREATER_THAN; } - break; - case 239: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy320 = OP_TYPE_LOWER_EQUAL; } - break; - case 240: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy320 = OP_TYPE_GREATER_EQUAL; } - break; - case 241: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy320 = OP_TYPE_NOT_EQUAL; } - break; - case 242: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy320 = OP_TYPE_EQUAL; } - break; - case 243: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy320 = OP_TYPE_LIKE; } - break; - case 244: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy320 = OP_TYPE_NOT_LIKE; } - break; - case 245: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy320 = OP_TYPE_MATCH; } - break; - case 246: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy320 = OP_TYPE_NMATCH; } - break; - case 247: /* in_op ::= IN */ -{ yymsp[0].minor.yy320 = OP_TYPE_IN; } - break; - case 248: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy320 = OP_TYPE_NOT_IN; } - break; - case 249: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy136)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; - break; - case 251: /* boolean_value_expression ::= NOT boolean_primary */ + case 246: /* predicate ::= expression IS NOT NULL */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), NULL)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 252: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 248: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy404 = OP_TYPE_LOWER_THAN; } + break; + case 249: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy404 = OP_TYPE_GREATER_THAN; } + break; + case 250: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy404 = OP_TYPE_LOWER_EQUAL; } + break; + case 251: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy404 = OP_TYPE_GREATER_EQUAL; } + break; + case 252: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy404 = OP_TYPE_NOT_EQUAL; } + break; + case 253: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy404 = OP_TYPE_EQUAL; } + break; + case 254: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy404 = OP_TYPE_LIKE; } + break; + case 255: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy404 = OP_TYPE_NOT_LIKE; } + break; + case 256: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy404 = OP_TYPE_MATCH; } + break; + case 257: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy404 = OP_TYPE_NMATCH; } + break; + case 258: /* in_op ::= IN */ +{ yymsp[0].minor.yy404 = OP_TYPE_IN; } + break; + case 259: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy404 = OP_TYPE_NOT_IN; } + break; + case 260: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy512)); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; + break; + case 262: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), NULL)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 253: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 263: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 258: /* from_clause ::= FROM table_reference_list */ - case 288: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==288); - case 311: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==311); -{ yymsp[-1].minor.yy140 = yymsp[0].minor.yy140; } + case 264: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 260: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy140 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy140, yymsp[0].minor.yy140, NULL); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 269: /* from_clause ::= FROM table_reference_list */ + case 299: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==299); + case 322: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==322); +{ yymsp[-1].minor.yy176 = yymsp[0].minor.yy176; } break; - case 263: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 271: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy176 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy176, yymsp[0].minor.yy176, NULL); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 264: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-3].minor.yy149, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 274: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy176 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 265: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy140 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 275: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy176 = createRealTableNode(pCxt, &yymsp[-3].minor.yy225, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 267: /* alias_opt ::= */ -{ yymsp[1].minor.yy149 = nil_token; } + case 276: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy176 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176), &yymsp[0].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 268: /* alias_opt ::= table_alias */ -{ yylhsminor.yy149 = yymsp[0].minor.yy149; } - yymsp[0].minor.yy149 = yylhsminor.yy149; + case 278: /* alias_opt ::= */ +{ yymsp[1].minor.yy225 = nil_token; } break; - case 269: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy149 = yymsp[0].minor.yy149; } + case 279: /* alias_opt ::= table_alias */ +{ yylhsminor.yy225 = yymsp[0].minor.yy225; } + yymsp[0].minor.yy225 = yylhsminor.yy225; break; - case 270: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 271: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==271); -{ yymsp[-2].minor.yy140 = yymsp[-1].minor.yy140; } + case 280: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy225 = yymsp[0].minor.yy225; } break; - case 272: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy140 = createJoinTableNode(pCxt, yymsp[-4].minor.yy144, yymsp[-5].minor.yy140, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + case 281: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 282: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==282); +{ yymsp[-2].minor.yy176 = yymsp[-1].minor.yy176; } break; - case 273: /* join_type ::= */ -{ yymsp[1].minor.yy144 = JOIN_TYPE_INNER; } + case 283: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy176 = createJoinTableNode(pCxt, yymsp[-4].minor.yy236, yymsp[-5].minor.yy176, yymsp[-2].minor.yy176, yymsp[0].minor.yy176); } + yymsp[-5].minor.yy176 = yylhsminor.yy176; break; - case 274: /* join_type ::= INNER */ -{ yymsp[0].minor.yy144 = JOIN_TYPE_INNER; } + case 284: /* join_type ::= */ +{ yymsp[1].minor.yy236 = JOIN_TYPE_INNER; } break; - case 275: /* 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 285: /* join_type ::= INNER */ +{ yymsp[0].minor.yy236 = JOIN_TYPE_INNER; } + break; + case 286: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy140 = createSelectStmt(pCxt, yymsp[-7].minor.yy497, yymsp[-6].minor.yy136, yymsp[-5].minor.yy140); - yymsp[-8].minor.yy140 = addWhereClause(pCxt, yymsp[-8].minor.yy140, yymsp[-4].minor.yy140); - yymsp[-8].minor.yy140 = addPartitionByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-3].minor.yy136); - yymsp[-8].minor.yy140 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy140, yymsp[-2].minor.yy140); - yymsp[-8].minor.yy140 = addGroupByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-1].minor.yy136); - yymsp[-8].minor.yy140 = addHavingClause(pCxt, yymsp[-8].minor.yy140, yymsp[0].minor.yy140); + yymsp[-8].minor.yy176 = createSelectStmt(pCxt, yymsp[-7].minor.yy505, yymsp[-6].minor.yy512, yymsp[-5].minor.yy176); + yymsp[-8].minor.yy176 = addWhereClause(pCxt, yymsp[-8].minor.yy176, yymsp[-4].minor.yy176); + yymsp[-8].minor.yy176 = addPartitionByClause(pCxt, yymsp[-8].minor.yy176, yymsp[-3].minor.yy512); + yymsp[-8].minor.yy176 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy176, yymsp[-2].minor.yy176); + yymsp[-8].minor.yy176 = addGroupByClause(pCxt, yymsp[-8].minor.yy176, yymsp[-1].minor.yy512); + yymsp[-8].minor.yy176 = addHavingClause(pCxt, yymsp[-8].minor.yy176, yymsp[0].minor.yy176); } break; - case 277: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy497 = true; } + case 288: /* set_quantifier_opt ::= DISTINCT */ +{ yymsp[0].minor.yy505 = true; } break; - case 278: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy497 = false; } + case 289: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy505 = false; } break; - case 279: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy136 = NULL; } + case 290: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy512 = NULL; } break; - case 283: /* select_item ::= common_expression */ + case 294: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), &t); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 284: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 295: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176), &yymsp[0].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 285: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), &yymsp[0].minor.yy149); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 296: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), &yymsp[0].minor.yy225); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 286: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy140 = createColumnNode(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 297: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy176 = createColumnNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 290: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 307: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==307); - case 317: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==317); -{ yymsp[-2].minor.yy136 = yymsp[0].minor.yy136; } + case 301: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 318: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==318); + case 328: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==328); +{ yymsp[-2].minor.yy512 = yymsp[0].minor.yy512; } break; - case 292: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy140 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } + case 303: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy176 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } break; - case 293: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy140 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } + case 304: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy176 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } break; - case 294: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 305: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy176 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), NULL, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } break; - case 295: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 306: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy176 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy176), releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } break; - case 297: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy140 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy140); } + case 308: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy176 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy176); } break; - case 299: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy140 = createFillNode(pCxt, yymsp[-1].minor.yy306, NULL); } + case 310: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy176 = createFillNode(pCxt, yymsp[-1].minor.yy142, NULL); } break; - case 300: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy140 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy136)); } + case 311: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy176 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy512)); } break; - case 301: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy306 = FILL_MODE_NONE; } + case 312: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy142 = FILL_MODE_NONE; } break; - case 302: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy306 = FILL_MODE_PREV; } + case 313: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy142 = FILL_MODE_PREV; } break; - case 303: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy306 = FILL_MODE_NULL; } + case 314: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy142 = FILL_MODE_NULL; } break; - case 304: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy306 = FILL_MODE_LINEAR; } + case 315: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy142 = FILL_MODE_LINEAR; } break; - case 305: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy306 = FILL_MODE_NEXT; } + case 316: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy142 = FILL_MODE_NEXT; } break; - case 308: /* group_by_list ::= expression */ -{ yylhsminor.yy136 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 319: /* group_by_list ::= expression */ +{ yylhsminor.yy512 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; - case 309: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-2].minor.yy136, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy136 = yylhsminor.yy136; + case 320: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } + yymsp[-2].minor.yy512 = yylhsminor.yy512; break; - case 312: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 323: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy140 = addOrderByClause(pCxt, yymsp[-3].minor.yy140, yymsp[-2].minor.yy136); - yylhsminor.yy140 = addSlimitClause(pCxt, yylhsminor.yy140, yymsp[-1].minor.yy140); - yylhsminor.yy140 = addLimitClause(pCxt, yylhsminor.yy140, yymsp[0].minor.yy140); + yylhsminor.yy176 = addOrderByClause(pCxt, yymsp[-3].minor.yy176, yymsp[-2].minor.yy512); + yylhsminor.yy176 = addSlimitClause(pCxt, yylhsminor.yy176, yymsp[-1].minor.yy176); + yylhsminor.yy176 = addLimitClause(pCxt, yylhsminor.yy176, yymsp[0].minor.yy176); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 314: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy140 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 325: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy176 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy176, yymsp[0].minor.yy176); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 319: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 323: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==323); -{ yymsp[-1].minor.yy140 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 330: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 334: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==334); +{ yymsp[-1].minor.yy176 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 320: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 324: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==324); -{ yymsp[-3].minor.yy140 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 331: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 335: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==335); +{ yymsp[-3].minor.yy176 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 321: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 325: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==325); -{ yymsp[-3].minor.yy140 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 332: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 336: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==336); +{ yymsp[-3].minor.yy176 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 326: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy140); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 337: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy176); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 330: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy140 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[-1].minor.yy158, yymsp[0].minor.yy73); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 341: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy176 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), yymsp[-1].minor.yy106, yymsp[0].minor.yy465); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 331: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy158 = ORDER_ASC; } + case 342: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy106 = ORDER_ASC; } break; - case 332: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy158 = ORDER_ASC; } + case 343: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy106 = ORDER_ASC; } break; - case 333: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy158 = ORDER_DESC; } + case 344: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy106 = ORDER_DESC; } break; - case 334: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy73 = NULL_ORDER_DEFAULT; } + case 345: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy465 = NULL_ORDER_DEFAULT; } break; - case 335: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy73 = NULL_ORDER_FIRST; } + case 346: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy465 = NULL_ORDER_FIRST; } break; - case 336: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy73 = NULL_ORDER_LAST; } + case 347: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy465 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 1813ad0827..87f20e8d25 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"); @@ -416,6 +423,7 @@ TEST_F(ParserTest, createDatabase) { "VGROUPS 100 " "SINGLE_STABLE 0 " "STREAM_MODE 1 " + "RETENTIONS '15s:7d,1m:21d,15m:5y'" ); ASSERT_TRUE(run()); } @@ -469,7 +477,7 @@ TEST_F(ParserTest, createTable) { "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) " "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, " "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)" + "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2" ); ASSERT_TRUE(run()); @@ -479,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()); @@ -491,7 +502,7 @@ TEST_F(ParserTest, createTable) { "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) " "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, " "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)" + "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2" ); ASSERT_TRUE(run()); } diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 740fb678fd..bd4b6481f1 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) { @@ -161,7 +201,11 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect // 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 +215,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 +457,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 +594,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 +631,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); } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index c95845f8c7..db0201bc81 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); } @@ -600,7 +562,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 +673,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); diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 3d17cc260b..ea6498c0c8 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,6 +217,32 @@ 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"); 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..34159a1355 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); } @@ -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/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index b79221cf82..cf34fc24a9 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -43,10 +43,12 @@ typedef struct SScalarCtx { #define SCL_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) #define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out); +SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows); + +#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) +#define GET_PARAM_BYTES(_c) ((_c)->pColumnInfoData->info.bytes) -int32_t sclMoveParamListData(SScalarParam *params, int32_t listNum, int32_t idx); -bool sclIsNull(SScalarParam* param, int32_t idx); -void sclSetNull(SScalarParam* param, int32_t idx); void sclFreeParam(SScalarParam *param); #ifdef __cplusplus diff --git a/source/libs/scalar/inc/sclfunc.h b/source/libs/scalar/inc/sclfunc.h deleted file mode 100644 index 8915f37261..0000000000 --- a/source/libs/scalar/inc/sclfunc.h +++ /dev/null @@ -1,44 +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 TDENGINE_TSCALARFUNCTION_H -#define TDENGINE_TSCALARFUNCTION_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "function.h" -#include "scalar.h" - -typedef struct SScalarFunctionSupport { - struct SExprInfo *pExprInfo; - int32_t numOfCols; - SColumnInfo *colList; - void *exprList; // client side used - int32_t offset; - char** data; -} SScalarFunctionSupport; - -extern struct SScalarFunctionInfo scalarFunc[8]; - -int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarParam* pOutput, - void* param, char* (*getSourceDataBlock)(void*, const char*, int32_t)); - - -#ifdef __cplusplus -} -#endif - -#endif // TDENGINE_TSCALARFUNCTION_H diff --git a/source/libs/scalar/inc/sclvector.h b/source/libs/scalar/inc/sclvector.h index 09b813359a..3f41ad875c 100644 --- a/source/libs/scalar/inc/sclvector.h +++ b/source/libs/scalar/inc/sclvector.h @@ -20,10 +20,66 @@ extern "C" { #endif -#include "sclfunc.h" +typedef double (*_getDoubleValue_fn_t)(void *src, int32_t index); -typedef double (*_mathFunc)(double, double, bool *); +static FORCE_INLINE double getVectorDoubleValue_TINYINT(void *src, int32_t index) { + return (double)*((int8_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_UTINYINT(void *src, int32_t index) { + return (double)*((uint8_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_SMALLINT(void *src, int32_t index) { + return (double)*((int16_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_USMALLINT(void *src, int32_t index) { + return (double)*((uint16_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_INT(void *src, int32_t index) { + return (double)*((int32_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_UINT(void *src, int32_t index) { + return (double)*((uint32_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_BIGINT(void *src, int32_t index) { + return (double)*((int64_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_UBIGINT(void *src, int32_t index) { + return (double)*((uint64_t *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_FLOAT(void *src, int32_t index) { + return (double)*((float *)src + index); +} +static FORCE_INLINE double getVectorDoubleValue_DOUBLE(void *src, int32_t index) { + return (double)*((double *)src + index); +} +static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) { + _getDoubleValue_fn_t p = NULL; + if (srcType == TSDB_DATA_TYPE_TINYINT) { + p = getVectorDoubleValue_TINYINT; + } else if (srcType == TSDB_DATA_TYPE_UTINYINT) { + p = getVectorDoubleValue_UTINYINT; + } else if (srcType == TSDB_DATA_TYPE_SMALLINT) { + p = getVectorDoubleValue_SMALLINT; + } else if (srcType == TSDB_DATA_TYPE_USMALLINT) { + p = getVectorDoubleValue_USMALLINT; + } else if (srcType == TSDB_DATA_TYPE_INT) { + p = getVectorDoubleValue_INT; + } else if (srcType == TSDB_DATA_TYPE_UINT) { + p = getVectorDoubleValue_UINT; + } else if (srcType == TSDB_DATA_TYPE_BIGINT) { + p = getVectorDoubleValue_BIGINT; + } else if (srcType == TSDB_DATA_TYPE_UBIGINT) { + p = getVectorDoubleValue_UBIGINT; + } else if (srcType == TSDB_DATA_TYPE_FLOAT) { + p = getVectorDoubleValue_FLOAT; + } else if (srcType == TSDB_DATA_TYPE_DOUBLE) { + p = getVectorDoubleValue_DOUBLE; + } else { + assert(0); + } + return p; +} typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType); typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output, int32_t order); diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 23e3e352c8..b0632bbc34 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -318,7 +318,7 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt r->prev = NULL; r->next = NULL; } else { - r = taosMemoryCalloc(1, sizeof(SFilterRangeNode)); + r = taosMemoryCalloc(1, sizeof(SFilterRangeNode)); } FILTER_COPY_RA(&r->ra, ra); @@ -1021,26 +1021,21 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { if (node->opType == OP_TYPE_IN && (!IS_VAR_DATA_TYPE(type))) { SNodeListNode *listNode = (SNodeListNode *)node->pRight; SListCell *cell = listNode->pNodeList->pHead; - SScalarParam in = {.num = 1}, out = {.num = 1, .type = type}; + + SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; + out.columnData->info.type = type; for (int32_t i = 0; i < listNode->pNodeList->length; ++i) { SValueNode *valueNode = (SValueNode *)cell->pNode; - in.type = valueNode->node.resType.type; - in.bytes = valueNode->node.resType.bytes; - in.data = nodesGetValueFromNode(valueNode); - out.data = taosMemoryMalloc(sizeof(int64_t)); - - code = vectorConvertImpl(&in, &out); + code = doConvertDataType(valueNode, &out); if (code) { - fltError("convert from %d to %d failed", in.type, out.type); - taosMemoryFreeClear(out.data); +// fltError("convert from %d to %d failed", in.type, out.type); FLT_ERR_RET(code); } len = tDataTypes[type].bytes; - filterAddField(info, NULL, &out.data, FLD_TYPE_VALUE, &right, len, true); - + filterAddField(info, NULL, (void**) &out.columnData->pData, FLD_TYPE_VALUE, &right, len, true); filterAddUnit(info, OP_TYPE_EQUAL, &left, &right, &uidx); SFilterGroup fgroup = {0}; @@ -1054,7 +1049,6 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { filterAddFieldFromNode(info, node->pRight, &right); FLT_ERR_RET(filterAddUnit(info, node->opType, &left, &right, &uidx)); - SFilterGroup fgroup = {0}; filterAddUnitToGroup(&fgroup, uidx); @@ -1080,7 +1074,6 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, POINTER_BYTES, false); // POINTER_BYTES should be sizeof(SHashObj), but POINTER_BYTES is also right. t = FILTER_GET_FIELD(dst, right); - FILTER_SET_FLAG(t->flag, FLD_DATA_IS_HASH); } else { filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, varDataTLen(data), false); @@ -1101,14 +1094,12 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *right, uint32_t uidx) { SFilterUnit *u = &info->units[uidx]; - u->compare.optr2 = optr; u->right2 = *right; return TSDB_CODE_SUCCESS; } - int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint32_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right, right2; uint32_t uidx = 0; @@ -1800,9 +1791,12 @@ int32_t fltInitValFieldData(SFilterInfo *info) { if (dType->type == type) { assignVal(fi->data, nodesGetValueFromNode(var), dType->bytes, type); } else { - SScalarParam in = {.data = nodesGetValueFromNode(var), .num = 1, .type = dType->type, .bytes = dType->bytes}; - SScalarParam out = {.data = fi->data, .num = 1, .type = type}; - if (vectorConvertImpl(&in, &out)) { + SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; + out.columnData->info.type = type; + + // todo refactor the convert + int32_t code = doConvertDataType(var, &out); + if (code != TSDB_CODE_SUCCESS) { qError("convert value to type[%d] failed", type); return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -3636,7 +3630,7 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) if (*pInfo == NULL) { *pInfo = taosMemoryCalloc(1, sizeof(SFilterInfo)); if (NULL == *pInfo) { - fltError("calloc %d failed", (int32_t)sizeof(SFilterInfo)); + fltError("taosMemoryCalloc %d failed", (int32_t)sizeof(SFilterInfo)); FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } } @@ -3676,18 +3670,18 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); taosArrayDestroy(pList); - - *p = output.orig.data; - output.orig.data = NULL; - - sclFreeParam(&output); - - int8_t *r = output.data; - for (int32_t i = 0; i < output.num; ++i) { - if (0 == *(r+i)) { - return false; - } - } + // TODO Fix it +// *p = output.orig.data; +// output.orig.data = NULL; +// +// sclFreeParam(&output); +// +// int8_t *r = output.data; +// for (int32_t i = 0; i < output.num; ++i) { +// if (0 == *(r+i)) { +// return false; +// } +// } return true; } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 83902c9df8..7b2cb9ca67 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -6,6 +6,7 @@ #include "sclvector.h" #include "tcommon.h" #include "tdatablock.h" +#include "scalar.h" int32_t scalarGetOperatorParamNum(EOperatorType type) { if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || OP_TYPE_IS_NOT_TRUE == type @@ -16,6 +17,41 @@ int32_t scalarGetOperatorParamNum(EOperatorType type) { return 2; } +SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows) { + SColumnInfoData* pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); + if (pColumnData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pColumnData->info.type = pType->type; + pColumnData->info.bytes = pType->bytes; + pColumnData->info.scale = pType->scale; + pColumnData->info.precision = pType->precision; + + int32_t code = blockDataEnsureColumnCapacity(pColumnData, numOfRows); + if (code != TSDB_CODE_SUCCESS) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pColumnData); + return NULL; + } else { + return pColumnData; + } +} + +int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) { + SScalarParam in = {.numOfRows = 1}; + in.columnData = createColumnInfoData(&pValueNode->node.resType, 1); + colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); + + blockDataEnsureColumnCapacity(out->columnData, 1); + + int32_t code = vectorConvertImpl(&in, out); + sclFreeParam(&in); + + return code; +} + int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false); if (NULL == pObj) { @@ -28,10 +64,8 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { int32_t code = 0; SNodeListNode *nodeList = (SNodeListNode *)pNode; SListCell *cell = nodeList->pNodeList->pHead; - SScalarParam in = {.num = 1}, out = {.num = 1, .type = type}; - int8_t dummy = 0; - int32_t bufLen = 60; - out.data = taosMemoryMalloc(bufLen); + SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; + int32_t len = 0; void *buf = NULL; @@ -39,22 +73,21 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SValueNode *valueNode = (SValueNode *)cell->pNode; if (valueNode->node.resType.type != type) { - in.type = valueNode->node.resType.type; - in.bytes = valueNode->node.resType.bytes; - in.data = nodesGetValueFromNode(valueNode); - - code = vectorConvertImpl(&in, &out); - if (code) { - sclError("convert from %d to %d failed", in.type, out.type); + out.columnData->info.type = type; + out.columnData->info.bytes = tDataTypes[type].bytes; + + code = doConvertDataType(valueNode, &out); + if (code != TSDB_CODE_SUCCESS) { +// sclError("convert data from %d to %d failed", in.type, out.type); SCL_ERR_JRET(code); } if (IS_VAR_DATA_TYPE(type)) { - len = varDataLen(out.data); - buf = varDataVal(out.data); + len = varDataLen(out.columnData->pData); + buf = varDataVal(out.columnData->pData); } else { len = tDataTypes[type].bytes; - buf = out.data; + buf = out.columnData->pData; } } else { buf = nodesGetValueFromNode(valueNode); @@ -63,11 +96,10 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { buf = varDataVal(buf); } else { len = valueNode->node.resType.bytes; - buf = out.data; - } + } } - if (taosHashPut(pObj, buf, (size_t)len, &dummy, sizeof(dummy))) { + if (taosHashPut(pObj, buf, (size_t)len, NULL, 0)) { sclError("taosHashPut failed"); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -75,40 +107,14 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { cell = cell->pNext; } - taosMemoryFreeClear(out.data); *data = pObj; - return TSDB_CODE_SUCCESS; _return: - - taosMemoryFreeClear(out.data); taosHashCleanup(pObj); - SCL_RET(code); } -FORCE_INLINE bool sclIsNull(SScalarParam* param, int32_t idx) { - if (param->dataInBlock) { - return colDataIsNull(param->orig.columnData, 0, idx, NULL); - } - - return param->bitmap ? colDataIsNull_f(param->bitmap, idx) : false; -} - -FORCE_INLINE void sclSetNull(SScalarParam* param, int32_t idx) { - if (NULL == param->bitmap) { - param->bitmap = taosMemoryCalloc(BitmapLen(param->num), sizeof(char)); - if (NULL == param->bitmap) { - sclError("calloc %d failed", param->num); - return; - } - } - - colDataSetNull_f(param->bitmap, idx); -} - - void sclFreeRes(SHashObj *res) { SScalarParam *p = NULL; void *pIter = taosHashIterate(res, NULL); @@ -118,31 +124,22 @@ void sclFreeRes(SHashObj *res) { if (p) { sclFreeParam(p); } - pIter = taosHashIterate(res, pIter); } - taosHashCleanup(res); } -void sclFreeParamNoData(SScalarParam *param) { - taosMemoryFreeClear(param->bitmap); -} - - void sclFreeParam(SScalarParam *param) { - sclFreeParamNoData(param); - - if (!param->dataInBlock) { - if (SCL_DATA_TYPE_DUMMY_HASH == param->type) { - taosHashCleanup((SHashObj *)param->orig.data); - } else { - taosMemoryFreeClear(param->orig.data); - } + if (param->columnData != NULL) { + colDataDestroy(param->columnData); + taosMemoryFreeClear(param->columnData); + } + + if (param->pHashFilter != NULL) { + taosHashCleanup(param->pHashFilter); } } - int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) { if (TSDB_DATA_TYPE_NULL == pNode->node.resType.type) { return TSDB_CODE_SUCCESS; @@ -155,7 +152,6 @@ int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) { } memcpy(*res, nodesGetValueFromNode(pNode), pNode->node.resType.bytes); - return TSDB_CODE_SUCCESS; } @@ -163,35 +159,26 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t switch (nodeType(node)) { case QUERY_NODE_VALUE: { SValueNode *valueNode = (SValueNode *)node; - //SCL_ERR_RET(sclCopyValueNodeValue(valueNode, ¶m->data)); - param->data = nodesGetValueFromNode(valueNode); - param->orig.data = param->data; - param->num = 1; - param->type = valueNode->node.resType.type; - param->bytes = valueNode->node.resType.bytes; - if (TSDB_DATA_TYPE_NULL == param->type) { - sclSetNull(param, 0); + + param->numOfRows = 1; + param->columnData = createColumnInfoData(&valueNode->node.resType, 1); + if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type) { + colDataAppend(param->columnData, 0, NULL, true); + } else { + colDataAppend(param->columnData, 0, nodesGetValueFromNode(valueNode), false); } - param->dataInBlock = false; - break; } case QUERY_NODE_NODE_LIST: { SNodeListNode *nodeList = (SNodeListNode *)node; - if (nodeList->pNodeList->length <= 0) { - sclError("invalid length in nodeList, length:%d", nodeList->pNodeList->length); + if (LIST_LENGTH(nodeList->pNodeList) <= 0) { + sclError("invalid length in nodeList, length:%d", LIST_LENGTH(nodeList->pNodeList)); SCL_RET(TSDB_CODE_QRY_INVALID_INPUT); } - SCL_ERR_RET(scalarGenerateSetFromList(¶m->data, node, nodeList->dataType.type)); - param->orig.data = param->data; - param->num = 1; - param->type = SCL_DATA_TYPE_DUMMY_HASH; - param->dataInBlock = false; - + SCL_ERR_RET(scalarGenerateSetFromList((void**) ¶m->pHashFilter, node, nodeList->dataType.type)); if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) { - taosHashCleanup(param->orig.data); - param->orig.data = NULL; + taosHashCleanup(param->pHashFilter); sclError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param)); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -210,73 +197,38 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, ref->dataBlockId); - if (NULL == block || ref->slotId >= taosArrayGetSize(block->pDataBlock)) { sclError("column slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(block->pDataBlock, ref->slotId); - param->data = NULL; - param->orig.columnData = columnData; - param->dataInBlock = true; - - param->num = block->info.rows; - param->type = columnData->info.type; - param->bytes = columnData->info.bytes; - + param->numOfRows = block->info.rows; + param->columnData = columnData; break; } - case QUERY_NODE_LOGIC_CONDITION: - case QUERY_NODE_OPERATOR: { + case QUERY_NODE_FUNCTION: + case QUERY_NODE_OPERATOR: + case QUERY_NODE_LOGIC_CONDITION: { SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES); if (NULL == res) { sclError("no result for node, type:%d, node:%p", nodeType(node), node); SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - *param = *res; - break; } - default: break; } - if (param->num > *rowNum) { - if ((1 != param->num) && (1 < *rowNum)) { - sclError("different row nums, rowNum:%d, newRowNum:%d", *rowNum, param->num); + if (param->numOfRows > *rowNum) { + if ((1 != param->numOfRows) && (1 < *rowNum)) { + sclError("different row nums, rowNum:%d, newRowNum:%d", *rowNum, param->numOfRows); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - *rowNum = param->num; - } - - return TSDB_CODE_SUCCESS; -} - -int32_t sclMoveParamListData(SScalarParam *params, int32_t listNum, int32_t idx) { - SScalarParam *param = NULL; - - for (int32_t i = 0; i < listNum; ++i) { - param = params + i; - - if (1 == param->num) { - continue; - } - - if (param->dataInBlock) { - param->data = colDataGetData(param->orig.columnData, idx); - } else if (idx) { - if (IS_VAR_DATA_TYPE(param->type)) { - param->data = (char *)(param->data) + varDataTLen(param->data); - } else { - param->data = (char *)(param->data) + tDataTypes[param->type].bytes; - } - } else { - param->data = param->orig.data; - } + *rowNum = param->numOfRows; } return TSDB_CODE_SUCCESS; @@ -298,16 +250,13 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC } SCL_ERR_JRET(sclInitParam(cell->pNode, ¶mList[i], ctx, rowNum)); - cell = cell->pNext; } *pParams = paramList; - return TSDB_CODE_SUCCESS; _return: - taosMemoryFreeClear(paramList); SCL_RET(code); } @@ -332,16 +281,13 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal } *pParams = paramList; - return TSDB_CODE_SUCCESS; _return: - taosMemoryFreeClear(paramList); SCL_RET(code); } - int32_t sclExecFuncion(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); @@ -359,37 +305,30 @@ int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outpu int32_t rowNum = 0; SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, &rowNum)); - output->type = node->node.resType.type; - output->data = taosMemoryCalloc(rowNum, sizeof(tDataTypes[output->type].bytes)); - if (NULL == output->data) { - sclError("calloc %d failed", (int32_t)(rowNum * sizeof(tDataTypes[output->type].bytes))); + output->columnData = createColumnInfoData(&node->node.resType, rowNum); + if (output->columnData == NULL) { + sclError("calloc %d failed", (int32_t)(rowNum * output->columnData->info.bytes)); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - output->orig.data = output->data; - - for (int32_t i = 0; i < rowNum; ++i) { - sclMoveParamListData(output, 1, i); - sclMoveParamListData(params, node->pParameterList->length, i); +// for (int32_t i = 0; i < rowNum; ++i) { code = (*ffpSet.process)(params, node->pParameterList->length, output); if (code) { sclError("scalar function exec failed, funcId:%d, code:%s", node->funcId, tstrerror(code)); SCL_ERR_JRET(code); - } +// } } _return: for (int32_t i = 0; i < node->pParameterList->length; ++i) { - sclFreeParamNoData(params + i); +// sclFreeParamNoData(params + i); } taosMemoryFreeClear(params); - SCL_RET(code); } - int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *output) { if (NULL == node->pParameterList || node->pParameterList->length <= 0) { sclError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); @@ -409,28 +348,24 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o SScalarParam *params = NULL; int32_t rowNum = 0; int32_t code = 0; - SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, &rowNum)); - output->type = node->node.resType.type; - output->bytes = sizeof(bool); - output->num = rowNum; - output->data = taosMemoryCalloc(rowNum, sizeof(bool)); - if (NULL == output->data) { + int32_t type = node->node.resType.type; + output->numOfRows = rowNum; + + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + output->columnData = createColumnInfoData(&t, rowNum); + if (output->columnData == NULL) { sclError("calloc %d failed", (int32_t)(rowNum * sizeof(bool))); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - output->orig.data = output->data; bool value = false; - for (int32_t i = 0; i < rowNum; ++i) { - sclMoveParamListData(output, 1, i); - sclMoveParamListData(params, node->pParameterList->length, i); - for (int32_t m = 0; m < node->pParameterList->length; ++m) { - GET_TYPED_DATA(value, bool, params[m].type, params[m].data); - + char* p = colDataGetData(params[m].columnData, i); + GET_TYPED_DATA(value, bool, params[m].columnData->info.type, p); + if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) { break; } else if (LOGIC_COND_TYPE_OR == node->condType && value) { @@ -440,13 +375,12 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o } } - *(bool *)output->data = value; + colDataAppend(output->columnData, i, (char*) &value, false); } _return: - for (int32_t i = 0; i < node->pParameterList->length; ++i) { - sclFreeParamNoData(params + i); +// sclFreeParamNoData(params + i); } taosMemoryFreeClear(params); @@ -459,16 +393,11 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp int32_t code = 0; SCL_ERR_RET(sclInitOperatorParams(¶ms, node, ctx, &rowNum)); - - output->type = node->node.resType.type; - output->num = rowNum; - output->bytes = tDataTypes[output->type].bytes; - output->data = taosMemoryCalloc(rowNum, tDataTypes[output->type].bytes); - if (NULL == output->data) { - sclError("calloc %d failed", (int32_t)rowNum * tDataTypes[output->type].bytes); + output->columnData = createColumnInfoData(&node->node.resType, rowNum); + if (output->columnData == NULL) { + sclError("calloc failed, size:%d", (int32_t)rowNum * node->node.resType.bytes); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - output->orig.data = output->data; _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType); @@ -479,18 +408,14 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp OperatorFn(pLeft, pRight, output, TSDB_ORDER_ASC); _return: - - for (int32_t i = 0; i < paramNum; ++i) { - sclFreeParamNoData(params + i); +// sclFreeParam(¶ms[i]); } taosMemoryFreeClear(params); - SCL_RET(code); } - EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)*pNode; SScalarParam output = {0}; @@ -510,11 +435,12 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { res->node.resType = node->node.resType; - if (IS_VAR_DATA_TYPE(output.type)) { - res->datum.p = output.data; - output.data = NULL; + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.data, tDataTypes[output.type].bytes); + memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); } nodesDestroyNode(*pNode); @@ -527,8 +453,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)*pNode; - SScalarParam output = {0}; + SScalarParam output = {0}; ctx->code = sclExecLogic(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; @@ -544,25 +470,25 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { res->node.resType = node->node.resType; - if (IS_VAR_DATA_TYPE(output.type)) { - res->datum.p = output.data; - output.data = NULL; + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.data, tDataTypes[output.type].bytes); + memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); } nodesDestroyNode(*pNode); *pNode = (SNode*)res; sclFreeParam(&output); - return DEAL_RES_CONTINUE; } EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)*pNode; - SScalarParam output = {0}; + SScalarParam output = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; ctx->code = sclExecOperator(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; @@ -578,22 +504,21 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { res->node.resType = node->node.resType; - if (IS_VAR_DATA_TYPE(output.type)) { - res->datum.p = output.data; - output.data = NULL; + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { // todo refactor + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.data, tDataTypes[output.type].bytes); + memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); } nodesDestroyNode(*pNode); *pNode = (SNode*)res; - sclFreeParam(&output); - + sclFreeParam(&output); return DEAL_RES_CONTINUE; } - EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode)) { return DEAL_RES_CONTINUE; @@ -614,13 +539,10 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { } sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode)); - ctx->code = TSDB_CODE_QRY_INVALID_INPUT; - return DEAL_RES_ERROR; } - EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)pNode; SScalarParam output = {0}; @@ -638,7 +560,6 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } - EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)pNode; SScalarParam output = {0}; @@ -656,7 +577,6 @@ EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } - EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)pNode; SScalarParam output = {0}; @@ -699,27 +619,26 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_ERROR; } - for (int32_t i = 0; i < res->num; ++i) { - sclMoveParamListData(res, 1, i); - - colDataAppend(col, i, res->data, sclIsNull(res, i)); + for (int32_t i = 0; i < res->numOfRows; ++i) { + if (colDataIsNull(res->columnData, res->numOfRows, i, NULL)) { + colDataAppend(col, i, NULL, true); + } else { + char *p = colDataGetData(res->columnData, i); + colDataAppend(col, i, p, false); + } } sclFreeParam(res); - taosHashRemove(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); - return DEAL_RES_CONTINUE; } - EDealRes sclCalcWalker(SNode* pNode, void* pContext) { if (QUERY_NODE_VALUE == nodeType(pNode) || QUERY_NODE_NODE_LIST == nodeType(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)) { return DEAL_RES_CONTINUE; } SScalarCtx *ctx = (SScalarCtx *)pContext; - if (QUERY_NODE_FUNCTION == nodeType(pNode)) { return sclWalkFunction(pNode, ctx); } @@ -737,14 +656,10 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) { } sclError("invalid node type for scalar calculating, type:%d", nodeType(pNode)); - ctx->code = TSDB_CODE_QRY_INVALID_INPUT; - return DEAL_RES_ERROR; } - - int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { if (NULL == pNode) { SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); @@ -759,15 +674,11 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { } nodesRewriteNodePostOrder(&pNode, sclConstantsRewriter, (void *)&ctx); - SCL_ERR_JRET(ctx.code); - *pRes = pNode; _return: - sclFreeRes(ctx.pRes); - return code; } @@ -786,7 +697,6 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { } nodesWalkNodePostOrder(pNode, sclCalcWalker, (void *)&ctx); - SCL_ERR_JRET(ctx.code); if (pDst) { @@ -796,18 +706,14 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { SCL_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } - sclMoveParamListData(res, 1, 0); - - *pDst = *res; - + colDataAssign(pDst->columnData, res->columnData, res->numOfRows); + pDst->numOfRows = res->numOfRows; taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); } _return: - //nodesDestroyNode(pNode); sclFreeRes(ctx.pRes); - return code; } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index f2fdb29e4a..db0aa21f42 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1,555 +1,279 @@ -#include "sclfunc.h" +#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) { - assignBasicParaInfo(pOutput, pInput); - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { + SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pOutputData = pOutput->columnData; + + int32_t type = GET_PARAM_TYPE(pInput); + if (!IS_NUMERIC_TYPE(type)) { return TSDB_CODE_FAILED; } - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; + switch (type) { + case TSDB_DATA_TYPE_FLOAT: { + float *in = (float *)pInputData->pData; + float *out = (float *)pOutputData->pData; + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = (in[i] > 0)? in[i] : -in[i]; + } + break; } - switch (pInput->type) { - case TSDB_DATA_TYPE_FLOAT: { - float v; - GET_TYPED_DATA(v, float, pInput->type, input); - float result; - result = (v > 0) ? v : -v; - SET_TYPED_DATA(output, pOutput->type, result); - break; + case TSDB_DATA_TYPE_DOUBLE: { + double *in = (double *)pInputData->pData; + double *out = (double *)pOutputData->pData; + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = (in[i] > 0)? in[i] : -in[i]; } + break; + } - case TSDB_DATA_TYPE_DOUBLE: { - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result; - result = (v > 0) ? v : -v; - SET_TYPED_DATA(output, pOutput->type, result); - break; + case TSDB_DATA_TYPE_TINYINT: { + int8_t *in = (int8_t *)pInputData->pData; + int8_t *out = (int8_t *)pOutputData->pData; + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = (in[i] > 0)? in[i] : -in[i]; } + break; + } - case TSDB_DATA_TYPE_TINYINT: { - int8_t v; - GET_TYPED_DATA(v, int8_t, pInput->type, input); - int8_t result; - result = (v > 0) ? v : -v; - SET_TYPED_DATA(output, pOutput->type, result); - break; + case TSDB_DATA_TYPE_SMALLINT: { + int16_t *in = (int16_t *)pInputData->pData; + int16_t *out = (int16_t *)pOutputData->pData; + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = (in[i] > 0)? in[i] : -in[i]; } + break; + } - case TSDB_DATA_TYPE_SMALLINT: { - int16_t v; - GET_TYPED_DATA(v, int16_t, pInput->type, input); - int16_t result; - result = (v > 0) ? v : -v; - SET_TYPED_DATA(output, pOutput->type, result); - break; + case TSDB_DATA_TYPE_INT: { + int32_t *in = (int32_t *)pInputData->pData; + int32_t *out = (int32_t *)pOutputData->pData; + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = (in[i] > 0)? in[i] : -in[i]; } + break; + } - case TSDB_DATA_TYPE_INT: { - int32_t v; - GET_TYPED_DATA(v, int32_t, pInput->type, input); - int32_t result; - result = (v > 0) ? v : -v; - SET_TYPED_DATA(output, pOutput->type, result); - break; + case TSDB_DATA_TYPE_BIGINT: { + int64_t *in = (int64_t *)pInputData->pData; + int64_t *out = (int64_t *)pOutputData->pData; + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = (in[i] > 0)? in[i] : -in[i]; } + break; + } - case TSDB_DATA_TYPE_BIGINT: { - int64_t v; - GET_TYPED_DATA(v, int64_t, pInput->type, input); - int64_t result; - result = (v > 0) ? v : -v; - SET_TYPED_DATA(output, pOutput->type, result); - break; - } - - default: { - memcpy(output, input, pInput->bytes); - break; - } + default: { + colDataAssign(pOutputData, pInputData, pInput->numOfRows); } } + pOutput->numOfRows = pInput->numOfRows; return TSDB_CODE_SUCCESS; } -int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) { +typedef float (*_float_fn)(float); +typedef double (*_double_fn)(double); +typedef double (*_double_fn_2)(double, double); + +double tlog(double v, double base) { + return log(v) / log(base); +} + +int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn valFn) { + int32_t type = GET_PARAM_TYPE(pInput); + if (inputNum != 1 || !IS_NUMERIC_TYPE(type)) { return TSDB_CODE_FAILED; } - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; + SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pOutputData = pOutput->columnData; - 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; + _getDoubleValue_fn_t getValueFn = getVectorDoubleValueFn(type); + + double *out = (double *)pOutputData->pData; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = valFn(getValueFn(pInputData->pData, i)); + } + + pOutput->numOfRows = pInput->numOfRows; + 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)) { + return TSDB_CODE_FAILED; + } + + SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pOutputData = pOutput->columnData; + + switch (type) { + case TSDB_DATA_TYPE_FLOAT: { + float *in = (float *)pInputData->pData; + float *out = (float *)pOutputData->pData; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = f1(in[i]); } - if (isNull(input[j], pInput[j].type)) { - hasNullInput = true; - break; + break; + } + + case TSDB_DATA_TYPE_DOUBLE: { + double *in = (double *)pInputData->pData; + double *out = (double *)pOutputData->pData; + + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + if (colDataIsNull_f(pInputData->nullbitmap, i)) { + colDataSetNull_f(pOutputData->nullbitmap, i); + continue; + } + out[i] = d1(in[i]); } - } - output = pOutput->data + i * pOutput->bytes; - - if (hasNullInput) { - setNull(output, pOutput->type, pOutput->bytes); - continue; + break; } - 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); - - return TSDB_CODE_SUCCESS; -} - -int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - 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); - - return TSDB_CODE_SUCCESS; -} - -int32_t sqrtFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = sqrt(v); - SET_TYPED_DATA(output, pOutput->type, result); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t sinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = sin(v); - SET_TYPED_DATA(output, pOutput->type, result); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = cos(v); - SET_TYPED_DATA(output, pOutput->type, result); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = tan(v); - SET_TYPED_DATA(output, pOutput->type, result); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t asinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = asin(v); - SET_TYPED_DATA(output, pOutput->type, result); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = acos(v); - SET_TYPED_DATA(output, pOutput->type, result); + default: { + colDataAssign(pOutputData, pInputData, pInput->numOfRows); + } } + pOutput->numOfRows = pInput->numOfRows; return TSDB_CODE_SUCCESS; } int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } + return doScalarFunctionUnique(pInput, inputNum, pOutput, atan); +} - pOutput->type = TSDB_DATA_TYPE_DOUBLE; - pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; +int32_t sinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doScalarFunctionUnique(pInput, inputNum, pOutput, sin); +} - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; +int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doScalarFunctionUnique(pInput, inputNum, pOutput, cos); +} - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } +int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doScalarFunctionUnique(pInput, inputNum, pOutput, tan); +} - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = atan(v); - SET_TYPED_DATA(output, pOutput->type, result); - } +int32_t asinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + return doScalarFunctionUnique(pInput, inputNum, pOutput, asin); +} - return TSDB_CODE_SUCCESS; +int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + 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); } int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - switch (pInput->type) { - case TSDB_DATA_TYPE_FLOAT: { - float v; - GET_TYPED_DATA(v, float, pInput->type, input); - float result = ceilf(v); - SET_TYPED_DATA(output, pOutput->type, result); - break; - } - - case TSDB_DATA_TYPE_DOUBLE: { - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = ceil(v); - SET_TYPED_DATA(output, pOutput->type, result); - break; - } - - default: { - memcpy(output, input, pInput->bytes); - break; - } - } - } - - return TSDB_CODE_SUCCESS; + return doScalarFunction(pInput, inputNum, pOutput, ceilf, ceil); } int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - assignBasicParaInfo(pOutput, pInput); - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - switch (pInput->type) { - case TSDB_DATA_TYPE_FLOAT: { - float v; - GET_TYPED_DATA(v, float, pInput->type, input); - float result = floorf(v); - SET_TYPED_DATA(output, pOutput->type, result); - break; - } - - case TSDB_DATA_TYPE_DOUBLE: { - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = floor(v); - SET_TYPED_DATA(output, pOutput->type, result); - break; - } - - default: { - memcpy(output, input, pInput->bytes); - break; - } - } - } - - return TSDB_CODE_SUCCESS; + return doScalarFunction(pInput, inputNum, pOutput, floorf, floor); } int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - assignBasicParaInfo(pOutput, pInput); - if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { - return TSDB_CODE_FAILED; - } - - char *input = NULL, *output = NULL; - for (int32_t i = 0; i < pOutput->num; ++i) { - if (pInput->num == 1) { - input = pInput->data; - } else { - input = pInput->data + i * pInput->bytes; - } - output = pOutput->data + i * pOutput->bytes; - - if (isNull(input, pInput->type)) { - setNull(output, pOutput->type, pOutput->bytes); - continue; - } - - switch (pInput->type) { - case TSDB_DATA_TYPE_FLOAT: { - float v; - GET_TYPED_DATA(v, float, pInput->type, input); - float result = roundf(v); - SET_TYPED_DATA(output, pOutput->type, result); - break; - } - - case TSDB_DATA_TYPE_DOUBLE: { - double v; - GET_TYPED_DATA(v, double, pInput->type, input); - double result = round(v); - SET_TYPED_DATA(output, pOutput->type, result); - break; - } - - default: { - memcpy(output, input, pInput->bytes); - break; - } - } - } - - return TSDB_CODE_SUCCESS; + return doScalarFunction(pInput, inputNum, pOutput, roundf, round); } static void tlength(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assert(numOfInput == 1); - +#if 0 int64_t* out = (int64_t*) pOutput->data; char* s = pLeft->data; for(int32_t i = 0; i < pLeft->num; ++i) { out[i] = varDataLen(POINTER_SHIFT(s, i * pLeft->bytes)); } +#endif } static void tconcat(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assert(numOfInput > 0); - +#if 0 int32_t rowLen = 0; int32_t num = 1; for(int32_t i = 0; i < numOfInput; ++i) { @@ -577,6 +301,7 @@ static void tconcat(SScalarParam* pOutput, size_t numOfInput, const SScalarParam rstart += rowLen; } +#endif } static void tltrim(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { @@ -652,154 +377,3 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf } } -static void setScalarFuncParam(SScalarParam* param, int32_t type, int32_t bytes, void* pInput, int32_t numOfRows) { - param->bytes = bytes; - param->type = type; - param->num = numOfRows; - param->data = pInput; -} - - -#if 0 -int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param, - char* (*getSourceDataBlock)(void*, const char*, int32_t)) { - if (pExprs == NULL) { - return 0; - } - - tExprNode* pLeft = pExprs->_node.pLeft; - tExprNode* pRight = pExprs->_node.pRight; - - /* the left output has result from the left child syntax tree */ - SScalarFuncParam leftOutput = {0}; - SScalarFuncParam rightOutput = {0}; - - if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) { - leftOutput.data = taosMemoryMalloc(sizeof(int64_t) * numOfRows); - evaluateExprNodeTree(pLeft, numOfRows, &leftOutput, param, getSourceDataBlock); - } - - // the right output has result from the right child syntax tree - if (pRight->nodeType == TEXPR_BINARYEXPR_NODE || pRight->nodeType == TEXPR_UNARYEXPR_NODE) { - rightOutput.data = taosMemoryMalloc(sizeof(int64_t) * numOfRows); - evaluateExprNodeTree(pRight, numOfRows, &rightOutput, param, getSourceDataBlock); - } - - if (pExprs->nodeType == TEXPR_BINARYEXPR_NODE) { - _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(pExprs->_node.optr); - - SScalarFuncParam left = {0}, right = {0}; - if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) { - setScalarFuncParam(&left, leftOutput.type, leftOutput.bytes, leftOutput.data, leftOutput.num); - } else if (pLeft->nodeType == TEXPR_COL_NODE) { - SSchema* pschema = pLeft->pSchema; - char* pLeftInputData = getSourceDataBlock(param, pschema->name, pschema->colId); - setScalarFuncParam(&right, pschema->type, pschema->bytes, pLeftInputData, numOfRows); - } else if (pLeft->nodeType == TEXPR_VALUE_NODE) { - SVariant* pVar = pRight->pVal; - setScalarFuncParam(&left, pVar->nType, pVar->nLen, &pVar->i, 1); - } - - if (pRight->nodeType == TEXPR_BINARYEXPR_NODE || pRight->nodeType == TEXPR_UNARYEXPR_NODE) { - setScalarFuncParam(&right, rightOutput.type, rightOutput.bytes, rightOutput.data, rightOutput.num); - } else if (pRight->nodeType == TEXPR_COL_NODE) { // exprLeft + columnRight - SSchema* pschema = pRight->pSchema; - char* pInputData = getSourceDataBlock(param, pschema->name, pschema->colId); - setScalarFuncParam(&right, pschema->type, pschema->bytes, pInputData, numOfRows); - } else if (pRight->nodeType == TEXPR_VALUE_NODE) { // exprLeft + 12 - SVariant* pVar = pRight->pVal; - setScalarFuncParam(&right, pVar->nType, pVar->nLen, &pVar->i, 1); - } - - void* outputBuf = pOutput->data; - if (isStringOp(pExprs->_node.optr)) { - outputBuf = taosMemoryRealloc(pOutput->data, (left.bytes + right.bytes) * left.num); - } - - OperatorFn(&left, &right, outputBuf, TSDB_ORDER_ASC); - // Set the result info - setScalarFuncParam(pOutput, TSDB_DATA_TYPE_DOUBLE, sizeof(double), outputBuf, numOfRows); - } else if (pExprs->nodeType == TEXPR_UNARYEXPR_NODE) { - _unary_scalar_fn_t OperatorFn = getUnaryScalarOperatorFn(pExprs->_node.optr); - SScalarFuncParam left = {0}; - - if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) { - setScalarFuncParam(&left, leftOutput.type, leftOutput.bytes, leftOutput.data, leftOutput.num); - } else if (pLeft->nodeType == TEXPR_COL_NODE) { - SSchema* pschema = pLeft->pSchema; - char* pLeftInputData = getSourceDataBlock(param, pschema->name, pschema->colId); - setScalarFuncParam(&left, pschema->type, pschema->bytes, pLeftInputData, numOfRows); - } else if (pLeft->nodeType == TEXPR_VALUE_NODE) { - SVariant* pVar = pLeft->pVal; - setScalarFuncParam(&left, pVar->nType, pVar->nLen, &pVar->i, 1); - } - - // reserve enough memory buffer - if (isBinaryStringOp(pExprs->_node.optr)) { - void* outputBuf = taosMemoryRealloc(pOutput->data, left.bytes * left.num); - assert(outputBuf != NULL); - pOutput->data = outputBuf; - } - - OperatorFn(&left, pOutput); - } - - taosMemoryFreeClear(leftOutput.data); - taosMemoryFreeClear(rightOutput.data); - - return 0; -} -#endif - - -//SScalarFunctionInfo scalarFunc[8] = { -// {"ceil", FUNCTION_TYPE_SCALAR, FUNCTION_CEIL, tceil}, -// {"floor", FUNCTION_TYPE_SCALAR, FUNCTION_FLOOR, tfloor}, -// {"abs", FUNCTION_TYPE_SCALAR, FUNCTION_ABS, _tabs}, -// {"round", FUNCTION_TYPE_SCALAR, FUNCTION_ROUND, tround}, -// {"length", FUNCTION_TYPE_SCALAR, FUNCTION_LENGTH, tlength}, -// {"concat", FUNCTION_TYPE_SCALAR, FUNCTION_CONCAT, tconcat}, -// {"ltrim", FUNCTION_TYPE_SCALAR, FUNCTION_LTRIM, tltrim}, -// {"rtrim", FUNCTION_TYPE_SCALAR, FUNCTION_RTRIM, trtrim}, -//}; - -void setScalarFunctionSupp(struct SScalarFunctionSupport* sas, SExprInfo *pExprInfo, SSDataBlock* pSDataBlock) { - sas->numOfCols = (int32_t) pSDataBlock->info.numOfCols; - sas->pExprInfo = pExprInfo; - if (sas->colList != NULL) { - return; - } - - sas->colList = taosMemoryCalloc(1, pSDataBlock->info.numOfCols*sizeof(SColumnInfo)); - for(int32_t i = 0; i < sas->numOfCols; ++i) { - SColumnInfoData* pColData = taosArrayGet(pSDataBlock->pDataBlock, i); - sas->colList[i] = pColData->info; - } - - sas->data = taosMemoryCalloc(sas->numOfCols, POINTER_BYTES); - - // set the input column data - for (int32_t f = 0; f < pSDataBlock->info.numOfCols; ++f) { - SColumnInfoData *pColumnInfoData = taosArrayGet(pSDataBlock->pDataBlock, f); - sas->data[f] = pColumnInfoData->pData; - } -} - -SScalarFunctionSupport* createScalarFuncSupport(int32_t num) { - SScalarFunctionSupport* pSupp = taosMemoryCalloc(num, sizeof(SScalarFunctionSupport)); - return pSupp; -} - -void destroyScalarFuncSupport(struct SScalarFunctionSupport* pSupport, int32_t num) { - if (pSupport == NULL) { - return; - } - - for(int32_t i = 0; i < num; ++i) { - SScalarFunctionSupport* pSupp = &pSupport[i]; - taosMemoryFreeClear(pSupp->data); - taosMemoryFreeClear(pSupp->colList); - } - - taosMemoryFreeClear(pSupport); -} diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 2300f5a1d3..f22f9a5c3c 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -25,108 +25,6 @@ #include "tdatablock.h" #include "ttypes.h" -//GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i])); - -void calc_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRight, void *output, int32_t order) { - int32_t *pLeft = (int32_t *)left; - int32_t *pRight = (int32_t *)right; - double * pOutput = (double *)output; - - int32_t i = (order == TSDB_ORDER_ASC) ? 0 : TMAX(numLeft, numRight) - 1; - int32_t step = (order == TSDB_ORDER_ASC) ? 1 : -1; - - if (numLeft == numRight) { - for (; i >= 0 && i < numRight; i += step, pOutput += 1) { - if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) { - SET_DOUBLE_NULL(pOutput); - continue; - } - - *pOutput = (double)pLeft[i] + pRight[i]; - } - } else if (numLeft == 1) { - for (; i >= 0 && i < numRight; i += step, pOutput += 1) { - if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) { - SET_DOUBLE_NULL(pOutput); - continue; - } - - *pOutput = (double)pLeft[0] + pRight[i]; - } - } else if (numRight == 1) { - for (; i >= 0 && i < numLeft; i += step, pOutput += 1) { - if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) { - SET_DOUBLE_NULL(pOutput); - continue; - } - *pOutput = (double)pLeft[i] + pRight[0]; - } - } -} - -typedef double (*_getDoubleValue_fn_t)(void *src, int32_t index); - -double getVectorDoubleValue_TINYINT(void *src, int32_t index) { - return (double)*((int8_t *)src + index); -} -double getVectorDoubleValue_UTINYINT(void *src, int32_t index) { - return (double)*((uint8_t *)src + index); -} -double getVectorDoubleValue_SMALLINT(void *src, int32_t index) { - return (double)*((int16_t *)src + index); -} -double getVectorDoubleValue_USMALLINT(void *src, int32_t index) { - return (double)*((uint16_t *)src + index); -} -double getVectorDoubleValue_INT(void *src, int32_t index) { - return (double)*((int32_t *)src + index); -} -double getVectorDoubleValue_UINT(void *src, int32_t index) { - return (double)*((uint32_t *)src + index); -} -double getVectorDoubleValue_BIGINT(void *src, int32_t index) { - return (double)*((int64_t *)src + index); -} -double getVectorDoubleValue_UBIGINT(void *src, int32_t index) { - return (double)*((uint64_t *)src + index); -} -double getVectorDoubleValue_FLOAT(void *src, int32_t index) { - return (double)*((float *)src + index); -} -double getVectorDoubleValue_DOUBLE(void *src, int32_t index) { - return (double)*((double *)src + index); -} - -_getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) { - _getDoubleValue_fn_t p = NULL; - if(srcType==TSDB_DATA_TYPE_TINYINT) { - p = getVectorDoubleValue_TINYINT; - }else if(srcType==TSDB_DATA_TYPE_UTINYINT) { - p = getVectorDoubleValue_UTINYINT; - }else if(srcType==TSDB_DATA_TYPE_SMALLINT) { - p = getVectorDoubleValue_SMALLINT; - }else if(srcType==TSDB_DATA_TYPE_USMALLINT) { - p = getVectorDoubleValue_USMALLINT; - }else if(srcType==TSDB_DATA_TYPE_INT) { - p = getVectorDoubleValue_INT; - }else if(srcType==TSDB_DATA_TYPE_UINT) { - p = getVectorDoubleValue_UINT; - }else if(srcType==TSDB_DATA_TYPE_BIGINT) { - p = getVectorDoubleValue_BIGINT; - }else if(srcType==TSDB_DATA_TYPE_UBIGINT) { - p = getVectorDoubleValue_UBIGINT; - }else if(srcType==TSDB_DATA_TYPE_FLOAT) { - p = getVectorDoubleValue_FLOAT; - }else if(srcType==TSDB_DATA_TYPE_DOUBLE) { - p = getVectorDoubleValue_DOUBLE; - }else { - assert(0); - } - return p; -} - - - typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index); int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { @@ -187,9 +85,6 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { return p; } - - - typedef void* (*_getValueAddr_fn_t)(void *src, int32_t index); void* getVectorValueAddr_TINYINT(void *src, int32_t index) { @@ -261,28 +156,35 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { return p; } -static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t outType) { +static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { int64_t value = strtoll(buf, NULL, 10); - SET_TYPED_DATA(pOut->data, outType, value); + colDataAppend(pOut->columnData, rowIndex, (char*) &value, false); } -static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t outType) { +static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { uint64_t value = strtoull(buf, NULL, 10); - SET_TYPED_DATA(pOut->data, outType, value); + colDataAppend(pOut->columnData, rowIndex, (char*) &value, false); } -static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t outType) { +static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex) { double value = strtod(buf, NULL); - SET_TYPED_DATA(pOut->data, outType, value); + colDataAppend(pOut->columnData, rowIndex, (char*) &value, false); } +static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex) { + int64_t value = strtoll(buf, NULL, 10); + bool v = (value != 0)? true:false; + colDataAppend(pOut->columnData, rowIndex, (char*) &v, false); +} + +int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { + int32_t bufSize = pIn->columnData->info.bytes; + char *tmp = taosMemoryMalloc(bufSize); -int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { - int32_t bufSize = 0; - char *tmp = NULL; _bufConverteFunc func = NULL; - - if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType || TSDB_DATA_TYPE_BOOL == outType) { + if (TSDB_DATA_TYPE_BOOL == outType) { + func = varToBool; + } else if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType) { func = varToSigned; } else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) { func = varToUnsigned; @@ -292,31 +194,22 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t sclError("invalid convert outType:%d", outType); return TSDB_CODE_QRY_APP_ERROR; } - - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + + pOut->numOfRows = pIn->numOfRows; + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) { + colDataAppend(pOut->columnData, i, NULL, true); continue; } + char* data = colDataGetData(pIn->columnData, i); if (TSDB_DATA_TYPE_BINARY == inType) { - if (varDataLen(pIn->data) >= bufSize) { - bufSize = varDataLen(pIn->data) + 1; - tmp = taosMemoryRealloc(tmp, bufSize); - } - - memcpy(tmp, varDataVal(pIn->data), varDataLen(pIn->data)); - tmp[varDataLen(pIn->data)] = 0; + memcpy(tmp, varDataVal(data), varDataLen(data)); + tmp[varDataLen(data)] = 0; } else { - if (varDataLen(pIn->data) * TSDB_NCHAR_SIZE >= bufSize) { - bufSize = varDataLen(pIn->data) * TSDB_NCHAR_SIZE + 1; - tmp = taosMemoryRealloc(tmp, bufSize); - } + ASSERT (varDataLen(data) <= bufSize); - int len = taosUcs4ToMbs((TdUcs4*)varDataVal(pIn->data), varDataLen(pIn->data), tmp); + int len = taosUcs4ToMbs((TdUcs4*)varDataVal(data), varDataLen(data), tmp); if (len < 0){ sclError("castConvert taosUcs4ToMbs error 1"); taosMemoryFreeClear(tmp); @@ -326,80 +219,82 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t tmp[len] = 0; } - (*func)(tmp, pOut, outType); + (*func)(tmp, pOut, i); } taosMemoryFreeClear(tmp); - return TSDB_CODE_SUCCESS; } -int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) { - int16_t inType = pIn->type; - int16_t inBytes = pIn->bytes; - int16_t outType = pOut->type; - int16_t outBytes = pOut->bytes; +// TODO opt performance +int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { + SColumnInfoData* pInputCol = pIn->columnData; + SColumnInfoData* pOutputCol = pOut->columnData; - if (inType == TSDB_DATA_TYPE_BINARY || inType == TSDB_DATA_TYPE_NCHAR) { + int16_t inType = pInputCol->info.type; + int16_t outType = pOutputCol->info.type; + + if (IS_VAR_DATA_TYPE(inType)) { return vectorConvertFromVarData(pIn, pOut, inType, outType); } switch (outType) { - case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_BOOL: { + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + bool value = 0; + GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); + colDataAppend(pOutputCol, i, (char*) &value, false); + } + break; + } case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TIMESTAMP: - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + case TSDB_DATA_TYPE_TIMESTAMP: { + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } int64_t value = 0; - - GET_TYPED_DATA(value, int64_t, inType, pIn->data); - SET_TYPED_DATA(pOut->data, outType, value); + GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); + colDataAppend(pOutputCol, i, (char *)&value, false); } break; - case TSDB_DATA_TYPE_UTINYINT: + } + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } uint64_t value = 0; - - GET_TYPED_DATA(value, uint64_t, inType, pIn->data); - SET_TYPED_DATA(pOut->data, outType, value); + GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i)); + colDataAppend(pOutputCol, i, (char*) &value, false); } break; case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } double value = 0; - - GET_TYPED_DATA(value, double, inType, pIn->data); - SET_TYPED_DATA(pOut->data, outType, value); + GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i)); + colDataAppend(pOutputCol, i, (char*) &value, false); } break; default: @@ -446,11 +341,13 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) { } int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) { - if (pLeft->type == pRight->type) { + if (pLeft->pHashFilter != NULL || pRight->pHashFilter != NULL) { return TSDB_CODE_SUCCESS; } - if (SCL_DATA_TYPE_DUMMY_HASH == pLeft->type || SCL_DATA_TYPE_DUMMY_HASH == pRight->type) { + int32_t leftType = GET_PARAM_TYPE(pLeft); + int32_t rightType = GET_PARAM_TYPE(pRight); + if (leftType == rightType) { return TSDB_CODE_SUCCESS; } @@ -458,7 +355,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p SScalarParam *param2 = NULL, *paramOut2 = NULL; int32_t code = 0; - if (pLeft->type < pRight->type) { + if (leftType < rightType) { param1 = pLeft; param2 = pRight; paramOut1 = pLeftOut; @@ -470,44 +367,38 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p paramOut2 = pLeftOut; } - - int8_t type = vectorGetConvertType(param1->type, param2->type); + int8_t type = vectorGetConvertType(GET_PARAM_TYPE(param1), GET_PARAM_TYPE(param2)); if (0 == type) { return TSDB_CODE_SUCCESS; } - if (type != param1->type) { - paramOut1->bytes = param1->bytes; - paramOut1->type = type; - paramOut1->num = param1->num; - paramOut1->data = taosMemoryMalloc(paramOut1->num * tDataTypes[paramOut1->type].bytes); - if (NULL == paramOut1->data) { - return TSDB_CODE_QRY_OUT_OF_MEMORY; + if (type != GET_PARAM_TYPE(param1)) { + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + paramOut1->numOfRows = param1->numOfRows; + + paramOut1->columnData = createColumnInfoData(&t, param1->numOfRows); + if (paramOut1->columnData == NULL) { + return terrno; } - paramOut1->orig.data = paramOut1->data; - + code = vectorConvertImpl(param1, paramOut1); if (code) { - taosMemoryFreeClear(paramOut1->data); +// taosMemoryFreeClear(paramOut1->data); return code; } } - if (type != param2->type) { - paramOut2->bytes = param2->bytes; - paramOut2->type = type; - paramOut2->num = param2->num; - paramOut2->data = taosMemoryMalloc(paramOut2->num * tDataTypes[paramOut2->type].bytes); - if (NULL == paramOut2->data) { - taosMemoryFreeClear(paramOut1->data); - return TSDB_CODE_QRY_OUT_OF_MEMORY; + if (type != GET_PARAM_TYPE(param2)) { + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + paramOut2->numOfRows = param2->numOfRows; + + paramOut2->columnData = createColumnInfoData(&t, param2->numOfRows); + if (paramOut2->columnData == NULL) { + return terrno; } - paramOut2->orig.data = paramOut2->data; - + code = vectorConvertImpl(param2, paramOut2); if (code) { - taosMemoryFreeClear(paramOut1->data); - taosMemoryFreeClear(paramOut2->data); return code; } } @@ -515,652 +406,387 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p return TSDB_CODE_SUCCESS; } -void vectorMath(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, _mathFunc func) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - double leftv = 0, rightv = 0; - bool isNull = false; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; +enum { + VECTOR_DO_CONVERT = 0x1, + VECTOR_UN_CONVERT = 0x2, +}; - if (vectorConvertImpl(pLeft, &leftParam)) { - return; +static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SScalarParam* pParam, int32_t type) { + SColumnInfoData* pCol = pParam->columnData; + + if (IS_VAR_DATA_TYPE(pCol->info.type)) { + pDest->numOfRows = pParam->numOfRows; + + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + pDest->columnData = createColumnInfoData(&t, pParam->numOfRows); + if (pDest->columnData == NULL) { + sclError("malloc %d failed", (int32_t)(pParam->numOfRows * sizeof(double))); + return TSDB_CODE_OUT_OF_MEMORY; } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; + + int32_t code = vectorConvertImpl(pParam, pDest); + if (code != TSDB_CODE_SUCCESS) { + return code; } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; + + *convert = VECTOR_DO_CONVERT; + } else { + *convert = VECTOR_UN_CONVERT; } - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); - if (isNull) { - sclSetNull(pOut, i); - isNull = false; - } - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); - if (isNull) { - sclSetNull(pOut, i); - isNull = false; - } - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); - if (isNull) { - sclSetNull(pOut, i); - isNull = false; - } - } - } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); + return TSDB_CODE_SUCCESS; } -double mathAdd(double leftv, double rightv, bool *isNull) { - return leftv + rightv; -} +// TODO not correct for descending order scan +static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); -double mathSub(double leftv, double rightv, bool *isNull) { - return leftv - rightv; -} + double *output = (double *)pOutputCol->pData; -double mathMultiply(double leftv, double rightv, bool *isNull) { - return leftv * rightv; -} - -double mathDivide(double leftv, double rightv, bool *isNull) { - double zero = 0; - if (0 == compareDoubleVal(&rightv, &zero)) { - *isNull = true; - return zero; + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } } - - return leftv / rightv; } -double mathRemainder(double leftv, double rightv, bool *isNull) { - double zero = 0; - if (0 == compareDoubleVal(&rightv, &zero)) { - *isNull = true; - return zero; +static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert) { + SScalarParam convertParam = {0}; + + int32_t code = doConvertHelper(&convertParam, doConvert, pInput, TSDB_DATA_TYPE_DOUBLE); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return NULL; } - return leftv - ((int64_t)(leftv / rightv)) * rightv; -} - - -void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorMath(pLeft, pRight, pOut, _ord, mathAdd); -} - -void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorMath(pLeft, pRight, pOut, _ord, mathSub); -} - -void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorMath(pLeft, pRight, pOut, _ord, mathMultiply); -} - -void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorMath(pLeft, pRight, pOut, _ord, mathDivide); -} - -void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorMath(pLeft, pRight, pOut, _ord, mathRemainder); -} - -#if 0 -void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - double leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; - - if (vectorConvertImpl(pLeft, &leftParam)) { - return; - } - pLeft = &leftParam; + if (*doConvert == VECTOR_DO_CONVERT) { + return convertParam.columnData; + } else { + return pInput->columnData; } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; +} + +static void doReleaseVec(SColumnInfoData* pCol, int32_t type) { + if (type == VECTOR_DO_CONVERT) { + colDataDestroy(pCol); + taosMemoryFree(pCol); + } +} + +void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + int32_t leftConvert = 0, rightConvert = 0; + SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, i); } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } } - pRight = &rightParam; + + } else if (pLeft->numOfRows == 1) { + vectorMathAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); } - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); + doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pRightCol, rightConvert); +} + +// TODO not correct for descending order scan +static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + *output = (getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, 0)) * factor; + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} + +void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pOutputCol = pOut->columnData; + + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + int32_t leftConvert = 0, rightConvert = 0; + SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + vectorMathSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i); + } else if (pRight->numOfRows == 1) { + vectorMathSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i); + } + + doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pRightCol, rightConvert); +} + +// TODO not correct for descending order scan +static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} + +void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pOutputCol = pOut->columnData; + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + int32_t leftConvert = 0, rightConvert = 0; + SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + vectorMathMultiplyHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorMathMultiplyHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); + } + + doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pRightCol, rightConvert); +} + +void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pOutputCol = pOut->columnData; + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + int32_t leftConvert = 0, rightConvert = 0; + SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { // check for the 0 value + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, 0) / getVectorDoubleValueFnRight(pRightCol->pData, i); + } + pOutputCol->hasNull = pRightCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pRightCol->nullbitmap, BitmapLen(pRight->numOfRows)); + } + } + } else if (pRight->numOfRows == 1) { + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { + *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(pLeft->numOfRows)); + } + } + } + + doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pRightCol, rightConvert); +} + +void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pOutputCol = pOut->columnData; + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + int32_t leftConvert = 0, rightConvert = 0; + SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + double zero = 0.0; + + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + if (colDataIsNull_f(pLeftCol->nullbitmap, i) || colDataIsNull_f(pRightCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, leftv + rightv); - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, leftv + rightv); - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); + double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); + double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); + if (compareDoubleVal(&zero, &rx)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - SET_DOUBLE_VAL(pOut->data, leftv + rightv); + *output = lx - ((int64_t)(lx / rx)) * rx; + } + } else if (pLeft->numOfRows == 1) { + double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, 0); + if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { + if (colDataIsNull_f(pRightCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); + if (compareDoubleVal(&zero, &rx)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + *output = lx - ((int64_t)(lx / rx)) * rx; + } + } + } else if (pRight->numOfRows == 1) { + double rx = getVectorDoubleValueFnRight(pRightCol->pData, 0); + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { + if (colDataIsNull_f(pRightCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + double lx = getVectorDoubleValueFnLeft(pRightCol->pData, i); + if (compareDoubleVal(&zero, &lx)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + *output = lx - ((int64_t)(lx / rx)) * rx; + } } } - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); + doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pRightCol, rightConvert); } -void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - double leftv = 0, rightv = 0; - - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; - - if (vectorConvertImpl(pLeft, &leftParam)) { - return; - } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; - } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; - } - - - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); - - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) - getVectorDoubleValueFnRight(pRight->data, i)); - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) - getVectorDoubleValueFnRight(pRight->data,i)); - } - } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); - continue; - } - - SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) - getVectorDoubleValueFnRight(pRight->data,0)); - } - } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); -} -void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - double leftv = 0, rightv = 0; - - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; - - if (vectorConvertImpl(pLeft, &leftParam)) { - return; - } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; - } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; - } - - - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); - - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) * getVectorDoubleValueFnRight(pRight->data, i)); - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) * getVectorDoubleValueFnRight(pRight->data,i)); - } - } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); - continue; - } - - SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) * getVectorDoubleValueFnRight(pRight->data,0)); - } - } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); -} - -void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - double leftv = 0, rightv = 0; - - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; - - if (vectorConvertImpl(pLeft, &leftParam)) { - return; - } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; - } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; - } - - - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); - - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) / getVectorDoubleValueFnRight(pRight->data, i)); - } - } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) / getVectorDoubleValueFnRight(pRight->data,i)); - } - } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); - continue; - } - - SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) / getVectorDoubleValueFnRight(pRight->data,0)); - } - } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); -} - -void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - double leftv = 0, rightv = 0; - - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; - - if (vectorConvertImpl(pLeft, &leftParam)) { - return; - } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; - } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; - } - - - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); - - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, pRight->data); - if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); - } - } else if (pLeft->num == 1) { - double left = getVectorDoubleValueFnLeft(pLeft->data, 0); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, pRight->data); - if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { - sclSetNull(pOut, i); - continue; - } - - double right = getVectorDoubleValueFnRight(pRight->data, i); - SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); - } - } else if (pRight->num == 1) { - double right = getVectorDoubleValueFnRight(pRight->data, 0); - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, pRight->data); - if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { - sclSetNull(pOut, i); - continue; - } - - double left = getVectorDoubleValueFnLeft(pLeft->data, i); - SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); - } - } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); -} - -#endif - void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +#if 0 int32_t len = pLeft->bytes + pRight->bytes; - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; char *output = (char *)out; - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += len) { + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += len) { char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i); char* right = POINTER_SHIFT(pRight->data, pRight->bytes * i); - if (isNull(left, pLeft->type) || isNull(right, pRight->type)) { + if (isNull(left, pLeftCol->info.type) || isNull(right, pRight->info.type)) { setVardataNull(output, TSDB_DATA_TYPE_BINARY); continue; } @@ -1170,10 +796,10 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t memcpy(varDataVal(output) + varDataLen(left), varDataVal(right), varDataLen(right)); varDataSetLen(output, varDataLen(left) + varDataLen(right)); } - } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step, output += len) { + } else if (pLeft->numOfRows == 1) { + for (; i >= 0 && i < pRight->numOfRows; i += step, output += len) { char *right = POINTER_SHIFT(pRight->data, pRight->bytes * i); - if (isNull(pLeft->data, pLeft->type) || isNull(right, pRight->type)) { + if (isNull(pLeft->data, pLeftCol->info.type) || isNull(right, pRight->info.type)) { setVardataNull(output, TSDB_DATA_TYPE_BINARY); continue; } @@ -1182,10 +808,10 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t memcpy(varDataVal(output) + varDataLen(pLeft->data), varDataVal(right), varDataLen(right)); varDataSetLen(output, varDataLen(pLeft->data) + varDataLen(right)); } - } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step, output += len) { + } else if (pRight->numOfRows == 1) { + for (; i >= 0 && i < pLeft->numOfRows; i += step, output += len) { char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i); - if (isNull(left, pLeft->type) || isNull(pRight->data, pRight->type)) { + if (isNull(left, pLeftCol->info.type) || isNull(pRight->data, pRight->info.type)) { SET_DOUBLE_NULL(output); continue; } @@ -1195,257 +821,182 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t varDataSetLen(output, varDataLen(left) + varDataLen(pRight->data)); } } +#endif } +static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; + SColumnInfoData *pOutputCol = pOut->columnData; + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - int64_t leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(int64_t)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; + int32_t leftConvert = 0, rightConvert = 0; + SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); - if (vectorConvertImpl(pLeft, &leftParam)) { - return; + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); + + int64_t *output = (int64_t *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, i); } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(int64_t)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] & pRightCol->nullbitmap[j]; + } } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; + + } else if (pLeft->numOfRows == 1) { + vectorBitAndHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); } + doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pRightCol, rightConvert); +} - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeft->type); - _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRight->type); +static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } + int64_t *output = (int64_t *)pOutputCol->pData; - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv & rightv); + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + int64_t rx = getVectorBigintValueFnRight(pRightCol->pData, 0); + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) | rx; } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv & rightv); - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - SET_BIGINT_VAL(pOut->data, leftv & rightv); + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); } } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); } void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; + SColumnInfoData *pOutputCol = pOut->columnData; + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - int64_t leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(int64_t)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; + int32_t leftConvert = 0, rightConvert = 0; + SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); - if (vectorConvertImpl(pLeft, &leftParam)) { - return; + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); + + int64_t *output = (int64_t *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) | getVectorBigintValueFnRight(pRightCol->pData, i); } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(int64_t)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; + } else if (pLeft->numOfRows == 1) { + vectorBitOrHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorBitOrHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); } - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeft->type); - _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRight->type); - - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv | rightv); - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv | rightv); - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - SET_BIGINT_VAL(pOut->data, leftv | rightv); - } - } - - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); + doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pRightCol, rightConvert); } - void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - __compar_fn_t fp = filterGetCompFunc(pLeft->type, optr); - bool res = false; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; + __compar_fn_t fp = filterGetCompFunc(GET_PARAM_TYPE(pLeft), optr); - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + if (pRight->pHashFilter != NULL) { + for (; i >= 0 && i < pLeft->numOfRows; i += step) { + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) /*|| + colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) { continue; } - res = filterDoCompare(fp, optr, pLeft->data, pRight->data); - - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + char *pLeftData = colDataGetData(pLeft->columnData, i); + bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter); + colDataAppend(pOut->columnData, i, (char *)&res, false); } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - - for (; i >= 0 && i < pRight->num; i += step) { - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; + return; + } + + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step) { + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) || + colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)) { + continue; // TODO set null or ignore } - - res = filterDoCompare(fp, optr, pLeft->data, pRight->data); - - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + char *pLeftData = colDataGetData(pLeft->columnData, i); + char *pRightData = colDataGetData(pRight->columnData, i); + bool res = filterDoCompare(fp, optr, pLeftData, pRightData); + colDataAppend(pOut->columnData, i, (char *)&res, false); } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { - sclSetNull(pOut, i); + } else if (pRight->numOfRows == 1) { + char *pRightData = colDataGetData(pRight->columnData, 0); + ASSERT(pLeft->pHashFilter == NULL); + + for (; i >= 0 && i < pLeft->numOfRows; i += step) { + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) /*|| + colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) { continue; } - res = filterDoCompare(fp, optr, pLeft->data, pRight->data); + char *pLeftData = colDataGetData(pLeft->columnData, i); + bool res = filterDoCompare(fp, optr, pLeftData, pRightData); + colDataAppend(pOut->columnData, i, (char *)&res, false); + } + } else if (pLeft->numOfRows == 1) { + char *pLeftData = colDataGetData(pLeft->columnData, 0); - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + for (; i >= 0 && i < pRight->numOfRows; i += step) { + if (colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL) /*|| + colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) { + continue; + } + + char *pRightData = colDataGetData(pLeft->columnData, i); + bool res = filterDoCompare(fp, optr, pLeftData, pRightData); + colDataAppend(pOut->columnData, i, (char *)&res, false); } } } @@ -1459,21 +1010,19 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut SScalarParam *param1 = NULL; SScalarParam *param2 = NULL; - int32_t type = 0; - if (pLeftOut.type) { + if (pLeftOut.columnData != NULL) { param1 = &pLeftOut; } else { param1 = pLeft; } - if (pRightOut.type) { + if (pRightOut.columnData != NULL) { param2 = &pRightOut; } else { param2 = pRight; } vectorCompareImpl(param1, param2, pOut, _ord, optr); - sclFreeParam(&pLeftOut); sclFreeParam(&pRightOut); } @@ -1527,63 +1076,44 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu } void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - bool res = false; - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i)) { - res = true; - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); - continue; + for(int32_t i = 0; i < pLeft->numOfRows; ++i) { + int8_t v = 0; + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL)) { + v = 1; } - - res = false; - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + colDataAppend(pOut->columnData, i, (char*) &v, false); } + + pOut->numOfRows = pLeft->numOfRows; } void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - bool res = false; - - for (; i >= 0 && i < pLeft->num; i += step) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i)) { - res = false; - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); - continue; + for(int32_t i = 0; i < pLeft->numOfRows; ++i) { + int8_t v = 1; + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL)) { + v = 0; } - - res = true; - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + colDataAppend(pOut->columnData, i, (char*) &v, false); } - + pOut->numOfRows = pLeft->numOfRows; } void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { vectorConvertImpl(pLeft, pOut); } - _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { switch (binFunctionId) { case OP_TYPE_ADD: - return vectorAdd; + return vectorMathAdd; case OP_TYPE_SUB: - return vectorSub; + return vectorMathSub; case OP_TYPE_MULTI: - return vectorMultiply; + return vectorMathMultiply; case OP_TYPE_DIV: - return vectorDivide; + return vectorMathDivide; case OP_TYPE_MOD: - return vectorRemainder; + return vectorMathRemainder; case OP_TYPE_GREATER_THAN: return vectorGreater; case OP_TYPE_GREATER_EQUAL: @@ -1622,6 +1152,4 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { assert(0); return NULL; } -} - - +} \ 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 f0025de6b8..153222516c 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -269,7 +269,7 @@ TEST(constantTest, bigint_add_bigint) { ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); SValueNode *v = (SValueNode *)res; ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_EQ(v->datum.d, (scltLeftV + scltRightV)); + ASSERT_FLOAT_EQ(v->datum.d, (scltLeftV + scltRightV)); nodesDestroyNode(res); } @@ -285,7 +285,7 @@ TEST(constantTest, double_sub_bigint) { ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); SValueNode *v = (SValueNode *)res; ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_EQ(v->datum.d, (scltLeftVd - scltRightV)); + ASSERT_FLOAT_EQ(v->datum.d, (scltLeftVd - scltRightV)); nodesDestroyNode(res); } @@ -340,7 +340,6 @@ TEST(constantTest, int_or_binary) { nodesDestroyNode(res); } - TEST(constantTest, int_greater_double) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); @@ -479,8 +478,6 @@ TEST(constantTest, int_not_equal_smallint2) { nodesDestroyNode(res); } - - TEST(constantTest, int_in_smallint1) { scltInitLogFile(); @@ -851,7 +848,6 @@ TEST(constantTest, int_add_int_is_true2) { nodesDestroyNode(res); } - TEST(constantTest, int_greater_int_is_true1) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; int32_t leftv = 1, rightv = 1; @@ -913,8 +909,6 @@ TEST(constantTest, greater_and_lower) { nodesDestroyNode(res); } - - TEST(columnTest, smallint_value_add_int_column) { scltInitLogFile(); @@ -967,7 +961,6 @@ TEST(columnTest, bigint_column_multi_binary_column) { scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - SArray *blockList = taosArrayInit(1, POINTER_BYTES); taosArrayPush(blockList, &src); SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); @@ -1271,7 +1264,6 @@ TEST(columnTest, binary_column_like_binary) { nodesDestroyNode(opNode); } - TEST(columnTest, binary_column_is_true) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; @@ -1286,7 +1278,7 @@ TEST(columnTest, binary_column_is_true) { } int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv); scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); @@ -1471,23 +1463,26 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t } } - input->type = type; - input->num = num; - input->data = taosMemoryCalloc(num, bytes); - input->bytes = bytes; + input->columnData = (SColumnInfoData*) taosMemoryCalloc(1, sizeof(SColumnInfoData)); + input->numOfRows = num; + + input->columnData->info = createColumnInfo(0, type, bytes); + blockDataEnsureColumnCapacity(input->columnData, num); + if (setVal) { for (int32_t i = 0; i < num; ++i) { - memcpy(input->data + i * bytes, pVal, bytes); + colDataAppend(input->columnData, i, (const char*) pVal, false); } } else { - memset(input->data, 0, num * bytes); +// memset(input->data, 0, num * bytes); } *pInput = input; } void scltDestroyDataBlock(SScalarParam *pInput) { - taosMemoryFree(pInput->data); + colDataDestroy(pInput->columnData); + taosMemoryFree(pInput->columnData); taosMemoryFree(pInput); } @@ -1500,25 +1495,25 @@ TEST(ScalarFunctionTest, absFunction_constant) { //TINYINT int8_t val_tinyint = 10; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), val_tinyint); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); val_tinyint = -10; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), -val_tinyint); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -val_tinyint); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1526,25 +1521,25 @@ TEST(ScalarFunctionTest, absFunction_constant) { //SMALLINT int16_t val_smallint = 10; type = TSDB_DATA_TYPE_SMALLINT; - scltMakeDataBlock(&pInput, type, &val_smallint, 1, true); + scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)pOutput->data + i), val_smallint); + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); val_smallint = -10; - scltMakeDataBlock(&pInput, type, &val_smallint, 1, true); + scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)pOutput->data + i), -val_smallint); + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -val_smallint); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1552,25 +1547,25 @@ TEST(ScalarFunctionTest, absFunction_constant) { //INT int32_t val_int = 10; type = TSDB_DATA_TYPE_INT; - scltMakeDataBlock(&pInput, type, &val_int, 1, true); + scltMakeDataBlock(&pInput, type, &val_int, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)pOutput->data + i), val_int); + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); val_int = -10; - scltMakeDataBlock(&pInput, type, &val_int, 1, true); + scltMakeDataBlock(&pInput, type, &val_int, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)pOutput->data + i), -val_int); + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -val_int); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1578,13 +1573,13 @@ TEST(ScalarFunctionTest, absFunction_constant) { //BIGINT int64_t val_bigint = 10; type = TSDB_DATA_TYPE_BIGINT; - scltMakeDataBlock(&pInput, type, &val_bigint, 1, true); + scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int64_t *)pOutput->data + i), val_bigint); + ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), val_bigint); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1596,7 +1591,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int64_t *)pOutput->data + i), -val_bigint); + ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), -val_bigint); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1604,29 +1599,29 @@ TEST(ScalarFunctionTest, absFunction_constant) { //FLOAT float val_float = 10.15; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("float before ABS:%f\n", *(float *)pInput->data); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), val_float); - PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); val_float = -10.15; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("float before ABS:%f\n", *(float *)pInput->data); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), -val_float); - PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -val_float); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1634,13 +1629,13 @@ TEST(ScalarFunctionTest, absFunction_constant) { //DOUBLE double val_double = 10.15; type = TSDB_DATA_TYPE_DOUBLE; - scltMakeDataBlock(&pInput, type, &val_double, 1, true); + scltMakeDataBlock(&pInput, type, &val_double, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), val_double); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1652,7 +1647,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), -val_double); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -val_double); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1671,15 +1666,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint + i; - PRINTF("tiny_int before ABS:%d\n", *((int8_t *)pInput->data + i)); + int8_t v = val_tinyint + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("tiny_int before ABS:%d\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), val_tinyint + i); - PRINTF("tiny_int after ABS:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint + i); + PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1688,15 +1684,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint + i; - PRINTF("tiny_int before ABS:%d\n", *((int8_t *)pInput->data + i)); + int8_t v = val_tinyint + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("tiny_int before ABS:%d\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), -(val_tinyint + i)); - PRINTF("tiny_int after ABS:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -(val_tinyint + i)); + PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1707,16 +1704,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int16_t *)pInput->data + i) = val_smallint + i; - PRINTF("small_int before ABS:%d\n", *((int16_t *)pInput->data + i)); + int16_t v = val_smallint + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("small_int before ABS:%d\n", v); } - code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)pOutput->data + i), val_smallint + i); - PRINTF("small_int after ABS:%d\n", *((int16_t *)pOutput->data + i)); + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint + i); + PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1725,15 +1722,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int16_t *)pInput->data + i) = val_smallint + i; - PRINTF("small_int before ABS:%d\n", *((int16_t *)pInput->data + i)); + int16_t v = val_smallint + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("small_int before ABS:%d\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)pOutput->data + i), -(val_smallint + i)); - PRINTF("small_int after ABS:%d\n", *((int16_t *)pOutput->data + i)); + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -(val_smallint + i)); + PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1744,16 +1742,17 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int32_t *)pInput->data + i) = val_int + i; - PRINTF("int before ABS:%d\n", *((int32_t *)pInput->data + i)); + int32_t v = val_int + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("int before ABS:%d\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)pOutput->data + i), val_int + i); - PRINTF("int after ABS:%d\n", *((int32_t *)pOutput->data + i)); + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int + i); + PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1762,15 +1761,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int32_t *)pInput->data + i) = val_int + i; - PRINTF("int before ABS:%d\n", *((int32_t *)pInput->data + i)); + int32_t v = val_int + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("int before ABS:%d\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)pOutput->data + i), -(val_int + i)); - PRINTF("int after ABS:%d\n", *((int32_t *)pOutput->data + i)); + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -(val_int + i)); + PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1781,15 +1781,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float + i; - PRINTF("float before ABS:%f\n", *((float *)pInput->data + i)); + float v = val_float + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("float before ABS:%f\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), val_float + i); - PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float + i); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1798,15 +1799,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float + i; - PRINTF("float before ABS:%f\n", *((float *)pInput->data + i)); + float v = val_float + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("float before ABS:%f\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), -(val_float + i)); - PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -(val_float + i)); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1817,15 +1819,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((double *)pInput->data + i) = val_double + i; - PRINTF("double before ABS:%f\n", *((double *)pInput->data + i)); + double v = val_double + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("double before ABS:%f\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), val_double + i); - PRINTF("double after ABS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double + i); + PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1834,15 +1837,16 @@ TEST(ScalarFunctionTest, absFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((double *)pInput->data + i) = val_double + i; - PRINTF("double before ABS:%f\n", *((double *)pInput->data + i)); + double v = val_double + i; + colDataAppend(pInput->columnData, i, (const char*) &v, false); + PRINTF("double before ABS:%f\n", v); } code = absFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), -(val_double + i)); - PRINTF("double after ABS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -(val_double + i)); + PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -1860,15 +1864,15 @@ TEST(ScalarFunctionTest, sinFunction_constant) { //TINYINT int8_t val_tinyint = 13; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data)); code = sinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after SIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1876,15 +1880,15 @@ TEST(ScalarFunctionTest, sinFunction_constant) { //FLOAT float val_float = 13.00; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("float before SIN:%f\n", *((float *)pInput->data)); code = sinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after SIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -1907,15 +1911,15 @@ TEST(ScalarFunctionTest, sinFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data + i)); + colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); + PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); } code = sinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after SIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1926,15 +1930,15 @@ TEST(ScalarFunctionTest, sinFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before SIN:%f\n", *((float *)pInput->data + i)); + colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); + PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = sinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after SIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -1952,15 +1956,15 @@ TEST(ScalarFunctionTest, cosFunction_constant) { //TINYINT int8_t val_tinyint = 13; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data)); code = cosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after COS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -1968,15 +1972,15 @@ TEST(ScalarFunctionTest, cosFunction_constant) { //FLOAT float val_float = 13.00; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("float before COS:%f\n", *((float *)pInput->data)); code = cosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after COS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -1997,15 +2001,15 @@ TEST(ScalarFunctionTest, cosFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data + i)); + colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); + PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); } code = cosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after COS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2016,15 +2020,15 @@ TEST(ScalarFunctionTest, cosFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before COS:%f\n", *((float *)pInput->data + i)); + colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); + PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i)); } code = cosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after COS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2042,15 +2046,15 @@ TEST(ScalarFunctionTest, tanFunction_constant) { //TINYINT int8_t val_tinyint = 13; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data)); code = tanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after TAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2058,15 +2062,15 @@ TEST(ScalarFunctionTest, tanFunction_constant) { //FLOAT float val_float = 13.00; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("float before TAN:%f\n", *((float *)pInput->data)); code = tanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after TAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2087,15 +2091,15 @@ TEST(ScalarFunctionTest, tanFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data + i)); + colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); + PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = tanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after TAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2106,15 +2110,15 @@ TEST(ScalarFunctionTest, tanFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before TAN:%f\n", *((float *)pInput->data + i)); + colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); + PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = tanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after TAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2132,15 +2136,15 @@ TEST(ScalarFunctionTest, asinFunction_constant) { //TINYINT int8_t val_tinyint = 1; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data)); code = asinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after ASIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2148,15 +2152,15 @@ TEST(ScalarFunctionTest, asinFunction_constant) { //FLOAT float val_float = 1.00; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("float before ASIN:%f\n", *((float *)pInput->data)); code = asinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after ASIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2178,15 +2182,15 @@ TEST(ScalarFunctionTest, asinFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data + i)); + colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); + PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = asinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after ASIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2197,15 +2201,15 @@ TEST(ScalarFunctionTest, asinFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before ASIN:%f\n", *((float *)pInput->data + i)); + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ASIN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = asinFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after ASIN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2223,15 +2227,15 @@ TEST(ScalarFunctionTest, acosFunction_constant) { //TINYINT int8_t val_tinyint = 1; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data)); code = acosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after ACOS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2239,15 +2243,15 @@ TEST(ScalarFunctionTest, acosFunction_constant) { //FLOAT float val_float = 1.00; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("float before ACOS:%f\n", *((float *)pInput->data)); code = acosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after ACOS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2268,15 +2272,15 @@ TEST(ScalarFunctionTest, acosFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data + i)); + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = acosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after ACOS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2287,15 +2291,15 @@ TEST(ScalarFunctionTest, acosFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before ACOS:%f\n", *((float *)pInput->data + i)); + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ACOS:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = acosFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after ACOS:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2313,15 +2317,15 @@ TEST(ScalarFunctionTest, atanFunction_constant) { //TINYINT int8_t val_tinyint = 1; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data)); code = atanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after ATAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2329,15 +2333,15 @@ TEST(ScalarFunctionTest, atanFunction_constant) { //FLOAT float val_float = 1.00; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("float before ATAN:%f\n", *((float *)pInput->data)); code = atanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after ATAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2358,15 +2362,15 @@ TEST(ScalarFunctionTest, atanFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data + i)); + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = atanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after ATAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2377,15 +2381,15 @@ TEST(ScalarFunctionTest, atanFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before ATAN:%f\n", *((float *)pInput->data + i)); + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ATAN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = atanFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after ATAN:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2402,15 +2406,15 @@ TEST(ScalarFunctionTest, ceilFunction_constant) { //TINYINT int8_t val_tinyint = 10; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data)); code = ceilFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), (int8_t)result); - PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); + PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2418,15 +2422,15 @@ TEST(ScalarFunctionTest, ceilFunction_constant) { //FLOAT float val_float = 9.5; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("float before CEIL:%f\n", *((float *)pInput->data)); code = ceilFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), (float)result); - PRINTF("float after CEIL:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); + PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2446,15 +2450,15 @@ TEST(ScalarFunctionTest, ceilFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data + i)); + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = ceilFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), result[i]); - PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2465,15 +2469,15 @@ TEST(ScalarFunctionTest, ceilFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before CEIL:%f\n", *((float *)pInput->data + i)); + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before CEIL:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = ceilFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), result[i]); - PRINTF("float after CEIL:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2490,15 +2494,15 @@ TEST(ScalarFunctionTest, floorFunction_constant) { //TINYINT int8_t val_tinyint = 10; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data)); code = floorFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), (int8_t)result); - PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); + PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2506,15 +2510,15 @@ TEST(ScalarFunctionTest, floorFunction_constant) { //FLOAT float val_float = 10.5; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("float before FLOOR:%f\n", *((float *)pInput->data)); code = floorFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), (float)result); - PRINTF("float after FLOOR:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); + PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2534,15 +2538,15 @@ TEST(ScalarFunctionTest, floorFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data + i)); + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = floorFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), result[i]); - PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2553,15 +2557,15 @@ TEST(ScalarFunctionTest, floorFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before FLOOR:%f\n", *((float *)pInput->data + i)); + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before FLOOR:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = floorFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), result[i]); - PRINTF("float after FLOOR:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2578,15 +2582,15 @@ TEST(ScalarFunctionTest, roundFunction_constant) { //TINYINT int8_t val_tinyint = 10; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data)); code = roundFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), (int8_t)result); - PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); + PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2594,15 +2598,15 @@ TEST(ScalarFunctionTest, roundFunction_constant) { //FLOAT float val_float = 9.5; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); PRINTF("float before ROUND:%f\n", *((float *)pInput->data)); code = roundFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), (float)result); - PRINTF("float after ROUND:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); + PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2622,15 +2626,15 @@ TEST(ScalarFunctionTest, roundFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data + i)); + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = roundFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)pOutput->data + i), result[i]); - PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)pOutput->data + i)); + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2641,15 +2645,15 @@ TEST(ScalarFunctionTest, roundFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before ROUND:%f\n", *((float *)pInput->data + i)); + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ROUND:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = roundFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)pOutput->data + i), result[i]); - PRINTF("float after ROUND:%f\n", *((float *)pOutput->data + i)); + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2667,15 +2671,15 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) { //TINYINT int8_t val_tinyint = 25; type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data)); code = sqrtFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after SQRT:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2683,15 +2687,15 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) { //FLOAT float val_float = 25.0; type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, 1, true); + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); PRINTF("float before SQRT:%f\n", *((float *)pInput->data)); code = sqrtFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after SQRT:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2712,15 +2716,15 @@ TEST(ScalarFunctionTest, sqrtFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)pInput->data + i) = val_tinyint[i]; - PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data + i)); + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); } code = sqrtFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after SQRT:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); scltDestroyDataBlock(pOutput); @@ -2731,15 +2735,15 @@ TEST(ScalarFunctionTest, sqrtFunction_column) { scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput->data + i) = val_float[i]; - PRINTF("float before SQRT:%f\n", *((float *)pInput->data + i)); + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before SQRT:%f\n", *((float *)colDataGetData(pInput->columnData, i))); } code = sqrtFunction(pInput, 1, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after SQRT:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(pInput); @@ -2760,7 +2764,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { int8_t val_tinyint[] = {27, 3}; type = TSDB_DATA_TYPE_TINYINT; for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_tinyint[i], 1, true); + scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true); pInput[i] = *input[i]; } scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); @@ -2770,8 +2774,8 @@ TEST(ScalarFunctionTest, logFunction_constant) { code = logFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after LOG:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[1]); @@ -2781,7 +2785,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { float val_float[] = {64.0, 4.0}; type = TSDB_DATA_TYPE_FLOAT; for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_float[i], 1, true); + scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true); pInput[i] = *input[i]; } scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); @@ -2791,8 +2795,8 @@ TEST(ScalarFunctionTest, logFunction_constant) { code = logFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after LOG:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[1]); @@ -2801,9 +2805,9 @@ TEST(ScalarFunctionTest, logFunction_constant) { //TINYINT AND FLOAT int8_t param0 = 64; float param1 = 4.0; - scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, 1, true); + scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true); pInput[0] = *input[0]; - scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, 1, true); + scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true); pInput[1] = *input[1]; scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); @@ -2812,8 +2816,8 @@ TEST(ScalarFunctionTest, logFunction_constant) { code = logFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int,float after LOG:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); @@ -2829,17 +2833,18 @@ 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); pInput[i] = *input[i]; for (int32_t j = 0; j < rowNum; ++j) { - *((int8_t *)pInput[i].data + j) = val_tinyint[i][j]; + colDataAppend(pInput[i].columnData, j, (const char*) &val_tinyint[i][j], false); + } PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), *((int8_t *)pInput[i].data + 1), @@ -2850,50 +2855,52 @@ TEST(ScalarFunctionTest, logFunction_column) { code = logFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after LOG:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[1]); 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); pInput[i] = *input[i]; for (int32_t j = 0; j < rowNum; ++j) { - *((float *)pInput[i].data + j) = val_float[i][j]; + colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false); } - PRINTF("float before LOG:%f,%f,%f\n", *((float *)pInput[i].data + 0), - *((float *)pInput[i].data + 1), - *((float *)pInput[i].data + 2)); + PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)), + *((float *)colDataGetData(pInput[i], 1)), + *((float *)colDataGetData(pInput[i], 2))); } scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); code = logFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after LOG:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[1]); 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) { - *((int8_t *)pInput[0].data + i) = param0[i]; + colDataAppend(pInput[0].columnData, i, (const char*) ¶m0[i], false); + } scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); pInput[1] = *input[1]; for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput[1].data + i) = param1[i]; + colDataAppend(pInput[1].columnData, i, (const char*) ¶m1[i], false); + } PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), @@ -2903,8 +2910,8 @@ TEST(ScalarFunctionTest, logFunction_column) { code = logFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int,float after LOG:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); @@ -2927,7 +2934,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { int8_t val_tinyint[] = {2, 4}; type = TSDB_DATA_TYPE_TINYINT; for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_tinyint[i], 1, true); + scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true); pInput[i] = *input[i]; } scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); @@ -2937,8 +2944,8 @@ TEST(ScalarFunctionTest, powFunction_constant) { code = powFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int after POW:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[1]); @@ -2948,7 +2955,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { float val_float[] = {2.0, 4.0}; type = TSDB_DATA_TYPE_FLOAT; for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_float[i], 1, true); + scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true); pInput[i] = *input[i]; } scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); @@ -2958,8 +2965,8 @@ TEST(ScalarFunctionTest, powFunction_constant) { code = powFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("float after POW:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[1]); @@ -2968,9 +2975,9 @@ TEST(ScalarFunctionTest, powFunction_constant) { //TINYINT AND FLOAT int8_t param0 = 2; float param1 = 4.0; - scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, 1, true); + scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true); pInput[0] = *input[0]; - scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, 1, true); + scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true); pInput[1] = *input[1]; scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); @@ -2979,8 +2986,8 @@ TEST(ScalarFunctionTest, powFunction_constant) { code = powFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result); - PRINTF("tiny_int,float after POW:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); @@ -2996,17 +3003,18 @@ 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) { - *((int8_t *)pInput[i].data + j) = val_tinyint[i][j]; + 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), *((int8_t *)pInput[i].data + 1), @@ -3017,8 +3025,8 @@ TEST(ScalarFunctionTest, powFunction_column) { code = powFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int after POW:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); @@ -3026,13 +3034,13 @@ 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); pInput[i] = *input[i]; for (int32_t j = 0; j < rowNum; ++j) { - *((float *)pInput[i].data + j) = val_float[i][j]; + colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false); } PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0), *((float *)pInput[i].data + 1), @@ -3043,8 +3051,8 @@ TEST(ScalarFunctionTest, powFunction_column) { code = powFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("float after POW:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[1]); @@ -3052,16 +3060,17 @@ 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) { - *((int8_t *)pInput[0].data + i) = param0[i]; + colDataAppend(pInput[0].columnData, i, (const char*) ¶m0[i], false); + } scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); pInput[1] = *input[1]; for (int32_t i = 0; i < rowNum; ++i) { - *((float *)pInput[1].data + i) = param1[i]; + colDataAppend(pInput[1].columnData, i, (const char*) ¶m1[i], false); } PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), @@ -3071,8 +3080,8 @@ TEST(ScalarFunctionTest, powFunction_column) { code = powFunction(pInput, 2, pOutput); ASSERT_EQ(code, TSDB_CODE_SUCCESS); for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)pOutput->data + i), result[i]); - PRINTF("tiny_int,float after POW:%f\n", *((double *)pOutput->data + i)); + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); } scltDestroyDataBlock(input[0]); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 028e310a25..fb6c0f6c12 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -16,6 +16,86 @@ #include "tstream.h" #include "executor.h" +static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* pMsg, SEpSet** ppEpSet) { + SStreamTaskExecReq req = { + .streamId = pTask->streamId, + .data = data, + }; + + int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req); + void* buf = rpcMallocCont(tlen); + + if (buf == NULL) { + return -1; + } + 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) { + // TODO fix tbname issue + char ctbName[TSDB_TABLE_FNAME_LEN + 22]; + // all groupId must be the same in an array + SSDataBlock* pBlock = taosArrayGet(data, 0); + sprintf(ctbName, "%s:%ld", pTask->shuffleDispatcher.stbFullName, pBlock->info.groupId); + + // TODO: get hash function by hashMethod + + // get groupId, compute hash value + uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName)); + // + // get node + // 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; + } + } + ASSERT(nodeId != 0); + ((SMsgHead*)buf)->vgId = htonl(nodeId); + } + + void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tEncodeSStreamTaskExecReq(&abuf, &req); + + pMsg->pCont = buf; + pMsg->contLen = tlen; + pMsg->code = 0; + pMsg->msgType = pTask->dispatchMsgType; + pMsg->noResp = 1; + + return 0; +} + +static int32_t streamShuffleDispatch(SStreamTask* pTask, SMsgCb* pMsgCb, SHashObj* data) { + void* pIter = NULL; + while (1) { + pIter = taosHashIterate(data, pIter); + if (pIter == NULL) return 0; + SArray* pData = *(SArray**)pIter; + SRpcMsg dispatchMsg = {0}; + SEpSet* pEpSet; + if (streamBuildDispatchMsg(pTask, pData, &dispatchMsg, &pEpSet) < 0) { + ASSERT(0); + return -1; + } + tmsgSendReq(pMsgCb, pEpSet, &dispatchMsg); + } + return 0; +} + int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, int32_t inputType, int32_t workId) { SArray* pRes = NULL; // source @@ -44,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); } @@ -83,28 +164,13 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in } // dispatch + if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - SStreamTaskExecReq req = { - .streamId = pTask->streamId, - .taskId = pTask->taskId, - .data = pRes, - }; - - int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req); - void* buf = rpcMallocCont(tlen); - - if (buf == NULL) { + SRpcMsg dispatchMsg = {0}; + if (streamBuildDispatchMsg(pTask, pRes, &dispatchMsg, NULL) < 0) { + ASSERT(0); return -1; } - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSStreamTaskExecReq(&abuf, &req); - - SRpcMsg dispatchMsg = { - .pCont = buf, - .contLen = tlen, - .code = 0, - .msgType = pTask->dispatchMsgType, - }; int32_t qType; if (pTask->dispatchMsgType == TDMT_VND_TASK_PIPE_EXEC || pTask->dispatchMsgType == TDMT_SND_TASK_PIPE_EXEC) { @@ -120,36 +186,38 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in tmsgPutToQueue(pMsgCb, qType, &dispatchMsg); } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { - SStreamTaskExecReq req = { - .streamId = pTask->streamId, - .taskId = pTask->fixedEpDispatcher.taskId, - .data = pRes, - }; - - int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req); - void* buf = rpcMallocCont(tlen); - - if (buf == NULL) { + SRpcMsg dispatchMsg = {0}; + SEpSet* pEpSet = NULL; + if (streamBuildDispatchMsg(pTask, pRes, &dispatchMsg, &pEpSet) < 0) { + ASSERT(0); return -1; } - ((SMsgHead*)buf)->vgId = htonl(pTask->fixedEpDispatcher.nodeId); - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSStreamTaskExecReq(&abuf, &req); - - SRpcMsg dispatchMsg = { - .pCont = buf, - .contLen = tlen, - .code = 0, - .msgType = pTask->dispatchMsgType, - }; - - SEpSet* pEpSet = &pTask->fixedEpDispatcher.epSet; - tmsgSendReq(pMsgCb, pEpSet, &dispatchMsg); } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - // TODO + SHashObj* pShuffleRes = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (pShuffleRes == NULL) { + return -1; + } + + int32_t sz = taosArrayGetSize(pRes); + for (int32_t i = 0; i < sz; i++) { + SSDataBlock* pDataBlock = taosArrayGet(pRes, i); + SArray* pArray = taosHashGet(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t)); + if (pArray == NULL) { + pArray = taosArrayInit(0, sizeof(SSDataBlock)); + if (pArray == NULL) { + return -1; + } + taosHashPut(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t), &pArray, sizeof(void*)); + } + taosArrayPush(pArray, pDataBlock); + } + + if (streamShuffleDispatch(pTask, pMsgCb, pShuffleRes) < 0) { + return -1; + } } else { ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE); @@ -196,7 +264,6 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI8(pEncoder, pTask->sinkType) < 0) return -1; if (tEncodeI8(pEncoder, pTask->dispatchType) < 0) return -1; if (tEncodeI16(pEncoder, pTask->dispatchMsgType) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->downstreamTaskId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1; @@ -225,7 +292,8 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - if (tEncodeI8(pEncoder, pTask->shuffleDispatcher.hashMethod) < 0) return -1; + if (tSerializeSUseDbRspImp(pEncoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; + /*if (tEncodeI8(pEncoder, pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ } /*tEndEncode(pEncoder);*/ @@ -242,7 +310,6 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { if (tDecodeI8(pDecoder, &pTask->sinkType) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->dispatchType) < 0) return -1; if (tDecodeI16(pDecoder, &pTask->dispatchMsgType) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->downstreamTaskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1; @@ -271,7 +338,8 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - if (tDecodeI8(pDecoder, &pTask->shuffleDispatcher.hashMethod) < 0) return -1; + /*if (tDecodeI8(pDecoder, &pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ + if (tDeserializeSUseDbRspImp(pDecoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; } /*tEndDecode(pDecoder);*/ 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/libs/transport/test/transportTests.cpp b/source/libs/transport/test/transportTests.cpp index 4165e6d8c9..ce795b1763 100644 --- a/source/libs/transport/test/transportTests.cpp +++ b/source/libs/transport/test/transportTests.cpp @@ -156,14 +156,14 @@ TEST_F(TransCtxEnv, mergeTest) { STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); transCtxInit(src); { - STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; + STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree}; val1.val = taosMemoryMalloc(12); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; } { - STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; + STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree}; val1.val = taosMemoryMalloc(12); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; @@ -176,14 +176,14 @@ TEST_F(TransCtxEnv, mergeTest) { STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); transCtxInit(src); { - STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; + STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree}; val1.val = taosMemoryMalloc(12); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; } { - STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; + STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree}; val1.val = taosMemoryMalloc(12); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); key++; @@ -198,7 +198,7 @@ TEST_F(TransCtxEnv, mergeTest) { STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); transCtxInit(src); { - STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; + STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree}; val1.val = taosMemoryCalloc(1, 11); memcpy(val1.val, val.c_str(), val.size()); @@ -206,7 +206,7 @@ TEST_F(TransCtxEnv, mergeTest) { key++; } { - STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; + STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree}; val1.val = taosMemoryCalloc(1, 11); memcpy(val1.val, val.c_str(), val.size()); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index eea3903911..c467ab5fa3 100644 --- a/source/os/CMakeLists.txt +++ b/source/os/CMakeLists.txt @@ -13,6 +13,9 @@ find_path(IconvApiIncludes iconv.h PATHS) if(NOT IconvApiIncludes) add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV) endif () +if(USE_TD_MEMORY) + add_definitions(-DUSE_TD_MEMORY) +endif () target_link_libraries( os pthread dl rt m ) diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 12e89fdd73..81ee259ff1 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -14,17 +14,17 @@ */ #define ALLOW_FORBID_FUNC +#include #include "os.h" #define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S') #define TD_MEMORY_STACK_TRACE_DEPTH 10 -typedef struct TdMemoryInfo -{ +typedef struct TdMemoryInfo { int32_t symbol; + int32_t memorySize; void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX - int32_t memorySize; } *TdMemoryInfoPtr , TdMemoryInfo; #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) @@ -32,6 +32,7 @@ typedef struct TdMemoryInfo #else #include + #define STACKCALL __attribute__((regparm(1), noinline)) void **STACKCALL taosGetEbp(void) { void **ebp = NULL; @@ -41,6 +42,7 @@ void **STACKCALL taosGetEbp(void) { : "memory"); /* not affect register */ return (void **)(*ebp); } + int32_t taosBackTrace(void **buffer, int32_t size) { int32_t frame = 0; void **ebp; @@ -59,6 +61,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) { } return frame; } + #endif // char **taosBackTraceSymbols(int32_t *size) { @@ -68,6 +71,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) { // } void *taosMemoryMalloc(int32_t size) { +#ifdef USE_TD_MEMORY void *tmp = malloc(size + sizeof(TdMemoryInfo)); if (tmp == NULL) return NULL; @@ -77,9 +81,13 @@ void *taosMemoryMalloc(int32_t size) { taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH); return (char*)tmp + sizeof(TdMemoryInfo); +#else + return malloc(size); +#endif } void *taosMemoryCalloc(int32_t num, int32_t size) { +#ifdef USE_TD_MEMORY int32_t memorySize = num * size; char *tmp = calloc(memorySize + sizeof(TdMemoryInfo), 1); if (tmp == NULL) return NULL; @@ -90,9 +98,13 @@ void *taosMemoryCalloc(int32_t num, int32_t size) { taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH); return (char*)tmp + sizeof(TdMemoryInfo); +#else + return calloc(num, size); +#endif } void *taosMemoryRealloc(void *ptr, int32_t size) { +#ifdef USE_TD_MEMORY if (ptr == NULL) return taosMemoryMalloc(size); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); @@ -108,9 +120,13 @@ void *taosMemoryRealloc(void *ptr, int32_t size) { ((TdMemoryInfoPtr)tmp)->memorySize = size; return (char*)tmp + sizeof(TdMemoryInfo); +#else + return realloc(ptr, size); +#endif } void taosMemoryFree(const void *ptr) { +#ifdef USE_TD_MEMORY if (ptr == NULL) return; TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); @@ -121,13 +137,20 @@ void taosMemoryFree(const void *ptr) { } else { free((void*)ptr); } +#else + return free((void*)ptr); +#endif } int32_t taosMemorySize(void *ptr) { +#ifdef USE_TD_MEMORY if (ptr == NULL) return 0; TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); return pTdMemoryInfo->memorySize; +#else + return malloc_usable_size(ptr); +#endif } diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index f5ce88179b..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,12 +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:%p:%d cont:%p:%d to queue:%p", pQueue->name, pHead, headLen, pBody, bodyLen, pQueue); + 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); @@ -277,16 +277,19 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea taosThreadMutexUnlock(pQueue->mutex); tsem_post(&pQueue->sem); terrno = TSDB_CODE_OUT_OF_SHM_MEM; - return -1; + 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); } @@ -301,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); @@ -320,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)); @@ -340,9 +344,11 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea *ppBody = pBody; *pHeadLen = headLen; *pBodyLen = bodyLen; + *pFuncType = (ProcFuncType)ftype; - uTrace("proc:%s, get msg:%p:%d cont:%p:%d from queue:%p", pQueue->name, pHead, headLen, pBody, bodyLen, pQueue); - return 0; + 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; } SProcObj *taosProcInit(const SProcCfg *pCfg) { @@ -394,21 +400,23 @@ 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 message from queue:%p", pQueue->name, pQueue); + uDebug("proc:%s, start to get msg from queue:%p", pQueue->name, pQueue); while (1) { - int32_t code = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen); - if (code < 0) { - uDebug("proc:%s, get no message from queue:%p and exiting", pQueue->name, pQueue); + 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; - } else if (code == 0) { - uTrace("proc:%s, get no message from queue:%p since %s", pQueue->name, pQueue, terrstr()); + } else if (numOfMsgs < 0) { + uTrace("proc:%s, get no msg from queue:%p since %s", pQueue->name, pQueue, terrstr()); taosMsleep(1); continue; } else { - (*consumeFp)(pParent, pHead, headLen, pBody, bodyLen); + (*consumeFp)(pParent, pHead, headLen, pBody, bodyLen, ftype); } } } @@ -456,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/source/util/src/tqueue.c b/source/util/src/tqueue.c index b01e1ea1da..3c3a8460b9 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -146,7 +146,7 @@ void taosFreeQitem(void *pItem) { taosMemoryFree(temp); } -int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { +void taosWriteQitem(STaosQueue *queue, void *pItem) { STaosQnode *pNode = (STaosQnode *)(((char *)pItem) - sizeof(STaosQnode)); pNode->next = NULL; @@ -167,8 +167,6 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { taosThreadMutexUnlock(&queue->mutex); if (queue->qset) tsem_post(&queue->qset->sem); - - return 0; } int32_t taosReadQitem(STaosQueue *queue, void **ppItem) { diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 992ec74b5b..7fc390e70b 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -287,8 +287,8 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) { int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) { SQWorkerPool *pPool = &pWorker->pool; pPool->name = pCfg->name; - pPool->min = pCfg->minNum; - pPool->max = pCfg->maxNum; + pPool->min = pCfg->min; + pPool->max = pCfg->max; if (tQWorkerInit(pPool) != 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -316,7 +316,7 @@ void tSingleWorkerCleanup(SSingleWorker *pWorker) { int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) { SWWorkerPool *pPool = &pWorker->pool; pPool->name = pCfg->name; - pPool->max = pCfg->maxNum; + pPool->max = pCfg->max; if (tWWorkerInit(pPool) != 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index dd44baed27..2cad518128 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -6,6 +6,8 @@ # ---- db ./test.sh -f tsim/db/basic1.sim +./test.sh -f tsim/db/basic2.sim +./test.sh -f tsim/db/basic3.sim ./test.sh -f tsim/db/basic6.sim ./test.sh -f tsim/db/basic7.sim ./test.sh -f tsim/db/error1.sim @@ -19,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 @@ -31,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..13b2baae32 100755 --- a/tests/script/sh/massiveTable/compileVersion.sh +++ b/tests/script/sh/massiveTable/compileVersion.sh @@ -75,10 +75,12 @@ 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/general/db/basic2.sim b/tests/script/tsim/db/basic2.sim similarity index 63% rename from tests/script/general/db/basic2.sim rename to tests/script/tsim/db/basic2.sim index acd035bd74..e9222c8d32 100644 --- a/tests/script/general/db/basic2.sim +++ b/tests/script/tsim/db/basic2.sim @@ -1,7 +1,24 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start -sleep 2000 + +$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 print =============== create database d1 @@ -13,7 +30,10 @@ sql create table t3 (ts timestamp, i int); sql create table t4 (ts timestamp, i int); sql show databases -if $rows != 1 then +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +if $rows != 2 then return -1 endi @@ -21,13 +41,13 @@ if $data00 != d1 then return -1 endi -if $data02 != 4 then +if $data02 != 2 then # vgroups return -1 endi -if $data03 != 1 then - return -1 -endi +#if $data03 != 4 then # ntables +# return -1 +#endi sql show tables if $rows != 4 then @@ -42,7 +62,7 @@ sql create table t2 (ts timestamp, i int); sql create table t3 (ts timestamp, i int); sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi diff --git a/tests/script/general/db/basic3.sim b/tests/script/tsim/db/basic3.sim similarity index 69% rename from tests/script/general/db/basic3.sim rename to tests/script/tsim/db/basic3.sim index fb64476696..52a587cc16 100644 --- a/tests/script/general/db/basic3.sim +++ b/tests/script/tsim/db/basic3.sim @@ -1,7 +1,24 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start -sleep 2000 + +$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 print =============== create database d1 @@ -12,7 +29,7 @@ sql create table d1.t3 (ts timestamp, i int); sql create table d1.t4 (ts timestamp, i int); sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -20,13 +37,13 @@ if $data00 != d1 then return -1 endi -if $data02 != 4 then +if $data02 != 2 then return -1 endi -if $data03 != 1 then - return -1 -endi +#if $data03 != 4 then +# return -1 +#endi sql show d1.tables if $rows != 4 then @@ -40,7 +57,7 @@ sql create table d2.t2 (ts timestamp, i int); sql create table d2.t3 (ts timestamp, i int); sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi 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..182d40c96a 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 @@ -662,7 +662,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; +} +