diff --git a/include/common/tmsg.h b/include/common/tmsg.h index a21e30c90039c876d387c521e5c224c788479f00..26cbd35e904e19c7d2e89cf9591dc86bc96854c4 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -230,12 +230,12 @@ typedef struct { int32_t totalLen; int32_t len; // head of SSubmitBlk - // int64_t uid; // table unique id - // int64_t suid; // stable id - // int32_t sversion; // data schema version - // int32_t dataLen; // data part length, not including the SSubmitBlk head - // int32_t schemaLen; // schema length, if length is 0, no schema exists - // int16_t numOfRows; // total number of rows in current submit block + int64_t uid; // table unique id + int64_t suid; // stable id + int32_t sversion; // data schema version + int32_t dataLen; // data part length, not including the SSubmitBlk head + int32_t schemaLen; // schema length, if length is 0, no schema exists + int16_t numOfRows; // total number of rows in current submit block // head of SSubmitBlk const void* pMsg; } SSubmitMsgIter; @@ -249,10 +249,10 @@ STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter); // 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts // 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later // 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter -// int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter); -// int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock); -// int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter); -// STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter); +int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter); +int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock); +int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter); +STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter); typedef struct { int32_t index; // index of failed block in submit blocks diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index c71fb266b1a72424ba60ab50353e64c426966a66..1605fe8ac8c9ad1f8a15337d4d72fc5b7ddeedc3 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -25,14 +25,16 @@ extern "C" { #include "tvariant.h" #define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags) -#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema))) -#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo))) +#define TABLE_META_SIZE(pMeta) \ + (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema))) +#define VGROUPS_INFO_SIZE(pInfo) \ + (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo))) typedef struct SRawExprNode { ENodeType nodeType; - char* p; - uint32_t n; - SNode* pNode; + char* p; + uint32_t n; + SNode* pNode; } SRawExprNode; typedef struct SDataType { @@ -45,170 +47,155 @@ typedef struct SDataType { typedef struct SExprNode { ENodeType type; SDataType resType; - char aliasName[TSDB_COL_NAME_LEN]; - SArray* pAssociation; + char aliasName[TSDB_COL_NAME_LEN]; + SArray* pAssociation; } SExprNode; -typedef enum EColumnType { - COLUMN_TYPE_COLUMN = 1, - COLUMN_TYPE_TAG -} EColumnType; +typedef enum EColumnType { COLUMN_TYPE_COLUMN = 1, COLUMN_TYPE_TAG } EColumnType; typedef struct SColumnNode { - SExprNode node; // QUERY_NODE_COLUMN - uint64_t tableId; - int8_t tableType; - col_id_t colId; - EColumnType colType; // column or tag - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - char tableAlias[TSDB_TABLE_NAME_LEN]; - char colName[TSDB_COL_NAME_LEN]; - SNode* pProjectRef; - int16_t dataBlockId; - int16_t slotId; + SExprNode node; // QUERY_NODE_COLUMN + uint64_t tableId; + int8_t tableType; + col_id_t colId; + EColumnType colType; // column or tag + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + char tableAlias[TSDB_TABLE_NAME_LEN]; + char colName[TSDB_COL_NAME_LEN]; + SNode* pProjectRef; + int16_t dataBlockId; + int16_t slotId; } SColumnNode; typedef struct STargetNode { ENodeType type; - int16_t dataBlockId; - int16_t slotId; - SNode* pExpr; + int16_t dataBlockId; + int16_t slotId; + SNode* pExpr; } STargetNode; typedef struct SValueNode { - SExprNode node; // QUERY_NODE_VALUE - char* literal; - bool isDuration; - bool translate; - int16_t placeholderNo; + SExprNode node; // QUERY_NODE_VALUE + char* literal; + bool isDuration; + bool translate; + int16_t placeholderNo; union { - bool b; - int64_t i; + bool b; + int64_t i; uint64_t u; - double d; - char* p; + double d; + char* p; } datum; char unit; } SValueNode; typedef struct SOperatorNode { - SExprNode node; // QUERY_NODE_OPERATOR + SExprNode node; // QUERY_NODE_OPERATOR EOperatorType opType; - SNode* pLeft; - SNode* pRight; + SNode* pLeft; + SNode* pRight; } SOperatorNode; - typedef struct SLogicConditionNode { - SExprNode node; // QUERY_NODE_LOGIC_CONDITION + SExprNode node; // QUERY_NODE_LOGIC_CONDITION ELogicConditionType condType; - SNodeList* pParameterList; + SNodeList* pParameterList; } SLogicConditionNode; typedef struct SNodeListNode { - ENodeType type; // QUERY_NODE_NODE_LIST - SDataType dataType; + ENodeType type; // QUERY_NODE_NODE_LIST + SDataType dataType; SNodeList* pNodeList; } SNodeListNode; typedef struct SFunctionNode { - SExprNode node; // QUERY_NODE_FUNCTION - char functionName[TSDB_FUNC_NAME_LEN]; - int32_t funcId; - int32_t funcType; + SExprNode node; // QUERY_NODE_FUNCTION + char functionName[TSDB_FUNC_NAME_LEN]; + int32_t funcId; + int32_t funcType; SNodeList* pParameterList; - int32_t udfBufSize; + int32_t udfBufSize; } SFunctionNode; typedef struct STableNode { SExprNode node; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - char tableAlias[TSDB_TABLE_NAME_LEN]; - uint8_t precision; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + char tableAlias[TSDB_TABLE_NAME_LEN]; + uint8_t precision; } STableNode; struct STableMeta; typedef struct SRealTableNode { - STableNode table; // QUERY_NODE_REAL_TABLE + STableNode table; // QUERY_NODE_REAL_TABLE struct STableMeta* pMeta; - SVgroupsInfo* pVgroupList; - char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES - double ratio; + SVgroupsInfo* pVgroupList; + char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES + double ratio; } SRealTableNode; typedef struct STempTableNode { - STableNode table; // QUERY_NODE_TEMP_TABLE - SNode* pSubquery; + STableNode table; // QUERY_NODE_TEMP_TABLE + SNode* pSubquery; } STempTableNode; -typedef enum EJoinType { - JOIN_TYPE_INNER = 1 -} EJoinType; +typedef enum EJoinType { JOIN_TYPE_INNER = 1 } EJoinType; typedef struct SJoinTableNode { - STableNode table; // QUERY_NODE_JOIN_TABLE - EJoinType joinType; - SNode* pLeft; - SNode* pRight; - SNode* pOnCond; + STableNode table; // QUERY_NODE_JOIN_TABLE + EJoinType joinType; + SNode* pLeft; + SNode* pRight; + SNode* pOnCond; } SJoinTableNode; -typedef enum EGroupingSetType { - GP_TYPE_NORMAL = 1 -} EGroupingSetType; +typedef enum EGroupingSetType { GP_TYPE_NORMAL = 1 } EGroupingSetType; typedef struct SGroupingSetNode { - ENodeType type; // QUERY_NODE_GROUPING_SET + ENodeType type; // QUERY_NODE_GROUPING_SET EGroupingSetType groupingSetType; - SNodeList* pParameterList; + SNodeList* pParameterList; } SGroupingSetNode; -typedef enum EOrder { - ORDER_ASC = 1, - ORDER_DESC -} EOrder; +typedef enum EOrder { ORDER_ASC = 1, ORDER_DESC } EOrder; -typedef enum ENullOrder { - NULL_ORDER_DEFAULT = 1, - NULL_ORDER_FIRST, - NULL_ORDER_LAST -} ENullOrder; +typedef enum ENullOrder { NULL_ORDER_DEFAULT = 1, NULL_ORDER_FIRST, NULL_ORDER_LAST } ENullOrder; typedef struct SOrderByExprNode { - ENodeType type; // QUERY_NODE_ORDER_BY_EXPR - SNode* pExpr; - EOrder order; + ENodeType type; // QUERY_NODE_ORDER_BY_EXPR + SNode* pExpr; + EOrder order; ENullOrder nullOrder; } SOrderByExprNode; typedef struct SLimitNode { - ENodeType type; // QUERY_NODE_LIMIT - int64_t limit; - int64_t offset; + ENodeType type; // QUERY_NODE_LIMIT + int64_t limit; + int64_t offset; } SLimitNode; typedef struct SStateWindowNode { - ENodeType type; // QUERY_NODE_STATE_WINDOW - SNode* pCol; // timestamp primary key - SNode* pExpr; + ENodeType type; // QUERY_NODE_STATE_WINDOW + SNode* pCol; // timestamp primary key + SNode* pExpr; } SStateWindowNode; typedef struct SSessionWindowNode { - ENodeType type; // QUERY_NODE_SESSION_WINDOW - SColumnNode* pCol; // timestamp primary key - SValueNode* pGap; // gap between two session window(in microseconds) + ENodeType type; // QUERY_NODE_SESSION_WINDOW + SColumnNode* pCol; // timestamp primary key + SValueNode* pGap; // gap between two session window(in microseconds) } SSessionWindowNode; typedef struct SIntervalWindowNode { - ENodeType type; // QUERY_NODE_INTERVAL_WINDOW - SNode* pCol; // timestamp primary key - SNode* pInterval; // SValueNode - SNode* pOffset; // SValueNode - SNode* pSliding; // SValueNode - SNode* pFill; + ENodeType type; // QUERY_NODE_INTERVAL_WINDOW + SNode* pCol; // timestamp primary key + SNode* pInterval; // SValueNode + SNode* pOffset; // SValueNode + SNode* pSliding; // SValueNode + SNode* pFill; } SIntervalWindowNode; typedef enum EFillMode { @@ -221,42 +208,40 @@ typedef enum EFillMode { } EFillMode; typedef struct SFillNode { - ENodeType type; // QUERY_NODE_FILL + ENodeType type; // QUERY_NODE_FILL EFillMode mode; - SNode* pValues; // SNodeListNode + SNode* pValues; // SNodeListNode } SFillNode; typedef struct SSelectStmt { - ENodeType type; // QUERY_NODE_SELECT_STMT - bool isDistinct; - SNodeList* pProjectionList; - SNode* pFromTable; - SNode* pWhere; - SNodeList* pPartitionByList; - SNode* pWindow; - SNodeList* pGroupByList; // SGroupingSetNode - SNode* pHaving; - SNodeList* pOrderByList; // SOrderByExprNode + ENodeType type; // QUERY_NODE_SELECT_STMT + bool isDistinct; + SNodeList* pProjectionList; + SNode* pFromTable; + SNode* pWhere; + SNodeList* pPartitionByList; + SNode* pWindow; + SNodeList* pGroupByList; // SGroupingSetNode + SNode* pHaving; + SNodeList* pOrderByList; // SOrderByExprNode SLimitNode* pLimit; SLimitNode* pSlimit; - char stmtName[TSDB_TABLE_NAME_LEN]; - uint8_t precision; - bool isEmptyResult; + char stmtName[TSDB_TABLE_NAME_LEN]; + uint8_t precision; + bool isEmptyResult; + bool hasAggFuncs; } SSelectStmt; -typedef enum ESetOperatorType { - SET_OP_TYPE_UNION_ALL = 1, - SET_OP_TYPE_UNION -} ESetOperatorType; +typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType; typedef struct SSetOperator { - ENodeType type; // QUERY_NODE_SET_OPERATOR + ENodeType type; // QUERY_NODE_SET_OPERATOR ESetOperatorType opType; - SNodeList* pProjectionList; - SNode* pLeft; - SNode* pRight; - SNodeList* pOrderByList; // SOrderByExprNode - SNode* pLimit; + SNodeList* pProjectionList; + SNode* pLeft; + SNode* pRight; + SNodeList* pOrderByList; // SOrderByExprNode + SNode* pLimit; } SSetOperator; typedef enum ESqlClause { @@ -271,7 +256,6 @@ typedef enum ESqlClause { SQL_CLAUSE_ORDER_BY } ESqlClause; - typedef enum { PAYLOAD_TYPE_KV = 0, PAYLOAD_TYPE_RAW = 1, @@ -281,29 +265,29 @@ typedef struct SVgDataBlocks { SVgroupInfo vg; int32_t numOfTables; // number of tables in current submit block uint32_t size; - char *pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ... + char* pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ... } SVgDataBlocks; typedef struct SVnodeModifOpStmt { - ENodeType nodeType; - ENodeType sqlNodeType; - SArray* pDataBlocks; // data block for each vgroup, SArray. - uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert - uint32_t insertType; // insert data from [file|sql statement| bound statement] - const char* sql; // current sql statement position + ENodeType nodeType; + ENodeType sqlNodeType; + SArray* pDataBlocks; // data block for each vgroup, SArray. + uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert + uint32_t insertType; // insert data from [file|sql statement| bound statement] + const char* sql; // current sql statement position } SVnodeModifOpStmt; typedef struct SExplainOptions { ENodeType type; - bool verbose; - double ratio; + bool verbose; + double ratio; } SExplainOptions; typedef struct SExplainStmt { - ENodeType type; - bool analyze; + ENodeType type; + bool analyze; SExplainOptions* pOptions; - SNode* pQuery; + SNode* pQuery; } SExplainStmt; void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext); @@ -324,10 +308,10 @@ bool nodesIsJsonOp(const SOperatorNode* pOp); bool nodesIsTimeorderQuery(const SNode* pQuery); bool nodesIsTimelineQuery(const SNode* pQuery); -void* nodesGetValueFromNode(SValueNode *pNode); -char* nodesGetStrValueFromNode(SValueNode *pNode); -char *getFillModeString(EFillMode mode); -void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal); +void* nodesGetValueFromNode(SValueNode* pNode); +char* nodesGetStrValueFromNode(SValueNode* pNode); +char* getFillModeString(EFillMode mode); +void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal); #ifdef __cplusplus } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 7abe1186c67e6e864ced25a8811d7d23dd71374e..98d0bae427ae1b5b08769a2f373dbf57cbf0e825 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -93,7 +93,7 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) { return row; } } -#if 0 + // TODO: KEEP one suite of iterator API finally. // 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts // 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later @@ -173,7 +173,7 @@ STSRow *tGetSubmitBlkNextEx(SSubmitBlkIter *pIter) { return row; } } -#endif + int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) { if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1; if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1; diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index dddc17081398a961b5a9122b975da46a632614f8..8af3068b8d5846de4158af32001f70b2d8734381 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -56,7 +56,6 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); void tsdbCleanupReadHandle(tsdbReaderT queryHandle); -int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); typedef enum { TSDB_FILE_HEAD = 0, // .head TSDB_FILE_DATA, // .data diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index fdb43a761b5b0692719baa1832e4562455461e0d..8cabada5113c330161e96a5f5fe008b8656bcda7 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -197,10 +197,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) } memcpy(data, msg, msgLen); - if (msgType == TDMT_VND_SUBMIT) { - if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) { - return -1; - } + // make sure msgType == TDMT_VND_SUBMIT + if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) { + return -1; } SRpcMsg req = { diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index ef7e34686779cdb1234bd0516d0d4b402f2746ef..aeb9f27eab4e7fd4b0d7c307eed88d73127e7c5d 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -33,24 +33,24 @@ STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) { int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t ver) { pReadHandle->pMsg = pMsg; - pMsg->length = htonl(pMsg->length); - pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); + // pMsg->length = htonl(pMsg->length); + // pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); // iterate and convert - if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1; + if (tInitSubmitMsgIterEx(pMsg, &pReadHandle->msgIter) < 0) return -1; while (true) { - if (tGetSubmitMsgNext(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1; + if (tGetSubmitMsgNextEx(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1; if (pReadHandle->pBlock == NULL) break; - pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid); - pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid); - pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion); - pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen); - pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen); - pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows); + // pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid); + // pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid); + // pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion); + // pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen); + // pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen); + // pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows); } - if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1; + if (tInitSubmitMsgIterEx(pMsg, &pReadHandle->msgIter) < 0) return -1; pReadHandle->ver = ver; memset(&pReadHandle->blkIter, 0, sizeof(SSubmitBlkIter)); return 0; @@ -58,7 +58,7 @@ int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t bool tqNextDataBlock(STqReadHandle* pHandle) { while (1) { - if (tGetSubmitMsgNext(&pHandle->msgIter, &pHandle->pBlock) < 0) { + if (tGetSubmitMsgNextEx(&pHandle->msgIter, &pHandle->pBlock) < 0) { return false; } if (pHandle->pBlock == NULL) return false; @@ -68,7 +68,7 @@ bool tqNextDataBlock(STqReadHandle* pHandle) { if (pHandle->tbIdHash == NULL) { return true; } - void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->pBlock->uid, sizeof(int64_t)); + void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->msgIter.uid, sizeof(int64_t)); if (ret != NULL) { /*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/ /*pHandle->pBlock->tid = htonl(pHandle->pBlock->tid);*/ @@ -90,23 +90,25 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p // TODO set to real sversion int32_t sversion = 0; if (pHandle->sver != sversion) { - pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->pBlock->uid, sversion); - + pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion); +#if 0 tb_uid_t quid; - STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->pBlock->uid); + STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->msgIter.uid); if (pTbCfg->type == META_CHILD_TABLE) { quid = pTbCfg->ctbCfg.suid; } else { - quid = pHandle->pBlock->uid; + quid = pHandle->msgIter.uid; } pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, quid, sversion, true); +#endif + pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.suid, sversion, true); pHandle->sver = sversion; } STSchema* pTschema = pHandle->pSchema; SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper; - *pNumOfRows = pHandle->pBlock->numOfRows; + *pNumOfRows = pHandle->msgIter.numOfRows; int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList); if (colNumNeed == 0) { @@ -175,8 +177,8 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p tdSTSRowIterInit(&iter, pTschema); STSRow* row; int32_t curRow = 0; - tInitSubmitBlkIter(pHandle->pBlock, &pHandle->blkIter); - while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) { + tInitSubmitBlkIterEx(&pHandle->msgIter, pHandle->pBlock, &pHandle->blkIter); + while ((row = tGetSubmitBlkNextEx(&pHandle->blkIter)) != NULL) { tdSTSRowIterReset(&iter, row); // get all wanted col of that block for (int32_t i = 0; i < colActual; i++) { diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 9143e8ed1247e06ee81a0578908f81480e47cc1d..806512f07d458a0f9cfd1e603678d671d277d2fa 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -678,9 +678,6 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers return TSDB_CODE_FAILED; } - if (tdScanAndConvertSubmitMsg(pMsg) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_FAILED; - } if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_TDB_INIT_FAILED; @@ -705,25 +702,25 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers SInterval interval = {0}; TSKEY lastWinSKey = INT64_MIN; - if (tInitSubmitMsgIter(pMsg, &msgIter) != TSDB_CODE_SUCCESS) { + if (tInitSubmitMsgIterEx(pMsg, &msgIter) != TSDB_CODE_SUCCESS) { return TSDB_CODE_FAILED; } while (true) { - tGetSubmitMsgNext(&msgIter, &pBlock); + tGetSubmitMsgNextEx(&msgIter, &pBlock); if (!pBlock) break; STSmaWrapper *pSW = NULL; STSma *pTSma = NULL; SSubmitBlkIter blkIter = {0}; - if (tInitSubmitBlkIter(pBlock, &blkIter) != TSDB_CODE_SUCCESS) { + if (tInitSubmitBlkIterEx(&msgIter, pBlock, &blkIter) != TSDB_CODE_SUCCESS) { pSW = tdFreeTSmaWrapper(pSW); break; } while (true) { - STSRow *row = tGetSubmitBlkNext(&blkIter); + STSRow *row = tGetSubmitBlkNextEx(&blkIter); if (!row) { tdFreeTSmaWrapper(pSW); break; @@ -1764,7 +1761,7 @@ int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) { TSDB_CODE_SUCCESS) { return TSDB_CODE_FAILED; } else { - tsdbDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, REPO_ID(pTsdb), pReq->stbCfg.suid); + tsdbDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, REPO_ID(pTsdb), pReq->stbCfg.suid); } return TSDB_CODE_SUCCESS; @@ -1791,7 +1788,7 @@ int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) { return TSDB_CODE_FAILED; } } - if (!taosArrayPush(pStore->tbUids, &uid)) { + if (!taosArrayPush(pStore->tbUids, uid)) { return TSDB_CODE_FAILED; } } @@ -1806,14 +1803,14 @@ int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) { if (uid) { SArray *uidArray = taosHashGet(pStore->uidHash, &suid, sizeof(tb_uid_t)); if (uidArray && ((uidArray = *(SArray **)uidArray))) { - taosArrayPush(uidArray, &uid); + taosArrayPush(uidArray, uid); } else { SArray *pUidArray = taosArrayInit(1, sizeof(tb_uid_t)); if (!pUidArray) { terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } - if (!taosArrayPush(pUidArray, &uid)) { + if (!taosArrayPush(pUidArray, uid)) { terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } @@ -1975,12 +1972,12 @@ static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) { // pMsg->length = htonl(pMsg->length); // pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); - if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1; + if (tInitSubmitMsgIterEx(pMsg, &msgIter) < 0) return -1; while (true) { - if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1; + if (tGetSubmitMsgNextEx(&msgIter, &pBlock) < 0) return -1; if (!pBlock) break; - tsdbUidStorePut(pStore, pBlock->suid, NULL); + tsdbUidStorePut(pStore, msgIter.suid, NULL); } if (terrno != TSDB_CODE_SUCCESS) return -1; @@ -2014,6 +2011,8 @@ int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t in if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) { if (pRSmaInfo->taskInfo[0]) { + tsdbDebug("vgId:%d execute rsma task for qTaskInfo:%p suid:%" PRIu64, REPO_ID(pTsdb), pRSmaInfo->taskInfo[0], + *suid); qSetStreamInput(pRSmaInfo->taskInfo[0], pMsg, inputType); while (1) { SSDataBlock *output; @@ -2026,7 +2025,11 @@ int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t in } taosArrayPush(pResult, output); } - blockDebugShowData(pResult); + if (taosArrayGetSize(pResult) > 0) { + blockDebugShowData(pResult); + } else { + tsdbWarn("vgId:%d no sma data generated since %s", REPO_ID(pTsdb), tstrerror(terrno)); + } } // if (pRSmaInfo->taskInfo[1]) { diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index e9071588973fb3ee3f8e22fd1ed5e767596c6ba6..8365fb9c36bc326d2546756aa0fcac00e9553830 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -81,9 +81,9 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg case TDMT_VND_DROP_TABLE: break; case TDMT_VND_SUBMIT: + tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, ptr, STREAM_DATA_TYPE_SUBMIT_BLOCK); pRsp->msgType = TDMT_VND_SUBMIT_RSP; vnodeProcessSubmitReq(pVnode, ptr, pRsp); - tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, ptr, STREAM_DATA_TYPE_SUBMIT_BLOCK); break; case TDMT_VND_MQ_VG_CHANGE: if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 70087ee46bf3b2f49a8876372c1df75c8cdb582a..805df08f2736dd4df279c7b12db3a758c2a4e210 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -50,7 +50,7 @@ static int32_t translateInOutNum(SFunctionNode* pFunc, char* pErrBuf, int32_t le return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[paraType].bytes, .type = paraType}; return TSDB_CODE_SUCCESS; } @@ -65,7 +65,7 @@ static int32_t translateInNumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_t return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } @@ -81,7 +81,7 @@ static int32_t translateIn2NumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_ return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } @@ -96,7 +96,7 @@ static int32_t translateInOutStr(SFunctionNode* pFunc, char* pErrBuf, int32_t le return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type}; return TSDB_CODE_SUCCESS; } @@ -126,7 +126,7 @@ static int32_t translateSum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { } else if (IS_FLOAT_TYPE(paraType)) { resType = TSDB_DATA_TYPE_DOUBLE; } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[resType].bytes, .type = resType}; return TSDB_CODE_SUCCESS; } @@ -143,9 +143,7 @@ static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in } static int32_t translateTimezone(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type}; - //pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY}; + pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY}; return TSDB_CODE_SUCCESS; } @@ -156,11 +154,11 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if (!IS_NUMERIC_TYPE(para1Type) || (!IS_SIGNED_NUMERIC_TYPE(para2Type) && !IS_UNSIGNED_NUMERIC_TYPE(para2Type))) { + if (!IS_NUMERIC_TYPE(para1Type) || (!IS_SIGNED_NUMERIC_TYPE(para2Type) && !IS_UNSIGNED_NUMERIC_TYPE(para2Type))) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } @@ -168,7 +166,8 @@ static bool validAperventileAlgo(const SValueNode* pVal) { if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) { return false; } - return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest")); + return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || + 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest")); } static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { @@ -185,17 +184,19 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t if (3 == paraNum) { SNode* pPara3 = nodesListGetNode(pFunc->pParameterList, 2); if (QUERY_NODE_VALUE != nodeType(pPara3) || !validAperventileAlgo((SValueNode*)pPara3)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Third parameter algorithm of apercentile must be 'default' or 't-digest'"); + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "Third parameter algorithm of apercentile must be 'default' or 't-digest'"); } } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } static int32_t translateTbnameColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { // pseudo column do not need to check parameters - pFunc->node.resType = (SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}; + pFunc->node.resType = + (SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}; return TSDB_CODE_SUCCESS; } @@ -228,11 +229,12 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); if (QUERY_NODE_COLUMN != nodeType(pPara)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "The parameters of first/last can only be columns"); + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "The parameters of first/last can only be columns"); } uint8_t paraType = ((SExprNode*)pPara)->resType.type; - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[paraType].bytes, .type = paraType}; return TSDB_CODE_SUCCESS; } @@ -245,11 +247,13 @@ static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT }; + pFunc->node.resType = + (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT}; return TSDB_CODE_SUCCESS; } -static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, bool hasSep) { +static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, + int32_t maxParaNum, bool hasSep) { int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); if (paraNum < minParaNum || paraNum > maxParaNum) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); @@ -261,7 +265,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t /* For concat/concat_ws function, if params have NCHAR type, promote the final result to NCHAR */ for (int32_t i = 0; i < paraNum; ++i) { - SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); + SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); uint8_t paraType = ((SExprNode*)pPara)->resType.type; if (!IS_VAR_DATA_TYPE(paraType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); @@ -272,7 +276,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t } for (int32_t i = 0; i < paraNum; ++i) { - SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); + SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); uint8_t paraType = ((SExprNode*)pPara)->resType.type; int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes; int32_t factor = 1; @@ -290,7 +294,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t resultBytes += sepBytes * (paraNum - 3); } - pFunc->node.resType = (SDataType) { .bytes = resultBytes, .type = resultType }; + pFunc->node.resType = (SDataType){.bytes = resultBytes, .type = resultType}; return TSDB_CODE_SUCCESS; } @@ -309,7 +313,7 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; if (!IS_VAR_DATA_TYPE(pPara1->resType.type) || !IS_INTEGER_TYPE(para2Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -320,7 +324,7 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } } - pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type}; return TSDB_CODE_SUCCESS; } @@ -339,7 +343,7 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } int32_t para2Bytes = pFunc->node.resType.bytes; - if (para2Bytes <= 0 || para2Bytes > 1000) { //cast dst var type length limits to 1000 + if (para2Bytes <= 0 || para2Bytes > 1000) { // cast dst var type length limits to 1000 return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); } return TSDB_CODE_SUCCESS; @@ -355,7 +359,7 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = 64, .type = TSDB_DATA_TYPE_BINARY}; + pFunc->node.resType = (SDataType){.bytes = 64, .type = TSDB_DATA_TYPE_BINARY}; return TSDB_CODE_SUCCESS; } @@ -368,7 +372,7 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } @@ -379,11 +383,13 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_ uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || !IS_INTEGER_TYPE(para2Type)) { + if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || + !IS_INTEGER_TYPE(para2Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; + pFunc->node.resType = + (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; return TSDB_CODE_SUCCESS; } @@ -406,7 +412,7 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le } } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } @@ -420,545 +426,440 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BINARY].bytes, .type = TSDB_DATA_TYPE_BINARY}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BINARY].bytes, .type = TSDB_DATA_TYPE_BINARY}; return TSDB_CODE_SUCCESS; } const SBuiltinFuncDefinition funcMgtBuiltins[] = { - { - .name = "count", - .type = FUNCTION_TYPE_COUNT, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateCount, - .dataRequiredFunc = countDataRequired, - .getEnvFunc = getCountFuncEnv, - .initFunc = functionSetup, - .processFunc = countFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "sum", - .type = FUNCTION_TYPE_SUM, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateSum, - .dataRequiredFunc = statisDataRequired, - .getEnvFunc = getSumFuncEnv, - .initFunc = functionSetup, - .processFunc = sumFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "min", - .type = FUNCTION_TYPE_MIN, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateInOutNum, - .dataRequiredFunc = statisDataRequired, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = minFunctionSetup, - .processFunc = minFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "max", - .type = FUNCTION_TYPE_MAX, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateInOutNum, - .dataRequiredFunc = statisDataRequired, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "stddev", - .type = FUNCTION_TYPE_STDDEV, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = getStddevFuncEnv, - .initFunc = stddevFunctionSetup, - .processFunc = stddevFunction, - .finalizeFunc = stddevFinalize - }, - { - .name = "avg", - .type = FUNCTION_TYPE_AVG, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = getAvgFuncEnv, - .initFunc = avgFunctionSetup, - .processFunc = avgFunction, - .finalizeFunc = avgFinalize - }, - { - .name = "percentile", - .type = FUNCTION_TYPE_PERCENTILE, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translatePercentile, - .getEnvFunc = getPercentileFuncEnv, - .initFunc = percentileFunctionSetup, - .processFunc = percentileFunction, - .finalizeFunc = percentileFinalize - }, - { - .name = "apercentile", - .type = FUNCTION_TYPE_APERCENTILE, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateApercentile, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "top", - .type = FUNCTION_TYPE_TOP, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateTop, - .getEnvFunc = getTopBotFuncEnv, - .initFunc = functionSetup, - .processFunc = topFunction, - .finalizeFunc = topBotFinalize, - }, - { - .name = "bottom", - .type = FUNCTION_TYPE_BOTTOM, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateBottom, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "spread", - .type = FUNCTION_TYPE_SPREAD, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateSpread, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "last_row", - .type = FUNCTION_TYPE_LAST_ROW, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, - .translateFunc = translateLastRow, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "first", - .type = FUNCTION_TYPE_FIRST, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, - .translateFunc = translateFirstLast, - .getEnvFunc = getFirstLastFuncEnv, - .initFunc = functionSetup, - .processFunc = firstFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "last", - .type = FUNCTION_TYPE_LAST, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, - .translateFunc = translateFirstLast, - .getEnvFunc = getFirstLastFuncEnv, - .initFunc = functionSetup, - .processFunc = lastFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "diff", - .type = FUNCTION_TYPE_DIFF, - .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = getDiffFuncEnv, - .initFunc = diffFunctionSetup, - .processFunc = diffFunction, - .finalizeFunc = functionFinalize - }, - { - .name = "abs", - .type = FUNCTION_TYPE_ABS, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = absFunction, - .finalizeFunc = NULL - }, - { - .name = "log", - .type = FUNCTION_TYPE_LOG, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateIn2NumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = logFunction, - .finalizeFunc = NULL - }, - { - .name = "pow", - .type = FUNCTION_TYPE_POW, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateIn2NumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = powFunction, - .finalizeFunc = NULL - }, - { - .name = "sqrt", - .type = FUNCTION_TYPE_SQRT, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = sqrtFunction, - .finalizeFunc = NULL - }, - { - .name = "ceil", - .type = FUNCTION_TYPE_CEIL, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = ceilFunction, - .finalizeFunc = NULL - }, - { - .name = "floor", - .type = FUNCTION_TYPE_FLOOR, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = floorFunction, - .finalizeFunc = NULL - }, - { - .name = "round", - .type = FUNCTION_TYPE_ROUND, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = roundFunction, - .finalizeFunc = NULL - }, - { - .name = "sin", - .type = FUNCTION_TYPE_SIN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = sinFunction, - .finalizeFunc = NULL - }, - { - .name = "cos", - .type = FUNCTION_TYPE_COS, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = cosFunction, - .finalizeFunc = NULL - }, - { - .name = "tan", - .type = FUNCTION_TYPE_TAN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = tanFunction, - .finalizeFunc = NULL - }, - { - .name = "asin", - .type = FUNCTION_TYPE_ASIN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = asinFunction, - .finalizeFunc = NULL - }, - { - .name = "acos", - .type = FUNCTION_TYPE_ACOS, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = acosFunction, - .finalizeFunc = NULL - }, - { - .name = "atan", - .type = FUNCTION_TYPE_ATAN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = atanFunction, - .finalizeFunc = NULL - }, - { - .name = "length", - .type = FUNCTION_TYPE_LENGTH, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateLength, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = lengthFunction, - .finalizeFunc = NULL - }, - { - .name = "char_length", - .type = FUNCTION_TYPE_CHAR_LENGTH, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateLength, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = charLengthFunction, - .finalizeFunc = NULL - }, - { - .name = "concat", - .type = FUNCTION_TYPE_CONCAT, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateConcat, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = concatFunction, - .finalizeFunc = NULL - }, - { - .name = "concat_ws", - .type = FUNCTION_TYPE_CONCAT_WS, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateConcatWs, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = concatWsFunction, - .finalizeFunc = NULL - }, - { - .name = "lower", - .type = FUNCTION_TYPE_LOWER, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = lowerFunction, - .finalizeFunc = NULL - }, - { - .name = "upper", - .type = FUNCTION_TYPE_UPPER, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = upperFunction, - .finalizeFunc = NULL - }, - { - .name = "ltrim", - .type = FUNCTION_TYPE_LTRIM, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = ltrimFunction, - .finalizeFunc = NULL - }, - { - .name = "rtrim", - .type = FUNCTION_TYPE_RTRIM, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = rtrimFunction, - .finalizeFunc = NULL - }, - { - .name = "substr", - .type = FUNCTION_TYPE_SUBSTR, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateSubstr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = substrFunction, - .finalizeFunc = NULL - }, - { - .name = "cast", - .type = FUNCTION_TYPE_CAST, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateCast, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = castFunction, - .finalizeFunc = NULL - }, - { - .name = "to_iso8601", - .type = FUNCTION_TYPE_TO_ISO8601, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateToIso8601, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = toISO8601Function, - .finalizeFunc = NULL - }, - { - .name = "to_unixtimestamp", - .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateToUnixtimestamp, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = toUnixtimestampFunction, - .finalizeFunc = NULL - }, - { - .name = "timetruncate", - .type = FUNCTION_TYPE_TIMETRUNCATE, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateTimeTruncate, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = timeTruncateFunction, - .finalizeFunc = NULL - }, - { - .name = "timediff", - .type = FUNCTION_TYPE_TIMEDIFF, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateTimeDiff, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = timeDiffFunction, - .finalizeFunc = NULL - }, - { - .name = "now", - .type = FUNCTION_TYPE_NOW, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = nowFunction, - .finalizeFunc = NULL - }, - { - .name = "today", - .type = FUNCTION_TYPE_TODAY, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = todayFunction, - .finalizeFunc = NULL - }, - { - .name = "timezone", - .type = FUNCTION_TYPE_TIMEZONE, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateTimezone, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = timezoneFunction, - .finalizeFunc = NULL - }, - { - .name = "_rowts", - .type = FUNCTION_TYPE_ROWTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = NULL, - .finalizeFunc = NULL - }, - { - .name = "tbname", - .type = FUNCTION_TYPE_TBNAME, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .translateFunc = translateTbnameColumn, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = NULL, - .finalizeFunc = NULL - }, - { - .name = "_qstartts", - .type = FUNCTION_TYPE_QSTARTTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = qStartTsFunction, - .finalizeFunc = NULL - }, - { - .name = "_qendts", - .type = FUNCTION_TYPE_QENDTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = qEndTsFunction, - .finalizeFunc = NULL - }, - { - .name = "_wstartts", - .type = FUNCTION_TYPE_WSTARTTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = winStartTsFunction, - .finalizeFunc = NULL - }, - { - .name = "_wendts", - .type = FUNCTION_TYPE_WENDTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = winEndTsFunction, - .finalizeFunc = NULL - }, - { - .name = "_wduration", - .type = FUNCTION_TYPE_WDURATION, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateWduration, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = winDurFunction, - .finalizeFunc = NULL - }, - { - .name = "to_json", - .type = FUNCTION_TYPE_TO_JSON, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateToJson, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = toJsonFunction, - .finalizeFunc = NULL - } -}; + {.name = "count", + .type = FUNCTION_TYPE_COUNT, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateCount, + .dataRequiredFunc = countDataRequired, + .getEnvFunc = getCountFuncEnv, + .initFunc = functionSetup, + .processFunc = countFunction, + .finalizeFunc = functionFinalize}, + {.name = "sum", + .type = FUNCTION_TYPE_SUM, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateSum, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getSumFuncEnv, + .initFunc = functionSetup, + .processFunc = sumFunction, + .finalizeFunc = functionFinalize}, + {.name = "min", + .type = FUNCTION_TYPE_MIN, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateInOutNum, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = minFunctionSetup, + .processFunc = minFunction, + .finalizeFunc = functionFinalize}, + {.name = "max", + .type = FUNCTION_TYPE_MAX, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateInOutNum, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize}, + {.name = "stddev", + .type = FUNCTION_TYPE_STDDEV, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = getStddevFuncEnv, + .initFunc = stddevFunctionSetup, + .processFunc = stddevFunction, + .finalizeFunc = stddevFinalize}, + {.name = "avg", + .type = FUNCTION_TYPE_AVG, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = getAvgFuncEnv, + .initFunc = avgFunctionSetup, + .processFunc = avgFunction, + .finalizeFunc = avgFinalize}, + {.name = "percentile", + .type = FUNCTION_TYPE_PERCENTILE, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translatePercentile, + .getEnvFunc = getPercentileFuncEnv, + .initFunc = percentileFunctionSetup, + .processFunc = percentileFunction, + .finalizeFunc = percentileFinalize}, + {.name = "apercentile", + .type = FUNCTION_TYPE_APERCENTILE, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateApercentile, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize}, + { + .name = "top", + .type = FUNCTION_TYPE_TOP, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateTop, + .getEnvFunc = getTopBotFuncEnv, + .initFunc = functionSetup, + .processFunc = topFunction, + .finalizeFunc = topBotFinalize, + }, + {.name = "bottom", + .type = FUNCTION_TYPE_BOTTOM, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateBottom, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize}, + {.name = "spread", + .type = FUNCTION_TYPE_SPREAD, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateSpread, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize}, + {.name = "last_row", + .type = FUNCTION_TYPE_LAST_ROW, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, + .translateFunc = translateLastRow, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize}, + {.name = "first", + .type = FUNCTION_TYPE_FIRST, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, + .translateFunc = translateFirstLast, + .getEnvFunc = getFirstLastFuncEnv, + .initFunc = functionSetup, + .processFunc = firstFunction, + .finalizeFunc = functionFinalize}, + {.name = "last", + .type = FUNCTION_TYPE_LAST, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, + .translateFunc = translateFirstLast, + .getEnvFunc = getFirstLastFuncEnv, + .initFunc = functionSetup, + .processFunc = lastFunction, + .finalizeFunc = functionFinalize}, + {.name = "diff", + .type = FUNCTION_TYPE_DIFF, + .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = getDiffFuncEnv, + .initFunc = diffFunctionSetup, + .processFunc = diffFunction, + .finalizeFunc = functionFinalize}, + {.name = "abs", + .type = FUNCTION_TYPE_ABS, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = absFunction, + .finalizeFunc = NULL}, + {.name = "log", + .type = FUNCTION_TYPE_LOG, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateIn2NumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = logFunction, + .finalizeFunc = NULL}, + {.name = "pow", + .type = FUNCTION_TYPE_POW, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateIn2NumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = powFunction, + .finalizeFunc = NULL}, + {.name = "sqrt", + .type = FUNCTION_TYPE_SQRT, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = sqrtFunction, + .finalizeFunc = NULL}, + {.name = "ceil", + .type = FUNCTION_TYPE_CEIL, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = ceilFunction, + .finalizeFunc = NULL}, + {.name = "floor", + .type = FUNCTION_TYPE_FLOOR, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = floorFunction, + .finalizeFunc = NULL}, + {.name = "round", + .type = FUNCTION_TYPE_ROUND, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = roundFunction, + .finalizeFunc = NULL}, + {.name = "sin", + .type = FUNCTION_TYPE_SIN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = sinFunction, + .finalizeFunc = NULL}, + {.name = "cos", + .type = FUNCTION_TYPE_COS, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = cosFunction, + .finalizeFunc = NULL}, + {.name = "tan", + .type = FUNCTION_TYPE_TAN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = tanFunction, + .finalizeFunc = NULL}, + {.name = "asin", + .type = FUNCTION_TYPE_ASIN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = asinFunction, + .finalizeFunc = NULL}, + {.name = "acos", + .type = FUNCTION_TYPE_ACOS, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = acosFunction, + .finalizeFunc = NULL}, + {.name = "atan", + .type = FUNCTION_TYPE_ATAN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = atanFunction, + .finalizeFunc = NULL}, + {.name = "length", + .type = FUNCTION_TYPE_LENGTH, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateLength, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = lengthFunction, + .finalizeFunc = NULL}, + {.name = "char_length", + .type = FUNCTION_TYPE_CHAR_LENGTH, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateLength, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = charLengthFunction, + .finalizeFunc = NULL}, + {.name = "concat", + .type = FUNCTION_TYPE_CONCAT, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateConcat, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = concatFunction, + .finalizeFunc = NULL}, + {.name = "concat_ws", + .type = FUNCTION_TYPE_CONCAT_WS, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateConcatWs, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = concatWsFunction, + .finalizeFunc = NULL}, + {.name = "lower", + .type = FUNCTION_TYPE_LOWER, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = lowerFunction, + .finalizeFunc = NULL}, + {.name = "upper", + .type = FUNCTION_TYPE_UPPER, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = upperFunction, + .finalizeFunc = NULL}, + {.name = "ltrim", + .type = FUNCTION_TYPE_LTRIM, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = ltrimFunction, + .finalizeFunc = NULL}, + {.name = "rtrim", + .type = FUNCTION_TYPE_RTRIM, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = rtrimFunction, + .finalizeFunc = NULL}, + {.name = "substr", + .type = FUNCTION_TYPE_SUBSTR, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateSubstr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = substrFunction, + .finalizeFunc = NULL}, + {.name = "cast", + .type = FUNCTION_TYPE_CAST, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateCast, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = castFunction, + .finalizeFunc = NULL}, + {.name = "to_iso8601", + .type = FUNCTION_TYPE_TO_ISO8601, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToIso8601, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toISO8601Function, + .finalizeFunc = NULL}, + {.name = "to_unixtimestamp", + .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToUnixtimestamp, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toUnixtimestampFunction, + .finalizeFunc = NULL}, + {.name = "timetruncate", + .type = FUNCTION_TYPE_TIMETRUNCATE, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimeTruncate, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeTruncateFunction, + .finalizeFunc = NULL}, + {.name = "timediff", + .type = FUNCTION_TYPE_TIMEDIFF, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimeDiff, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeDiffFunction, + .finalizeFunc = NULL}, + {.name = "now", + .type = FUNCTION_TYPE_NOW, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = nowFunction, + .finalizeFunc = NULL}, + {.name = "today", + .type = FUNCTION_TYPE_TODAY, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = todayFunction, + .finalizeFunc = NULL}, + {.name = "timezone", + .type = FUNCTION_TYPE_TIMEZONE, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimezone, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timezoneFunction, + .finalizeFunc = NULL}, + {.name = "_rowts", + .type = FUNCTION_TYPE_ROWTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL}, + {.name = "tbname", + .type = FUNCTION_TYPE_TBNAME, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .translateFunc = translateTbnameColumn, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL}, + {.name = "_qstartts", + .type = FUNCTION_TYPE_QSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = qStartTsFunction, + .finalizeFunc = NULL}, + {.name = "_qendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = qEndTsFunction, + .finalizeFunc = NULL}, + {.name = "_wstartts", + .type = FUNCTION_TYPE_WSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winStartTsFunction, + .finalizeFunc = NULL}, + {.name = "_wendts", + .type = FUNCTION_TYPE_WENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winEndTsFunction, + .finalizeFunc = NULL}, + {.name = "_wduration", + .type = FUNCTION_TYPE_WDURATION, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateWduration, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winDurFunction, + .finalizeFunc = NULL}, + {.name = "to_json", + .type = FUNCTION_TYPE_TO_JSON, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToJson, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toJsonFunction, + .finalizeFunc = NULL}}; const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); diff --git a/source/libs/nodes/inc/nodesUtil.h b/source/libs/nodes/inc/nodesUtil.h index c6233ba9808439f3e0132e0904140638051307fe..e092c18834b7159deb4ec5a76496a82e7f7b03db 100644 --- a/source/libs/nodes/inc/nodesUtil.h +++ b/source/libs/nodes/inc/nodesUtil.h @@ -20,17 +20,39 @@ extern "C" { #endif -#define nodesFatal(...) qFatal("NODES: " __VA_ARGS__) -#define nodesError(...) qError("NODES: " __VA_ARGS__) -#define nodesWarn(...) qWarn("NODES: " __VA_ARGS__) -#define nodesInfo(...) qInfo("NODES: " __VA_ARGS__) -#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__) -#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__) +#define nodesFatal(...) qFatal("NODES: " __VA_ARGS__) +#define nodesError(...) qError("NODES: " __VA_ARGS__) +#define nodesWarn(...) qWarn("NODES: " __VA_ARGS__) +#define nodesInfo(...) qInfo("NODES: " __VA_ARGS__) +#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__) +#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__) -#define NODES_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define NODES_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define NODES_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define NODES_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define NODES_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) + +#define NODES_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ + } while (0) #ifdef __cplusplus } diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 975036575de0a57ac3e038812599a3308e9df940..89cacf9298f854ab31c7edc84769339572189678 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -19,71 +19,71 @@ #include "taos.h" #include "taoserror.h" -#define COPY_ALL_SCALAR_FIELDS \ - do { \ +#define COPY_ALL_SCALAR_FIELDS \ + do { \ memcpy((pDst), (pSrc), sizeof(*pSrc)); \ - } while (0) + } while (0) -#define COPY_SCALAR_FIELD(fldname) \ - do { \ +#define COPY_SCALAR_FIELD(fldname) \ + do { \ (pDst)->fldname = (pSrc)->fldname; \ - } while (0) + } while (0) -#define COPY_CHAR_ARRAY_FIELD(fldname) \ - do { \ +#define COPY_CHAR_ARRAY_FIELD(fldname) \ + do { \ strcpy((pDst)->fldname, (pSrc)->fldname); \ - } while (0) + } while (0) -#define COPY_CHAR_POINT_FIELD(fldname) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ +#define COPY_CHAR_POINT_FIELD(fldname) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = strdup((pSrc)->fldname); \ - } while (0) + } while (0) -#define CLONE_NODE_FIELD(fldname) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ +#define CLONE_NODE_FIELD(fldname) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = nodesCloneNode((pSrc)->fldname); \ - if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)(pDst)); \ - return NULL; \ - } \ - } while (0) - -#define CLONE_NODE_LIST_FIELD(fldname) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ + if (NULL == (pDst)->fldname) { \ + nodesDestroyNode((SNode*)(pDst)); \ + return NULL; \ + } \ + } while (0) + +#define CLONE_NODE_LIST_FIELD(fldname) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = nodesCloneList((pSrc)->fldname); \ - if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)(pDst)); \ - return NULL; \ - } \ - } while (0) - -#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ + if (NULL == (pDst)->fldname) { \ + nodesDestroyNode((SNode*)(pDst)); \ + return NULL; \ + } \ + } while (0) + +#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = cloneFunc((pSrc)->fldname); \ - if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)(pDst)); \ - return NULL; \ - } \ - } while (0) - -#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \ - do { \ + if (NULL == (pDst)->fldname) { \ + nodesDestroyNode((SNode*)(pDst)); \ + return NULL; \ + } \ + } while (0) + +#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \ + do { \ if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \ - return NULL; \ - } \ - } while (0) + return NULL; \ + } \ + } while (0) static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) { COPY_SCALAR_FIELD(type); @@ -201,7 +201,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) { } static STableMeta* tableMetaClone(const STableMeta* pSrc) { - int32_t len = TABLE_META_SIZE(pSrc); + int32_t len = TABLE_META_SIZE(pSrc); STableMeta* pDst = taosMemoryMalloc(len); if (NULL == pDst) { return NULL; @@ -211,7 +211,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) { } static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) { - int32_t len = VGROUPS_INFO_SIZE(pSrc); + int32_t len = VGROUPS_INFO_SIZE(pSrc); SVgroupsInfo* pDst = taosMemoryMalloc(len); if (NULL == pDst) { return NULL; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 1d54448e5580aa56901b06dd056c7a7fa8e323cd..f8a56109ee67621e9187356342385a4b4703cdd6 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -16,8 +16,8 @@ #include "cmdnodes.h" #include "nodesUtil.h" #include "plannodes.h" -#include "querynodes.h" #include "query.h" +#include "querynodes.h" #include "taoserror.h" #include "tjson.h" @@ -29,7 +29,7 @@ static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode); const char* nodesNodeName(ENodeType type) { switch (type) { case QUERY_NODE_COLUMN: - return "Column"; + return "Column"; case QUERY_NODE_VALUE: return "Value"; case QUERY_NODE_OPERATOR: @@ -306,7 +306,7 @@ static int32_t tableComInfoToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkTableComInfoRowSize, pNode->rowSize); } - + return code; } @@ -323,7 +323,7 @@ static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetNumberValue(pJson, jkTableComInfoRowSize, pNode->rowSize); } - + return code; } @@ -345,7 +345,7 @@ static int32_t schemaToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddStringToObject(pJson, jkSchemaName, pNode->name); } - + return code; } @@ -362,7 +362,7 @@ static int32_t jsonToSchema(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetStringValue(pJson, jkSchemaName, pNode->name); } - + return code; } @@ -398,7 +398,8 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) { code = tjsonAddObject(pJson, jkTableMetaComInfo, tableComInfoToJson, &pNode->tableInfo); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema), TABLE_TOTAL_COL_NUM(pNode)); + code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema), + TABLE_TOTAL_COL_NUM(pNode)); } return code; @@ -713,13 +714,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) { return code; } -static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) { - return physiScanNodeToJson(pObj, pJson); -} +static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); } -static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { - return jsonToPhysiScanNode(pJson, pObj); -} +static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); } static const char* jkTableScanPhysiPlanScanCount = "ScanCount"; static const char* jkTableScanPhysiPlanReverseScanCount = "ReverseScanCount"; @@ -732,7 +729,7 @@ static const char* jkTableScanPhysiPlanInterval = "Interval"; static const char* jkTableScanPhysiPlanOffset = "Offset"; static const char* jkTableScanPhysiPlanSliding = "Sliding"; static const char* jkTableScanPhysiPlanIntervalUnit = "intervalUnit"; -static const char* jkTableScanPhysiPlanSlidingUnit = "slidingUnit"; +static const char* jkTableScanPhysiPlanSlidingUnit = "slidingUnit"; static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) { const STableScanPhysiNode* pNode = (const STableScanPhysiNode*)pObj; @@ -822,13 +819,9 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) { return code; } -static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { - return physiScanNodeToJson(pObj, pJson); -} +static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); } -static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { - return jsonToPhysiScanNode(pJson, pObj); -} +static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); } static const char* jkEndPointFqdn = "Fqdn"; static const char* jkEndPointPort = "Port"; @@ -1178,7 +1171,7 @@ static const char* jkIntervalPhysiPlanInterval = "Interval"; static const char* jkIntervalPhysiPlanOffset = "Offset"; static const char* jkIntervalPhysiPlanSliding = "Sliding"; static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit"; -static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; +static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; static const char* jkIntervalPhysiPlanFill = "Fill"; static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { @@ -1331,13 +1324,9 @@ static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) { return jsonToNodeObject(pJson, jkDataSinkInputDataBlockDesc, (SNode**)&pNode->pInputDataBlockDesc); } -static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { - return physicDataSinkNodeToJson(pObj, pJson); -} +static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return physicDataSinkNodeToJson(pObj, pJson); } -static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { - return jsonToPhysicDataSinkNode(pJson, pObj); -} +static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { return jsonToPhysicDataSinkNode(pJson, pObj); } static const char* jkSubplanIdQueryId = "QueryId"; static const char* jkSubplanIdGroupId = "GroupId"; @@ -1709,7 +1698,7 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) { break; } - return code ; + return code; } static int32_t valueNodeToJson(const void* pObj, SJson* pJson) { @@ -2015,7 +2004,8 @@ static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) { int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups); if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), pNode->numOfVgroups); + code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), + pNode->numOfVgroups); } return code; @@ -2381,6 +2371,7 @@ static const char* jkSelectStmtOrderBy = "OrderBy"; static const char* jkSelectStmtLimit = "Limit"; static const char* jkSelectStmtSlimit = "Slimit"; static const char* jkSelectStmtStmtName = "StmtName"; +static const char* jkSelectStmtHasAggFuncs = "HasAggFuncs"; static int32_t selectStmtTojson(const void* pObj, SJson* pJson) { const SSelectStmt* pNode = (const SSelectStmt*)pObj; @@ -2419,6 +2410,9 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddBoolToObject(pJson, jkSelectStmtHasAggFuncs, pNode->hasAggFuncs); + } return code; } @@ -2460,6 +2454,9 @@ static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBoolValue(pJson, jkSelectStmtHasAggFuncs, &pNode->hasAggFuncs); + } return code; } @@ -2660,10 +2657,10 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToPhysiTagScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: return jsonToPhysiTableScanNode(pJson, pObj); - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: return jsonToPhysiStreamScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: - return jsonToPhysiSysTableScanNode(pJson, pObj); + return jsonToPhysiSysTableScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return jsonToPhysiProjectNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_JOIN: diff --git a/source/libs/nodes/src/nodesEqualFuncs.c b/source/libs/nodes/src/nodesEqualFuncs.c index 4185754355ddfd98fc9c7243ab961ed727a8d4d4..bd1662db4c9984d1961071fd6ef6342afff142f9 100644 --- a/source/libs/nodes/src/nodesEqualFuncs.c +++ b/source/libs/nodes/src/nodesEqualFuncs.c @@ -15,32 +15,27 @@ #include "querynodes.h" -#define COMPARE_SCALAR_FIELD(fldname) \ - do { \ - if (a->fldname != b->fldname) \ - return false; \ - } while (0) - -#define COMPARE_STRING(a, b) \ - (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b)) - -#define COMPARE_STRING_FIELD(fldname) \ - do { \ - if (!COMPARE_STRING(a->fldname, b->fldname)) \ - return false; \ - } while (0) - -#define COMPARE_NODE_FIELD(fldname) \ - do { \ - if (!nodesEqualNode(a->fldname, b->fldname)) \ - return false; \ - } while (0) - -#define COMPARE_NODE_LIST_FIELD(fldname) \ - do { \ - if (!nodeNodeListEqual(a->fldname, b->fldname)) \ - return false; \ - } while (0) +#define COMPARE_SCALAR_FIELD(fldname) \ + do { \ + if (a->fldname != b->fldname) return false; \ + } while (0) + +#define COMPARE_STRING(a, b) (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b)) + +#define COMPARE_STRING_FIELD(fldname) \ + do { \ + if (!COMPARE_STRING(a->fldname, b->fldname)) return false; \ + } while (0) + +#define COMPARE_NODE_FIELD(fldname) \ + do { \ + if (!nodesEqualNode(a->fldname, b->fldname)) return false; \ + } while (0) + +#define COMPARE_NODE_LIST_FIELD(fldname) \ + do { \ + if (!nodeNodeListEqual(a->fldname, b->fldname)) return false; \ + } while (0) static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) { if (a == b) { @@ -55,7 +50,7 @@ static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) { return false; } - SNode* na, *nb; + SNode *na, *nb; FORBOTH(na, a, nb, b) { if (!nodesEqualNode(na, nb)) { return false; @@ -125,7 +120,7 @@ bool nodesEqualNode(const SNodeptr a, const SNodeptr b) { case QUERY_NODE_GROUPING_SET: case QUERY_NODE_ORDER_BY_EXPR: case QUERY_NODE_LIMIT: - return false; // todo + return false; // todo default: break; } diff --git a/source/libs/nodes/src/nodesToSQLFuncs.c b/source/libs/nodes/src/nodesToSQLFuncs.c index aa1336b59d849436e3dbac4072b462a8afb8a74d..3b129740e81b4743dbae25dd82da36ac2a49407e 100644 --- a/source/libs/nodes/src/nodesToSQLFuncs.c +++ b/source/libs/nodes/src/nodesToSQLFuncs.c @@ -21,9 +21,35 @@ #include "taoserror.h" #include "thash.h" -char *gOperatorStr[] = {NULL, "+", "-", "*", "/", "%", "-", "&", "|", ">", ">=", "<", "<=", "=", "<>", - "IN", "NOT IN", "LIKE", "NOT LIKE", "MATCH", "NMATCH", "IS NULL", "IS NOT NULL", - "IS TRUE", "IS FALSE", "IS UNKNOWN", "IS NOT TRUE", "IS NOT FALSE", "IS NOT UNKNOWN"}; +char *gOperatorStr[] = {NULL, + "+", + "-", + "*", + "/", + "%", + "-", + "&", + "|", + ">", + ">=", + "<", + "<=", + "=", + "<>", + "IN", + "NOT IN", + "LIKE", + "NOT LIKE", + "MATCH", + "NMATCH", + "IS NULL", + "IS NOT NULL", + "IS TRUE", + "IS FALSE", + "IS UNKNOWN", + "IS NOT TRUE", + "IS NOT FALSE", + "IS NOT UNKNOWN"}; char *gLogicConditionStr[] = {"AND", "OR", "NOT"}; int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { @@ -33,36 +59,36 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { if (colNode->dbName[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName); } - + if (colNode->tableAlias[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias); } else if (colNode->tableName[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName); } - + if (colNode->tableAlias[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->colName); } else { *len += snprintf(buf + *len, bufSize - *len, "%s", colNode->colName); } - + return TSDB_CODE_SUCCESS; } - case QUERY_NODE_VALUE:{ + case QUERY_NODE_VALUE: { SValueNode *colNode = (SValueNode *)pNode; - char *t = nodesGetStrValueFromNode(colNode); + char *t = nodesGetStrValueFromNode(colNode); if (NULL == t) { nodesError("fail to get str value from valueNode"); NODES_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - + *len += snprintf(buf + *len, bufSize - *len, "%s", t); taosMemoryFree(t); - + return TSDB_CODE_SUCCESS; } case QUERY_NODE_OPERATOR: { - SOperatorNode* pOpNode = (SOperatorNode*)pNode; + SOperatorNode *pOpNode = (SOperatorNode *)pNode; *len += snprintf(buf + *len, bufSize - *len, "("); if (pOpNode->pLeft) { NODES_ERR_RET(nodesNodeToSQL(pOpNode->pLeft, buf, bufSize, len)); @@ -72,24 +98,24 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { nodesError("unknown operation type:%d", pOpNode->opType); NODES_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - + *len += snprintf(buf + *len, bufSize - *len, " %s ", gOperatorStr[pOpNode->opType]); if (pOpNode->pRight) { NODES_ERR_RET(nodesNodeToSQL(pOpNode->pRight, buf, bufSize, len)); - } + } *len += snprintf(buf + *len, bufSize - *len, ")"); return TSDB_CODE_SUCCESS; } - case QUERY_NODE_LOGIC_CONDITION:{ - SLogicConditionNode* pLogicNode = (SLogicConditionNode*)pNode; - SNode* node = NULL; - bool first = true; - + case QUERY_NODE_LOGIC_CONDITION: { + SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode; + SNode *node = NULL; + bool first = true; + *len += snprintf(buf + *len, bufSize - *len, "("); - + FOREACH(node, pLogicNode->pParameterList) { if (!first) { *len += snprintf(buf + *len, bufSize - *len, " %s ", gLogicConditionStr[pLogicNode->condType]); @@ -102,13 +128,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { return TSDB_CODE_SUCCESS; } - case QUERY_NODE_FUNCTION:{ - SFunctionNode* pFuncNode = (SFunctionNode*)pNode; - SNode* node = NULL; - bool first = true; - + case QUERY_NODE_FUNCTION: { + SFunctionNode *pFuncNode = (SFunctionNode *)pNode; + SNode *node = NULL; + bool first = true; + *len += snprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName); - + FOREACH(node, pFuncNode->pParameterList) { if (!first) { *len += snprintf(buf + *len, bufSize - *len, ", "); @@ -121,13 +147,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { return TSDB_CODE_SUCCESS; } - case QUERY_NODE_NODE_LIST:{ - SNodeListNode* pListNode = (SNodeListNode *)pNode; - SNode* node = NULL; - bool first = true; - + case QUERY_NODE_NODE_LIST: { + SNodeListNode *pListNode = (SNodeListNode *)pNode; + SNode *node = NULL; + bool first = true; + *len += snprintf(buf + *len, bufSize - *len, "("); - + FOREACH(node, pListNode->pNodeList) { if (!first) { *len += snprintf(buf + *len, bufSize - *len, ", "); @@ -135,7 +161,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len)); first = false; } - + *len += snprintf(buf + *len, bufSize - *len, ")"); return TSDB_CODE_SUCCESS; @@ -143,7 +169,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { default: break; } - + nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type)); NODES_RET(TSDB_CODE_QRY_APP_ERROR); } diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index e74ecfd0f4563f904ca73cba7b2681b41c45e548..84eccf85325083265025efaa156276f68fece4ff 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include "querynodes.h" #include "plannodes.h" +#include "querynodes.h" typedef enum ETraversalOrder { TRAVERSAL_PREORDER = 1, @@ -29,7 +29,8 @@ static EDealRes walkExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeWalk static EDealRes walkPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext); static EDealRes walkPhysiPlans(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext); -static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext, FNodeDispatcher dispatcher) { +static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext, + FNodeDispatcher dispatcher) { if (NULL == pNode) { return DEAL_RES_CONTINUE; } @@ -77,7 +78,7 @@ static EDealRes dispatchExpr(SNode* pNode, ETraversalOrder order, FNodeWalker wa break; case QUERY_NODE_REAL_TABLE: case QUERY_NODE_TEMP_TABLE: - break; // todo + break; // todo case QUERY_NODE_JOIN_TABLE: { SJoinTableNode* pJoinTableNode = (SJoinTableNode*)pNode; res = walkExpr(pJoinTableNode->pLeft, order, walker, pContext); @@ -217,7 +218,7 @@ static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewrit break; case QUERY_NODE_REAL_TABLE: case QUERY_NODE_TEMP_TABLE: - break; // todo + break; // todo case QUERY_NODE_JOIN_TABLE: { SJoinTableNode* pJoinTableNode = (SJoinTableNode*)pNode; res = rewriteExpr(&(pJoinTableNode->pLeft), order, rewriter, pContext); @@ -339,7 +340,7 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa case SQL_CLAUSE_DISTINCT: nodesWalkExprs(pSelect->pOrderByList, walker, pContext); case SQL_CLAUSE_ORDER_BY: - nodesWalkExprs(pSelect->pProjectionList, walker, pContext); + nodesWalkExprs(pSelect->pProjectionList, walker, pContext); default: break; } @@ -368,7 +369,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit case SQL_CLAUSE_DISTINCT: nodesRewriteExprs(pSelect->pOrderByList, rewriter, pContext); case SQL_CLAUSE_ORDER_BY: - nodesRewriteExprs(pSelect->pProjectionList, rewriter, pContext); + nodesRewriteExprs(pSelect->pProjectionList, rewriter, pContext); default: break; } @@ -395,7 +396,8 @@ static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNod return res; } -static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, void* pContext) { +static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, + void* pContext) { EDealRes res = walkScanPhysi((SScanPhysiNode*)pScan, order, walker, pContext); if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkPhysiPlans(pScan->pDynamicScanFuncs, order, walker, pContext); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 6415c16db587754e77b29c193b23fca7280ef7a7..092d0f435d144e15eaf6f17c8b0f8c7baa3eb867 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -97,7 +97,7 @@ SNodeptr nodesMakeNode(ENodeType type) { case QUERY_NODE_CREATE_DATABASE_STMT: return makeNode(type, sizeof(SCreateDatabaseStmt)); case QUERY_NODE_DROP_DATABASE_STMT: - return makeNode(type, sizeof(SDropDatabaseStmt)); + return makeNode(type, sizeof(SDropDatabaseStmt)); case QUERY_NODE_ALTER_DATABASE_STMT: return makeNode(type, sizeof(SAlterDatabaseStmt)); case QUERY_NODE_CREATE_TABLE_STMT: @@ -298,9 +298,7 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) { nodesDestroyList(pNode->pScanCols); } -static void destroyDataSinkNode(SDataSinkNode* pNode) { - nodesDestroyNode(pNode->pInputDataBlockDesc); -} +static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode(pNode->pInputDataBlockDesc); } void nodesDestroyNode(SNodeptr pNode) { if (NULL == pNode) { @@ -308,7 +306,7 @@ void nodesDestroyNode(SNodeptr pNode) { } switch (nodeType(pNode)) { - case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release + case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release break; case QUERY_NODE_VALUE: { SValueNode* pValue = (SValueNode*)pNode; @@ -352,7 +350,7 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_ORDER_BY_EXPR: nodesDestroyNode(((SOrderByExprNode*)pNode)->pExpr); break; - case QUERY_NODE_LIMIT: // no pointer field + case QUERY_NODE_LIMIT: // no pointer field break; case QUERY_NODE_STATE_WINDOW: nodesDestroyNode(((SStateWindowNode*)pNode)->pExpr); @@ -387,9 +385,9 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_DATABLOCK_DESC: nodesDestroyList(((SDataBlockDescNode*)pNode)->pSlots); break; - case QUERY_NODE_SLOT_DESC: // no pointer field - case QUERY_NODE_COLUMN_DEF: // no pointer field - case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field + case QUERY_NODE_SLOT_DESC: // no pointer field + case QUERY_NODE_COLUMN_DEF: // no pointer field + case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field break; case QUERY_NODE_DATABASE_OPTIONS: nodesDestroyList(((SDatabaseOptions*)pNode)->pRetentions); @@ -436,7 +434,7 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_CREATE_DATABASE_STMT: nodesDestroyNode(((SCreateDatabaseStmt*)pNode)->pOptions); break; - case QUERY_NODE_DROP_DATABASE_STMT: // no pointer field + case QUERY_NODE_DROP_DATABASE_STMT: // no pointer field break; case QUERY_NODE_ALTER_DATABASE_STMT: nodesDestroyNode(((SAlterDatabaseStmt*)pNode)->pOptions); @@ -457,12 +455,12 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_CREATE_MULTI_TABLE_STMT: nodesDestroyList(((SCreateMultiTableStmt*)pNode)->pSubTables); break; - case QUERY_NODE_DROP_TABLE_CLAUSE: // no pointer field + case QUERY_NODE_DROP_TABLE_CLAUSE: // no pointer field break; case QUERY_NODE_DROP_TABLE_STMT: nodesDestroyNode(((SDropTableStmt*)pNode)->pTables); break; - case QUERY_NODE_DROP_SUPER_TABLE_STMT: // no pointer field + case QUERY_NODE_DROP_SUPER_TABLE_STMT: // no pointer field break; case QUERY_NODE_ALTER_TABLE_STMT: { SAlterTableStmt* pStmt = (SAlterTableStmt*)pNode; @@ -470,13 +468,13 @@ void nodesDestroyNode(SNodeptr pNode) { nodesDestroyNode(pStmt->pVal); break; } - case QUERY_NODE_CREATE_USER_STMT: // no pointer field - case QUERY_NODE_ALTER_USER_STMT: // no pointer field - case QUERY_NODE_DROP_USER_STMT: // no pointer field - case QUERY_NODE_USE_DATABASE_STMT: // no pointer field - case QUERY_NODE_CREATE_DNODE_STMT: // no pointer field - case QUERY_NODE_DROP_DNODE_STMT: // no pointer field - case QUERY_NODE_ALTER_DNODE_STMT: // no pointer field + case QUERY_NODE_CREATE_USER_STMT: // no pointer field + case QUERY_NODE_ALTER_USER_STMT: // no pointer field + case QUERY_NODE_DROP_USER_STMT: // no pointer field + case QUERY_NODE_USE_DATABASE_STMT: // no pointer field + case QUERY_NODE_CREATE_DNODE_STMT: // no pointer field + case QUERY_NODE_DROP_DNODE_STMT: // no pointer field + case QUERY_NODE_ALTER_DNODE_STMT: // no pointer field break; case QUERY_NODE_CREATE_INDEX_STMT: { SCreateIndexStmt* pStmt = (SCreateIndexStmt*)pNode; @@ -484,15 +482,15 @@ void nodesDestroyNode(SNodeptr pNode) { nodesDestroyList(pStmt->pCols); break; } - case QUERY_NODE_DROP_INDEX_STMT: // no pointer field - case QUERY_NODE_CREATE_QNODE_STMT: // no pointer field - case QUERY_NODE_DROP_QNODE_STMT: // no pointer field + case QUERY_NODE_DROP_INDEX_STMT: // no pointer field + case QUERY_NODE_CREATE_QNODE_STMT: // no pointer field + case QUERY_NODE_DROP_QNODE_STMT: // no pointer field break; case QUERY_NODE_CREATE_TOPIC_STMT: nodesDestroyNode(((SCreateTopicStmt*)pNode)->pQuery); break; - case QUERY_NODE_DROP_TOPIC_STMT: // no pointer field - case QUERY_NODE_ALTER_LOCAL_STMT: // no pointer field + case QUERY_NODE_DROP_TOPIC_STMT: // no pointer field + case QUERY_NODE_ALTER_LOCAL_STMT: // no pointer field break; case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_TABLES_STMT: @@ -658,7 +656,7 @@ void nodesDestroyNode(SNodeptr pNode) { SQueryPlan* pPlan = (SQueryPlan*)pNode; if (NULL != pPlan->pSubplans) { // only need to destroy the top-level subplans, because they will recurse to all the subplans below - bool first = true; + bool first = true; SNode* pElement = NULL; FOREACH(pElement, pPlan->pSubplans) { if (first) { @@ -866,7 +864,7 @@ void nodesClearList(SNodeList* pList) { taosMemoryFreeClear(pList); } -void* nodesGetValueFromNode(SValueNode *pNode) { +void* nodesGetValueFromNode(SValueNode* pNode) { switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_BOOL: return (void*)&pNode->datum.b; @@ -895,10 +893,10 @@ void* nodesGetValueFromNode(SValueNode *pNode) { return NULL; } -char* nodesGetStrValueFromNode(SValueNode *pNode) { +char* nodesGetStrValueFromNode(SValueNode* pNode) { switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_BOOL: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -911,7 +909,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -923,7 +921,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -933,7 +931,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { } case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -945,7 +943,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: { int32_t bufSize = varDataLen(pNode->datum.p) + 2 + 1; - void *buf = taosMemoryMalloc(bufSize); + void* buf = taosMemoryMalloc(bufSize); if (NULL == buf) { return NULL; } @@ -962,7 +960,8 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { bool nodesIsExprNode(const SNode* pNode) { ENodeType type = nodeType(pNode); - return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || QUERY_NODE_FUNCTION == type); + return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || + QUERY_NODE_FUNCTION == type); } bool nodesIsUnaryOp(const SOperatorNode* pOp) { @@ -1037,23 +1036,19 @@ bool nodesIsJsonOp(const SOperatorNode* pOp) { return false; } -bool nodesIsTimeorderQuery(const SNode* pQuery) { - return false; -} +bool nodesIsTimeorderQuery(const SNode* pQuery) { return false; } -bool nodesIsTimelineQuery(const SNode* pQuery) { - return false; -} +bool nodesIsTimelineQuery(const SNode* pQuery) { return false; } typedef struct SCollectColumnsCxt { - int32_t errCode; + int32_t errCode; const char* pTableAlias; - SNodeList* pCols; - SHashObj* pColHash; + SNodeList* pCols; + SHashObj* pColHash; } SCollectColumnsCxt; static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pNode) { - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; int32_t len = 0; if ('\0' == pCol->tableAlias[0]) { len = sprintf(name, "%s", pCol->colName); @@ -1086,11 +1081,10 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* } SCollectColumnsCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .pTableAlias = pTableAlias, - .pCols = nodesMakeList(), - .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK) - }; + .errCode = TSDB_CODE_SUCCESS, + .pTableAlias = pTableAlias, + .pCols = nodesMakeList(), + .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)}; if (NULL == cxt.pCols || NULL == cxt.pColHash) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1110,9 +1104,9 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* } typedef struct SCollectFuncsCxt { - int32_t errCode; + int32_t errCode; FFuncClassifier classifier; - SNodeList* pFuncs; + SNodeList* pFuncs; } SCollectFuncsCxt; static EDealRes collectFuncs(SNode* pNode, void* pContext) { @@ -1129,11 +1123,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod return TSDB_CODE_SUCCESS; } - SCollectFuncsCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .classifier = classifier, - .pFuncs = nodesMakeList() - }; + SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .classifier = classifier, .pFuncs = nodesMakeList()}; if (NULL == cxt.pFuncs) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1148,12 +1138,11 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod nodesDestroyList(cxt.pFuncs); *pFuncs = NULL; } - + return TSDB_CODE_SUCCESS; } - -char *getFillModeString(EFillMode mode) { +char* getFillModeString(EFillMode mode) { switch (mode) { case FILL_MODE_NONE: return "none"; @@ -1172,12 +1161,12 @@ char *getFillModeString(EFillMode mode) { } } -char *nodesGetNameFromColumnNode(SNode *pNode) { +char* nodesGetNameFromColumnNode(SNode* pNode) { if (NULL == pNode || QUERY_NODE_COLUMN != pNode->type) { return "NULL"; } - - return ((SColumnNode *)pNode)->colName; + + return ((SColumnNode*)pNode)->colName; } int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) { @@ -1185,14 +1174,14 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) { return 0; } - SNode* pNode = NULL; + SNode* pNode = NULL; int32_t num = 0; FOREACH(pNode, pSlots) { if (QUERY_NODE_SLOT_DESC != pNode->type) { continue; } - SSlotDescNode *descNode = (SSlotDescNode *)pNode; + SSlotDescNode* descNode = (SSlotDescNode*)pNode; if (descNode->output) { ++num; } @@ -1201,13 +1190,12 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) { return num; } - void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) { pVal->nType = pNode->node.resType.type; pVal->nLen = pNode->node.resType.bytes; switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_NULL: - break; + break; case TSDB_DATA_TYPE_BOOL: pVal->i = pNode->datum.b; break; @@ -1241,6 +1229,3 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) { break; } } - - - diff --git a/source/libs/nodes/test/nodesTest.cpp b/source/libs/nodes/test/nodesTest.cpp index fdfb9522dbed5a38759962b0640fa320bda783d2..0515e8bbc0ae1319042f868b4d70315cc1e31b9c 100644 --- a/source/libs/nodes/test/nodesTest.cpp +++ b/source/libs/nodes/test/nodesTest.cpp @@ -20,42 +20,42 @@ using namespace std; static EDealRes rewriterTest(SNode** pNode, void* pContext) { - EDealRes* pRes = (EDealRes*)pContext; - if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { - SOperatorNode* pOp = (SOperatorNode*)(*pNode); - if (QUERY_NODE_VALUE != nodeType(pOp->pLeft) || QUERY_NODE_VALUE != nodeType(pOp->pRight)) { - *pRes = DEAL_RES_ERROR; - } - SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); - string tmp = to_string(stoi(((SValueNode*)(pOp->pLeft))->literal) + stoi(((SValueNode*)(pOp->pRight))->literal)); - pVal->literal = strdup(tmp.c_str()); - nodesDestroyNode(*pNode); - *pNode = (SNode*)pVal; - } - return DEAL_RES_CONTINUE; + EDealRes* pRes = (EDealRes*)pContext; + if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { + SOperatorNode* pOp = (SOperatorNode*)(*pNode); + if (QUERY_NODE_VALUE != nodeType(pOp->pLeft) || QUERY_NODE_VALUE != nodeType(pOp->pRight)) { + *pRes = DEAL_RES_ERROR; + } + SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + string tmp = to_string(stoi(((SValueNode*)(pOp->pLeft))->literal) + stoi(((SValueNode*)(pOp->pRight))->literal)); + pVal->literal = strdup(tmp.c_str()); + nodesDestroyNode(*pNode); + *pNode = (SNode*)pVal; + } + return DEAL_RES_CONTINUE; } TEST(NodesTest, traverseTest) { - SNode* pRoot = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); - SOperatorNode* pOp = (SOperatorNode*)pRoot; - SOperatorNode* pLeft = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR); - pLeft->pLeft = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); - ((SValueNode*)(pLeft->pLeft))->literal = strdup("10"); - pLeft->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); - ((SValueNode*)(pLeft->pRight))->literal = strdup("5"); - pOp->pLeft = (SNode*)pLeft; - pOp->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); - ((SValueNode*)(pOp->pRight))->literal = strdup("3"); + SNode* pRoot = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); + SOperatorNode* pOp = (SOperatorNode*)pRoot; + SOperatorNode* pLeft = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR); + pLeft->pLeft = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); + ((SValueNode*)(pLeft->pLeft))->literal = strdup("10"); + pLeft->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); + ((SValueNode*)(pLeft->pRight))->literal = strdup("5"); + pOp->pLeft = (SNode*)pLeft; + pOp->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); + ((SValueNode*)(pOp->pRight))->literal = strdup("3"); - EXPECT_EQ(nodeType(pRoot), QUERY_NODE_OPERATOR); - EDealRes res = DEAL_RES_CONTINUE; - nodesRewriteExprPostOrder(&pRoot, rewriterTest, &res); - EXPECT_EQ(res, DEAL_RES_CONTINUE); - EXPECT_EQ(nodeType(pRoot), QUERY_NODE_VALUE); - EXPECT_EQ(string(((SValueNode*)pRoot)->literal), "18"); + EXPECT_EQ(nodeType(pRoot), QUERY_NODE_OPERATOR); + EDealRes res = DEAL_RES_CONTINUE; + nodesRewriteExprPostOrder(&pRoot, rewriterTest, &res); + EXPECT_EQ(res, DEAL_RES_CONTINUE); + EXPECT_EQ(nodeType(pRoot), QUERY_NODE_VALUE); + EXPECT_EQ(string(((SValueNode*)pRoot)->literal), "18"); } int main(int argc, char* argv[]) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 712276be79e10b11266ba0ae454484b29985409c..f885508374806fbf38537e125003d14e2b1b9d70 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -21,18 +21,18 @@ extern "C" { #endif #include "cmdnodes.h" -#include "parser.h" #include "parToken.h" #include "parUtil.h" +#include "parser.h" #include "querynodes.h" typedef struct SAstCreateContext { SParseContext* pQueryCxt; - SMsgBuf msgBuf; - bool notSupport; - bool valid; - SNode* pRootNode; - int16_t placeholderNo; + SMsgBuf msgBuf; + bool notSupport; + bool valid; + SNode* pRootNode; + int16_t placeholderNo; } SAstCreateContext; typedef enum EDatabaseOptionType { @@ -67,9 +67,9 @@ typedef enum ETableOptionType { } ETableOptionType; typedef struct SAlterOption { - int32_t type; + int32_t type; SValueNode* pVal; - SNodeList* pList; + SNodeList* pList; } SAlterOption; extern SToken nil_token; @@ -105,7 +105,8 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder); SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap); SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr); -SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill); +SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, + SNode* pFill); SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues); SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode); @@ -120,26 +121,30 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit); SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable); SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight); -SNode* createDatabaseOptions(SAstCreateContext* pCxt); -SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); -SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); -SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); -SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); -SNode* createTableOptions(SAstCreateContext* pCxt); -SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); -SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment); +SNode* createDatabaseOptions(SAstCreateContext* pCxt); +SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); +SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); +SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); +SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); +SNode* createTableOptions(SAstCreateContext* pCxt); +SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); +SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment); SDataType createDataType(uint8_t type); SDataType createVarLenDataType(uint8_t type, const SToken* pLen); -SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions); -SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags); +SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, + SNodeList* pTags, SNode* pOptions); +SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, + SNodeList* pSpecificTags, SNodeList* pValsOfTags); SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables); SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables); SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions); -SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType); +SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, + const SToken* pColName, SDataType dataType); SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName); -SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName); +SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, + const SToken* pOldColName, const SToken* pNewColName); SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern); @@ -151,13 +156,15 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName); SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort); SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode); SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue); -SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions); +SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, + SToken* pTableName, SNodeList* pCols, SNode* pOptions); SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding); SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName); SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId); SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId); SNode* createTopicOptions(SAstCreateContext* pCxt); -SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions); +SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, + const SToken* pSubscribeDbName, SNode* pOptions); SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName); SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue); SNode* createDefaultExplainOptions(SAstCreateContext* pCxt); @@ -167,10 +174,12 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable); SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt); SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups); -SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize); +SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, + const SToken* pLibPath, SDataType dataType, int32_t bufSize); SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName); SNode* createStreamOptions(SAstCreateContext* pCxt); -SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery); +SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, + SNode* pOptions, SNode* pQuery); SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName); SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId); SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2); diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index ed7267655c61f9cf3cec9297d0f3bd33b1a67eaf..02be32a49e1ad41ee5314db20da302e661f8bf6d 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -18,8 +18,8 @@ #include "catalog.h" #include "os.h" -#include "ttypes.h" #include "tname.h" +#include "ttypes.h" #define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED) @@ -52,8 +52,8 @@ typedef struct SParsedDataColInfo { uint16_t flen; // TODO: get from STSchema uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow) uint16_t extendedVarLen; - uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part) - col_id_t *boundColumns; // bound column idx according to schema + uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part) + col_id_t *boundColumns; // bound column idx according to schema SBoundColumn *cols; SBoundIdxInfo *colIdxInfo; int8_t orderStatus; // bound columns @@ -72,12 +72,13 @@ typedef struct STableDataBlocks { int32_t numOfTables; // number of tables in current submit block int32_t rowSize; // row size for current table uint32_t nAllocSize; - uint32_t headerSize; // header for table info (uid, tid, submit metadata) + uint32_t headerSize; // header for table info (uid, tid, submit metadata) uint32_t size; - STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache - char *pData; - bool cloned; - int32_t createTbReqLen; + STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to + // avoid to be removed from cache + char *pData; + bool cloned; + int32_t createTbReqLen; SParsedDataColInfo boundColumnInfo; SRowBuilder rowBuilder; } STableDataBlocks; @@ -89,8 +90,8 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) { (int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1); } -static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, - int32_t *toffset, col_id_t *colIdx) { +static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset, + col_id_t *colIdx) { col_id_t schemaIdx = 0; if (IS_DATA_COL_ORDERED(spd)) { schemaIdx = spd->boundColumns[idx] - PRIMARYKEY_TIMESTAMP_COL_ID; @@ -114,8 +115,9 @@ static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo } } -static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks* dataBuf, int32_t numOfRows) { - pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid); +static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows) { + pBlocks->suid = + (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid); pBlocks->uid = dataBuf->pTableMeta->uid; pBlocks->sversion = dataBuf->pTableMeta->sversion; pBlocks->schemaLen = dataBuf->createTbReqLen; @@ -131,14 +133,15 @@ static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks* int32_t schemaIdxCompar(const void *lhs, const void *rhs); int32_t boundIdxCompar(const void *lhs, const void *rhs); void setBoundColumnInfo(SParsedDataColInfo *pColList, SSchema *pSchema, col_id_t numOfCols); -void destroyBlockArrayList(SArray* pDataBlockList); -void destroyBlockHashmap(SHashObj* pDataBlockHash); -int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo); -int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t * numOfRows); -int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq); -int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** pVgDataBlocks); -int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq); +void destroyBlockArrayList(SArray *pDataBlockList); +void destroyBlockHashmap(SHashObj *pDataBlockHash); +int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo); +int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t *numOfRows); +int32_t getDataBlockFromList(SHashObj *pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, + const STableMeta *pTableMeta, STableDataBlocks **dataBlocks, SArray *pBlockList, + SVCreateTbReq *pCreateTbReq); +int32_t mergeTableDataBlocks(SHashObj *pHashObj, uint8_t payloadType, SArray **pVgDataBlocks); +int32_t buildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq); int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize); #endif // TDENGINE_DATABLOCKMGT_H diff --git a/source/libs/parser/inc/parInt.h b/source/libs/parser/inc/parInt.h index 87348e292ebb1cc92a2fed126e4976ebd9e4da9b..7641b6951eb53f56fa200f7e673ff96068c2efae 100644 --- a/source/libs/parser/inc/parInt.h +++ b/source/libs/parser/inc/parInt.h @@ -20,9 +20,9 @@ extern "C" { #endif -#include "parser.h" #include "parToken.h" #include "parUtil.h" +#include "parser.h" int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery); diff --git a/source/libs/parser/inc/parToken.h b/source/libs/parser/inc/parToken.h index d8a2c22fd8a29cd00673f8a71277dab58a430aa9..787abf287e3bcf4f42e505d40bea0b7230cfc7e7 100644 --- a/source/libs/parser/inc/parToken.h +++ b/source/libs/parser/inc/parToken.h @@ -20,6 +20,8 @@ extern "C" { #endif +#include "os.h" + #include "ttokendef.h" // used to denote the minimum unite in sql parsing @@ -35,7 +37,7 @@ typedef struct SToken { * @return */ #define isNumber(tk) \ -((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_NK_HEX || (tk)->type == TK_NK_BIN) + ((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_NK_HEX || (tk)->type == TK_NK_BIN) /** * tokenizer for sql string @@ -68,12 +70,12 @@ bool taosIsKeyWordToken(const char *z, int32_t len); * @param pToken * @return token type, if it is not a number, TK_NK_ILLEGAL will return */ -static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { - const char* z = pToken->z; - int32_t type = TK_NK_ILLEGAL; +static FORCE_INLINE int32_t tGetNumericStringType(const SToken *pToken) { + const char *z = pToken->z; + int32_t type = TK_NK_ILLEGAL; uint32_t i = 0; - for(; i < pToken->n; ++i) { + for (; i < pToken->n; ++i) { switch (z[i]) { case '+': case '-': { @@ -86,7 +88,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { * .123 * .123e4 */ - if (!isdigit(z[i+1])) { + if (!isdigit(z[i + 1])) { return TK_NK_ILLEGAL; } @@ -107,13 +109,13 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { case '0': { char next = z[i + 1]; - if (next == 'b') { // bin number + if (next == 'b') { // bin number type = TK_NK_BIN; for (i += 2; (z[i] == '0' || z[i] == '1'); ++i) { } goto _end; - } else if (next == 'x') { //hex number + } else if (next == 'x') { // hex number type = TK_NK_HEX; for (i += 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) { } @@ -167,15 +169,15 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { } } - _end: - return (i < pToken->n)? TK_NK_ILLEGAL:type; +_end: + return (i < pToken->n) ? TK_NK_ILLEGAL : type; } void taosCleanupKeywordsTable(); -SToken tscReplaceStrToken(char **str, SToken *token, const char* newToken); +SToken tscReplaceStrToken(char **str, SToken *token, const char *newToken); -SToken taosTokenDup(SToken* pToken, char* buf, int32_t len); +SToken taosTokenDup(SToken *pToken, char *buf, int32_t len); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/parUtil.h b/source/libs/parser/inc/parUtil.h index 460a089802a2629f38abbb56100d95298c6ac6f1..62d197d61169f89de73eb73346b3e756e9839931 100644 --- a/source/libs/parser/inc/parUtil.h +++ b/source/libs/parser/inc/parUtil.h @@ -23,31 +23,31 @@ extern "C" { #include "os.h" #include "query.h" -#define parserFatal(param, ...) qFatal("PARSER: " param, __VA_ARGS__) -#define parserError(param, ...) qError("PARSER: " param, __VA_ARGS__) -#define parserWarn(param, ...) qWarn("PARSER: " param, __VA_ARGS__) -#define parserInfo(param, ...) qInfo("PARSER: " param, __VA_ARGS__) -#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__) -#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__) +#define parserFatal(param, ...) qFatal("PARSER: " param, __VA_ARGS__) +#define parserError(param, ...) qError("PARSER: " param, __VA_ARGS__) +#define parserWarn(param, ...) qWarn("PARSER: " param, __VA_ARGS__) +#define parserInfo(param, ...) qInfo("PARSER: " param, __VA_ARGS__) +#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__) +#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__) #define PK_TS_COL_INTERNAL_NAME "_rowts" typedef struct SMsgBuf { int32_t len; - char *buf; + char* buf; } SMsgBuf; int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...); int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg); -int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr); +int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr); -STableMeta* tableMetaDup(const STableMeta* pTableMeta); -SSchema *getTableColumnSchema(const STableMeta *pTableMeta); -SSchema *getTableTagSchema(const STableMeta* pTableMeta); -int32_t getNumOfColumns(const STableMeta* pTableMeta); -int32_t getNumOfTags(const STableMeta* pTableMeta); +STableMeta* tableMetaDup(const STableMeta* pTableMeta); +SSchema* getTableColumnSchema(const STableMeta* pTableMeta); +SSchema* getTableTagSchema(const STableMeta* pTableMeta); +int32_t getNumOfColumns(const STableMeta* pTableMeta); +int32_t getNumOfTags(const STableMeta* pTableMeta); STableComInfo getTableInfo(const STableMeta* pTableMeta); -int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* errMsg, int16_t startColId); +int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* errMsg, int16_t startColId); int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 79e2c31154737c27598a224dc2c7533e4c196a76..4c8c33dd0ab3c13916c5d61f11844f08a1310e88 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -18,24 +18,24 @@ #include "parUtil.h" #include "ttime.h" -#define CHECK_OUT_OF_MEM(p) \ - do { \ - if (NULL == (p)) { \ - pCxt->valid = false; \ +#define CHECK_OUT_OF_MEM(p) \ + do { \ + if (NULL == (p)) { \ + pCxt->valid = false; \ snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \ - return NULL; \ - } \ + return NULL; \ + } \ } while (0) -#define CHECK_RAW_EXPR_NODE(node) \ - do { \ +#define CHECK_RAW_EXPR_NODE(node) \ + do { \ if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \ - pCxt->valid = false; \ - return NULL; \ - } \ + pCxt->valid = false; \ + return NULL; \ + } \ } while (0) -SToken nil_token = { .type = TK_NK_NIL, .n = 0, .z = NULL }; +SToken nil_token = {.type = TK_NK_NIL, .n = 0, .z = NULL}; void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { pCxt->pQueryCxt = pParseCxt; @@ -90,7 +90,7 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* pFqdn, int32_t* pPort) { if (NULL == pEp) { pCxt->valid = false; - } else if (pEp->n >= TSDB_FQDN_LEN + 2 + 6) { // format 'fqdn:port' + } else if (pEp->n >= TSDB_FQDN_LEN + 2 + 6) { // format 'fqdn:port' generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); pCxt->valid = false; } else { @@ -206,7 +206,7 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { CHECK_RAW_EXPR_NODE(pNode); SRawExprNode* pRawExpr = (SRawExprNode*)pNode; - SNode* pExpr = pRawExpr->pNode; + SNode* pExpr = pRawExpr->pNode; if (nodesIsExprNode(pExpr)) { int32_t len = TMIN(sizeof(((SExprNode*)pExpr)->aliasName) - 1, pRawExpr->n); strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, len); @@ -222,7 +222,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { return nil_token; } SRawExprNode* target = (SRawExprNode*)pNode; - SToken t = { .type = 0, .z = target->p, .n = target->n}; + SToken t = {.type = 0, .z = target->p, .n = target->n}; return t; } @@ -352,12 +352,13 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) { return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, - createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight)); + createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), + createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight)); } SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) { - return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, - createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight)); + return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), + createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight)); } SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) { @@ -410,7 +411,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa } else { strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n); } - strncpy(realTable->table.tableName, pTableName->z, pTableName->n); + strncpy(realTable->table.tableName, pTableName->z, pTableName->n); return (SNode*)realTable; } @@ -483,7 +484,8 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) { return (SNode*)state; } -SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill) { +SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, + SNode* pFill) { SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW); CHECK_OUT_OF_MEM(interval); interval->pCol = nodesMakeNode(QUERY_NODE_COLUMN); @@ -749,17 +751,17 @@ SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType } SDataType createDataType(uint8_t type) { - SDataType dt = { .type = type, .precision = 0, .scale = 0, .bytes = tDataTypes[type].bytes }; + SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = tDataTypes[type].bytes}; return dt; } SDataType createVarLenDataType(uint8_t type, const SToken* pLen) { - SDataType dt = { .type = type, .precision = 0, .scale = 0, .bytes = strtol(pLen->z, NULL, 10) }; + SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = strtol(pLen->z, NULL, 10)}; return dt; } -SNode* createCreateTableStmt(SAstCreateContext* pCxt, - bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions) { +SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, + SNodeList* pTags, SNode* pOptions) { if (NULL == pRealTable) { return NULL; } @@ -775,8 +777,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, return (SNode*)pStmt; } -SNode* createCreateSubTableClause(SAstCreateContext* pCxt, - bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags) { +SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, + SNodeList* pSpecificTags, SNodeList* pValsOfTags) { if (NULL == pRealTable) { return NULL; } @@ -842,7 +844,8 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* return (SNode*)pStmt; } -SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType) { +SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, + const SToken* pColName, SDataType dataType) { if (NULL == pRealTable) { return NULL; } @@ -865,7 +868,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_ return (SNode*)pStmt; } -SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName) { +SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, + const SToken* pOldColName, const SToken* pNewColName) { if (NULL == pRealTable) { return NULL; } @@ -900,7 +904,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) { } static bool needDbShowStmt(ENodeType type) { - return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type || QUERY_NODE_SHOW_VGROUPS_STMT == type; + return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type || + QUERY_NODE_SHOW_VGROUPS_STMT == type; } SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) { @@ -909,7 +914,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S pCxt->valid = false; return NULL; } - SShowStmt* pStmt = nodesMakeNode(type);; + SShowStmt* pStmt = nodesMakeNode(type); + ; CHECK_OUT_OF_MEM(pStmt); pStmt->pDbName = pDbName; pStmt->pTbNamePattern = pTbNamePattern; @@ -971,7 +977,7 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) { SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort) { int32_t port = 0; - char fqdn[TSDB_FQDN_LEN] = {0}; + char fqdn[TSDB_FQDN_LEN] = {0}; if (NULL == pPort) { if (!checkAndSplitEndpoint(pCxt, pFqdn, fqdn, &port)) { return NULL; @@ -1004,7 +1010,8 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) { return (SNode*)pStmt; } -SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue) { +SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, + const SToken* pValue) { SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->dnodeId = strtol(pDnode->z, NULL, 10); @@ -1015,7 +1022,8 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const return (SNode*)pStmt; } -SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions) { +SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, + SToken* pTableName, SNodeList* pCols, SNode* pOptions) { if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) { return NULL; } @@ -1030,7 +1038,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno return (SNode*)pStmt; } -SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding) { +SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, + SNode* pSliding) { SIndexOptions* pOptions = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS); CHECK_OUT_OF_MEM(pOptions); pOptions->pFuncs = pFuncs; @@ -1055,14 +1064,16 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) { SCreateComponentNodeStmt* pStmt = nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); - pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);; + pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10); + ; return (SNode*)pStmt; } SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) { SDropComponentNodeStmt* pStmt = nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); - pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);; + pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10); + ; return (SNode*)pStmt; } @@ -1075,8 +1086,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) { return (SNode*)pOptions; } -SNode* createCreateTopicStmt(SAstCreateContext* pCxt, - bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions) { +SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, + const SToken* pSubscribeDbName, SNode* pOptions) { SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT); CHECK_OUT_OF_MEM(pStmt); strncpy(pStmt->topicName, pTopicName->z, pTopicName->n); @@ -1158,8 +1169,8 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) { return pStmt; } -SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, - bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize) { +SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, + const SToken* pLibPath, SDataType dataType, int32_t bufSize) { if (pLibPath->n <= 2) { pCxt->valid = false; return NULL; @@ -1188,7 +1199,8 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) { return (SNode*)pOptions; } -SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery) { +SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, + SNode* pOptions, SNode* pQuery) { SCreateStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT); CHECK_OUT_OF_MEM(pStmt); strncpy(pStmt->streamName, pStreamName->z, pStreamName->n); diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index fcc15b197f238d268a4789903ace235eab5fc001..723ad577f4e7b439e21a7506ed6e9c74b5fa64a9 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -23,14 +23,14 @@ typedef void* (*FMalloc)(size_t); typedef void (*FFree)(void*); extern void* ParseAlloc(FMalloc); -extern void Parse(void*, int, SToken, void*); -extern void ParseFree(void*, FFree); -extern void ParseTrace(FILE*, char*); +extern void Parse(void*, int, SToken, void*); +extern void ParseFree(void*, FFree); +extern void ParseTrace(FILE*, char*); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) { SAstCreateContext cxt; initAstCreateContext(pParseCxt, &cxt); - void *pParser = ParseAlloc((FMalloc)taosMemoryMalloc); + void* pParser = ParseAlloc((FMalloc)taosMemoryMalloc); int32_t i = 0; while (1) { SToken t0 = {0}; @@ -38,8 +38,8 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) { Parse(pParser, 0, t0, &cxt); goto abort_parse; } - t0.n = tGetToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type); - t0.z = (char *)(cxt.pQueryCxt->pSql + i); + t0.n = tGetToken((char*)&cxt.pQueryCxt->pSql[i], &t0.type); + t0.z = (char*)(cxt.pQueryCxt->pSql + i); i += t0.n; switch (t0.type) { diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 88d0ca514d3662d7b0956bc0717a483cf57671c7..d0e670df6e71cffa8136040fd4e9af81d0e45bc9 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -20,8 +20,8 @@ typedef struct SCalcConstContext { SParseContext* pParseCxt; - SMsgBuf msgBuf; - int32_t code; + SMsgBuf msgBuf; + int32_t code; } SCalcConstContext; static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery); @@ -35,7 +35,7 @@ static int32_t calcConstNode(SNode** pNode) { return TSDB_CODE_SUCCESS; } - SNode* pNew = NULL; + SNode* pNew = NULL; int32_t code = scalarCalculateConstants(*pNode, &pNew); if (TSDB_CODE_SUCCESS == code) { *pNode = pNew; @@ -46,7 +46,7 @@ static int32_t calcConstNode(SNode** pNode) { static int32_t calcConstList(SNodeList* pList) { SNode* pNode = NULL; FOREACH(pNode, pList) { - SNode* pNew = NULL; + SNode* pNew = NULL; int32_t code = scalarCalculateConstants(pNode, &pNew); if (TSDB_CODE_SUCCESS == code) { REPLACE_NODE(pNew); @@ -128,7 +128,7 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab } // todo empty table break; - } + } default: break; } @@ -196,7 +196,7 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProject ERASE_NODE(pProjections); continue; } - SNode* pNew = NULL; + SNode* pNew = NULL; int32_t code = calcConstProject(pProj, &pNew); if (TSDB_CODE_SUCCESS == code) { REPLACE_NODE(pNew); @@ -281,13 +281,11 @@ static bool isEmptyResultQuery(SNode* pStmt) { } int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) { - SCalcConstContext cxt = { - .pParseCxt = pParseCxt, - .msgBuf.buf = pParseCxt->pMsg, - .msgBuf.len = pParseCxt->msgLen, - .code = TSDB_CODE_SUCCESS - }; - int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false); + SCalcConstContext cxt = {.pParseCxt = pParseCxt, + .msgBuf.buf = pParseCxt->pMsg, + .msgBuf.len = pParseCxt->msgLen, + .code = TSDB_CODE_SUCCESS}; + int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false); if (TSDB_CODE_SUCCESS == code && isEmptyResultQuery(pQuery->pRoot)) { pQuery->execMode = QUERY_EXEC_MODE_EMPTY_RESULT; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index f69a3830056933b866c402f6cc3963a290edafb7..5a93c5cef5e0f01d64023ac5ca5c11b1dd2aabfa 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -42,20 +42,20 @@ } while (0) typedef struct SInsertParseContext { - SParseContext* pComCxt; // input - char *pSql; // input - SMsgBuf msg; // input - STableMeta* pTableMeta; // each table - SParsedDataColInfo tags; // each table - SKVRowBuilder tagsBuilder; // each table - SVCreateTbReq createTblReq; // each table - SHashObj* pVgroupsHashObj; // global - SHashObj* pTableBlockHashObj; // global - SHashObj* pSubTableHashObj; // global - SArray* pVgDataBlocks; // global - int32_t totalNum; + SParseContext* pComCxt; // input + char* pSql; // input + SMsgBuf msg; // input + STableMeta* pTableMeta; // each table + SParsedDataColInfo tags; // each table + SKVRowBuilder tagsBuilder; // each table + SVCreateTbReq createTblReq; // each table + SHashObj* pVgroupsHashObj; // global + SHashObj* pTableBlockHashObj; // global + SHashObj* pSubTableHashObj; // global + SArray* pVgDataBlocks; // global + int32_t totalNum; SVnodeModifOpStmt* pOutput; - SStmtCallback* pStmtCb; + SStmtCallback* pStmtCb; } SInsertParseContext; typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param); @@ -64,8 +64,8 @@ static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; typedef struct SKvParam { - SKVRowBuilder *builder; - SSchema *schema; + SKVRowBuilder* builder; + SSchema* schema; char buf[TSDB_MAX_TAGS_LEN]; } SKvParam; @@ -76,16 +76,14 @@ typedef struct SMemParam { col_id_t colIdx; } SMemParam; - -#define CHECK_CODE(expr) \ - do { \ - int32_t code = expr; \ +#define CHECK_CODE(expr) \ + do { \ + int32_t code = expr; \ if (TSDB_CODE_SUCCESS != code) { \ - return code; \ - } \ + return code; \ + } \ } while (0) - static int32_t skipInsertInto(SInsertParseContext* pCxt) { SToken sToken; NEXT_TOKEN(pCxt->pSql, sToken); @@ -179,7 +177,6 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD return TSDB_CODE_SUCCESS; } - static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) { const char* msg1 = "name too long"; const char* msg2 = "invalid database name"; @@ -242,8 +239,8 @@ static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, con static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool isStb) { SParseContext* pBasicCtx = pCxt->pComCxt; - SName name = {0}; - createSName(&name, pTname, pBasicCtx->acctId, pBasicCtx->db, &pCxt->msg); + SName name = {0}; + createSName(&name, pTname, pBasicCtx->acctId, pBasicCtx->db, &pCxt->msg); if (isStb) { CHECK_CODE(catalogGetSTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &pCxt->pTableMeta)); @@ -316,7 +313,7 @@ static int32_t buildOutput(SInsertParseContext* pCxt) { return TSDB_CODE_SUCCESS; } -int32_t checkTimestamp(STableDataBlocks *pDataBlocks, const char *start) { +int32_t checkTimestamp(STableDataBlocks* pDataBlocks, const char* start) { // once the data block is disordered, we do NOT keep previous timestamp any more if (!pDataBlocks->ordered) { return TSDB_CODE_SUCCESS; @@ -601,7 +598,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } case TSDB_DATA_TYPE_JSON: { - if(pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE){ + if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { return buildSyntaxErrMsg(pMsgBuf, "json string too long than 4095", pToken->z); } return func(pMsgBuf, pToken->z, pToken->n, param); @@ -720,7 +717,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* qsort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar); } - if(pColList->numOfCols > pColList->numOfBound){ + if (pColList->numOfCols > pColList->numOfBound) { memset(&pColList->boundColumns[pColList->numOfBound], 0, sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound)); } @@ -728,18 +725,19 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* return TSDB_CODE_SUCCESS; } -static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, void *param) { - SKvParam* pa = (SKvParam*) param; +static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) { + SKvParam* pa = (SKvParam*)param; int8_t type = pa->schema->type; int16_t colId = pa->schema->colId; - if(TSDB_DATA_TYPE_JSON == type){ + if (TSDB_DATA_TYPE_JSON == type) { return parseJsontoTagData(value, pa->builder, pMsgBuf, colId); } if (value == NULL) { // it is a null data - // tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx); + // tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, + // pa->colIdx); return TSDB_CODE_SUCCESS; } @@ -764,7 +762,7 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, voi return TSDB_CODE_SUCCESS; } -static int32_t buildCreateTbReq(SVCreateTbReq *pTbReq, const SName* pName, SKVRow row, int64_t suid) { +static int32_t buildCreateTbReq(SVCreateTbReq* pTbReq, const SName* pName, SKVRow row, int64_t suid) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(pName, dbFName); pTbReq->type = TD_CHILD_TABLE; @@ -782,9 +780,9 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint } SKvParam param = {.builder = &pCxt->tagsBuilder}; - SToken sToken; - bool isParseBindParam = false; - char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" + SToken sToken; + bool isParseBindParam = false; + char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" for (int i = 0; i < pCxt->tags.numOfBound; ++i) { NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); @@ -800,8 +798,8 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint if (isParseBindParam) { return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and tag values"); } - - SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i] - 1]; // colId starts with 1 + + SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i] - 1]; // colId starts with 1 param.schema = pTagSchema; CHECK_CODE( parseValueToken(&pCxt->pSql, &sToken, pTagSchema, precision, tmpTokenBuf, KvRowAppend, ¶m, &pCxt->msg)); @@ -886,7 +884,8 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken) return TSDB_CODE_SUCCESS; } -static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow, char* tmpTokenBuf) { +static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow, + char* tmpTokenBuf) { SParsedDataColInfo* spd = &pDataBlocks->boundColumnInfo; SRowBuilder* pBuilder = &pDataBlocks->rowBuilder; STSRow* row = (STSRow*)(pDataBlocks->pData + pDataBlocks->size); // skip the SSubmitBlk header @@ -914,7 +913,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, if (isParseBindParam) { return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and values"); } - + param.schema = pSchema; getSTSRowAppendInfo(pBuilder->rowType, spd, i, ¶m.toffset, ¶m.colIdx); CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, timePrec, tmpTokenBuf, MemRowAppend, ¶m, &pCxt->msg)); @@ -970,7 +969,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo bool gotRow = false; CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf)); if (gotRow) { - pDataBlock->size += extendedRowSize; //len; + pDataBlock->size += extendedRowSize; // len; } NEXT_TOKEN(pCxt->pSql, sToken); @@ -984,7 +983,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo } if (0 == (*numOfRows) && (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT))) { - return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); + return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); } return TSDB_CODE_SUCCESS; } @@ -1050,11 +1049,11 @@ static void destroyInsertParseContext(SInsertParseContext* pCxt) { // [...]; static int32_t parseInsertBody(SInsertParseContext* pCxt) { int32_t tbNum = 0; - + // for each table while (1) { SToken sToken; - char *tbName = NULL; + char* tbName = NULL; // pSql -> tb_name ... NEXT_TOKEN(pCxt->pSql, sToken); @@ -1068,7 +1067,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { } if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && tbNum > 0) { - return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt");; + return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt"); + ; } destroyInsertParseContextForTable(pCxt); @@ -1076,14 +1076,14 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { if (TK_NK_QUESTION == sToken.type) { if (pCxt->pStmtCb) { CHECK_CODE((*pCxt->pStmtCb->getTbNameFn)(pCxt->pStmtCb->pStmt, &tbName)); - + sToken.z = tbName; sToken.n = strlen(tbName); } else { return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z); } } - + SToken tbnameToken = sToken; NEXT_TOKEN(pCxt->pSql, sToken); @@ -1131,9 +1131,9 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", sToken.z); } - + if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) { - SParsedDataColInfo *tags = taosMemoryMalloc(sizeof(pCxt->tags)); + SParsedDataColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags)); if (NULL == tags) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1144,10 +1144,10 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { (*pCxt->pStmtCb->setExecInfoFn)(pCxt->pStmtCb->pStmt, pCxt->pVgroupsHashObj, pCxt->pTableBlockHashObj); pCxt->pVgroupsHashObj = NULL; pCxt->pTableBlockHashObj = NULL; - + return TSDB_CODE_SUCCESS; } - + // merge according to vgId if (taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { CHECK_CODE(mergeTableDataBlocks(pCxt->pTableBlockHashObj, pCxt->pOutput->payloadType, &pCxt->pVgDataBlocks)); @@ -1163,25 +1163,25 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { // [...]; int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { SInsertParseContext context = { - .pComCxt = pContext, - .pSql = (char*) pContext->pSql, - .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, - .pTableMeta = NULL, - .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false), - .totalNum = 0, - .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT), - .pStmtCb = pContext->pStmtCb - }; + .pComCxt = pContext, + .pSql = (char*)pContext->pSql, + .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, + .pTableMeta = NULL, + .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false), + .totalNum = 0, + .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT), + .pStmtCb = pContext->pStmtCb}; if (pContext->pStmtCb && *pQuery) { - (*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj, &context.pTableBlockHashObj); + (*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj, + &context.pTableBlockHashObj); } else { context.pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false); context.pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); } - - if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || - NULL == context.pSubTableHashObj || NULL == context.pOutput) { + + if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pSubTableHashObj || + NULL == context.pOutput) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1199,7 +1199,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { (*pQuery)->msgType = TDMT_VND_SUBMIT; (*pQuery)->pRoot = (SNode*)context.pOutput; } - + context.pOutput->payloadType = PAYLOAD_TYPE_KV; int32_t code = skipInsertInto(&context); @@ -1210,15 +1210,15 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { return code; } - -int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen) { - SMsgBuf msg = {.buf = msgBuf, .len =msgBufLen}; - SToken sToken; +int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf, + int32_t msgBufLen) { + SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen}; + SToken sToken; int32_t code = 0; - char *tbName = NULL; - + char* tbName = NULL; + NEXT_TOKEN(pTableName, sToken); - + if (sToken.n == 0) { return buildInvalidOperationMsg(&msg, "empty table name"); } @@ -1237,16 +1237,15 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* return TSDB_CODE_SUCCESS; } - int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) { - SVnodeModifOpStmt *modifyNode = (SVnodeModifOpStmt *)pQuery->pRoot; - int32_t code = 0; + SVnodeModifOpStmt* modifyNode = (SVnodeModifOpStmt*)pQuery->pRoot; + int32_t code = 0; SInsertParseContext insertCtx = { - .pVgroupsHashObj = pVgHash, - .pTableBlockHashObj = pBlockHash, - .pOutput = (SVnodeModifOpStmt*)pQuery->pRoot, + .pVgroupsHashObj = pVgHash, + .pTableBlockHashObj = pBlockHash, + .pOutput = (SVnodeModifOpStmt*)pQuery->pRoot, }; - + // merge according to vgId if (taosHashGetSize(insertCtx.pTableBlockHashObj) > 0) { CHECK_CODE(mergeTableDataBlocks(insertCtx.pTableBlockHashObj, modifyNode->payloadType, &insertCtx.pVgDataBlocks)); @@ -1257,9 +1256,10 @@ int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash return TSDB_CODE_SUCCESS; } -int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen){ - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; +int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, SName* pName, TAOS_BIND_v2* bind, char* msgBuf, + int32_t msgBufLen) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags; if (NULL == tags) { return TSDB_CODE_QRY_APP_ERROR; @@ -1278,16 +1278,16 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p KvRowAppend(&pBuf, NULL, 0, ¶m); continue; } - - SSchema* pTagSchema = &pSchema[tags->boundColumns[c] - 1]; // colId starts with 1 + + SSchema* pTagSchema = &pSchema[tags->boundColumns[c] - 1]; // colId starts with 1 param.schema = pTagSchema; int32_t colLen = pTagSchema->bytes; if (IS_VAR_DATA_TYPE(pTagSchema->type)) { colLen = bind[c].length[0]; } - - CHECK_CODE(KvRowAppend(&pBuf, (char *)bind[c].buffer, colLen, ¶m)); + + CHECK_CODE(KvRowAppend(&pBuf, (char*)bind[c].buffer, colLen, ¶m)); } SKVRow row = tdGetKVRowFromBuilder(&tagBuilder); @@ -1307,25 +1307,24 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p return TSDB_CODE_SUCCESS; } - -int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); - int32_t extendedRowSize = getExtendedRowSize(pDataBlock); +int32_t qBindStmtColsValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); + int32_t extendedRowSize = getExtendedRowSize(pDataBlock); SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo; SRowBuilder* pBuilder = &pDataBlock->rowBuilder; - SMemParam param = {.rb = pBuilder}; - SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; - int32_t rowNum = bind->num; - + SMemParam param = {.rb = pBuilder}; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + int32_t rowNum = bind->num; + CHECK_CODE(initRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo)); CHECK_CODE(allocateMemForSize(pDataBlock, extendedRowSize * bind->num)); - + for (int32_t r = 0; r < bind->num; ++r) { STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header tdSRowResetBuf(pBuilder, row); - + for (int c = 0; c < spd->numOfBound; ++c) { SSchema* pColSchema = &pSchema[spd->boundColumns[c] - 1]; @@ -1336,7 +1335,7 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 if (bind[c].num != rowNum) { return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); } - + param.schema = pColSchema; getSTSRowAppendInfo(pBuilder->rowType, spd, c, ¶m.toffset, ¶m.colIdx); @@ -1344,23 +1343,23 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL"); } - + CHECK_CODE(MemRowAppend(&pBuf, NULL, 0, ¶m)); } else { int32_t colLen = pColSchema->bytes; if (IS_VAR_DATA_TYPE(pColSchema->type)) { colLen = bind[c].length[r]; } - - CHECK_CODE(MemRowAppend(&pBuf, (char *)bind[c].buffer + bind[c].buffer_length * r, colLen, ¶m)); + + CHECK_CODE(MemRowAppend(&pBuf, (char*)bind[c].buffer + bind[c].buffer_length * r, colLen, ¶m)); } - + if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) { TSKEY tsKey = TD_ROW_KEY(row); - checkTimestamp(pDataBlock, (const char *)&tsKey); + checkTimestamp(pDataBlock, (const char*)&tsKey); } } - + // set the null value for the columns that do not assign values if ((spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) { for (int32_t i = 0; i < spd->numOfCols; ++i) { @@ -1370,11 +1369,11 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 } } } - + pDataBlock->size += extendedRowSize; } - SSubmitBlk *pBlocks = (SSubmitBlk *)(pDataBlock->pData); + SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData); if (TSDB_CODE_SUCCESS != setBlockInfo(pBlocks, pDataBlock, bind->num)) { return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than 32767"); } @@ -1382,22 +1381,23 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 return TSDB_CODE_SUCCESS; } -int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); - int32_t extendedRowSize = getExtendedRowSize(pDataBlock); +int32_t qBindStmtSingleColValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx, + int32_t rowNum) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); + int32_t extendedRowSize = getExtendedRowSize(pDataBlock); SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo; SRowBuilder* pBuilder = &pDataBlock->rowBuilder; - SMemParam param = {.rb = pBuilder}; - SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; - bool rowStart = (0 == colIdx); - bool rowEnd = ((colIdx + 1) == spd->numOfBound); + SMemParam param = {.rb = pBuilder}; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + bool rowStart = (0 == colIdx); + bool rowEnd = ((colIdx + 1) == spd->numOfBound); if (rowStart) { CHECK_CODE(initRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo)); CHECK_CODE(allocateMemForSize(pDataBlock, extendedRowSize * bind->num)); } - + for (int32_t r = 0; r < bind->num; ++r) { STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size + extendedRowSize * r); // skip the SSubmitBlk header if (rowStart) { @@ -1405,13 +1405,13 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, } else { tdSRowGetBuf(pBuilder, row); } - + SSchema* pColSchema = &pSchema[spd->boundColumns[colIdx] - 1]; - + if (bind->num != rowNum) { return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); } - + param.schema = pColSchema; getSTSRowAppendInfo(pBuilder->rowType, spd, colIdx, ¶m.toffset, ¶m.colIdx); @@ -1419,7 +1419,7 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL"); } - + CHECK_CODE(MemRowAppend(&pBuf, NULL, 0, ¶m)); } else { if (bind->buffer_type != pColSchema->type) { @@ -1430,15 +1430,15 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, if (IS_VAR_DATA_TYPE(pColSchema->type)) { colLen = bind->length[r]; } - - CHECK_CODE(MemRowAppend(&pBuf, (char *)bind->buffer + bind->buffer_length * r, colLen, ¶m)); + + CHECK_CODE(MemRowAppend(&pBuf, (char*)bind->buffer + bind->buffer_length * r, colLen, ¶m)); } - + if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) { TSKEY tsKey = TD_ROW_KEY(row); - checkTimestamp(pDataBlock, (const char *)&tsKey); + checkTimestamp(pDataBlock, (const char*)&tsKey); } - + // set the null value for the columns that do not assign values if (rowEnd && (spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) { for (int32_t i = 0; i < spd->numOfCols; ++i) { @@ -1447,13 +1447,13 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, spd->cols[i].toffset); } } - } + } } if (rowEnd) { pDataBlock->size += extendedRowSize * bind->num; - SSubmitBlk *pBlocks = (SSubmitBlk *)(pDataBlock->pData); + SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData); if (TSDB_CODE_SUCCESS != setBlockInfo(pBlocks, pDataBlock, bind->num)) { return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than 32767"); } @@ -1462,8 +1462,7 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, return TSDB_CODE_SUCCESS; } - -int32_t buildBoundFields(SParsedDataColInfo *boundInfo, SSchema *pSchema, int32_t *fieldNum, TAOS_FIELD** fields) { +int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD** fields) { if (fields) { *fields = taosMemoryCalloc(boundInfo->numOfBound, sizeof(TAOS_FIELD)); if (NULL == *fields) { @@ -1483,15 +1482,14 @@ int32_t buildBoundFields(SParsedDataColInfo *boundInfo, SSchema *pSchema, int32_ return TSDB_CODE_SUCCESS; } - -int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TAOS_FIELD** fields) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; +int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags; if (NULL == tags) { return TSDB_CODE_QRY_APP_ERROR; } - - SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta); + + SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta); if (tags->numOfBound <= 0) { *fieldNum = 0; *fields = NULL; @@ -1500,13 +1498,13 @@ int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TA } CHECK_CODE(buildBoundFields(tags, pSchema, fieldNum, fields)); - + return TSDB_CODE_SUCCESS; } -int32_t qBuildStmtColFields(void *pBlock, int32_t *fieldNum, TAOS_FIELD** fields) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); +int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD** fields) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); if (pDataBlock->boundColumnInfo.numOfBound <= 0) { *fieldNum = 0; if (fields) { @@ -1517,9 +1515,6 @@ int32_t qBuildStmtColFields(void *pBlock, int32_t *fieldNum, TAOS_FIELD** fields } CHECK_CODE(buildBoundFields(&pDataBlock->boundColumnInfo, pSchema, fieldNum, fields)); - + return TSDB_CODE_SUCCESS; } - - - diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index bf30915fcbdbfff64abee067f419f887d6018e16..42dde12bff586be5114129442a9a3f87bd427a13 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -16,9 +16,9 @@ #include "parInsertData.h" #include "catalog.h" +#include "parInt.h" #include "parUtil.h" #include "querynodes.h" -#include "parInt.h" #define IS_RAW_PAYLOAD(t) \ (((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert @@ -33,9 +33,9 @@ typedef struct SBlockKeyInfo { SBlockKeyTuple* pKeyTuple; } SBlockKeyInfo; -static int32_t rowDataCompar(const void *lhs, const void *rhs) { - TSKEY left = *(TSKEY *)lhs; - TSKEY right = *(TSKEY *)rhs; +static int32_t rowDataCompar(const void* lhs, const void* rhs) { + TSKEY left = *(TSKEY*)lhs; + TSKEY right = *(TSKEY*)rhs; if (left == right) { return 0; @@ -81,9 +81,9 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t pColList->extendedVarLen = (uint16_t)(nVar * sizeof(VarDataOffsetT)); } -int32_t schemaIdxCompar(const void *lhs, const void *rhs) { - uint16_t left = *(uint16_t *)lhs; - uint16_t right = *(uint16_t *)rhs; +int32_t schemaIdxCompar(const void* lhs, const void* rhs) { + uint16_t left = *(uint16_t*)lhs; + uint16_t right = *(uint16_t*)rhs; if (left == right) { return 0; @@ -92,9 +92,9 @@ int32_t schemaIdxCompar(const void *lhs, const void *rhs) { } } -int32_t boundIdxCompar(const void *lhs, const void *rhs) { - uint16_t left = *(uint16_t *)POINTER_SHIFT(lhs, sizeof(uint16_t)); - uint16_t right = *(uint16_t *)POINTER_SHIFT(rhs, sizeof(uint16_t)); +int32_t boundIdxCompar(const void* lhs, const void* rhs) { + uint16_t left = *(uint16_t*)POINTER_SHIFT(lhs, sizeof(uint16_t)); + uint16_t right = *(uint16_t*)POINTER_SHIFT(rhs, sizeof(uint16_t)); if (left == right) { return 0; @@ -109,14 +109,14 @@ void destroyBoundColumnInfo(void* pBoundInfo) { } SParsedDataColInfo* pColList = (SParsedDataColInfo*)pBoundInfo; - + taosMemoryFreeClear(pColList->boundColumns); taosMemoryFreeClear(pColList->cols); taosMemoryFreeClear(pColList->colIdxInfo); } -static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks) { +static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, const STableMeta* pTableMeta, + STableDataBlocks** dataBlocks) { STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks)); if (dataBuf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -137,18 +137,18 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star } memset(dataBuf->pData, 0, sizeof(SSubmitBlk)); - //Here we keep the tableMeta to avoid it to be remove by other threads. + // Here we keep the tableMeta to avoid it to be remove by other threads. dataBuf->pTableMeta = tableMetaDup(pTableMeta); SParsedDataColInfo* pColInfo = &dataBuf->boundColumnInfo; - SSchema* pSchema = getTableColumnSchema(dataBuf->pTableMeta); + SSchema* pSchema = getTableColumnSchema(dataBuf->pTableMeta); setBoundColumnInfo(pColInfo, pSchema, dataBuf->pTableMeta->tableInfo.numOfColumns); - dataBuf->ordered = true; - dataBuf->prevTS = INT64_MIN; - dataBuf->rowSize = rowSize; - dataBuf->size = startOffset; - dataBuf->vgId = dataBuf->pTableMeta->vgId; + dataBuf->ordered = true; + dataBuf->prevTS = INT64_MIN; + dataBuf->rowSize = rowSize; + dataBuf->size = startOffset; + dataBuf->vgId = dataBuf->pTableMeta->vgId; assert(defaultSize > 0 && pTableMeta != NULL && dataBuf->pTableMeta != NULL); @@ -177,7 +177,8 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) } int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq) { + const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, + SVCreateTbReq* pCreateTbReq) { *dataBlocks = NULL; STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id)); if (t1 != NULL) { @@ -267,14 +268,14 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash) { } // data block is disordered, sort it in ascending order -void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) { - SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData; +void sortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf) { + SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; // size is less than the total size, since duplicated rows may be removed yet. assert(pBlocks->numOfRows * dataBuf->rowSize + sizeof(SSubmitBlk) == dataBuf->size); if (!dataBuf->ordered) { - char *pBlockData = pBlocks->data; + char* pBlockData = pBlocks->data; qsort(pBlockData, pBlocks->numOfRows, dataBuf->rowSize, rowDataCompar); int32_t i = 0; @@ -282,8 +283,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) { // delete rows with timestamp conflicts while (j < pBlocks->numOfRows) { - TSKEY ti = *(TSKEY *)(pBlockData + dataBuf->rowSize * i); - TSKEY tj = *(TSKEY *)(pBlockData + dataBuf->rowSize * j); + TSKEY ti = *(TSKEY*)(pBlockData + dataBuf->rowSize * i); + TSKEY tj = *(TSKEY*)(pBlockData + dataBuf->rowSize * j); if (ti == tj) { ++j; @@ -308,8 +309,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) { } // data block is disordered, sort it in ascending order -int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKeyInfo) { - SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData; +int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo) { + SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; int16_t nRows = pBlocks->numOfRows; // size is less than the total size, since duplicated rows may be removed yet. @@ -317,21 +318,21 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey // allocate memory size_t nAlloc = nRows * sizeof(SBlockKeyTuple); if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { - char *tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc); + char* tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc); if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple *)tmp; + pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple*)tmp; pBlkKeyInfo->maxBytesAlloc = (int32_t)nAlloc; } memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc); int32_t extendedRowSize = getExtendedRowSize(dataBuf); - SBlockKeyTuple *pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; - char * pBlockData = pBlocks->data + pBlocks->schemaLen; + SBlockKeyTuple* pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + char* pBlockData = pBlocks->data + pBlocks->schemaLen; int n = 0; while (n < nRows) { - pBlkKeyTuple->skey = TD_ROW_KEY((STSRow *)pBlockData); + pBlkKeyTuple->skey = TD_ROW_KEY((STSRow*)pBlockData); pBlkKeyTuple->payloadAddr = pBlockData; // next loop @@ -374,13 +375,14 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey } // Erase the empty space reserved for binary data -static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, bool isRawPayload) { +static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, + bool isRawPayload) { // TODO: optimize this function, handle the case while binary is not presented - STableMeta* pTableMeta = pTableDataBlock->pTableMeta; - STableComInfo tinfo = getTableInfo(pTableMeta); - SSchema* pSchema = getTableColumnSchema(pTableMeta); + STableMeta* pTableMeta = pTableDataBlock->pTableMeta; + STableComInfo tinfo = getTableInfo(pTableMeta); + SSchema* pSchema = getTableColumnSchema(pTableMeta); - int32_t nonDataLen = sizeof(SSubmitBlk) + pTableDataBlock->createTbReqLen; + int32_t nonDataLen = sizeof(SSubmitBlk) + pTableDataBlock->createTbReqLen; SSubmitBlk* pBlock = pDataBlock; memcpy(pDataBlock, pTableDataBlock->pData, nonDataLen); pDataBlock = (char*)pDataBlock + nonDataLen; @@ -399,7 +401,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB if (isRawPayload) { SRowBuilder builder = {0}; - + tdSRowInit(&builder, pTableMeta->sversion); tdSRowSetInfo(&builder, getNumOfColumns(pTableMeta), -1, flen); @@ -419,8 +421,8 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB } } else { for (int32_t i = 0; i < numOfRows; ++i) { - char* payload = (blkKeyTuple + i)->payloadAddr; - TDRowLenT rowTLen = TD_ROW_LEN((STSRow*)payload); + char* payload = (blkKeyTuple + i)->payloadAddr; + TDRowLenT rowTLen = TD_ROW_LEN((STSRow*)payload); memcpy(pDataBlock, payload, rowTLen); pDataBlock = POINTER_SHIFT(pDataBlock, rowTLen); pBlock->dataLen += rowTLen; @@ -438,14 +440,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES); STableDataBlocks** p = taosHashIterate(pHashObj, NULL); - STableDataBlocks* pOneTableBlock = *p; - SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock + STableDataBlocks* pOneTableBlock = *p; + SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock while (pOneTableBlock) { - SSubmitBlk* pBlocks = (SSubmitBlk*) pOneTableBlock->pData; + SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData; if (pBlocks->numOfRows > 0) { STableDataBlocks* dataBuf = NULL; - int32_t ret = getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE, - INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL); + int32_t ret = + getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0, + pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL); if (ret != TSDB_CODE_SUCCESS) { taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); @@ -490,7 +493,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta); // erase the empty space reserved for binary data - int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload); + int32_t finalLen = + trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload); assert(finalLen <= len); dataBuf->size += (finalLen + sizeof(SSubmitBlk)); @@ -513,15 +517,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p return TSDB_CODE_SUCCESS; } -int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize) { - size_t remain = pDataBlock->nAllocSize - pDataBlock->size; +int32_t allocateMemForSize(STableDataBlocks* pDataBlock, int32_t allSize) { + size_t remain = pDataBlock->nAllocSize - pDataBlock->size; uint32_t nAllocSizeOld = pDataBlock->nAllocSize; - + // expand the allocated size if (remain < allSize) { pDataBlock->nAllocSize = (pDataBlock->size + allSize) * 1.5; - char *tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); + char* tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); if (tmp != NULL) { pDataBlock->pData = tmp; memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size); @@ -535,11 +539,11 @@ int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize) { return TSDB_CODE_SUCCESS; } -int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t * numOfRows) { +int32_t allocateMemIfNeed(STableDataBlocks* pDataBlock, int32_t rowSize, int32_t* numOfRows) { size_t remain = pDataBlock->nAllocSize - pDataBlock->size; const int factor = 5; - uint32_t nAllocSizeOld = pDataBlock->nAllocSize; - + uint32_t nAllocSizeOld = pDataBlock->nAllocSize; + // expand the allocated size if (remain < rowSize * factor) { while (remain < rowSize * factor) { @@ -547,7 +551,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t remain = pDataBlock->nAllocSize - pDataBlock->size; } - char *tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); + char* tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); if (tmp != NULL) { pDataBlock->pData = tmp; memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size); @@ -563,7 +567,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t return TSDB_CODE_SUCCESS; } -int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo) { +int initRowBuilder(SRowBuilder* pBuilder, int16_t schemaVer, SParsedDataColInfo* pColInfo) { ASSERT(pColInfo->numOfCols > 0 && (pColInfo->numOfBound <= pColInfo->numOfCols)); tdSRowInit(pBuilder, schemaVer); tdSRowSetExtendedInfo(pBuilder, pColInfo->numOfCols, pColInfo->numOfBound, pColInfo->flen, pColInfo->allNullLen, @@ -571,7 +575,6 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo return TSDB_CODE_SUCCESS; } - int32_t qResetStmtDataBlock(void* block, bool keepBuf) { STableDataBlocks* pBlock = (STableDataBlocks*)block; @@ -583,32 +586,31 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) { } memset(pBlock->pData, 0, sizeof(SSubmitBlk)); } else { - pBlock->pData = NULL; + pBlock->pData = NULL; } - - pBlock->ordered = true; - pBlock->prevTS = INT64_MIN; - pBlock->size = sizeof(SSubmitBlk); + + pBlock->ordered = true; + pBlock->prevTS = INT64_MIN; + pBlock->size = sizeof(SSubmitBlk); pBlock->tsSource = -1; pBlock->numOfTables = 1; pBlock->nAllocSize = TSDB_PAYLOAD_SIZE; pBlock->headerSize = pBlock->size; - + memset(&pBlock->rowBuilder, 0, sizeof(pBlock->rowBuilder)); return TSDB_CODE_SUCCESS; } - int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) { *pDst = taosMemoryMalloc(sizeof(STableDataBlocks)); if (NULL == *pDst) { return TSDB_CODE_OUT_OF_MEMORY; } - + memcpy(*pDst, pSrc, sizeof(STableDataBlocks)); ((STableDataBlocks*)(*pDst))->cloned = true; - + return qResetStmtDataBlock(*pDst, false); } @@ -618,7 +620,7 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) { return code; } - STableDataBlocks *pBlock = (STableDataBlocks*)*pDst; + STableDataBlocks* pBlock = (STableDataBlocks*)*pDst; pBlock->pData = taosMemoryMalloc(pBlock->nAllocSize); if (NULL == pBlock->pData) { qFreeStmtDataBlock(pBlock); @@ -630,7 +632,6 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) { return TSDB_CODE_SUCCESS; } - void qFreeStmtDataBlock(void* pDataBlock) { if (pDataBlock == NULL) { return; @@ -650,4 +651,3 @@ void qDestroyStmtDataBlock(void* pBlock) { pDataBlock->cloned = false; destroyDataBlock(pDataBlock); } - diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index fe7835d355bc1a1cea4906ecca124ef1791dd4f8..1338a11f424dacb39ae3c68903669a5db65796f9 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -15,8 +15,8 @@ #include "os.h" #include "parToken.h" -#include "thash.h" #include "taosdef.h" +#include "thash.h" #include "ttokendef.h" // All the keywords of the SQL language are stored in a hash table @@ -28,188 +28,188 @@ typedef struct SKeyword { // keywords in sql string static SKeyword keywordTable[] = { - {"ACCOUNT", TK_ACCOUNT}, - {"ACCOUNTS", TK_ACCOUNTS}, - {"ADD", TK_ADD}, - {"AGGREGATE", TK_AGGREGATE}, - {"ALL", TK_ALL}, - {"ALTER", TK_ALTER}, - {"ANALYZE", TK_ANALYZE}, - {"AND", TK_AND}, - {"APPS", TK_APPS}, - {"AS", TK_AS}, - {"ASC", TK_ASC}, - {"AT_ONCE", TK_AT_ONCE}, - {"BETWEEN", TK_BETWEEN}, - {"BINARY", TK_BINARY}, - {"BIGINT", TK_BIGINT}, - {"BLOCKS", TK_BLOCKS}, - {"BNODE", TK_BNODE}, - {"BNODES", TK_BNODES}, - {"BOOL", TK_BOOL}, - {"BUFSIZE", TK_BUFSIZE}, - {"BY", TK_BY}, - {"CACHE", TK_CACHE}, - {"CACHELAST", TK_CACHELAST}, - {"CAST", TK_CAST}, - {"CLUSTER", TK_CLUSTER}, - {"COLUMN", TK_COLUMN}, - {"COMMENT", TK_COMMENT}, - {"COMP", TK_COMP}, - {"COMPACT", TK_COMPACT}, - {"CONNS", TK_CONNS}, - {"CONNECTION", TK_CONNECTION}, - {"CONNECTIONS", TK_CONNECTIONS}, - {"COUNT", TK_COUNT}, - {"CREATE", TK_CREATE}, - {"DATABASE", TK_DATABASE}, - {"DATABASES", TK_DATABASES}, - {"DAYS", TK_DAYS}, - {"DBS", TK_DBS}, - {"DELAY", TK_DELAY}, - {"DESC", TK_DESC}, - {"DESCRIBE", TK_DESCRIBE}, - {"DISTINCT", TK_DISTINCT}, - {"DNODE", TK_DNODE}, - {"DNODES", TK_DNODES}, - {"DOUBLE", TK_DOUBLE}, - {"DROP", TK_DROP}, - {"EXISTS", TK_EXISTS}, - {"EXPLAIN", TK_EXPLAIN}, - {"FILE_FACTOR", TK_FILE_FACTOR}, - {"FILL", TK_FILL}, - {"FIRST", TK_FIRST}, - {"FLOAT", TK_FLOAT}, - {"FROM", TK_FROM}, - {"FSYNC", TK_FSYNC}, - {"FUNCTION", TK_FUNCTION}, - {"FUNCTIONS", TK_FUNCTIONS}, - {"GRANTS", TK_GRANTS}, - {"GROUP", TK_GROUP}, - {"HAVING", TK_HAVING}, - {"IF", TK_IF}, - {"IMPORT", TK_IMPORT}, - {"IN", TK_IN}, - {"INDEX", TK_INDEX}, - {"INDEXES", TK_INDEXES}, - {"INNER", TK_INNER}, - {"INT", TK_INT}, - {"INSERT", TK_INSERT}, - {"INTEGER", TK_INTEGER}, - {"INTERVAL", TK_INTERVAL}, - {"INTO", TK_INTO}, - {"IS", TK_IS}, - {"JOIN", TK_JOIN}, - {"JSON", TK_JSON}, - {"KEEP", TK_KEEP}, - {"KILL", TK_KILL}, - {"LAST", TK_LAST}, - {"LAST_ROW", TK_LAST_ROW}, - {"LICENCE", TK_LICENCE}, - {"LIKE", TK_LIKE}, - {"LIMIT", TK_LIMIT}, - {"LINEAR", TK_LINEAR}, - {"LOCAL", TK_LOCAL}, - {"MATCH", TK_MATCH}, - {"MAXROWS", TK_MAXROWS}, - {"MINROWS", TK_MINROWS}, - {"MINUS", TK_MINUS}, - {"MNODE", TK_MNODE}, - {"MNODES", TK_MNODES}, - {"MODIFY", TK_MODIFY}, - {"MODULES", TK_MODULES}, - {"NCHAR", TK_NCHAR}, - {"NMATCH", TK_NMATCH}, - {"NONE", TK_NONE}, - {"NOT", TK_NOT}, - {"NOW", TK_NOW}, - {"NULL", TK_NULL}, - {"NULLS", TK_NULLS}, - {"OFFSET", TK_OFFSET}, - {"ON", TK_ON}, - {"OR", TK_OR}, - {"ORDER", TK_ORDER}, - {"OUTPUTTYPE", TK_OUTPUTTYPE}, - {"PARTITION", TK_PARTITION}, - {"PASS", TK_PASS}, - {"PORT", TK_PORT}, - {"PPS", TK_PPS}, - {"PRECISION", TK_PRECISION}, - {"PRIVILEGE", TK_PRIVILEGE}, - {"PREV", TK_PREV}, - {"QNODE", TK_QNODE}, - {"QNODES", TK_QNODES}, - {"QTIME", TK_QTIME}, - {"QUERIES", TK_QUERIES}, - {"QUERY", TK_QUERY}, - {"QUORUM", TK_QUORUM}, - {"RATIO", TK_RATIO}, - {"REPLICA", TK_REPLICA}, - {"RESET", TK_RESET}, - {"RETENTIONS", TK_RETENTIONS}, - {"ROLLUP", TK_ROLLUP}, - {"SCHEMA", TK_SCHEMA}, - {"SCORES", TK_SCORES}, - {"SELECT", TK_SELECT}, - {"SESSION", TK_SESSION}, - {"SET", TK_SET}, - {"SHOW", TK_SHOW}, + {"ACCOUNT", TK_ACCOUNT}, + {"ACCOUNTS", TK_ACCOUNTS}, + {"ADD", TK_ADD}, + {"AGGREGATE", TK_AGGREGATE}, + {"ALL", TK_ALL}, + {"ALTER", TK_ALTER}, + {"ANALYZE", TK_ANALYZE}, + {"AND", TK_AND}, + {"APPS", TK_APPS}, + {"AS", TK_AS}, + {"ASC", TK_ASC}, + {"AT_ONCE", TK_AT_ONCE}, + {"BETWEEN", TK_BETWEEN}, + {"BINARY", TK_BINARY}, + {"BIGINT", TK_BIGINT}, + {"BLOCKS", TK_BLOCKS}, + {"BNODE", TK_BNODE}, + {"BNODES", TK_BNODES}, + {"BOOL", TK_BOOL}, + {"BUFSIZE", TK_BUFSIZE}, + {"BY", TK_BY}, + {"CACHE", TK_CACHE}, + {"CACHELAST", TK_CACHELAST}, + {"CAST", TK_CAST}, + {"CLUSTER", TK_CLUSTER}, + {"COLUMN", TK_COLUMN}, + {"COMMENT", TK_COMMENT}, + {"COMP", TK_COMP}, + {"COMPACT", TK_COMPACT}, + {"CONNS", TK_CONNS}, + {"CONNECTION", TK_CONNECTION}, + {"CONNECTIONS", TK_CONNECTIONS}, + {"COUNT", TK_COUNT}, + {"CREATE", TK_CREATE}, + {"DATABASE", TK_DATABASE}, + {"DATABASES", TK_DATABASES}, + {"DAYS", TK_DAYS}, + {"DBS", TK_DBS}, + {"DELAY", TK_DELAY}, + {"DESC", TK_DESC}, + {"DESCRIBE", TK_DESCRIBE}, + {"DISTINCT", TK_DISTINCT}, + {"DNODE", TK_DNODE}, + {"DNODES", TK_DNODES}, + {"DOUBLE", TK_DOUBLE}, + {"DROP", TK_DROP}, + {"EXISTS", TK_EXISTS}, + {"EXPLAIN", TK_EXPLAIN}, + {"FILE_FACTOR", TK_FILE_FACTOR}, + {"FILL", TK_FILL}, + {"FIRST", TK_FIRST}, + {"FLOAT", TK_FLOAT}, + {"FROM", TK_FROM}, + {"FSYNC", TK_FSYNC}, + {"FUNCTION", TK_FUNCTION}, + {"FUNCTIONS", TK_FUNCTIONS}, + {"GRANTS", TK_GRANTS}, + {"GROUP", TK_GROUP}, + {"HAVING", TK_HAVING}, + {"IF", TK_IF}, + {"IMPORT", TK_IMPORT}, + {"IN", TK_IN}, + {"INDEX", TK_INDEX}, + {"INDEXES", TK_INDEXES}, + {"INNER", TK_INNER}, + {"INT", TK_INT}, + {"INSERT", TK_INSERT}, + {"INTEGER", TK_INTEGER}, + {"INTERVAL", TK_INTERVAL}, + {"INTO", TK_INTO}, + {"IS", TK_IS}, + {"JOIN", TK_JOIN}, + {"JSON", TK_JSON}, + {"KEEP", TK_KEEP}, + {"KILL", TK_KILL}, + {"LAST", TK_LAST}, + {"LAST_ROW", TK_LAST_ROW}, + {"LICENCE", TK_LICENCE}, + {"LIKE", TK_LIKE}, + {"LIMIT", TK_LIMIT}, + {"LINEAR", TK_LINEAR}, + {"LOCAL", TK_LOCAL}, + {"MATCH", TK_MATCH}, + {"MAXROWS", TK_MAXROWS}, + {"MINROWS", TK_MINROWS}, + {"MINUS", TK_MINUS}, + {"MNODE", TK_MNODE}, + {"MNODES", TK_MNODES}, + {"MODIFY", TK_MODIFY}, + {"MODULES", TK_MODULES}, + {"NCHAR", TK_NCHAR}, + {"NMATCH", TK_NMATCH}, + {"NONE", TK_NONE}, + {"NOT", TK_NOT}, + {"NOW", TK_NOW}, + {"NULL", TK_NULL}, + {"NULLS", TK_NULLS}, + {"OFFSET", TK_OFFSET}, + {"ON", TK_ON}, + {"OR", TK_OR}, + {"ORDER", TK_ORDER}, + {"OUTPUTTYPE", TK_OUTPUTTYPE}, + {"PARTITION", TK_PARTITION}, + {"PASS", TK_PASS}, + {"PORT", TK_PORT}, + {"PPS", TK_PPS}, + {"PRECISION", TK_PRECISION}, + {"PRIVILEGE", TK_PRIVILEGE}, + {"PREV", TK_PREV}, + {"QNODE", TK_QNODE}, + {"QNODES", TK_QNODES}, + {"QTIME", TK_QTIME}, + {"QUERIES", TK_QUERIES}, + {"QUERY", TK_QUERY}, + {"QUORUM", TK_QUORUM}, + {"RATIO", TK_RATIO}, + {"REPLICA", TK_REPLICA}, + {"RESET", TK_RESET}, + {"RETENTIONS", TK_RETENTIONS}, + {"ROLLUP", TK_ROLLUP}, + {"SCHEMA", TK_SCHEMA}, + {"SCORES", TK_SCORES}, + {"SELECT", TK_SELECT}, + {"SESSION", TK_SESSION}, + {"SET", TK_SET}, + {"SHOW", TK_SHOW}, {"SINGLE_STABLE", TK_SINGLE_STABLE}, - {"SLIDING", TK_SLIDING}, - {"SLIMIT", TK_SLIMIT}, - {"SMA", TK_SMA}, - {"SMALLINT", TK_SMALLINT}, - {"SNODE", TK_SNODE}, - {"SNODES", TK_SNODES}, - {"SOFFSET", TK_SOFFSET}, - {"STABLE", TK_STABLE}, - {"STABLES", TK_STABLES}, - {"STATE", TK_STATE}, - {"STATE_WINDOW", TK_STATE_WINDOW}, - {"STORAGE", TK_STORAGE}, - {"STREAM", TK_STREAM}, - {"STREAMS", TK_STREAMS}, - {"STREAM_MODE", TK_STREAM_MODE}, - {"STRICT", TK_STRICT}, - {"SYNCDB", TK_SYNCDB}, - {"TABLE", TK_TABLE}, - {"TABLES", TK_TABLES}, - {"TAG", TK_TAG}, - {"TAGS", TK_TAGS}, - {"TBNAME", TK_TBNAME}, - {"TIMESTAMP", TK_TIMESTAMP}, - {"TIMEZONE", TK_TIMEZONE}, - {"TINYINT", TK_TINYINT}, - {"TODAY", TK_TODAY}, - {"TOPIC", TK_TOPIC}, - {"TOPICS", TK_TOPICS}, - {"TRIGGER", TK_TRIGGER}, - {"TSERIES", TK_TSERIES}, - {"TTL", TK_TTL}, - {"UNION", TK_UNION}, - {"UNSIGNED", TK_UNSIGNED}, - {"USE", TK_USE}, - {"USER", TK_USER}, - {"USERS", TK_USERS}, - {"USING", TK_USING}, - {"VALUE", TK_VALUE}, - {"VALUES", TK_VALUES}, - {"VARCHAR", TK_VARCHAR}, - {"VARIABLES", TK_VARIABLES}, - {"VERBOSE", TK_VERBOSE}, - {"VGROUPS", TK_VGROUPS}, - {"VNODES", TK_VNODES}, - {"WAL", TK_WAL}, - {"WATERMARK", TK_WATERMARK}, - {"WHERE", TK_WHERE}, - {"WINDOW_CLOSE", TK_WINDOW_CLOSE}, - {"WITH", TK_WITH}, - {"_QENDTS", TK_QENDTS}, - {"_QSTARTTS", TK_QSTARTTS}, - {"_ROWTS", TK_ROWTS}, - {"_WDURATION", TK_WDURATION}, - {"_WENDTS", TK_WENDTS}, - {"_WSTARTTS", TK_WSTARTTS}, + {"SLIDING", TK_SLIDING}, + {"SLIMIT", TK_SLIMIT}, + {"SMA", TK_SMA}, + {"SMALLINT", TK_SMALLINT}, + {"SNODE", TK_SNODE}, + {"SNODES", TK_SNODES}, + {"SOFFSET", TK_SOFFSET}, + {"STABLE", TK_STABLE}, + {"STABLES", TK_STABLES}, + {"STATE", TK_STATE}, + {"STATE_WINDOW", TK_STATE_WINDOW}, + {"STORAGE", TK_STORAGE}, + {"STREAM", TK_STREAM}, + {"STREAMS", TK_STREAMS}, + {"STREAM_MODE", TK_STREAM_MODE}, + {"STRICT", TK_STRICT}, + {"SYNCDB", TK_SYNCDB}, + {"TABLE", TK_TABLE}, + {"TABLES", TK_TABLES}, + {"TAG", TK_TAG}, + {"TAGS", TK_TAGS}, + {"TBNAME", TK_TBNAME}, + {"TIMESTAMP", TK_TIMESTAMP}, + {"TIMEZONE", TK_TIMEZONE}, + {"TINYINT", TK_TINYINT}, + {"TODAY", TK_TODAY}, + {"TOPIC", TK_TOPIC}, + {"TOPICS", TK_TOPICS}, + {"TRIGGER", TK_TRIGGER}, + {"TSERIES", TK_TSERIES}, + {"TTL", TK_TTL}, + {"UNION", TK_UNION}, + {"UNSIGNED", TK_UNSIGNED}, + {"USE", TK_USE}, + {"USER", TK_USER}, + {"USERS", TK_USERS}, + {"USING", TK_USING}, + {"VALUE", TK_VALUE}, + {"VALUES", TK_VALUES}, + {"VARCHAR", TK_VARCHAR}, + {"VARIABLES", TK_VARIABLES}, + {"VERBOSE", TK_VERBOSE}, + {"VGROUPS", TK_VGROUPS}, + {"VNODES", TK_VNODES}, + {"WAL", TK_WAL}, + {"WATERMARK", TK_WATERMARK}, + {"WHERE", TK_WHERE}, + {"WINDOW_CLOSE", TK_WINDOW_CLOSE}, + {"WITH", TK_WITH}, + {"_QENDTS", TK_QENDTS}, + {"_QSTARTTS", TK_QSTARTTS}, + {"_ROWTS", TK_ROWTS}, + {"_WDURATION", TK_WDURATION}, + {"_WENDTS", TK_WENDTS}, + {"_WSTARTTS", TK_WSTARTTS}, // {"ID", TK_ID}, // {"STRING", TK_STRING}, // {"EQ", TK_EQ}, @@ -293,7 +293,7 @@ static void* keywordHashTable = NULL; static void doInitKeywordsTable(void) { int numOfEntries = tListLen(keywordTable); - + keywordHashTable = taosHashInit(numOfEntries, MurmurHash3_32, true, false); for (int32_t i = 0; i < numOfEntries; i++) { keywordTable[i].len = (uint8_t)strlen(keywordTable[i].name); @@ -306,12 +306,12 @@ static TdThreadOnce keywordsHashTableInit = PTHREAD_ONCE_INIT; static int32_t tKeywordCode(const char* z, int n) { taosThreadOnce(&keywordsHashTableInit, doInitKeywordsTable); - + char key[512] = {0}; - if (n > tListLen(key)) { // too long token, can not be any other token type + if (n > tListLen(key)) { // too long token, can not be any other token type return TK_NK_ID; } - + for (int32_t j = 0; j < n; ++j) { if (z[j] >= 'a' && z[j] <= 'z') { key[j] = (char)(z[j] & 0xDF); // to uppercase and set the null-terminated @@ -325,7 +325,7 @@ static int32_t tKeywordCode(const char* z, int n) { } SKeyword** pKey = (SKeyword**)taosHashGet(keywordHashTable, key, n); - return (pKey != NULL)? (*pKey)->type:TK_NK_ID; + return (pKey != NULL) ? (*pKey)->type : TK_NK_ID; } /* @@ -468,11 +468,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { int delim = z[0]; bool strEnd = false; for (i = 1; z[i]; i++) { - if (z[i] == '\\') { // ignore the escaped character that follows this backslash + if (z[i] == '\\') { // ignore the escaped character that follows this backslash i++; continue; } - + if (z[i] == delim) { if (z[i + 1] == delim) { i++; @@ -482,11 +482,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } } } - + if (z[i]) i++; if (strEnd) { - *tokenId = (delim == '`')? TK_NK_ID:TK_NK_STRING; + *tokenId = (delim == '`') ? TK_NK_ID : TK_NK_STRING; return i; } @@ -521,7 +521,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { case '0': { char next = z[1]; - if (next == 'b') { // bin number + if (next == 'b') { // bin number *tokenId = TK_NK_BIN; for (i = 2; (z[i] == '0' || z[i] == '1'); ++i) { } @@ -531,7 +531,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } return i; - } else if (next == 'x') { //hex number + } else if (next == 'x') { // hex number *tokenId = TK_NK_HEX; for (i = 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) { } @@ -557,10 +557,9 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } /* here is the 1u/1a/2s/3m/9y */ - if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || - z[i] == 'y' || z[i] == 'w' || - z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || - z[i] == 'Y' || z[i] == 'W') && + if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || + z[i] == 'n' || z[i] == 'y' || z[i] == 'w' || z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || + z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'Y' || z[i] == 'W') && (isIdChar[(uint8_t)z[i + 1]] == 0)) { *tokenId = TK_NK_VARIABLE; i += 1; @@ -602,7 +601,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { case 't': case 'F': case 'f': { - for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) { + for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t)z[i]]; i++) { } if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) { @@ -611,10 +610,10 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } } default: { - if (((*z & 0x80) != 0) || !isIdChar[(uint8_t) *z]) { + if (((*z & 0x80) != 0) || !isIdChar[(uint8_t)*z]) { break; } - for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) { + for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t)z[i]]; i++) { } *tokenId = tKeywordCode(z, i); return i; @@ -625,12 +624,12 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { return 0; } -SToken tscReplaceStrToken(char **str, SToken *token, const char* newToken) { - char *src = *str; - size_t nsize = strlen(newToken); +SToken tscReplaceStrToken(char** str, SToken* token, const char* newToken) { + char* src = *str; + size_t nsize = strlen(newToken); int32_t size = (int32_t)strlen(*str) - token->n + (int32_t)nsize + 1; int32_t bsize = (int32_t)((uint64_t)token->z - (uint64_t)src); - SToken ntoken; + SToken ntoken; *str = taosMemoryCalloc(1, size); @@ -660,13 +659,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) { *i += t0.n; int32_t numOfComma = 0; - char t = str[*i]; + char t = str[*i]; while (t == ' ' || t == '\n' || t == '\r' || t == '\t' || t == '\f' || t == ',') { if (t == ',' && (++numOfComma > 1)) { // comma only allowed once t0.n = 0; return t0; } - + t = str[++(*i)]; } @@ -722,15 +721,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) { } } - t0.z = (char*) str + (*i); + t0.z = (char*)str + (*i); *i += t0.n; return t0; } -bool taosIsKeyWordToken(const char* z, int32_t len) { - return (tKeywordCode((char*)z, len) != TK_NK_ID); -} +bool taosIsKeyWordToken(const char* z, int32_t len) { return (tKeywordCode((char*)z, len) != TK_NK_ID); } void taosCleanupKeywordsTable() { void* m = keywordHashTable; @@ -741,7 +738,7 @@ void taosCleanupKeywordsTable() { SToken taosTokenDup(SToken* pToken, char* buf, int32_t len) { assert(pToken != NULL && buf != NULL && len > pToken->n); - + strncpy(buf, pToken->z, pToken->n); buf[pToken->n] = 0; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 01b46c7e1e2cfc7f097912d7f7bd71262dfc9b28..5bb82449b3238a7afb2d80b22946fde2d6bd9448 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -591,25 +591,27 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) { } static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) { - SFmGetFuncInfoParam param = { - .pCtg = pCxt->pParseCxt->pCatalog, - .pRpc = pCxt->pParseCxt->pTransporter, - .pMgmtEps = &pCxt->pParseCxt->mgmtEpSet, - .pErrBuf = pCxt->msgBuf.buf, - .errBufLen = pCxt->msgBuf.len - }; + SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog, + .pRpc = pCxt->pParseCxt->pTransporter, + .pMgmtEps = &pCxt->pParseCxt->mgmtEpSet, + .pErrBuf = pCxt->msgBuf.buf, + .errBufLen = pCxt->msgBuf.len}; pCxt->errCode = fmGetFuncInfo(¶m, pFunc); if (TSDB_CODE_SUCCESS != pCxt->errCode) { return DEAL_RES_ERROR; } - if (fmIsAggFunc(pFunc->funcId) && beforeHaving(pCxt->currClause)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); - } - bool haveAggFunc = false; - nodesWalkExprs(pFunc->pParameterList, haveAggFunction, &haveAggFunc); - if (haveAggFunc) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING); + if (fmIsAggFunc(pFunc->funcId)) { + if (beforeHaving(pCxt->currClause)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); + } + bool haveAggFunc = false; + nodesWalkExprs(pFunc->pParameterList, haveAggFunction, &haveAggFunc); + if (haveAggFunc) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING); + } + pCxt->pCurrStmt->hasAggFuncs = true; } + return DEAL_RES_CONTINUE; } @@ -771,7 +773,7 @@ static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) return TSDB_CODE_OUT_OF_MEMORY; } } - SVgroupInfo vg = { .vgId = MNODE_HANDLE }; + SVgroupInfo vg = {.vgId = MNODE_HANDLE}; memcpy(&vg.epSet, pEpSet, sizeof(SEpSet)); taosArrayPush(*pVgroupList, &vg); return TSDB_CODE_SUCCESS; @@ -787,7 +789,7 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea if ('\0' != pRealTable->qualDbName[0]) { // todo release after mnode can be processed // if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) { - code = getDBVgInfo(pCxt, pRealTable->qualDbName, &vgroupList); + code = getDBVgInfo(pCxt, pRealTable->qualDbName, &vgroupList); // } } else { code = getDBVgInfoImpl(pCxt, pName, &vgroupList); @@ -3481,7 +3483,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName); } SValueNode* pVal = NULL; - int32_t code = translateTagVal(pCxt, pNode, &pVal); + int32_t code = translateTagVal(pCxt, pNode, &pVal); if (TSDB_CODE_SUCCESS == code) { if (NULL == pVal) { pVal = (SValueNode*)pNode; @@ -3511,7 +3513,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau int32_t index = 0; FOREACH(pNode, pStmt->pValsOfTags) { SValueNode* pVal = NULL; - int32_t code = translateTagVal(pCxt, pNode, &pVal); + int32_t code = translateTagVal(pCxt, pNode, &pVal); if (TSDB_CODE_SUCCESS == code) { if (NULL == pVal) { pVal = (SValueNode*)pNode; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 8335d491ed979ec645bc993ccebc636012b5174c..3ffdaad3e6443df4dea09504421ebe867da2f15d 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -63,13 +63,13 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR: return "Corresponding super table not in this db"; case TSDB_CODE_PAR_INVALID_RANGE_OPTION: - return "Invalid option %s: %"PRId64" valid range: [%d, %d]"; + return "Invalid option %s: %" PRId64 " valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_STR_OPTION: return "Invalid option %s: %s"; case TSDB_CODE_PAR_INVALID_ENUM_OPTION: - return "Invalid option %s: %"PRId64", only %d, %d allowed"; + return "Invalid option %s: %" PRId64 ", only %d, %d allowed"; case TSDB_CODE_PAR_INVALID_TTL_OPTION: - return "Invalid option ttl: %"PRId64", should be greater than or equal to %d"; + return "Invalid option ttl: %" PRId64 ", should be greater than or equal to %d"; case TSDB_CODE_PAR_INVALID_KEEP_NUM: return "Invalid number of keep options"; case TSDB_CODE_PAR_INVALID_KEEP_ORDER: @@ -194,20 +194,22 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) { return p; } -SSchema *getTableColumnSchema(const STableMeta *pTableMeta) { +SSchema* getTableColumnSchema(const STableMeta* pTableMeta) { assert(pTableMeta != NULL); - return (SSchema*) pTableMeta->schema; + return (SSchema*)pTableMeta->schema; } static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) { - assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta))); + assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && + colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta))); - SSchema* pSchema = (SSchema*) pTableMeta->schema; + SSchema* pSchema = (SSchema*)pTableMeta->schema; return &pSchema[colIndex]; } SSchema* getTableTagSchema(const STableMeta* pTableMeta) { - assert(pTableMeta != NULL && (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE)); + assert(pTableMeta != NULL && + (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE)); return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns); } @@ -228,40 +230,40 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta) { } int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) { - if (len <=0 || dlen <= 0) return 0; + if (len <= 0 || dlen <= 0) return 0; - char delim = src[0]; + char delim = src[0]; int32_t j = 0; for (uint32_t k = 1; k < len - 1; ++k) { if (j >= dlen) { dst[j - 1] = '\0'; return j; } - if (src[k] == delim && src[k + 1] == delim) { // deal with "", '' + if (src[k] == delim && src[k + 1] == delim) { // deal with "", '' dst[j] = src[k + 1]; j++; k++; continue; } - if (src[k] == '\\') { // deal with escape character - if(src[k+1] == 'n'){ + if (src[k] == '\\') { // deal with escape character + if (src[k + 1] == 'n') { dst[j] = '\n'; - }else if(src[k+1] == 'r'){ + } else if (src[k + 1] == 'r') { dst[j] = '\r'; - }else if(src[k+1] == 't'){ + } else if (src[k + 1] == 't') { dst[j] = '\t'; - }else if(src[k+1] == '\\'){ + } else if (src[k + 1] == '\\') { dst[j] = '\\'; - }else if(src[k+1] == '\''){ + } else if (src[k + 1] == '\'') { dst[j] = '\''; - }else if(src[k+1] == '"'){ + } else if (src[k + 1] == '"') { dst[j] = '"'; - }else if(src[k+1] == '%' || src[k+1] == '_'){ + } else if (src[k + 1] == '%' || src[k + 1] == '_') { dst[j++] = src[k]; - dst[j] = src[k+1]; - }else{ - dst[j] = src[k+1]; + dst[j] = src[k + 1]; + } else { + dst[j] = src[k + 1]; } j++; k++; @@ -275,7 +277,7 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) { return j; } -static bool isValidateTag(char *input) { +static bool isValidateTag(char* input) { if (!input) return false; for (size_t i = 0; i < strlen(input); ++i) { if (isprint(input[i]) == 0) return false; @@ -283,30 +285,30 @@ static bool isValidateTag(char *input) { return true; } -int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* pMsgBuf, int16_t startColId){ +int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* pMsgBuf, int16_t startColId) { // set json NULL data uint8_t jsonNULL = TSDB_DATA_TYPE_NULL; - int jsonIndex = startColId + 1; - if (!json || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0){ + int jsonIndex = startColId + 1; + if (!json || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0) { tdAddColToKVRow(kvRowBuilder, jsonIndex, &jsonNULL, CHAR_BYTES); return TSDB_CODE_SUCCESS; } // set json real data - cJSON *root = cJSON_Parse(json); - if (root == NULL){ + cJSON* root = cJSON_Parse(json); + if (root == NULL) { return buildSyntaxErrMsg(pMsgBuf, "json parse error", json); } int size = cJSON_GetArraySize(root); - if(!cJSON_IsObject(root)){ + if (!cJSON_IsObject(root)) { return buildSyntaxErrMsg(pMsgBuf, "json error invalide value", json); } - int retCode = 0; - char *tagKV = NULL; + int retCode = 0; + char* tagKV = NULL; SHashObj* keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { cJSON* item = cJSON_GetArrayItem(root, i); if (!item) { qError("json inner error:%d", i); @@ -314,40 +316,41 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p goto end; } - char *jsonKey = item->string; - if(!isValidateTag(jsonKey)){ + char* jsonKey = item->string; + if (!isValidateTag(jsonKey)) { retCode = buildSyntaxErrMsg(pMsgBuf, "json key not validate", jsonKey); goto end; } -// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){ -// tscError("json key too long error"); -// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL); -// goto end; -// } + // if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){ + // tscError("json key too long error"); + // retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL); + // goto end; + // } size_t keyLen = strlen(jsonKey); - if(keyLen == 0 || taosHashGet(keyHash, jsonKey, keyLen) != NULL){ + if (keyLen == 0 || taosHashGet(keyHash, jsonKey, keyLen) != NULL) { continue; } // key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: LONG_BYTES tagKV = taosMemoryCalloc(keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES, 1); - if(!tagKV) { + if (!tagKV) { retCode = TSDB_CODE_TSC_OUT_OF_MEMORY; goto end; } strncpy(varDataVal(tagKV), jsonKey, keyLen); varDataSetLen(tagKV, keyLen); - if(taosHashGetSize(keyHash) == 0){ + if (taosHashGetSize(keyHash) == 0) { uint8_t jsonNotNULL = TSDB_DATA_TYPE_JSON; - tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNotNULL, CHAR_BYTES); // add json type + tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNotNULL, CHAR_BYTES); // add json type } - taosHashPut(keyHash, jsonKey, keyLen, &keyLen, CHAR_BYTES); // add key to hash to remove dumplicate, value is useless + taosHashPut(keyHash, jsonKey, keyLen, &keyLen, + CHAR_BYTES); // add key to hash to remove dumplicate, value is useless - if(item->type == cJSON_String){ // add json value format: type|data - char *jsonValue = item->valuestring; + if (item->type == cJSON_String) { // add json value format: type|data + char* jsonValue = item->valuestring; int32_t valLen = (int32_t)strlen(jsonValue); int32_t totalLen = keyLen + VARSTR_HEADER_SIZE + valLen * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE + CHAR_BYTES; - char *tmp = taosMemoryRealloc(tagKV, totalLen); - if(!tmp) { + char* tmp = taosMemoryRealloc(tagKV, totalLen); + if (!tmp) { retCode = TSDB_CODE_TSC_OUT_OF_MEMORY; goto end; } @@ -356,44 +359,47 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); *valueType = TSDB_DATA_TYPE_NCHAR; if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)varDataVal(valueData), - (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) { - qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, strerror(errno)); + (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) { + qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, + strerror(errno)); retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue); goto end; } varDataSetLen(valueData, valLen); tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, totalLen); - }else if(item->type == cJSON_Number){ - if(!isfinite(item->valuedouble)){ + } else if (item->type == cJSON_Number) { + if (!isfinite(item->valuedouble)) { qError("json value is invalidate"); - retCode = buildSyntaxErrMsg(pMsgBuf, "json value number is illegal", json); + retCode = buildSyntaxErrMsg(pMsgBuf, "json value number is illegal", json); goto end; } char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE); char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); - *valueType = (item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE; - if(*valueType== TSDB_DATA_TYPE_DOUBLE) *((double *)valueData) = item->valuedouble; - else if(*valueType == TSDB_DATA_TYPE_BIGINT) *((int64_t *)valueData) = item->valueint; - tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES +LONG_BYTES); - }else if(item->type == cJSON_True || item->type == cJSON_False){ + *valueType = + (item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE; + if (*valueType == TSDB_DATA_TYPE_DOUBLE) + *((double*)valueData) = item->valuedouble; + else if (*valueType == TSDB_DATA_TYPE_BIGINT) + *((int64_t*)valueData) = item->valueint; + tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES); + } else if (item->type == cJSON_True || item->type == cJSON_False) { char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE); char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); *valueType = TSDB_DATA_TYPE_BOOL; *valueData = (char)(item->valueint); tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + CHAR_BYTES); - }else if(item->type == cJSON_NULL){ + } else if (item->type == cJSON_NULL) { char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE); *valueType = TSDB_DATA_TYPE_NULL; tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); - } - else{ + } else { retCode = buildSyntaxErrMsg(pMsgBuf, "invalidate json value", json); goto end; } } - if(taosHashGetSize(keyHash) == 0){ // set json NULL true + if (taosHashGetSize(keyHash) == 0) { // set json NULL true tdAddColToKVRow(kvRowBuilder, jsonIndex, &jsonNULL, CHAR_BYTES); } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index f17322063adc8a176fd0e61115ef81dc39a5121f..09ef130bc1e2c8288f887d214e837281f6eafaa9 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include "os.h" #include "parser.h" +#include "os.h" #include "parInt.h" #include "parToken.h" @@ -23,11 +23,11 @@ bool isInsertSql(const char* pStr, size_t length) { if (NULL == pStr) { return false; } - + int32_t index = 0; do { - SToken t0 = tStrGetToken((char*) pStr, &index, false); + SToken t0 = tStrGetToken((char*)pStr, &index, false); if (t0.type != TK_NK_LP) { return t0.type == TK_INSERT || t0.type == TK_IMPORT; } diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 0f3e2fe414e18ef213f6b1b9257eb053a4c573a6..289888c71b3d6ff8063215e13d12e859f0d9e9fe 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -30,103 +30,128 @@ namespace { void generateInformationSchema(MockCatalogService* mcs) { { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN); builder.done(); } { ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_indexes", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_stables", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1).addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1) + .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_tables", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + ITableBuilder& builder = + mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1).addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1) + .addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } } void generateTestT1(MockCatalogService* mcs) { ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6) - .setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) - .addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20).addColumn("c3", TSDB_DATA_TYPE_BIGINT) - .addColumn("c4", TSDB_DATA_TYPE_DOUBLE).addColumn("c5", TSDB_DATA_TYPE_DOUBLE); + .setPrecision(TSDB_TIME_PRECISION_MILLI) + .setVgid(1) + .addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) + .addColumn("c1", TSDB_DATA_TYPE_INT) + .addColumn("c2", TSDB_DATA_TYPE_BINARY, 20) + .addColumn("c3", TSDB_DATA_TYPE_BIGINT) + .addColumn("c4", TSDB_DATA_TYPE_DOUBLE) + .addColumn("c5", TSDB_DATA_TYPE_DOUBLE); builder.done(); } void generateTestST1(MockCatalogService* mcs) { ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2) - .setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) - .addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20) - .addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20); + .setPrecision(TSDB_TIME_PRECISION_MILLI) + .addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) + .addColumn("c1", TSDB_DATA_TYPE_INT) + .addColumn("c2", TSDB_DATA_TYPE_BINARY, 20) + .addTag("tag1", TSDB_DATA_TYPE_INT) + .addTag("tag2", TSDB_DATA_TYPE_BINARY, 20); builder.done(); mcs->createSubTable("test", "st1", "st1s1", 1); mcs->createSubTable("test", "st1", "st1s2", 2); } -} +} // namespace -int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) { - return 0; -} +int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; } -int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { +int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName, + STableMeta** pTableMeta) { return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta); } -int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo* vgInfo) { +int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps, + const SName* pTableName, SVgroupInfo* vgInfo) { return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo); } -int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgList) { +int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName, + SArray** pVgList) { return mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList); } -int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum) { +int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, + int32_t* tableNum) { return 0; } -int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SArray** vgroupList) { +int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* dbFName, + SArray** vgroupList) { return 0; } @@ -189,6 +214,4 @@ void generateMetaData() { mockCatalogService->showTables(); } -void destroyMetaDataEnv() { - mockCatalogService.reset(); -} +void destroyMetaDataEnv() { mockCatalogService.reset(); } diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index d36448b6869131b72f5d9c56be9bfe6e87d66532..ef989e919051c4e9f5565e7963796d8d8d46a0e5 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -13,19 +13,20 @@ * along with this program. If not, see . */ +#include "mockCatalogService.h" + #include #include #include -#include "mockCatalogService.h" -#include "tdatablock.h" +#include "tdatablock.h" #include "tname.h" #include "ttypes.h" std::unique_ptr mockCatalogService; class TableBuilder : public ITableBuilder { -public: + public: virtual TableBuilder& addColumn(const std::string& name, int8_t type, int32_t bytes) { assert(colId_ <= schema()->tableInfo.numOfTags + schema()->tableInfo.numOfColumns); SSchema* col = schema()->schema + (colId_ - 1); @@ -40,7 +41,7 @@ public: virtual TableBuilder& setVgid(int16_t vgid) { schema()->vgId = vgid; - SVgroupInfo vgroup = { vgid, 0, 0, {0}, 0}; + SVgroupInfo vgroup = {vgid, 0, 0, {0}, 0}; addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030); @@ -55,15 +56,14 @@ public: return *this; } - virtual void done() { - schema()->tableInfo.rowSize = rowsize_; - } + virtual void done() { schema()->tableInfo.rowSize = rowsize_; } -private: + private: friend class MockCatalogServiceImpl; static std::unique_ptr createTableBuilder(int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { - STableMeta* meta = (STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags)); + STableMeta* meta = + (STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags)); if (nullptr == meta) { throw std::bad_alloc(); } @@ -77,29 +77,22 @@ private: meta_->schema = schemaMeta; } - STableMeta* schema() { - return meta_->schema; - } + STableMeta* schema() { return meta_->schema; } - std::shared_ptr table() { - return meta_; - } + std::shared_ptr table() { return meta_; } col_id_t colId_; - int32_t rowsize_; + int32_t rowsize_; std::shared_ptr meta_; }; class MockCatalogServiceImpl { -public: + public: static const int32_t numOfDataTypes = sizeof(tDataTypes) / sizeof(tDataTypes[0]); - MockCatalogServiceImpl() : id_(1) { - } + MockCatalogServiceImpl() : id_(1) {} - int32_t catalogGetHandle() const { - return 0; - } + int32_t catalogGetHandle() const { return 0; } int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { std::unique_ptr table; @@ -108,7 +101,7 @@ public: tNameGetDbName(pTableName, db); const char* tname = tNameGetTableName(pTableName); - int32_t code = copyTableSchemaMeta(db, tname, &table); + int32_t code = copyTableSchemaMeta(db, tname, &table); if (TSDB_CODE_SUCCESS != code) { std::cout << "db : " << db << ", table :" << tname << std::endl; return code; @@ -129,7 +122,8 @@ public: return copyTableVgroup(db, tNameGetTableName(pTableName), vgList); } - TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { + TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, + int32_t numOfColumns, int32_t numOfTags) { builder_ = TableBuilder::createTableBuilder(tableType, numOfColumns, numOfTags); meta_[db][tbname] = builder_->table(); meta_[db][tbname]->schema->uid = id_++; @@ -146,7 +140,7 @@ public: meta_[db][tbname]->schema->uid = id_++; meta_[db][tbname]->schema->tableType = TSDB_CHILD_TABLE; - SVgroupInfo vgroup = { vgid, 0, 0, {0}, 0}; + SVgroupInfo vgroup = {vgid, 0, 0, {0}, 0}; addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030); @@ -158,26 +152,28 @@ public: } void showTables() const { - // number of forward fills - #define NOF(n) ((n) / 2) - // number of backward fills - #define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2) - // center aligned - #define CA(n, s) std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" << "|" - // string field length - #define SFL 20 - // string field header - #define SH(h) CA(SFL, std::string(h)) - // string field - #define SF(n) CA(SFL, n) - // integer field length - #define IFL 10 - // integer field header - #define IH(i) CA(IFL, std::string(i)) - // integer field - #define IF(i) CA(IFL, std::to_string(i)) - // split line - #define SL(sn, in) std::setfill('=') << std::setw((sn) * (SFL + 1) + (in) * (IFL + 1)) << "" << std::setfill(' ') +// number of forward fills +#define NOF(n) ((n) / 2) +// number of backward fills +#define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2) +// center aligned +#define CA(n, s) \ + std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" \ + << "|" +// string field length +#define SFL 20 +// string field header +#define SH(h) CA(SFL, std::string(h)) +// string field +#define SF(n) CA(SFL, n) +// integer field length +#define IFL 10 +// integer field header +#define IH(i) CA(IFL, std::string(i)) +// integer field +#define IF(i) CA(IFL, std::to_string(i)) +// split line +#define SL(sn, in) std::setfill('=') << std::setw((sn) * (SFL + 1) + (in) * (IFL + 1)) << "" << std::setfill(' ') for (const auto& db : meta_) { std::cout << "Databse:" << db.first << std::endl; @@ -185,7 +181,8 @@ public: std::cout << SL(3, 1) << std::endl; for (const auto& table : db.second) { const auto& schema = table.second->schema; - std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision)) << IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl; + std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision)) + << IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl; } std::cout << std::endl; } @@ -200,7 +197,8 @@ public: int16_t numOfFields = numOfColumns + schema->tableInfo.numOfTags; for (int16_t i = 0; i < numOfFields; ++i) { const SSchema* col = schema->schema + i; - std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type)) << IF(col->bytes) << std::endl; + std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type)) + << IF(col->bytes) << std::endl; } std::cout << std::endl; } @@ -219,9 +217,9 @@ public: return tit->second; } -private: + private: typedef std::map> TableMetaCache; - typedef std::map DbMetaCache; + typedef std::map DbMetaCache; std::string toDbname(const std::string& dbFullName) const { std::string::size_type n = dbFullName.find("."); @@ -257,9 +255,7 @@ private: } } - std::string dtToString(int8_t type) const { - return tDataTypes[type].name; - } + std::string dtToString(int8_t type) const { return tDataTypes[type].name; } std::string ftToString(int16_t colid, int16_t numOfColumns) const { return (0 == colid ? "column" : (colid < numOfColumns ? "column" : "tag")); @@ -270,7 +266,8 @@ private: return table ? table->schema : nullptr; } - int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, std::unique_ptr* dst) const { + int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, + std::unique_ptr* dst) const { STableMeta* src = getTableSchemaMeta(db, tbname); if (nullptr == src) { return TSDB_CODE_TSC_INVALID_TABLE_NAME; @@ -305,30 +302,29 @@ private: return TSDB_CODE_SUCCESS; } - uint64_t id_; + uint64_t id_; std::unique_ptr builder_; - DbMetaCache meta_; + DbMetaCache meta_; }; -MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) { -} +MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {} -MockCatalogService::~MockCatalogService() { -} +MockCatalogService::~MockCatalogService() {} -ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { +ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname, + int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { return impl_->createTableBuilder(db, tbname, tableType, numOfColumns, numOfTags); } -void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid) { +void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, + int16_t vgid) { impl_->createSubTable(db, stbname, tbname, vgid); } -void MockCatalogService::showTables() const { - impl_->showTables(); -} +void MockCatalogService::showTables() const { impl_->showTables(); } -std::shared_ptr MockCatalogService::getTableMeta(const std::string& db, const std::string& tbname) const { +std::shared_ptr MockCatalogService::getTableMeta(const std::string& db, + const std::string& tbname) const { return impl_->getTableMeta(db, tbname); } diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index 887979f11e47af79a58ba7d94be4a6e46fbc17c2..edfc40dbc2114611707276d34bbc491714152b26 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -20,17 +20,15 @@ #include #include +#define ALLOW_FORBID_FUNC + #include "catalog.h" class ITableBuilder { -public: - ITableBuilder& addTag(const std::string& name, int8_t type) { - return addColumn(name, type, tDataTypes[type].bytes); - } + public: + ITableBuilder& addTag(const std::string& name, int8_t type) { return addColumn(name, type, tDataTypes[type].bytes); } - ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) { - return addColumn(name, type, bytes); - } + ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) { return addColumn(name, type, bytes); } ITableBuilder& addColumn(const std::string& name, int8_t type) { return addColumn(name, type, tDataTypes[type].bytes); @@ -39,24 +37,23 @@ public: virtual ITableBuilder& addColumn(const std::string& name, int8_t type, int32_t bytes) = 0; virtual ITableBuilder& setVgid(int16_t vgid) = 0; virtual ITableBuilder& setPrecision(uint8_t precision) = 0; - virtual void done() = 0; + virtual void done() = 0; }; struct MockTableMeta { - ~MockTableMeta() { - taosMemoryFree(schema); - } + ~MockTableMeta() { taosMemoryFree(schema); } - STableMeta* schema; + STableMeta* schema; std::vector vgs; }; class MockCatalogServiceImpl; class MockCatalogService { -public: + public: MockCatalogService(); ~MockCatalogService(); - ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags = 0); + ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, + int32_t numOfColumns, int32_t numOfTags = 0); void createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid); void showTables() const; std::shared_ptr getTableMeta(const std::string& db, const std::string& tbname) const; @@ -65,7 +62,7 @@ public: int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const; int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const; -private: + private: std::unique_ptr impl_; }; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 491a923457f19a70b047865e959da66c7d88e970..3cfc16600fb3b10ee5dc78460670ae079cd60759 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -18,14 +18,14 @@ #include -#include "parserTestUtil.h" #include "parInt.h" +#include "parserTestUtil.h" using namespace std; using namespace testing; class ParserTest : public Test { -protected: + protected: void setDatabase(const string& acctId, const string& db) { acctId_ = acctId; db_ = db; @@ -51,7 +51,7 @@ protected: return res; } -private: + private: static const int max_err_len = 1024; bool runImpl(int32_t parseCode, int32_t translateCode) { @@ -105,7 +105,7 @@ private: } string toString(const SNode* pRoot, bool format = false) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; int32_t code = nodesNodeToString(pRoot, format, &pStr, &len); if (code != TSDB_CODE_SUCCESS) { @@ -130,18 +130,18 @@ private: calcConstAstStr_.clear(); } - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - string sqlBuf_; + string acctId_; + string db_; + char errMagBuf_[max_err_len]; + string sqlBuf_; SParseContext cxt_; - SQuery* query_; - string parseErrStr_; - string parsedAstStr_; - string translateErrStr_; - string translatedAstStr_; - string calcConstErrStr_; - string calcConstAstStr_; + SQuery* query_; + string parseErrStr_; + string parsedAstStr_; + string translateErrStr_; + string translatedAstStr_; + string calcConstErrStr_; + string calcConstAstStr_; }; TEST_F(ParserTest, createAccount) { @@ -207,7 +207,9 @@ TEST_F(ParserTest, selectConstant) { bind("SELECT 123, 20.4, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 10s FROM t1"); ASSERT_TRUE(run()); - bind("SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1"); + bind( + "SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", " + "TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1"); ASSERT_TRUE(run()); bind("SELECT 123 + 45 FROM t1 where 2 - 1"); @@ -449,32 +451,32 @@ TEST_F(ParserTest, createDatabase) { bind("create database wxy_db"); ASSERT_TRUE(run()); - bind("create database if not exists wxy_db " - "BLOCKS 100 " - "CACHE 100 " - "CACHELAST 2 " - "COMP 1 " - "DAYS 100 " - "FSYNC 100 " - "MAXROWS 1000 " - "MINROWS 100 " - "KEEP 100 " - "PRECISION 'ms' " - "QUORUM 1 " - "REPLICA 3 " - "TTL 100 " - "WAL 2 " - "VGROUPS 100 " - "SINGLE_STABLE 0 " - "STREAM_MODE 1 " - "RETENTIONS '15s:7d,1m:21d,15m:5y'" - ); + bind( + "create database if not exists wxy_db " + "BLOCKS 100 " + "CACHE 100 " + "CACHELAST 2 " + "COMP 1 " + "DAYS 100 " + "FSYNC 100 " + "MAXROWS 1000 " + "MINROWS 100 " + "KEEP 100 " + "PRECISION 'ms' " + "QUORUM 1 " + "REPLICA 3 " + "TTL 100 " + "WAL 2 " + "VGROUPS 100 " + "SINGLE_STABLE 0 " + "STREAM_MODE 1 " + "RETENTIONS '15s:7d,1m:21d,15m:5y'"); ASSERT_TRUE(run()); - bind("create database if not exists wxy_db " - "DAYS 100m " - "KEEP 200m,300h,400d " - ); + bind( + "create database if not exists wxy_db " + "DAYS 100m " + "KEEP 200m,300h,400d "); ASSERT_TRUE(run()); } @@ -484,14 +486,14 @@ TEST_F(ParserTest, alterDatabase) { bind("alter database wxy_db BLOCKS 200"); ASSERT_TRUE(run()); - bind("alter database wxy_db " - "BLOCKS 200 " - "CACHELAST 1 " - "FSYNC 200 " - "KEEP 200 " - "QUORUM 2 " - "WAL 1 " - ); + bind( + "alter database wxy_db " + "BLOCKS 200 " + "CACHELAST 1 " + "FSYNC 200 " + "KEEP 200 " + "QUORUM 2 " + "WAL 1 "); ASSERT_TRUE(run()); } @@ -515,45 +517,55 @@ TEST_F(ParserTest, createTable) { bind("create table t1(ts timestamp, c1 int)"); ASSERT_TRUE(run()); - bind("create table if not exists test.t1(" - "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, " - "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)" - ); + bind( + "create table if not exists test.t1(" + "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " + "SMALLINT, " + "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), " + "c14 JSON, c15 VARCHAR(50)) " + "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"); ASSERT_TRUE(run()); - - bind("create table if not exists test.t1(" - "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, " - "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) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2" - ); + + bind( + "create table if not exists test.t1(" + "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " + "SMALLINT, " + "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) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"); ASSERT_TRUE(run()); - + bind("create table if not exists t1 using st1 tags(1, 'wxy')"); ASSERT_TRUE(run()); - 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.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)" - ); + 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.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()); bind("create stable t1(ts timestamp, c1 int) TAGS(id int)"); ASSERT_TRUE(run()); - bind("create stable if not exists test.t1(" - "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, " - "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) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2" - ); + bind( + "create stable if not exists test.t1(" + "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " + "SMALLINT, " + "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) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"); ASSERT_TRUE(run()); } diff --git a/source/libs/parser/test/parserInsertTest.cpp b/source/libs/parser/test/parserInsertTest.cpp index 4aec141b5537fdb9b9773fe67dbe1474d85fcabc..308152bf3ea12255ac41640b367a20c96dd50fa7 100644 --- a/source/libs/parser/test/parserInsertTest.cpp +++ b/source/libs/parser/test/parserInsertTest.cpp @@ -22,10 +22,8 @@ using namespace std; using namespace testing; namespace { - string toString(int32_t code) { - return tstrerror(code); - } -} +string toString(int32_t code) { return tstrerror(code); } +} // namespace // syntax: // INSERT INTO @@ -35,7 +33,7 @@ namespace { // VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path // [...]; class InsertTest : public Test { -protected: + protected: void setDatabase(const string& acctId, const string& db) { acctId_ = acctId; db_ = db; @@ -44,12 +42,11 @@ protected: void bind(const char* sql) { reset(); cxt_.acctId = atoi(acctId_.c_str()); - cxt_.db = (char*) db_.c_str(); + cxt_.db = (char*)db_.c_str(); strcpy(sqlBuf_, sql); cxt_.sqlLen = strlen(sql); sqlBuf_[cxt_.sqlLen] = '\0'; cxt_.pSql = sqlBuf_; - } int32_t run() { @@ -62,19 +59,21 @@ protected: void dumpReslut() { SVnodeModifOpStmt* pStmt = getVnodeModifStmt(res_); - size_t num = taosArrayGetSize(pStmt->pDataBlocks); - cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType << ", numOfVgs:" << num << endl; + size_t num = taosArrayGetSize(pStmt->pDataBlocks); + cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType + << ", numOfVgs:" << num << endl; for (size_t i = 0; i < num; ++i) { SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(pStmt->pDataBlocks, i); cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl; SSubmitReq* submit = (SSubmitReq*)vg->pData; cout << "length:" << ntohl(submit->length) << ", numOfBlocks:" << ntohl(submit->numOfBlocks) << endl; - int32_t numOfBlocks = ntohl(submit->numOfBlocks); + int32_t numOfBlocks = ntohl(submit->numOfBlocks); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); for (int32_t i = 0; i < numOfBlocks; ++i) { cout << "Block:" << i << endl; - cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding) << ", sversion:" << ntohl(blk->sversion) - << ", dataLen:" << ntohl(blk->dataLen) << ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl; + cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding) + << ", sversion:" << ntohl(blk->sversion) << ", dataLen:" << ntohl(blk->dataLen) + << ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl; blk = (SSubmitBlk*)(blk->data + ntohl(blk->dataLen)); } } @@ -93,7 +92,7 @@ protected: SSubmitReq* submit = (SSubmitReq*)vg->pData; ASSERT_GE(ntohl(submit->length), 0); ASSERT_GE(ntohl(submit->numOfBlocks), 0); - int32_t numOfBlocks = ntohl(submit->numOfBlocks); + int32_t numOfBlocks = ntohl(submit->numOfBlocks); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); for (int32_t i = 0; i < numOfBlocks; ++i) { ASSERT_EQ(ntohs(blk->numOfRows), (0 == i ? numOfRows1 : (numOfRows2 > 0 ? numOfRows2 : numOfRows1))); @@ -102,7 +101,7 @@ protected: } } -private: + private: static const int max_err_len = 1024; static const int max_sql_len = 1024 * 1024; @@ -114,17 +113,15 @@ private: code_ = TSDB_CODE_SUCCESS; } - SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) { - return (SVnodeModifOpStmt*)pQuery->pRoot; - } + SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) { return (SVnodeModifOpStmt*)pQuery->pRoot; } - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - char sqlBuf_[max_sql_len]; + string acctId_; + string db_; + char errMagBuf_[max_err_len]; + char sqlBuf_[max_sql_len]; SParseContext cxt_; - int32_t code_; - SQuery* res_; + int32_t code_; + SQuery* res_; }; // INSERT INTO tb_name VALUES (field1_value, ...) @@ -141,7 +138,9 @@ TEST_F(InsertTest, singleTableSingleRowTest) { TEST_F(InsertTest, singleTableMultiRowTest) { setDatabase("root", "test"); - bind("insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, 10, 11)"); + bind( + "insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, " + "10, 11)"); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); dumpReslut(); checkReslut(1, 3); @@ -161,20 +160,23 @@ TEST_F(InsertTest, multiTableSingleRowTest) { TEST_F(InsertTest, multiTableMultiRowTest) { setDatabase("root", "test"); - bind("insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")" - " st1s2 values (now, 10, \"131028\")(now+1s, 20, \"132028\")"); + bind( + "insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")" + " st1s2 values (now, 10, \"131028\")(now+1s, 20, \"132028\")"); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); dumpReslut(); checkReslut(2, 3, 2); } -// INSERT INTO +// INSERT INTO // tb1_name USING st1_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...) // tb2_name USING st2_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...) TEST_F(InsertTest, autoCreateTableTest) { setDatabase("root", "test"); - bind("insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")"); + bind( + "insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, " + "\"guangzhou\")"); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); dumpReslut(); checkReslut(1, 3); diff --git a/source/libs/parser/test/parserTestMain.cpp b/source/libs/parser/test/parserTestMain.cpp index 95faadfc34cd9428f9ef49ae1a1addba1179aa3d..62b092251cf143f12da5a619c1b1b8fac7fee07a 100644 --- a/source/libs/parser/test/parserTestMain.cpp +++ b/source/libs/parser/test/parserTestMain.cpp @@ -13,9 +13,9 @@ * along with this program. If not, see . */ -#include #include #include +#include #include #include @@ -23,16 +23,16 @@ #ifdef WINDOWS #define TD_USE_WINSOCK #endif -#include "os.h" -#include "parserTestUtil.h" -#include "parToken.h" #include "functionMgt.h" #include "mockCatalog.h" +#include "os.h" +#include "parToken.h" +#include "parserTestUtil.h" bool g_isDump = false; class ParserEnv : public testing::Environment { -public: + public: virtual void SetUp() { initMetaDataEnv(); generateMetaData(); @@ -49,12 +49,9 @@ public: }; static void parseArg(int argc, char* argv[]) { - int opt = 0; - const char *optstring = ""; - static struct option long_options[] = { - {"dump", no_argument, NULL, 'd'}, - {0, 0, 0, 0} - }; + int opt = 0; + const char* optstring = ""; + static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}}; while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (opt) { case 'd': @@ -67,8 +64,8 @@ static void parseArg(int argc, char* argv[]) { } int main(int argc, char* argv[]) { - testing::AddGlobalTestEnvironment(new ParserEnv()); - testing::InitGoogleTest(&argc, argv); + testing::AddGlobalTestEnvironment(new ParserEnv()); + testing::InitGoogleTest(&argc, argv); parseArg(argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); } diff --git a/source/libs/planner/inc/planInt.h b/source/libs/planner/inc/planInt.h index 7f8bf144999149296519cea8713e700e42b64ecd..e6534f710db03b1f3bf36bab7ead2d281faceee8 100644 --- a/source/libs/planner/inc/planInt.h +++ b/source/libs/planner/inc/planInt.h @@ -26,12 +26,12 @@ extern "C" { #define QUERY_POLICY_HYBRID 2 #define QUERY_POLICY_QNODE 3 -#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__) -#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__) -#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__) -#define planInfo(param, ...) qInfo("PLAN: " param, __VA_ARGS__) -#define planDebug(param, ...) qDebug("PLAN: " param, __VA_ARGS__) -#define planTrace(param, ...) qTrace("PLAN: " param, __VA_ARGS__) +#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__) +#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__) +#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__) +#define planInfo(param, ...) qInfo("PLAN: " param, __VA_ARGS__) +#define planDebug(param, ...) qDebug("PLAN: " param, __VA_ARGS__) +#define planTrace(param, ...) qTrace("PLAN: " param, __VA_ARGS__) int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode); int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index ac5188170af6d148cf0956a670ffe0d92197f568..f8ff2848afd61a5c11dd325a5b51285891b1456e 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -24,11 +24,12 @@ typedef struct SLogicPlanContext { typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, SSelectStmt*, SLogicNode**); typedef int32_t (*FCreateSetOpLogicNode)(SLogicPlanContext*, SSetOperator*, SLogicNode**); -static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode); +static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, + SLogicNode** pLogicNode); static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode); typedef struct SRewriteExprCxt { - int32_t errCode; + int32_t errCode; SNodeList* pExprs; } SRewriteExprCxt; @@ -38,8 +39,8 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) { case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_FUNCTION: { SRewriteExprCxt* pCxt = (SRewriteExprCxt*)pContext; - SNode* pExpr; - int32_t index = 0; + SNode* pExpr; + int32_t index = 0; FOREACH(pExpr, pCxt->pExprs) { if (QUERY_NODE_GROUPING_SET == nodeType(pExpr)) { pExpr = nodesListGetNode(((SGroupingSetNode*)pExpr)->pParameterList, 0); @@ -87,13 +88,13 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) { static int32_t rewriteExprForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) { nodesWalkExprs(pExprs, doNameExpr, NULL); - SRewriteExprCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs }; + SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs}; nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt); return cxt.errCode; } static int32_t rewriteExprs(SNodeList* pExprs, SNodeList* pTarget) { - SRewriteExprCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs }; + SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs}; nodesRewriteExprs(pTarget, doRewriteExpr, &cxt); return cxt.errCode; } @@ -115,9 +116,10 @@ static int32_t pushLogicNode(SLogicPlanContext* pCxt, SLogicNode** pOldRoot, SLo return TSDB_CODE_SUCCESS; } -static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func, SLogicNode** pRoot) { +static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func, + SLogicNode** pRoot) { SLogicNode* pNode = NULL; - int32_t code = func(pCxt, pSelect, &pNode); + int32_t code = func(pCxt, pSelect, &pNode); if (TSDB_CODE_SUCCESS == code && NULL != pNode) { code = pushLogicNode(pCxt, pRoot, pNode); } @@ -173,7 +175,7 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) { } } - bool found = false; + bool found = false; SNode* pCol = NULL; FOREACH(pCol, *pCols) { if (PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pCol)->colId) { @@ -191,7 +193,8 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) { return TSDB_CODE_SUCCESS; } -static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, SLogicNode** pLogicNode) { +static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, + SLogicNode** pLogicNode) { SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; @@ -201,7 +204,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect TSWAP(pScan->pVgroupList, pRealTable->pVgroupList, SVgroupsInfo*); pScan->scanSeq[0] = 1; pScan->scanSeq[1] = 0; - pScan->scanRange = TSWINDOW_INITIALIZER; + pScan->scanRange = TSWINDOW_INITIALIZER; pScan->tableName.type = TSDB_TABLE_NAME_T; pScan->tableName.acctId = pCxt->pPlanCxt->acctId; strcpy(pScan->tableName.dbname, pRealTable->table.dbName); @@ -212,7 +215,7 @@ 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); + int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, &pCols); if (TSDB_CODE_SUCCESS == code) { code = addPrimaryKeyCol(pScan->pMeta->uid, &pCols); } @@ -245,18 +248,18 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } -static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, SLogicNode** pLogicNode) { +static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, + SLogicNode** pLogicNode) { int32_t code = createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode); if (TSDB_CODE_SUCCESS == code) { SNode* pNode; - FOREACH(pNode, (*pLogicNode)->pTargets) { - strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias); - } + FOREACH(pNode, (*pLogicNode)->pTargets) { strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias); } } return code; } -static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable, SLogicNode** pLogicNode) { +static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable, + SLogicNode** pLogicNode) { SJoinLogicNode* pJoin = (SJoinLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; @@ -316,7 +319,8 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } -static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) { +static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, + SLogicNode** pLogicNode) { switch (nodeType(pTable)) { case QUERY_NODE_REAL_TABLE: return createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pTable, pLogicNode); @@ -330,9 +334,10 @@ static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pS return TSDB_CODE_FAILED; } -static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) { +static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, + SLogicNode** pLogicNode) { SLogicNode* pNode = NULL; - int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode); + int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode); if (TSDB_CODE_SUCCESS == code) { pNode->pConditions = nodesCloneNode(pSelect->pWhere); if (NULL != pSelect->pWhere && NULL == pNode->pConditions) { @@ -358,7 +363,7 @@ static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr) } typedef struct SCreateColumnCxt { - int32_t errCode; + int32_t errCode; SNodeList* pList; } SCreateColumnCxt; @@ -375,7 +380,7 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) { case QUERY_NODE_OPERATOR: case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_FUNCTION: { - SExprNode* pExpr = (SExprNode*)pNode; + SExprNode* pExpr = (SExprNode*)pNode; SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); if (NULL == pCol) { return DEAL_RES_ERROR; @@ -392,7 +397,7 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) { } static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pExprs, SNodeList** pList) { - SCreateColumnCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pList = (NULL == *pList ? nodesMakeList() : *pList) }; + SCreateColumnCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pList = (NULL == *pList ? nodesMakeList() : *pList)}; if (NULL == cxt.pList) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -409,12 +414,7 @@ static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pEx } static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { - SNodeList* pAggFuncs = NULL; - int32_t code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAggFuncs); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - if (NULL == pAggFuncs && NULL == pSelect->pGroupByList) { + if (!pSelect->hasAggFuncs && NULL == pSelect->pGroupByList) { return TSDB_CODE_SUCCESS; } @@ -423,18 +423,13 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, return TSDB_CODE_OUT_OF_MEMORY; } + int32_t code = TSDB_CODE_SUCCESS; + // set grouyp keys, agg funcs and having conditions if (NULL != pSelect->pGroupByList) { pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList); if (NULL == pAgg->pGroupKeys) { code = TSDB_CODE_OUT_OF_MEMORY; - } - } - - if (TSDB_CODE_SUCCESS == code && NULL != pAggFuncs) { - pAgg->pAggFuncs = nodesCloneList(pAggFuncs); - if (NULL == pAgg->pAggFuncs) { - code = TSDB_CODE_OUT_OF_MEMORY; } } @@ -442,6 +437,12 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, if (TSDB_CODE_SUCCESS == code) { code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY); } + + if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) { + code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAgg->pAggFuncs); + } + + // rewrite the expression in subsequent clauses if (TSDB_CODE_SUCCESS == code) { code = rewriteExprForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY); } @@ -470,7 +471,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, return code; } -static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, + SLogicNode** pLogicNode) { int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs); if (pCxt->pPlanCxt->streamQuery) { @@ -486,6 +488,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm code = createColumnByRewriteExps(pCxt, pWindow->pFuncs, &pWindow->node.pTargets); } + pSelect->hasAggFuncs = false; + if (TSDB_CODE_SUCCESS == code) { *pLogicNode = (SLogicNode*)pWindow; } else { @@ -495,7 +499,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm return code; } -static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect, + SLogicNode** pLogicNode) { SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW); if (NULL == pWindow) { return TSDB_CODE_OUT_OF_MEMORY; @@ -513,7 +518,8 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } -static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession, SSelectStmt* pSelect, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession, + SSelectStmt* pSelect, SLogicNode** pLogicNode) { SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW); if (NULL == pWindow) { return TSDB_CODE_OUT_OF_MEMORY; @@ -531,7 +537,8 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } -static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, SSelectStmt* pSelect, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, + SSelectStmt* pSelect, SLogicNode** pLogicNode) { SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW); if (NULL == pWindow) { return TSDB_CODE_OUT_OF_MEMORY; @@ -542,7 +549,8 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva pWindow->intervalUnit = ((SValueNode*)pInterval->pInterval)->unit; pWindow->offset = (NULL != pInterval->pOffset ? ((SValueNode*)pInterval->pOffset)->datum.i : 0); pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval); - pWindow->slidingUnit = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit); + pWindow->slidingUnit = + (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit); pWindow->pTspk = nodesCloneNode(pInterval->pCol); if (NULL == pWindow->pTspk) { @@ -591,7 +599,7 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect } SNodeList* pCols = NULL; - int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, &pCols); + int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, &pCols); if (TSDB_CODE_SUCCESS == code && NULL != pCols) { pSort->node.pTargets = nodesCloneList(pCols); if (NULL == pSort->node.pTargets) { @@ -615,14 +623,15 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } -static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, SNodeList** pCols) { +static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, + SNodeList** pCols) { SNodeList* pList = nodesMakeList(); if (NULL == pList) { return TSDB_CODE_OUT_OF_MEMORY; } SNode* pNode; - FOREACH(pNode, pExprs) { + FOREACH(pNode, pExprs) { if (TSDB_CODE_SUCCESS != nodesListAppend(pList, createColumnByExpr(pStmtName, (SExprNode*)pNode))) { nodesDestroyList(pList); return TSDB_CODE_OUT_OF_MEMORY; @@ -687,7 +696,7 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS } SNodeList* pCols = NULL; - int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_PARTITION_BY, NULL, &pCols); + int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_PARTITION_BY, NULL, &pCols); if (TSDB_CODE_SUCCESS == code && NULL != pCols) { pPartition->node.pTargets = nodesCloneList(pCols); if (NULL == pPartition->node.pTargets) { @@ -749,7 +758,7 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { SLogicNode* pRoot = NULL; - int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot); + int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot); if (TSDB_CODE_SUCCESS == code) { code = createChildLogicNode(pCxt, pSelect, createWindowLogicNode, &pRoot); } @@ -778,9 +787,10 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele return code; } -static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, FCreateSetOpLogicNode func, SLogicNode** pRoot) { +static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, + FCreateSetOpLogicNode func, SLogicNode** pRoot) { SLogicNode* pNode = NULL; - int32_t code = func(pCxt, pSetOperator, &pNode); + int32_t code = func(pCxt, pSetOperator, &pNode); if (TSDB_CODE_SUCCESS == code && NULL != pNode) { code = pushLogicNode(pCxt, pRoot, pNode); } @@ -823,7 +833,8 @@ static int32_t createSetOpSortLogicNode(SLogicPlanContext* pCxt, SSetOperator* p return code; } -static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { +static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, + SLogicNode** pLogicNode) { SProjectLogicNode* pProject = (SProjectLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PROJECT); if (NULL == pProject) { return TSDB_CODE_OUT_OF_MEMORY; @@ -890,7 +901,7 @@ static int32_t createSetOpAggLogicNode(SLogicPlanContext* pCxt, SSetOperator* pS static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { SLogicNode* pSetOp = NULL; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; switch (pSetOperator->opType) { case SET_OP_TYPE_UNION_ALL: code = createSetOpProjectLogicNode(pCxt, pSetOperator, &pSetOp); @@ -927,9 +938,10 @@ static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetO return code; } -static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { +static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, + SLogicNode** pLogicNode) { SLogicNode* pRoot = NULL; - int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot); + int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot); if (TSDB_CODE_SUCCESS == code) { code = createSetOpChildLogicNode(pCxt, pSetOperator, createSetOpSortLogicNode, &pRoot); } @@ -944,7 +956,9 @@ static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* } static int32_t getMsgType(ENodeType sqlType) { - return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) ? TDMT_VND_CREATE_TABLE : TDMT_VND_SUBMIT; + return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) + ? TDMT_VND_CREATE_TABLE + : TDMT_VND_SUBMIT; } static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) { @@ -975,8 +989,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi } int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode) { - SLogicPlanContext cxt = { .pPlanCxt = pCxt }; - int32_t code = createQueryLogicNode(&cxt, pCxt->pAstRoot, pLogicNode); + SLogicPlanContext cxt = {.pPlanCxt = pCxt}; + int32_t code = createQueryLogicNode(&cxt, pCxt->pAstRoot, pLogicNode); if (TSDB_CODE_SUCCESS != code) { return code; } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 21e55fc34adb40066551008366ebfb067789b780..f1b16353b6e88b521f5d8a2a3aae1ac096947ed6 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -13,43 +13,43 @@ * along with this program. If not, see . */ -#include "planInt.h" -#include "functionMgt.h" #include "filter.h" +#include "functionMgt.h" +#include "planInt.h" -#define OPTIMIZE_FLAG_MASK(n) (1 << n) +#define OPTIMIZE_FLAG_MASK(n) (1 << n) #define OPTIMIZE_FLAG_OSD OPTIMIZE_FLAG_MASK(0) #define OPTIMIZE_FLAG_CPD OPTIMIZE_FLAG_MASK(1) #define OPTIMIZE_FLAG_OPK OPTIMIZE_FLAG_MASK(2) -#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask) +#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask) #define OPTIMIZE_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) typedef struct SOptimizeContext { SPlanContext* pPlanCxt; - bool optimized; + bool optimized; } SOptimizeContext; typedef int32_t (*FMatch)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); typedef int32_t (*FOptimize)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); typedef struct SOptimizeRule { - char* pName; + char* pName; FOptimize optimizeFunc; } SOptimizeRule; typedef struct SOsdInfo { SScanLogicNode* pScan; - SNodeList* pSdrFuncs; - SNodeList* pDsoFuncs; + SNodeList* pSdrFuncs; + SNodeList* pDsoFuncs; } SOsdInfo; typedef struct SCpdIsMultiTableCondCxt { SNodeList* pLeftCols; SNodeList* pRightCols; - bool havaLeftCol; - bool haveRightCol; + bool havaLeftCol; + bool haveRightCol; } SCpdIsMultiTableCondCxt; typedef enum ECondAction { @@ -101,8 +101,8 @@ static bool osdMayBeOptimized(SLogicNode* pNode) { if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) { return false; } - if (NULL == pNode->pParent || - (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) { + if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && + QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) { return false; } if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent)) { @@ -125,7 +125,7 @@ static SNodeList* osdGetAllFuncs(SLogicNode* pNode) { static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs, SNodeList** pDsoFuncs) { SNodeList* pAllFuncs = osdGetAllFuncs(pScan->node.pParent); - SNode* pFunc = NULL; + SNode* pFunc = NULL; FOREACH(pFunc, pAllFuncs) { int32_t code = TSDB_CODE_SUCCESS; if (fmIsSpecialDataRequiredFunc(((SFunctionNode*)pFunc)->funcId)) { @@ -138,7 +138,7 @@ static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs, nodesDestroyList(*pDsoFuncs); return code; } - } + } return TSDB_CODE_SUCCESS; } @@ -150,7 +150,7 @@ static int32_t osdMatch(SOptimizeContext* pCxt, SLogicNode* pLogicNode, SOsdInfo return osdGetRelatedFuncs(pInfo->pScan, &pInfo->pSdrFuncs, &pInfo->pDsoFuncs); } -static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l , EFuncDataRequired r) { +static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l, EFuncDataRequired r) { switch (l) { case FUNC_DATA_REQUIRED_DATA_LOAD: return l; @@ -169,7 +169,7 @@ static int32_t osdGetDataRequired(SNodeList* pFuncs) { return FUNC_DATA_REQUIRED_DATA_LOAD; } EFuncDataRequired dataRequired = FUNC_DATA_REQUIRED_FILTEROUT; - SNode* pFunc = NULL; + SNode* pFunc = NULL; FOREACH(pFunc, pFuncs) { dataRequired = osdPromoteDataRequired(dataRequired, fmFuncDataRequired((SFunctionNode*)pFunc, NULL)); } @@ -189,7 +189,7 @@ static void setScanWindowInfo(SScanLogicNode* pScan) { static int32_t osdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { SOsdInfo info = {0}; - int32_t code = osdMatch(pCxt, pLogicNode, &info); + int32_t code = osdMatch(pCxt, pLogicNode, &info); if (TSDB_CODE_SUCCESS == code && (NULL != info.pDsoFuncs || NULL != info.pSdrFuncs)) { info.pScan->dataRequired = osdGetDataRequired(info.pSdrFuncs); info.pScan->pDynamicScanFuncs = info.pDsoFuncs; @@ -234,7 +234,7 @@ static int32_t cpdMergeConds(SNode** pDst, SNodeList** pSrc) { return TSDB_CODE_OUT_OF_MEMORY; } pLogicCond->node.resType.type = TSDB_DATA_TYPE_BOOL; - pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; + pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; pLogicCond->condType = LOGIC_COND_TYPE_AND; pLogicCond->pParameterList = *pSrc; *pDst = (SNode*)pLogicCond; @@ -283,7 +283,7 @@ static int32_t cpdPartitionScanLogicCond(SScanLogicNode* pScan, SNode** pPrimary SNodeList* pPrimaryKeyConds = NULL; SNodeList* pOtherConds = NULL; - SNode* pCond = NULL; + SNode* pCond = NULL; FOREACH(pCond, pLogicCond->pParameterList) { if (cpdIsPrimaryKeyCond(pCond)) { code = nodesListMakeAppend(&pPrimaryKeyConds, nodesCloneNode(pCond)); @@ -321,7 +321,7 @@ static int32_t cpdPartitionScanLogicCond(SScanLogicNode* pScan, SNode** pPrimary static int32_t cpdPartitionScanCond(SScanLogicNode* pScan, SNode** pPrimaryKeyCond, SNode** pOtherCond) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(pScan->node.pConditions) && - LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)pScan->node.pConditions)->condType) { + LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)pScan->node.pConditions)->condType) { return cpdPartitionScanLogicCond(pScan, pPrimaryKeyCond, pOtherCond); } @@ -336,7 +336,7 @@ static int32_t cpdPartitionScanCond(SScanLogicNode* pScan, SNode** pPrimaryKeyCo } static int32_t cpdCalcTimeRange(SScanLogicNode* pScan, SNode** pPrimaryKeyCond, SNode** pOtherCond) { - bool isStrict = false; + bool isStrict = false; int32_t code = filterGetTimeRange(*pPrimaryKeyCond, &pScan->scanRange, &isStrict); if (TSDB_CODE_SUCCESS == code) { if (isStrict) { @@ -354,8 +354,8 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode* return TSDB_CODE_SUCCESS; } - SNode* pPrimaryKeyCond = NULL; - SNode* pOtherCond = NULL; + SNode* pPrimaryKeyCond = NULL; + SNode* pOtherCond = NULL; int32_t code = cpdPartitionScanCond(pScan, &pPrimaryKeyCond, &pOtherCond); if (TSDB_CODE_SUCCESS == code && NULL != pPrimaryKeyCond) { code = cpdCalcTimeRange(pScan, &pPrimaryKeyCond, &pOtherCond); @@ -399,13 +399,18 @@ static EDealRes cpdIsMultiTableCondImpl(SNode* pNode, void* pContext) { } static ECondAction cpdCondAction(EJoinType joinType, SNodeList* pLeftCols, SNodeList* pRightCols, SNode* pNode) { - SCpdIsMultiTableCondCxt cxt = { .pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false }; + SCpdIsMultiTableCondCxt cxt = { + .pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false}; nodesWalkExpr(pNode, cpdIsMultiTableCondImpl, &cxt); - return (JOIN_TYPE_INNER != joinType ? COND_ACTION_STAY : - (cxt.havaLeftCol && cxt.haveRightCol ? COND_ACTION_PUSH_JOIN : (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD))); + return (JOIN_TYPE_INNER != joinType + ? COND_ACTION_STAY + : (cxt.havaLeftCol && cxt.haveRightCol + ? COND_ACTION_PUSH_JOIN + : (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD))); } -static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { +static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, + SNode** pRightChildCond) { SLogicConditionNode* pLogicCond = (SLogicConditionNode*)pJoin->node.pConditions; if (LOGIC_COND_TYPE_AND != pLogicCond->condType) { return TSDB_CODE_SUCCESS; @@ -413,13 +418,13 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SNodeList* pOnConds = NULL; SNodeList* pLeftChildConds = NULL; SNodeList* pRightChildConds = NULL; SNodeList* pRemainConds = NULL; - SNode* pCond = NULL; + SNode* pCond = NULL; FOREACH(pCond, pLogicCond->pParameterList) { ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pCond); if (COND_ACTION_PUSH_JOIN == condAction) { @@ -473,9 +478,10 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo return code; } -static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { - SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; - SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; +static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, + SNode** pRightChildCond) { + SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; + SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pJoin->node.pConditions); if (COND_ACTION_STAY == condAction) { return TSDB_CODE_SUCCESS; @@ -490,7 +496,8 @@ static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode* return TSDB_CODE_SUCCESS; } -static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { +static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, + SNode** pRightChildCond) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(pJoin->node.pConditions)) { return cpdPartitionLogicCond(pJoin, pOnCond, pLeftChildCond, pRightChildCond); } else { @@ -509,7 +516,7 @@ static int32_t cpdPushCondToScan(SOptimizeContext* pCxt, SScanLogicNode* pScan, static int32_t cpdPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SNode** pCond) { switch (nodeType(pChild)) { case QUERY_NODE_LOGIC_PLAN_SCAN: - return cpdPushCondToScan(pCxt, (SScanLogicNode*)pChild, pCond); + return cpdPushCondToScan(pCxt, (SScanLogicNode*)pChild, pCond); default: break; } @@ -531,8 +538,8 @@ static bool cpdIsPrimaryKeyEqualCond(SJoinLogicNode* pJoin, SNode* pCond) { if (QUERY_NODE_OPERATOR != nodeType(pCond)) { return false; } - SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; - SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; + SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; + SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; SOperatorNode* pOper = (SOperatorNode*)pJoin->pOnConditions; if (cpdIsPrimaryKey(pOper->pLeft, pLeftCols)) { return cpdIsPrimaryKey(pOper->pRight, pRightCols); @@ -586,9 +593,9 @@ static int32_t cpdPushJoinCondition(SOptimizeContext* pCxt, SJoinLogicNode* pJoi return cpdCheckJoinOnCond(pCxt, pJoin); } - SNode* pOnCond = NULL; - SNode* pLeftChildCond = NULL; - SNode* pRightChildCond = NULL; + SNode* pOnCond = NULL; + SNode* pLeftChildCond = NULL; + SNode* pRightChildCond = NULL; int32_t code = cpdPartitionCond(pJoin, &pOnCond, &pLeftChildCond, &pRightChildCond); if (TSDB_CODE_SUCCESS == code && NULL != pOnCond) { code = cpdPushCondToOnCond(pCxt, pJoin, &pOnCond); @@ -694,7 +701,7 @@ static int32_t opkGetScanNodesImpl(SLogicNode* pNode, bool* pNotOptimize, SNodeL } static int32_t opkGetScanNodes(SLogicNode* pNode, SNodeList** pScanNodes) { - bool notOptimize = false; + bool notOptimize = false; int32_t code = opkGetScanNodesImpl(pNode, ¬Optimize, pScanNodes); if (TSDB_CODE_SUCCESS != code || notOptimize) { nodesClearList(*pScanNodes); @@ -746,7 +753,7 @@ static int32_t opkOptimizeImpl(SOptimizeContext* pCxt, SSortLogicNode* pSort) { return TSDB_CODE_SUCCESS; } SNodeList* pScanNodes = NULL; - int32_t code = opkGetScanNodes(nodesListGetNode(pSort->node.pChildren, 0), &pScanNodes); + int32_t code = opkGetScanNodes(nodesListGetNode(pSort->node.pChildren, 0), &pScanNodes); if (TSDB_CODE_SUCCESS == code && NULL != pScanNodes) { code = opkDoOptimized(pCxt, pSort, pScanNodes); } @@ -762,16 +769,14 @@ static int32_t opkOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { return opkOptimizeImpl(pCxt, pSort); } -static const SOptimizeRule optimizeRuleSet[] = { - { .pName = "OptimizeScanData", .optimizeFunc = osdOptimize }, - { .pName = "ConditionPushDown", .optimizeFunc = cpdOptimize }, - { .pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize } -}; +static const SOptimizeRule optimizeRuleSet[] = {{.pName = "OptimizeScanData", .optimizeFunc = osdOptimize}, + {.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize}, + {.pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize}}; static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule)); static int32_t applyOptimizeRule(SPlanContext* pCxt, SLogicNode* pLogicNode) { - SOptimizeContext cxt = { .pPlanCxt = pCxt, .optimized = false }; + SOptimizeContext cxt = {.pPlanCxt = pCxt, .optimized = false}; do { cxt.optimized = false; for (int32_t i = 0; i < optimizeRuleNum; ++i) { @@ -784,6 +789,4 @@ static int32_t applyOptimizeRule(SPlanContext* pCxt, SLogicNode* pLogicNode) { return TSDB_CODE_SUCCESS; } -int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { - return applyOptimizeRule(pCxt, pLogicNode); -} +int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { return applyOptimizeRule(pCxt, pLogicNode); } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 28635ef940dfcfae6d3f7f2b2f4174740c42b64c..4997cfd64465dbf0b5d87a0f9b32e77335eb264f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -15,26 +15,26 @@ #include "planInt.h" +#include "catalog.h" #include "functionMgt.h" #include "tglobal.h" -#include "catalog.h" typedef struct SSlotIdInfo { int16_t slotId; - bool set; + bool set; } SSlotIdInfo; typedef struct SSlotIndex { int16_t dataBlockId; - SArray* pSlotIdsInfo; // duplicate name slot + SArray* pSlotIdsInfo; // duplicate name slot } SSlotIndex; typedef struct SPhysiPlanContext { SPlanContext* pPlanCxt; - int32_t errCode; - int16_t nextDataBlockId; - SArray* pLocationHelper; - SArray* pExecNodeList; + int32_t errCode; + int16_t nextDataBlockId; + SArray* pLocationHelper; + SArray* pExecNodeList; } SPhysiPlanContext; static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) { @@ -84,27 +84,28 @@ static int32_t createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId, S static int32_t putSlotToHashImpl(int16_t dataBlockId, int16_t slotId, const char* pName, int32_t len, SHashObj* pHash) { SSlotIndex* pIndex = taosHashGet(pHash, pName, len); if (NULL != pIndex) { - SSlotIdInfo info = { .slotId = slotId, .set = false }; + SSlotIdInfo info = {.slotId = slotId, .set = false}; taosArrayPush(pIndex->pSlotIdsInfo, &info); return TSDB_CODE_SUCCESS; } - SSlotIndex index = { .dataBlockId = dataBlockId, .pSlotIdsInfo = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SSlotIdInfo)) }; + SSlotIndex index = {.dataBlockId = dataBlockId, .pSlotIdsInfo = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SSlotIdInfo))}; if (NULL == index.pSlotIdsInfo) { return TSDB_CODE_OUT_OF_MEMORY; } - SSlotIdInfo info = { .slotId = slotId, .set = false }; + SSlotIdInfo info = {.slotId = slotId, .set = false}; taosArrayPush(index.pSlotIdsInfo, &info); return taosHashPut(pHash, pName, len, &index, sizeof(SSlotIndex)); } static int32_t putSlotToHash(int16_t dataBlockId, int16_t slotId, SNode* pNode, SHashObj* pHash) { - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; int32_t len = getSlotKey(pNode, NULL, name); return putSlotToHashImpl(dataBlockId, slotId, name, len, pHash); } -static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, SHashObj** pDescHash) { +static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, + SHashObj** pDescHash) { SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == pHash) { return TSDB_CODE_OUT_OF_MEMORY; @@ -118,7 +119,8 @@ static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity return TSDB_CODE_SUCCESS; } -static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, SHashObj* pHash) { +static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, + SHashObj* pHash) { pDataBlockDesc->pSlots = nodesMakeList(); if (NULL == pDataBlockDesc->pSlots) { return TSDB_CODE_OUT_OF_MEMORY; @@ -126,7 +128,7 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD int32_t code = TSDB_CODE_SUCCESS; int16_t slotId = 0; - SNode* pNode = NULL; + SNode* pNode = NULL; FOREACH(pNode, pList) { code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, slotId, true)); if (TSDB_CODE_SUCCESS == code) { @@ -151,7 +153,7 @@ static int32_t createDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SD pDesc->dataBlockId = pCxt->nextDataBlockId++; SHashObj* pHash = NULL; - int32_t code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash); + int32_t code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash); if (TSDB_CODE_SUCCESS == code) { code = buildDataBlockSlots(pCxt, pList, pDesc, pHash); } @@ -177,19 +179,20 @@ static int16_t getUnsetSlotId(const SArray* pSlotIdsInfo) { return ((SSlotIdInfo*)taosArrayGet(pSlotIdsInfo, 0))->slotId; } -static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, const char* pStmtName, bool output) { +static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, + const char* pStmtName, bool output) { if (NULL == pList) { return TSDB_CODE_SUCCESS; } - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SHashObj* pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId); - int16_t nextSlotId = taosHashGetSize(pHash), slotId = 0; - SNode* pNode = NULL; + 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(pExpr, pStmtName, name); + 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(pExpr, pStmtName, name); SSlotIndex* pIndex = taosHashGet(pHash, name, len); if (NULL == pIndex) { code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pExpr, nextSlotId, output)); @@ -213,7 +216,7 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, REPLACE_NODE(pTarget); } } - + if (TSDB_CODE_SUCCESS != code) { break; } @@ -231,7 +234,7 @@ static int32_t addDataBlockSlot(SPhysiPlanContext* pCxt, SNode** pNode, SDataBlo } SNodeList* pList = NULL; - int32_t code = nodesListMakeAppend(&pList, *pNode); + int32_t code = nodesListMakeAppend(&pList, *pNode); if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pList, pDataBlockDesc); } @@ -242,7 +245,8 @@ static int32_t addDataBlockSlot(SPhysiPlanContext* pCxt, SNode** pNode, SDataBlo return code; } -static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) { +static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, + SDataBlockDescNode* pDataBlockDesc) { return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, pStmtName, true); } @@ -251,7 +255,7 @@ static int32_t pushdownDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, } typedef struct SSetSlotIdCxt { - int32_t errCode; + int32_t errCode; SHashObj* pLeftHash; SHashObj* pRightHash; } SSetSlotIdCxt; @@ -259,9 +263,9 @@ typedef struct SSetSlotIdCxt { static EDealRes doSetSlotId(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode) && 0 != strcmp(((SColumnNode*)pNode)->colName, "*")) { SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext; - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; - int32_t len = getSlotKey(pNode, NULL, name); - SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, len); + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; + int32_t len = getSlotKey(pNode, NULL, name); + SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, len); if (NULL == pIndex) { pIndex = taosHashGet(pCxt->pRightHash, name, len); } @@ -277,17 +281,17 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } -static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode, SNode** pOutput) { +static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode, + SNode** pOutput) { SNode* pRes = nodesCloneNode(pNode); if (NULL == pRes) { return TSDB_CODE_OUT_OF_MEMORY; } SSetSlotIdCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), - .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)) - }; + .errCode = TSDB_CODE_SUCCESS, + .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), + .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))}; nodesWalkExpr(pRes, doSetSlotId, &cxt); if (TSDB_CODE_SUCCESS != cxt.errCode) { nodesDestroyNode(pRes); @@ -298,17 +302,17 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i return TSDB_CODE_SUCCESS; } -static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, const SNodeList* pList, SNodeList** pOutput) { +static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, + const SNodeList* pList, SNodeList** pOutput) { SNodeList* pRes = nodesCloneList(pList); if (NULL == pRes) { return TSDB_CODE_OUT_OF_MEMORY; } SSetSlotIdCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), - .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)) - }; + .errCode = TSDB_CODE_SUCCESS, + .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), + .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))}; nodesWalkExprs(pRes, doSetSlotId, &cxt); if (TSDB_CODE_SUCCESS != cxt.errCode) { nodesDestroyList(pRes); @@ -346,7 +350,8 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, uint8_t precision, SLo static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pLogicNode, SPhysiNode* pPhysiNode) { if (NULL != pLogicNode->pConditions) { - return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions, &pPhysiNode->pConditions); + return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions, + &pPhysiNode->pConditions); } return TSDB_CODE_SUCCESS; } @@ -364,15 +369,11 @@ static int32_t sortScanCols(SNodeList* pScanCols) { } SNode* pCol = NULL; - FOREACH(pCol, pScanCols) { - taosArrayPush(pArray, &pCol); - } + FOREACH(pCol, pScanCols) { taosArrayPush(pArray, &pCol); } taosArraySort(pArray, colIdCompare); int32_t index = 0; - FOREACH(pCol, pScanCols) { - REPLACE_NODE(taosArrayGetP(pArray, index++)); - } + FOREACH(pCol, pScanCols) { REPLACE_NODE(taosArrayGetP(pArray, index++)); } taosArrayDestroy(pArray); return TSDB_CODE_SUCCESS; @@ -386,7 +387,8 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys return sortScanCols(pScanPhysiNode->pScanCols); } -static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) { +static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, + SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) { int32_t code = createScanCols(pCxt, pScanPhysiNode, pScanLogicNode->pScanCols); if (TSDB_CODE_SUCCESS == code) { // Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t @@ -412,19 +414,23 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNo static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAddr) { pNodeAddr->nodeId = vg->vgId; - pNodeAddr->epSet = vg->epSet; + pNodeAddr->epSet = vg->epSet; } static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); + STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode( + pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); if (NULL == pTagScan) { return TSDB_CODE_OUT_OF_MEMORY; } return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTagScan, pPhyNode); } -static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); +static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { + STableScanPhysiNode* pTableScan = + (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, + QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); if (NULL == pTableScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -451,8 +457,11 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode); } -static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); +static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, + SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { + SSystemTableScanPhysiNode* pScan = + (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, + (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -463,7 +472,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode); } else { - SQueryNodeAddr addr = { .nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet }; + SQueryNodeAddr addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}; taosArrayPush(pCxt->pExecNodeList, &addr); } pScan->mgmtEpSet = pCxt->pPlanCxt->mgmtEpSet; @@ -472,15 +481,19 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode); } -static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); +static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { + SStreamScanPhysiNode* pScan = + (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, + (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode); } -static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { +static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { switch (pScanLogicNode->scanType) { case SCAN_TYPE_TAG: return createTagScanPhysiNode(pCxt, pScanLogicNode, pPhyNode); @@ -496,22 +509,26 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, return TSDB_CODE_FAILED; } -static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) { - SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); +static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, + SPhysiNode** pPhyNode) { + SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, + QUERY_NODE_PHYSICAL_PLAN_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; } SDataBlockDescNode* pLeftDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc; SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; pJoin->joinType = pJoinLogicNode->joinType; if (NULL != pJoinLogicNode->pOnConditions) { - code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); + code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, + &pJoin->pOnConditions); } if (TSDB_CODE_SUCCESS == code) { - code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets); + code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, + &pJoin->pTargets); } if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc); @@ -530,9 +547,9 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren } typedef struct SRewritePrecalcExprsCxt { - int32_t errCode; - int32_t planNodeId; - int32_t rewriteId; + int32_t errCode; + int32_t planNodeId; + int32_t rewriteId; SNodeList* pPrecalcExprs; } SRewritePrecalcExprsCxt; @@ -555,7 +572,8 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) if ('\0' != pRewrittenExpr->aliasName[0]) { strcpy(pCol->colName, pRewrittenExpr->aliasName); } else { - snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, pCxt->rewriteId); + snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, + pCxt->rewriteId); strcpy(pCol->colName, pRewrittenExpr->aliasName); } nodesDestroyNode(*pNode); @@ -581,7 +599,8 @@ static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } -static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs, SNodeList** pRewrittenList) { +static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs, + SNodeList** pRewrittenList) { if (NULL == pList) { return TSDB_CODE_SUCCESS; } @@ -613,7 +632,7 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN return TSDB_CODE_OUT_OF_MEMORY; } } - SRewritePrecalcExprsCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pPrecalcExprs = *pPrecalcExprs }; + SRewritePrecalcExprsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pPrecalcExprs = *pPrecalcExprs}; nodesRewriteExprs(*pRewrittenList, doRewritePrecalcExprs, &cxt); if (0 == LIST_LENGTH(cxt.pPrecalcExprs)) { nodesDestroyList(cxt.pPrecalcExprs); @@ -622,13 +641,14 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN return cxt.errCode; } -static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs, SNode** pRewritten) { +static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs, + SNode** pRewritten) { if (NULL == pNode) { return TSDB_CODE_SUCCESS; } SNodeList* pList = NULL; - int32_t code = nodesListMakeAppend(&pList, pNode); + int32_t code = nodesListMakeAppend(&pList, pNode); SNodeList* pRewrittenList = NULL; if (TSDB_CODE_SUCCESS == code) { code = rewritePrecalcExprs(pCxt, pList, pPrecalcExprs, &pRewrittenList); @@ -641,8 +661,10 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi return code; } -static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) { - SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG); +static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, + SPhysiNode** pPhyNode) { + SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, + QUERY_NODE_PHYSICAL_PLAN_AGG); if (NULL == pAgg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -650,7 +672,7 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SNodeList* pPrecalcExprs = NULL; SNodeList* pGroupKeys = NULL; SNodeList* pAggFuncs = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pAggLogicNode->pGroupKeys, &pPrecalcExprs, &pGroupKeys); + int32_t code = rewritePrecalcExprs(pCxt, pAggLogicNode->pGroupKeys, &pPrecalcExprs, &pGroupKeys); if (TSDB_CODE_SUCCESS == code) { code = rewritePrecalcExprs(pCxt, pAggLogicNode->pAggFuncs, &pPrecalcExprs, &pAggFuncs); } @@ -695,8 +717,10 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, return code; } -static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { - SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); +static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { + SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); if (NULL == pProject) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -706,9 +730,11 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild pProject->slimit = pProjectLogicNode->slimit; pProject->soffset = pProjectLogicNode->soffset; - int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, pProjectLogicNode->pProjections, &pProject->pProjections); + 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); + code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, + pProject->node.pOutputDataBlockDesc); } if (TSDB_CODE_SUCCESS == code) { code = setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject); @@ -723,8 +749,10 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild return code; } -static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); +static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, + SPhysiNode** pPhyNode) { + SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode( + pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); if (NULL == pExchange) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -734,12 +762,14 @@ static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogic return TSDB_CODE_SUCCESS; } -static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); +static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, + SPhysiNode** pPhyNode) { + SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode( + pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } - + int32_t code = TSDB_CODE_SUCCESS; pScan->pScanCols = nodesCloneList(pExchangeLogicNode->node.pTargets); @@ -767,7 +797,8 @@ static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExc return code; } -static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { +static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, + SPhysiNode** pPhyNode) { if (pCxt->pPlanCxt->streamQuery) { return createStreamScanPhysiNodeByExchange(pCxt, pExchangeLogicNode, pPhyNode); } else { @@ -775,10 +806,11 @@ static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNo } } -static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { +static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { SNodeList* pPrecalcExprs = NULL; SNodeList* pFuncs = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pWindowLogicNode->pFuncs, &pPrecalcExprs, &pFuncs); + int32_t code = rewritePrecalcExprs(pCxt, pWindowLogicNode->pFuncs, &pPrecalcExprs, &pFuncs); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -812,8 +844,10 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* return code; } -static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); +static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { + SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); if (NULL == pInterval) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -833,8 +867,10 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode); } -static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); +static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { + SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); if (NULL == pSession) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -844,15 +880,17 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* return createWindowPhysiNodeFinalize(pCxt, pChildren, &pSession->window, pWindowLogicNode, pPhyNode); } -static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); +static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { + SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); if (NULL == pState) { return TSDB_CODE_OUT_OF_MEMORY; } SNodeList* pPrecalcExprs = NULL; - SNode* pStateKey = NULL; - int32_t code = rewritePrecalcExpr(pCxt, pWindowLogicNode->pStateExpr, &pPrecalcExprs, &pStateKey); + SNode* pStateKey = NULL; + int32_t code = rewritePrecalcExpr(pCxt, pWindowLogicNode->pStateExpr, &pPrecalcExprs, &pStateKey); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -878,7 +916,8 @@ static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pC return createWindowPhysiNodeFinalize(pCxt, pChildren, &pState->window, pWindowLogicNode, pPhyNode); } -static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { +static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, + SPhysiNode** pPhyNode) { switch (pWindowLogicNode->winType) { case WINDOW_TYPE_INTERVAL: return createIntervalPhysiNode(pCxt, pChildren, pWindowLogicNode, pPhyNode); @@ -892,15 +931,17 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr return TSDB_CODE_FAILED; } -static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) { - SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT); +static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, + SPhysiNode** pPhyNode) { + SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, + QUERY_NODE_PHYSICAL_PLAN_SORT); if (NULL == pSort) { return TSDB_CODE_OUT_OF_MEMORY; } SNodeList* pPrecalcExprs = NULL; SNodeList* pSortKeys = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pSortLogicNode->pSortKeys, &pPrecalcExprs, &pSortKeys); + int32_t code = rewritePrecalcExprs(pCxt, pSortLogicNode->pSortKeys, &pPrecalcExprs, &pSortKeys); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -931,15 +972,17 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren return code; } -static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) { - SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); +static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) { + SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); if (NULL == pPart) { return TSDB_CODE_OUT_OF_MEMORY; } SNodeList* pPrecalcExprs = NULL; SNodeList* pPartitionKeys = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pPartLogicNode->pPartitionKeys, &pPrecalcExprs, &pPartitionKeys); + int32_t code = rewritePrecalcExprs(pCxt, pPartLogicNode->pPartitionKeys, &pPrecalcExprs, &pPartitionKeys); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -970,7 +1013,8 @@ static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi return code; } -static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SNodeList* pChildren, SPhysiNode** pPhyNode) { +static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, + SNodeList* pChildren, SPhysiNode** pPhyNode) { switch (nodeType(pLogicNode)) { case QUERY_NODE_LOGIC_PLAN_SCAN: return createScanPhysiNode(pCxt, pSubplan, (SScanLogicNode*)pLogicNode, pPhyNode); @@ -995,7 +1039,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode return TSDB_CODE_FAILED; } -static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SPhysiNode** pPhyNode) { +static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, + SPhysiNode** pPhyNode) { SNodeList* pChildren = nodesMakeList(); if (NULL == pChildren) { return TSDB_CODE_OUT_OF_MEMORY; @@ -1019,9 +1064,7 @@ static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, if (TSDB_CODE_SUCCESS == code) { (*pPhyNode)->pChildren = pChildren; SNode* pChild; - FOREACH(pChild, (*pPhyNode)->pChildren) { - ((SPhysiNode*)pChild)->pParent = (*pPhyNode); - } + FOREACH(pChild, (*pPhyNode)->pChildren) { ((SPhysiNode*)pChild)->pParent = (*pPhyNode); } } else { nodesDestroyList(pChildren); } @@ -1097,7 +1140,7 @@ static int32_t createPhysiSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogic } else { nodesDestroyNode(pSubplan); } - + return code; } @@ -1137,9 +1180,10 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l return nodesListStrictAppend(pGroup->pNodeList, pSubplan); } -static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, SQueryPlan* pQueryPlan) { +static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, + SQueryPlan* pQueryPlan) { SSubplan* pSubplan = NULL; - int32_t code = createPhysiSubplan(pCxt, pLogicSubplan, &pSubplan); + int32_t code = createPhysiSubplan(pCxt, pLogicSubplan, &pSubplan); if (TSDB_CODE_SUCCESS == code) { code = pushSubplan(pCxt, pSubplan, pLogicSubplan->level, pQueryPlan->pSubplans); @@ -1196,7 +1240,7 @@ static int32_t doCreatePhysiPlan(SPhysiPlanContext* pCxt, SQueryLogicPlan* pLogi } static void destoryLocationHash(void* p) { - SHashObj* pHash = *(SHashObj**)p; + SHashObj* pHash = *(SHashObj**)p; SSlotIndex* pIndex = taosHashIterate(pHash, NULL); while (NULL != pIndex) { taosArrayDestroy(pIndex->pSlotIdsInfo); @@ -1221,13 +1265,11 @@ static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) { } int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) { - SPhysiPlanContext cxt = { - .pPlanCxt = pCxt, - .errCode = TSDB_CODE_SUCCESS, - .nextDataBlockId = 0, - .pLocationHelper = taosArrayInit(32, POINTER_BYTES), - .pExecNodeList = pExecNodeList - }; + SPhysiPlanContext cxt = {.pPlanCxt = pCxt, + .errCode = TSDB_CODE_SUCCESS, + .nextDataBlockId = 0, + .pLocationHelper = taosArrayInit(32, POINTER_BYTES), + .pExecNodeList = pExecNodeList}; if (NULL == cxt.pLocationHelper) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/planner/src/planScaleOut.c b/source/libs/planner/src/planScaleOut.c index 7bb97b59d70b1c827d7ce7831fe3d9573b8cd1d6..73c8666673ca23168d5dc2bf495cb9553bee55b8 100644 --- a/source/libs/planner/src/planScaleOut.c +++ b/source/libs/planner/src/planScaleOut.c @@ -17,7 +17,7 @@ typedef struct SScaleOutContext { SPlanContext* pPlanCxt; - int32_t subplanId; + int32_t subplanId; } SScaleOutContext; static SLogicSubplan* singleCloneSubLogicPlan(SScaleOutContext* pCxt, SLogicSubplan* pSrc, int32_t level) { @@ -40,7 +40,7 @@ static SLogicSubplan* singleCloneSubLogicPlan(SScaleOutContext* pCxt, SLogicSubp static int32_t scaleOutForModify(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { SVnodeModifLogicNode* pNode = (SVnodeModifLogicNode*)pSubplan->pNode; - size_t numOfVgroups = taosArrayGetSize(pNode->pDataBlocks); + size_t numOfVgroups = taosArrayGetSize(pNode->pDataBlocks); for (int32_t i = 0; i < numOfVgroups; ++i) { SLogicSubplan* pNewSubplan = singleCloneSubLogicPlan(pCxt, pSubplan, level); if (NULL == pNewSubplan) { @@ -108,8 +108,8 @@ static int32_t scaleOutForScan(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, static int32_t pushHierarchicalPlan(SNodeList* pParentsGroup, SNodeList* pCurrentGroup) { int32_t code = TSDB_CODE_SUCCESS; - bool topLevel = (0 == LIST_LENGTH(pParentsGroup)); - SNode* pChild = NULL; + bool topLevel = (0 == LIST_LENGTH(pParentsGroup)); + SNode* pChild = NULL; FOREACH(pChild, pCurrentGroup) { if (topLevel) { code = nodesListAppend(pParentsGroup, pChild); @@ -192,8 +192,8 @@ int32_t scaleOutLogicPlan(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SQue return TSDB_CODE_OUT_OF_MEMORY; } - SScaleOutContext cxt = { .pPlanCxt = pCxt, .subplanId = 1 }; - int32_t code = doScaleOut(&cxt, pLogicSubplan, 0, pPlan->pTopSubplans); + SScaleOutContext cxt = {.pPlanCxt = pCxt, .subplanId = 1}; + int32_t code = doScaleOut(&cxt, pLogicSubplan, 0, pPlan->pTopSubplans); if (TSDB_CODE_SUCCESS == code) { *pLogicPlan = pPlan; } else { diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index b419414ca6ddaa3454ca4d371ea6b6f52d1f44fe..51bd36f9f956e2b432385b23a3e2cffe726e2331 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -15,39 +15,39 @@ #include "planInt.h" -#define SPLIT_FLAG_MASK(n) (1 << n) +#define SPLIT_FLAG_MASK(n) (1 << n) #define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0) #define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1) -#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask) +#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask) #define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) typedef struct SSplitContext { int32_t groupId; - bool split; + bool split; } SSplitContext; typedef int32_t (*FSplit)(SSplitContext* pCxt, SLogicSubplan* pSubplan); typedef struct SSplitRule { - char* pName; + char* pName; FSplit splitFunc; } SSplitRule; typedef struct SStsInfo { SScanLogicNode* pScan; - SLogicSubplan* pSubplan; + SLogicSubplan* pSubplan; } SStsInfo; typedef struct SCtjInfo { SScanLogicNode* pScan; - SLogicSubplan* pSubplan; + SLogicSubplan* pSubplan; } SCtjInfo; typedef struct SUaInfo { SProjectLogicNode* pProject; - SLogicSubplan* pSubplan; + SLogicSubplan* pSubplan; } SUaInfo; typedef struct SUnInfo { @@ -70,7 +70,8 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* return pSubplan; } -static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan, ESubplanType subplanType) { +static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan, + ESubplanType subplanType) { SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE); if (NULL == pExchange) { return TSDB_CODE_OUT_OF_MEMORY; @@ -117,8 +118,8 @@ static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag, } static SLogicNode* stsMatchByNode(SLogicNode* pNode) { - if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && - NULL != ((SScanLogicNode*)pNode)->pVgroupList && ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) { + if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && NULL != ((SScanLogicNode*)pNode)->pVgroupList && + ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) { return pNode; } SNode* pChild; @@ -145,7 +146,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, (FSplFindSplitNode)stsFindSplitNode, &info)) { return TSDB_CODE_SUCCESS; } - int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS)); + int32_t code = + nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS)); if (TSDB_CODE_SUCCESS == code) { code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE); } @@ -163,7 +165,8 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) { SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0); SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pNode->pChildren, 1); if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ctjIsSingleTable(((SScanLogicNode*)pLeft)->pMeta->tableType) && - QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) { + QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && + ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) { return pRight; } } @@ -191,7 +194,8 @@ static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, (FSplFindSplitNode)ctjFindSplitNode, &info)) { return TSDB_CODE_SUCCESS; } - int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ)); + int32_t code = + nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ)); if (TSDB_CODE_SUCCESS == code) { code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType); } @@ -360,17 +364,15 @@ static int32_t unSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { return code; } -static const SSplitRule splitRuleSet[] = { - { .pName = "SuperTableScan", .splitFunc = stsSplit }, - { .pName = "ChildTableJoin", .splitFunc = ctjSplit }, - { .pName = "UnionAll", .splitFunc = uaSplit }, - { .pName = "Union", .splitFunc = unSplit } -}; +static const SSplitRule splitRuleSet[] = {{.pName = "SuperTableScan", .splitFunc = stsSplit}, + {.pName = "ChildTableJoin", .splitFunc = ctjSplit}, + {.pName = "UnionAll", .splitFunc = uaSplit}, + {.pName = "Union", .splitFunc = unSplit}}; static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule)); static int32_t applySplitRule(SLogicSubplan* pSubplan) { - SSplitContext cxt = { .groupId = pSubplan->id.groupId + 1, .split = false }; + SSplitContext cxt = {.groupId = pSubplan->id.groupId + 1, .split = false}; do { cxt.split = false; for (int32_t i = 0; i < splitRuleNum; ++i) { @@ -386,14 +388,10 @@ static int32_t applySplitRule(SLogicSubplan* pSubplan) { static void doSetLogicNodeParent(SLogicNode* pNode, SLogicNode* pParent) { pNode->pParent = pParent; SNode* pChild; - FOREACH(pChild, pNode->pChildren) { - doSetLogicNodeParent((SLogicNode*)pChild, pNode); - } + FOREACH(pChild, pNode->pChildren) { doSetLogicNodeParent((SLogicNode*)pChild, pNode); } } -static void setLogicNodeParent(SLogicNode* pNode) { - doSetLogicNodeParent(pNode, NULL); -} +static void setLogicNodeParent(SLogicNode* pNode) { doSetLogicNodeParent(pNode, NULL); } int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan** pLogicSubplan) { SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); @@ -408,7 +406,8 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan } if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIF == nodeType(pLogicNode)) { pSubplan->subplanType = SUBPLAN_TYPE_MODIFY; - TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks, SArray*); + TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks, + SArray*); } else { pSubplan->subplanType = SUBPLAN_TYPE_SCAN; } diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 004f0b18fd2e1796ab932d1c062645772f5c664e..2fa6395aed7bc08fa5cffd44d60cf605a4e7968c 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -18,7 +18,7 @@ #include "planInt.h" typedef struct SCollectPlaceholderValuesCxt { - int32_t errCode; + int32_t errCode; SNodeList* pValues; } SCollectPlaceholderValuesCxt; @@ -32,7 +32,7 @@ static EDealRes collectPlaceholderValuesImpl(SNode* pNode, void* pContext) { } static int32_t collectPlaceholderValues(SPlanContext* pCxt, SQueryPlan* pPlan) { - SCollectPlaceholderValuesCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pValues = NULL }; + SCollectPlaceholderValuesCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pValues = NULL}; nodesWalkPhysiPlan((SNode*)pPlan, collectPlaceholderValuesImpl, &cxt); if (TSDB_CODE_SUCCESS == cxt.errCode) { pPlan->pPlaceholderValues = cxt.pValues; @@ -43,14 +43,14 @@ static int32_t collectPlaceholderValues(SPlanContext* pCxt, SQueryPlan* pPlan) { } int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNodeList) { - SLogicNode* pLogicNode = NULL; - SLogicSubplan* pLogicSubplan = NULL; + SLogicNode* pLogicNode = NULL; + SLogicSubplan* pLogicSubplan = NULL; SQueryLogicPlan* pLogicPlan = NULL; int32_t code = createLogicPlan(pCxt, &pLogicNode); if (TSDB_CODE_SUCCESS == code) { code = optimizeLogicPlan(pCxt, pLogicNode); - } + } if (TSDB_CODE_SUCCESS == code) { code = splitLogicPlan(pCxt, pLogicNode, &pLogicSubplan); } @@ -170,10 +170,8 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_BIND_v2* pParam) { int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_BIND_v2* pParams) { int32_t index = 0; - SNode* pNode = NULL; - FOREACH(pNode, pPlan->pPlaceholderValues) { - setValueByBindParam((SValueNode*)pNode, pParams + index); - } + SNode* pNode = NULL; + FOREACH(pNode, pPlan->pPlaceholderValues) { setValueByBindParam((SValueNode*)pNode, pParams + index); } return TSDB_CODE_SUCCESS; } @@ -188,12 +186,10 @@ int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) { return nodesNodeToString((const SNode*)pSubplan, false, pStr, pLen); } -int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) { - return nodesStringToNode(pStr, (SNode**)pSubplan); -} +int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) { return nodesStringToNode(pStr, (SNode**)pSubplan); } char* qQueryPlanToString(const SQueryPlan* pPlan) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; if (TSDB_CODE_SUCCESS != nodesNodeToString(pPlan, false, &pStr, &len)) { return NULL; @@ -209,6 +205,4 @@ SQueryPlan* qStringToQueryPlan(const char* pStr) { return pPlan; } -void qDestroyQueryPlan(SQueryPlan* pPlan) { - nodesDestroyNode(pPlan); -} +void qDestroyQueryPlan(SQueryPlan* pPlan) { nodesDestroyNode(pPlan); } diff --git a/source/libs/planner/test/planOptTest.cpp b/source/libs/planner/test/planOptTest.cpp index 4a682a5e17ff8443ab43d020fbe77fa6e18182e7..deb20c65a4a3eb9c76ec455556f52977fb9a3218 100644 --- a/source/libs/planner/test/planOptTest.cpp +++ b/source/libs/planner/test/planOptTest.cpp @@ -18,9 +18,7 @@ using namespace std; -class PlanOptimizeTest : public PlannerTestBase { - -}; +class PlanOptimizeTest : public PlannerTestBase {}; TEST_F(PlanOptimizeTest, orderByPrimaryKey) { useDb("root", "test"); diff --git a/source/libs/planner/test/planSTableTest.cpp b/source/libs/planner/test/planSTableTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49002fe8269004e736b3a4c847b2d5c9ed3393f8 --- /dev/null +++ b/source/libs/planner/test/planSTableTest.cpp @@ -0,0 +1,26 @@ +/* + * 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 "planTestUtil.h" + +using namespace std; + +class PlanSuperTableTest : public PlannerTestBase {}; + +TEST_F(PlanSuperTableTest, unionAll) { + useDb("root", "test"); + + run("select tbname from st1"); +} diff --git a/source/libs/planner/test/planSetOpTest.cpp b/source/libs/planner/test/planSetOpTest.cpp index 5ace503959f0987fe0d96cdcca04b8869bf2389e..ba7fde3c777e8dea2096df3c2ee0931122f19f41 100644 --- a/source/libs/planner/test/planSetOpTest.cpp +++ b/source/libs/planner/test/planSetOpTest.cpp @@ -18,9 +18,7 @@ using namespace std; -class PlanSetOpTest : public PlannerTestBase { - -}; +class PlanSetOpTest : public PlannerTestBase {}; TEST_F(PlanSetOpTest, unionAll) { useDb("root", "test"); diff --git a/source/libs/planner/test/planStmtTest.cpp b/source/libs/planner/test/planStmtTest.cpp index ca206c784356eccfec485d428c5eb104fb46b7bf..7366e7663e5c6b16deb506a4cae4d99a927240dd 100644 --- a/source/libs/planner/test/planStmtTest.cpp +++ b/source/libs/planner/test/planStmtTest.cpp @@ -19,7 +19,7 @@ using namespace std; class PlanStmtTest : public PlannerTestBase { -public: + public: void prepare(const string& sql) { run(sql); // todo calloc pBindParams_ @@ -42,9 +42,9 @@ public: // todo } -private: + private: TAOS_BIND_v2* pBindParams_; - int32_t paramNo_; + int32_t paramNo_; }; TEST_F(PlanStmtTest, stmt) { diff --git a/source/libs/planner/test/planTestMain.cpp b/source/libs/planner/test/planTestMain.cpp index 84cf75c5be8aede5873e1547c05c469c9f81a2bb..a7726973f0ebe9d6979bc8d4a39e6b38cd6fd191 100644 --- a/source/libs/planner/test/planTestMain.cpp +++ b/source/libs/planner/test/planTestMain.cpp @@ -21,27 +21,22 @@ #include "planTestUtil.h" class PlannerEnv : public testing::Environment { -public: + public: virtual void SetUp() { initMetaDataEnv(); generateMetaData(); } - virtual void TearDown() { - destroyMetaDataEnv(); - } + virtual void TearDown() { destroyMetaDataEnv(); } PlannerEnv() {} virtual ~PlannerEnv() {} }; static void parseArg(int argc, char* argv[]) { - int opt = 0; - const char *optstring = ""; - static struct option long_options[] = { - {"dump", no_argument, NULL, 'd'}, - {0, 0, 0, 0} - }; + int opt = 0; + const char* optstring = ""; + static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}}; while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (opt) { case 'd': @@ -54,8 +49,8 @@ static void parseArg(int argc, char* argv[]) { } int main(int argc, char* argv[]) { - testing::AddGlobalTestEnvironment(new PlannerEnv()); - testing::InitGoogleTest(&argc, argv); + testing::AddGlobalTestEnvironment(new PlannerEnv()); + testing::InitGoogleTest(&argc, argv); parseArg(argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); } diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index f124970875ceedc582d133ecf0185975f4fab3ad..c619e9b405cdd3661fc8d87df9e0e505f42cfb8b 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include #include "planTestUtil.h" +#include #include @@ -25,18 +25,19 @@ using namespace std; using namespace testing; -#define DO_WITH_THROW(func, ...) \ - do { \ - int32_t code__ = func(__VA_ARGS__); \ - if (TSDB_CODE_SUCCESS != code__) { \ - throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + ", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \ - } \ - } while(0); +#define DO_WITH_THROW(func, ...) \ + do { \ + int32_t code__ = func(__VA_ARGS__); \ + if (TSDB_CODE_SUCCESS != code__) { \ + throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + \ + ", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \ + } \ + } while (0); bool g_isDump = false; class PlannerTestBaseImpl { -public: + public: void useDb(const string& acctId, const string& db) { caseEnv_.acctId_ = acctId; caseEnv_.db_ = db; @@ -74,24 +75,24 @@ public: } } -private: + private: struct caseEnv { string acctId_; string db_; }; struct stmtEnv { - string sql_; + string sql_; array msgBuf_; }; struct stmtRes { - string ast_; - string rawLogicPlan_; - string optimizedLogicPlan_; - string splitLogicPlan_; - string scaledLogicPlan_; - string physiPlan_; + string ast_; + string rawLogicPlan_; + string optimizedLogicPlan_; + string splitLogicPlan_; + string scaledLogicPlan_; + string physiPlan_; vector physiSubplans_; }; @@ -126,11 +127,11 @@ private: cout << subplan << endl; } } - + void doParseSql(const string& sql, SQuery** pQuery) { stmtEnv_.sql_ = sql; transform(stmtEnv_.sql_.begin(), stmtEnv_.sql_.end(), stmtEnv_.sql_.begin(), ::tolower); - + SParseContext cxt = {0}; cxt.acctId = atoi(caseEnv_.acctId_.c_str()); cxt.db = caseEnv_.db_.c_str(); @@ -138,7 +139,7 @@ private: cxt.sqlLen = stmtEnv_.sql_.length(); cxt.pMsg = stmtEnv_.msgBuf_.data(); cxt.msgLen = stmtEnv_.msgBuf_.max_size(); - + DO_WITH_THROW(qParseQuerySql, &cxt, pQuery); res_.ast_ = toString((*pQuery)->pRoot); } @@ -170,9 +171,7 @@ private: SNode* pNode; FOREACH(pNode, (*pPlan)->pSubplans) { SNode* pSubplan; - FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { - res_.physiSubplans_.push_back(toString(pSubplan)); - } + FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { res_.physiSubplans_.push_back(toString(pSubplan)); } } } @@ -197,7 +196,7 @@ private: } string toString(const SNode* pRoot) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; DO_WITH_THROW(nodesNodeToString, pRoot, false, &pStr, &len) string str(pStr); @@ -210,16 +209,10 @@ private: stmtRes res_; }; -PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) { -} +PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {} -PlannerTestBase::~PlannerTestBase() { -} +PlannerTestBase::~PlannerTestBase() {} -void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) { - impl_->useDb(acctId, db); -} +void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) { impl_->useDb(acctId, db); } -void PlannerTestBase::run(const std::string& sql) { - return impl_->run(sql); -} +void PlannerTestBase::run(const std::string& sql) { return impl_->run(sql); } diff --git a/source/libs/planner/test/planTestUtil.h b/source/libs/planner/test/planTestUtil.h index dbd14237eebb92f53319947f90e4b5af333031a5..7aabff811f06e6ad1485162102be1f350d8d0f94 100644 --- a/source/libs/planner/test/planTestUtil.h +++ b/source/libs/planner/test/planTestUtil.h @@ -21,14 +21,14 @@ class PlannerTestBaseImpl; class PlannerTestBase : public testing::Test { -public: + public: PlannerTestBase(); virtual ~PlannerTestBase(); void useDb(const std::string& acctId, const std::string& db); void run(const std::string& sql); -private: + private: std::unique_ptr impl_; }; diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 7ab61a8daaab0b6e66dfd453e3afc780a26a571a..11280768237d225aaa8a51bdc1d0b7ad558060e0 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -25,7 +25,7 @@ using namespace std; using namespace testing; class PlannerTest : public Test { -protected: + protected: void setDatabase(const string& acctId, const string& db) { acctId_ = acctId; db_ = db; @@ -45,13 +45,14 @@ protected: int32_t code = qParseQuerySql(&cxt_, &query_); if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl; + cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code) + << ", msg:" << errMagBuf_ << endl; return false; } const string syntaxTreeStr = toString(query_->pRoot, false); - - SLogicNode* pLogicNode = nullptr; + + SLogicNode* pLogicNode = nullptr; SPlanContext cxt = {0}; cxt.queryId = 1; cxt.acctId = 0; @@ -63,7 +64,7 @@ protected: cout << "sql:[" << cxt_.pSql << "] createLogicPlan code:" << code << ", strerror:" << tstrerror(code) << endl; return false; } - + cout << "====================sql : [" << cxt_.pSql << "]" << endl; cout << "syntax tree : " << endl; cout << syntaxTreeStr << endl; @@ -90,12 +91,13 @@ protected: return false; } - code = createPhysiPlan(&cxt, pLogicPlan, &plan_, NULL); + SArray* pExecNodeList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SQueryNodeAddr)); + code = createPhysiPlan(&cxt, pLogicPlan, &plan_, pExecNodeList); if (code != TSDB_CODE_SUCCESS) { cout << "sql:[" << cxt_.pSql << "] createPhysiPlan code:" << code << ", strerror:" << tstrerror(code) << endl; return false; } - + cout << "unformatted physical plan : " << endl; cout << toString((const SNode*)plan_, false) << endl; SNode* pNode; @@ -110,7 +112,7 @@ protected: return true; } -private: + private: static const int max_err_len = 1024; void setPlanContext(SQuery* pQuery, SPlanContext* pCxt) { @@ -141,7 +143,7 @@ private: } string toString(const SNode* pRoot, bool format = true) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; int32_t code = nodesNodeToString(pRoot, format, &pStr, &len); if (code != TSDB_CODE_SUCCESS) { @@ -153,13 +155,13 @@ private: return str; } - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - string sqlBuf_; + string acctId_; + string db_; + char errMagBuf_[max_err_len]; + string sqlBuf_; SParseContext cxt_; - SQuery* query_; - SQueryPlan* plan_; + SQuery* query_; + SQueryPlan* plan_; }; TEST_F(PlannerTest, selectBasic) { @@ -192,7 +194,9 @@ TEST_F(PlannerTest, selectJoin) { bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); ASSERT_TRUE(run()); - bind("SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and t2.c2 = 'qwe'"); + bind( + "SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and " + "t2.c2 = 'qwe'"); ASSERT_TRUE(run()); } @@ -210,12 +214,17 @@ TEST_F(PlannerTest, selectGroupBy) { bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3"); ASSERT_TRUE(run()); + + bind("SELECT sum(ceil(c1)) FROM t1 GROUP BY ceil(c1)"); + ASSERT_TRUE(run()); } TEST_F(PlannerTest, selectSubquery) { setDatabase("root", "test"); - bind("SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 group by b"); + bind( + "SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 " + "group by b"); ASSERT_TRUE(run()); } @@ -362,7 +371,9 @@ TEST_F(PlannerTest, createTopic) { TEST_F(PlannerTest, createStream) { setDatabase("root", "test"); - bind("create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 interval(10s)"); + bind( + "create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 " + "interval(10s)"); ASSERT_TRUE(run()); }