Merge branch '3.0' of github.com:taosdata/TDengine into szhou/feature/project-elimation
This commit is contained in:
commit
0e905bb3c1
|
@ -1817,6 +1817,8 @@ typedef struct SVCreateTbReq {
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
int64_t ctime;
|
int64_t ctime;
|
||||||
int32_t ttl;
|
int32_t ttl;
|
||||||
|
int32_t commentLen;
|
||||||
|
char* comment;
|
||||||
int8_t type;
|
int8_t type;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
|
@ -1834,6 +1836,7 @@ int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
|
||||||
|
|
||||||
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
|
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
|
||||||
taosMemoryFreeClear(req->name);
|
taosMemoryFreeClear(req->name);
|
||||||
|
taosMemoryFreeClear(req->comment);
|
||||||
if (req->type == TSDB_CHILD_TABLE) {
|
if (req->type == TSDB_CHILD_TABLE) {
|
||||||
taosMemoryFreeClear(req->ctb.pTag);
|
taosMemoryFreeClear(req->ctb.pTag);
|
||||||
} else if (req->type == TSDB_NORMAL_TABLE) {
|
} else if (req->type == TSDB_NORMAL_TABLE) {
|
||||||
|
@ -1930,7 +1933,7 @@ typedef struct {
|
||||||
// TSDB_ALTER_TABLE_UPDATE_OPTIONS
|
// TSDB_ALTER_TABLE_UPDATE_OPTIONS
|
||||||
int8_t updateTTL;
|
int8_t updateTTL;
|
||||||
int32_t newTTL;
|
int32_t newTTL;
|
||||||
int8_t updateComment;
|
int32_t newCommentLen;
|
||||||
char* newComment;
|
char* newComment;
|
||||||
} SVAlterTbReq;
|
} SVAlterTbReq;
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_CONFIRM, "alter-confirm", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_CONFIRM, "alter-confirm", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_DROP_TTL_TABLE, "drop-ttl-stb", NULL, NULL)
|
||||||
TD_NEW_MSG_SEG(TDMT_QND_MSG)
|
TD_NEW_MSG_SEG(TDMT_QND_MSG)
|
||||||
|
|
||||||
//shared by snode and vnode
|
//shared by snode and vnode
|
||||||
|
|
|
@ -241,20 +241,22 @@
|
||||||
#define TK_LINEAR 223
|
#define TK_LINEAR 223
|
||||||
#define TK_NEXT 224
|
#define TK_NEXT 224
|
||||||
#define TK_HAVING 225
|
#define TK_HAVING 225
|
||||||
#define TK_ORDER 226
|
#define TK_RANGE 226
|
||||||
#define TK_SLIMIT 227
|
#define TK_EVERY 227
|
||||||
#define TK_SOFFSET 228
|
#define TK_ORDER 228
|
||||||
#define TK_LIMIT 229
|
#define TK_SLIMIT 229
|
||||||
#define TK_OFFSET 230
|
#define TK_SOFFSET 230
|
||||||
#define TK_ASC 231
|
#define TK_LIMIT 231
|
||||||
#define TK_NULLS 232
|
#define TK_OFFSET 232
|
||||||
#define TK_ID 233
|
#define TK_ASC 233
|
||||||
#define TK_NK_BITNOT 234
|
#define TK_NULLS 234
|
||||||
#define TK_INSERT 235
|
#define TK_ID 235
|
||||||
#define TK_VALUES 236
|
#define TK_NK_BITNOT 236
|
||||||
#define TK_IMPORT 237
|
#define TK_INSERT 237
|
||||||
#define TK_NK_SEMI 238
|
#define TK_VALUES 238
|
||||||
#define TK_FILE 239
|
#define TK_IMPORT 239
|
||||||
|
#define TK_NK_SEMI 240
|
||||||
|
#define TK_FILE 241
|
||||||
|
|
||||||
#define TK_NK_SPACE 300
|
#define TK_NK_SPACE 300
|
||||||
#define TK_NK_COMMENT 301
|
#define TK_NK_COMMENT 301
|
||||||
|
|
|
@ -189,6 +189,7 @@ bool fmIsForbidStreamFunc(int32_t funcId);
|
||||||
bool fmIsForbidWindowFunc(int32_t funcId);
|
bool fmIsForbidWindowFunc(int32_t funcId);
|
||||||
bool fmIsForbidGroupByFunc(int32_t funcId);
|
bool fmIsForbidGroupByFunc(int32_t funcId);
|
||||||
bool fmIsIntervalInterpoFunc(int32_t funcId);
|
bool fmIsIntervalInterpoFunc(int32_t funcId);
|
||||||
|
bool fmIsInterpFunc(int32_t funcId);
|
||||||
|
|
||||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ typedef struct SAlterDatabaseStmt {
|
||||||
|
|
||||||
typedef struct STableOptions {
|
typedef struct STableOptions {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
|
bool commentNull;
|
||||||
char comment[TSDB_TB_COMMENT_LEN];
|
char comment[TSDB_TB_COMMENT_LEN];
|
||||||
SNodeList* pMaxDelay;
|
SNodeList* pMaxDelay;
|
||||||
int64_t maxDelay1;
|
int64_t maxDelay1;
|
||||||
|
@ -126,6 +127,7 @@ typedef struct SCreateSubTableClause {
|
||||||
bool ignoreExists;
|
bool ignoreExists;
|
||||||
SNodeList* pSpecificTags;
|
SNodeList* pSpecificTags;
|
||||||
SNodeList* pValsOfTags;
|
SNodeList* pValsOfTags;
|
||||||
|
STableOptions* pOptions;
|
||||||
} SCreateSubTableClause;
|
} SCreateSubTableClause;
|
||||||
|
|
||||||
typedef struct SCreateMultiTableStmt {
|
typedef struct SCreateMultiTableStmt {
|
||||||
|
|
|
@ -205,6 +205,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_LOGIC_PLAN_SORT,
|
QUERY_NODE_LOGIC_PLAN_SORT,
|
||||||
QUERY_NODE_LOGIC_PLAN_PARTITION,
|
QUERY_NODE_LOGIC_PLAN_PARTITION,
|
||||||
QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
|
QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
|
||||||
|
QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
|
||||||
QUERY_NODE_LOGIC_SUBPLAN,
|
QUERY_NODE_LOGIC_SUBPLAN,
|
||||||
QUERY_NODE_LOGIC_PLAN,
|
QUERY_NODE_LOGIC_PLAN,
|
||||||
|
|
||||||
|
@ -236,6 +237,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE,
|
QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE,
|
||||||
QUERY_NODE_PHYSICAL_PLAN_PARTITION,
|
QUERY_NODE_PHYSICAL_PLAN_PARTITION,
|
||||||
QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
|
QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
|
||||||
|
QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
|
||||||
QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
|
QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
|
||||||
QUERY_NODE_PHYSICAL_PLAN_INSERT,
|
QUERY_NODE_PHYSICAL_PLAN_INSERT,
|
||||||
QUERY_NODE_PHYSICAL_PLAN_DELETE,
|
QUERY_NODE_PHYSICAL_PLAN_DELETE,
|
||||||
|
|
|
@ -98,9 +98,16 @@ typedef struct SProjectLogicNode {
|
||||||
|
|
||||||
typedef struct SIndefRowsFuncLogicNode {
|
typedef struct SIndefRowsFuncLogicNode {
|
||||||
SLogicNode node;
|
SLogicNode node;
|
||||||
SNodeList* pVectorFuncs;
|
SNodeList* pFuncs;
|
||||||
} SIndefRowsFuncLogicNode;
|
} SIndefRowsFuncLogicNode;
|
||||||
|
|
||||||
|
typedef struct SInterpFuncLogicNode {
|
||||||
|
SLogicNode node;
|
||||||
|
SNodeList* pFuncs;
|
||||||
|
STimeWindow timeRange;
|
||||||
|
int64_t interval;
|
||||||
|
} SInterpFuncLogicNode;
|
||||||
|
|
||||||
typedef enum EModifyTableType { MODIFY_TABLE_TYPE_INSERT = 1, MODIFY_TABLE_TYPE_DELETE } EModifyTableType;
|
typedef enum EModifyTableType { MODIFY_TABLE_TYPE_INSERT = 1, MODIFY_TABLE_TYPE_DELETE } EModifyTableType;
|
||||||
|
|
||||||
typedef struct SVnodeModifyLogicNode {
|
typedef struct SVnodeModifyLogicNode {
|
||||||
|
@ -154,6 +161,7 @@ typedef struct SWindowLogicNode {
|
||||||
int8_t slidingUnit;
|
int8_t slidingUnit;
|
||||||
int64_t sessionGap;
|
int64_t sessionGap;
|
||||||
SNode* pTspk;
|
SNode* pTspk;
|
||||||
|
SNode* pTsEnd;
|
||||||
SNode* pStateExpr;
|
SNode* pStateExpr;
|
||||||
int8_t triggerType;
|
int8_t triggerType;
|
||||||
int64_t watermark;
|
int64_t watermark;
|
||||||
|
@ -292,9 +300,17 @@ typedef struct SProjectPhysiNode {
|
||||||
typedef struct SIndefRowsFuncPhysiNode {
|
typedef struct SIndefRowsFuncPhysiNode {
|
||||||
SPhysiNode node;
|
SPhysiNode node;
|
||||||
SNodeList* pExprs;
|
SNodeList* pExprs;
|
||||||
SNodeList* pVectorFuncs;
|
SNodeList* pFuncs;
|
||||||
} SIndefRowsFuncPhysiNode;
|
} SIndefRowsFuncPhysiNode;
|
||||||
|
|
||||||
|
typedef struct SInterpFuncPhysiNode {
|
||||||
|
SPhysiNode node;
|
||||||
|
SNodeList* pExprs;
|
||||||
|
SNodeList* pFuncs;
|
||||||
|
STimeWindow timeRange;
|
||||||
|
int64_t interval;
|
||||||
|
} SInterpFuncPhysiNode;
|
||||||
|
|
||||||
typedef struct SJoinPhysiNode {
|
typedef struct SJoinPhysiNode {
|
||||||
SPhysiNode node;
|
SPhysiNode node;
|
||||||
EJoinType joinType;
|
EJoinType joinType;
|
||||||
|
@ -338,6 +354,7 @@ typedef struct SWinodwPhysiNode {
|
||||||
SNodeList* pExprs; // these are expression list of parameter expression of function
|
SNodeList* pExprs; // these are expression list of parameter expression of function
|
||||||
SNodeList* pFuncs;
|
SNodeList* pFuncs;
|
||||||
SNode* pTspk; // timestamp primary key
|
SNode* pTspk; // timestamp primary key
|
||||||
|
SNode* pTsEnd; // window end timestamp
|
||||||
int8_t triggerType;
|
int8_t triggerType;
|
||||||
int64_t watermark;
|
int64_t watermark;
|
||||||
double filesFactor;
|
double filesFactor;
|
||||||
|
|
|
@ -240,6 +240,9 @@ typedef struct SSelectStmt {
|
||||||
SNode* pWindow;
|
SNode* pWindow;
|
||||||
SNodeList* pGroupByList; // SGroupingSetNode
|
SNodeList* pGroupByList; // SGroupingSetNode
|
||||||
SNode* pHaving;
|
SNode* pHaving;
|
||||||
|
SNode* pRange;
|
||||||
|
SNode* pEvery;
|
||||||
|
SNode* pFill;
|
||||||
SNodeList* pOrderByList; // SOrderByExprNode
|
SNodeList* pOrderByList; // SOrderByExprNode
|
||||||
SLimitNode* pLimit;
|
SLimitNode* pLimit;
|
||||||
SLimitNode* pSlimit;
|
SLimitNode* pSlimit;
|
||||||
|
@ -254,6 +257,7 @@ typedef struct SSelectStmt {
|
||||||
bool hasSelectValFunc;
|
bool hasSelectValFunc;
|
||||||
bool hasUniqueFunc;
|
bool hasUniqueFunc;
|
||||||
bool hasTailFunc;
|
bool hasTailFunc;
|
||||||
|
bool hasInterpFunc;
|
||||||
} SSelectStmt;
|
} 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;
|
||||||
|
|
|
@ -124,7 +124,7 @@ static const SSysDbTableSchema userStbsSchema[] = {
|
||||||
{.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
{.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SSysDbTableSchema streamSchema[] = {
|
static const SSysDbTableSchema streamSchema[] = {
|
||||||
|
@ -148,7 +148,7 @@ static const SSysDbTableSchema userTblsSchema[] = {
|
||||||
{.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
{.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "table_comment", .bytes = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
{.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||||
{.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
{.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -524,7 +524,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReq->commentLen > 0) {
|
if (pReq->commentLen > 0) {
|
||||||
if (tEncodeBinary(&encoder, pReq->comment, pReq->commentLen) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->comment) < 0) return -1;
|
||||||
}
|
}
|
||||||
if (pReq->ast1Len > 0) {
|
if (pReq->ast1Len > 0) {
|
||||||
if (tEncodeBinary(&encoder, pReq->pAst1, pReq->ast1Len) < 0) return -1;
|
if (tEncodeBinary(&encoder, pReq->pAst1, pReq->ast1Len) < 0) return -1;
|
||||||
|
@ -589,7 +589,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReq->commentLen > 0) {
|
if (pReq->commentLen > 0) {
|
||||||
pReq->comment = taosMemoryMalloc(pReq->commentLen);
|
pReq->comment = taosMemoryMalloc(pReq->commentLen + 1);
|
||||||
if (pReq->comment == NULL) return -1;
|
if (pReq->comment == NULL) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1;
|
||||||
}
|
}
|
||||||
|
@ -707,7 +707,7 @@ int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq
|
||||||
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1;
|
||||||
if (pReq->commentLen > 0) {
|
if (pReq->commentLen > 0) {
|
||||||
pReq->comment = taosMemoryMalloc(pReq->commentLen);
|
pReq->comment = taosMemoryMalloc(pReq->commentLen + 1);
|
||||||
if (pReq->comment == NULL) return -1;
|
if (pReq->comment == NULL) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1;
|
||||||
}
|
}
|
||||||
|
@ -4374,6 +4374,10 @@ int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) {
|
||||||
if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1;
|
if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1;
|
||||||
if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1;
|
if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1;
|
||||||
if (tEncodeI8(pCoder, pReq->type) < 0) return -1;
|
if (tEncodeI8(pCoder, pReq->type) < 0) return -1;
|
||||||
|
if (tEncodeI32(pCoder, pReq->commentLen) < 0) return -1;
|
||||||
|
if (pReq->commentLen > 0) {
|
||||||
|
if (tEncodeCStr(pCoder, pReq->comment) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (pReq->type == TSDB_CHILD_TABLE) {
|
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||||
if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1;
|
if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1;
|
||||||
|
@ -4397,6 +4401,12 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
||||||
if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1;
|
if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1;
|
||||||
if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1;
|
if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1;
|
||||||
if (tDecodeI8(pCoder, &pReq->type) < 0) return -1;
|
if (tDecodeI8(pCoder, &pReq->type) < 0) return -1;
|
||||||
|
if (tDecodeI32(pCoder, &pReq->commentLen) < 0) return -1;
|
||||||
|
if (pReq->commentLen > 0) {
|
||||||
|
pReq->comment = taosMemoryMalloc(pReq->commentLen + 1);
|
||||||
|
if (pReq->comment == NULL) return -1;
|
||||||
|
if (tDecodeCStrTo(pCoder, pReq->comment) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (pReq->type == TSDB_CHILD_TABLE) {
|
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||||
if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
|
if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
|
||||||
|
@ -4750,8 +4760,8 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
|
||||||
if (pReq->updateTTL) {
|
if (pReq->updateTTL) {
|
||||||
if (tEncodeI32v(pEncoder, pReq->newTTL) < 0) return -1;
|
if (tEncodeI32v(pEncoder, pReq->newTTL) < 0) return -1;
|
||||||
}
|
}
|
||||||
if (tEncodeI8(pEncoder, pReq->updateComment) < 0) return -1;
|
if (tEncodeI32v(pEncoder, pReq->newCommentLen) < 0) return -1;
|
||||||
if (pReq->updateComment) {
|
if (pReq->newCommentLen > 0) {
|
||||||
if (tEncodeCStr(pEncoder, pReq->newComment) < 0) return -1;
|
if (tEncodeCStr(pEncoder, pReq->newComment) < 0) return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -4798,8 +4808,8 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
|
||||||
if (pReq->updateTTL) {
|
if (pReq->updateTTL) {
|
||||||
if (tDecodeI32v(pDecoder, &pReq->newTTL) < 0) return -1;
|
if (tDecodeI32v(pDecoder, &pReq->newTTL) < 0) return -1;
|
||||||
}
|
}
|
||||||
if (tDecodeI8(pDecoder, &pReq->updateComment) < 0) return -1;
|
if (tDecodeI32v(pDecoder, &pReq->newCommentLen) < 0) return -1;
|
||||||
if (pReq->updateComment) {
|
if (pReq->newCommentLen > 0) {
|
||||||
if (tDecodeCStr(pDecoder, &pReq->newComment) < 0) return -1;
|
if (tDecodeCStr(pDecoder, &pReq->newComment) < 0) return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -334,6 +334,7 @@ SArray *vmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TTL_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
|
@ -77,12 +77,50 @@ static void mndPullupTelem(SMnode *pMnode) {
|
||||||
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mndPushTtlTime(SMnode *pMnode) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
void *pIter = NULL;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
int32_t contLen = sizeof(SMsgHead) + sizeof(int32_t);
|
||||||
|
SMsgHead *pHead = rpcMallocCont(contLen);
|
||||||
|
if (pHead == NULL) {
|
||||||
|
mError("ttl time malloc err. contLen:%d", contLen);
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pHead->contLen = htonl(contLen);
|
||||||
|
pHead->vgId = htonl(pVgroup->vgId);
|
||||||
|
|
||||||
|
int32_t t = taosGetTimestampSec();
|
||||||
|
*(int32_t*)(POINTER_SHIFT(pHead, sizeof(SMsgHead))) = htonl(t);
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen};
|
||||||
|
|
||||||
|
SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
|
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||||
|
if(code != 0){
|
||||||
|
mError("ttl time seed err. code:%d", code);
|
||||||
|
}
|
||||||
|
mError("ttl time seed succ. time:%d", t);
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void *mndThreadFp(void *param) {
|
static void *mndThreadFp(void *param) {
|
||||||
SMnode *pMnode = param;
|
SMnode *pMnode = param;
|
||||||
int64_t lastTime = 0;
|
int64_t lastTime = 0;
|
||||||
setThreadName("mnode-timer");
|
setThreadName("mnode-timer");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (lastTime % (864000) == 0) { // sleep 1 day for ttl
|
||||||
|
mndPushTtlTime(pMnode);
|
||||||
|
}
|
||||||
|
|
||||||
lastTime++;
|
lastTime++;
|
||||||
taosMsleep(100);
|
taosMsleep(100);
|
||||||
if (mndGetStop(pMnode)) break;
|
if (mndGetStop(pMnode)) break;
|
||||||
|
|
|
@ -117,7 +117,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStb->commentLen > 0) {
|
if (pStb->commentLen > 0) {
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, _OVER)
|
SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER)
|
||||||
}
|
}
|
||||||
if (pStb->ast1Len > 0) {
|
if (pStb->ast1Len > 0) {
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pStb->pAst1, pStb->ast1Len, _OVER)
|
SDB_SET_BINARY(pRaw, dataPos, pStb->pAst1, pStb->ast1Len, _OVER)
|
||||||
|
@ -204,9 +204,9 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStb->commentLen > 0) {
|
if (pStb->commentLen > 0) {
|
||||||
pStb->comment = taosMemoryCalloc(pStb->commentLen, 1);
|
pStb->comment = taosMemoryCalloc(pStb->commentLen + 1, 1);
|
||||||
if (pStb->comment == NULL) goto _OVER;
|
if (pStb->comment == NULL) goto _OVER;
|
||||||
SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, _OVER)
|
SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER)
|
||||||
}
|
}
|
||||||
if (pStb->ast1Len > 0) {
|
if (pStb->ast1Len > 0) {
|
||||||
pStb->pAst1 = taosMemoryCalloc(pStb->ast1Len, 1);
|
pStb->pAst1 = taosMemoryCalloc(pStb->ast1Len, 1);
|
||||||
|
@ -280,8 +280,8 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pOld->commentLen < pNew->commentLen) {
|
if (pOld->commentLen < pNew->commentLen && pNew->commentLen > 0) {
|
||||||
void *comment = taosMemoryMalloc(pNew->commentLen);
|
void *comment = taosMemoryMalloc(pNew->commentLen + 1);
|
||||||
if (comment != NULL) {
|
if (comment != NULL) {
|
||||||
taosMemoryFree(pOld->comment);
|
taosMemoryFree(pOld->comment);
|
||||||
pOld->comment = comment;
|
pOld->comment = comment;
|
||||||
|
@ -291,6 +291,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
|
||||||
taosWUnLockLatch(&pOld->lock);
|
taosWUnLockLatch(&pOld->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pOld->commentLen = pNew->commentLen;
|
||||||
|
|
||||||
if (pOld->ast1Len < pNew->ast1Len) {
|
if (pOld->ast1Len < pNew->ast1Len) {
|
||||||
void *pAst1 = taosMemoryMalloc(pNew->ast1Len);
|
void *pAst1 = taosMemoryMalloc(pNew->ast1Len);
|
||||||
|
@ -330,8 +331,8 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
|
||||||
pOld->numOfTags = pNew->numOfTags;
|
pOld->numOfTags = pNew->numOfTags;
|
||||||
memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema));
|
memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema));
|
||||||
}
|
}
|
||||||
if (pNew->commentLen != 0) {
|
if (pNew->commentLen > 0) {
|
||||||
memcpy(pOld->comment, pNew->comment, pNew->commentLen);
|
memcpy(pOld->comment, pNew->comment, pNew->commentLen + 1);
|
||||||
}
|
}
|
||||||
if (pNew->ast1Len != 0) {
|
if (pNew->ast1Len != 0) {
|
||||||
memcpy(pOld->pAst1, pNew->pAst1, pNew->ast1Len);
|
memcpy(pOld->pAst1, pNew->pAst1, pNew->ast1Len);
|
||||||
|
@ -676,12 +677,12 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat
|
||||||
pDst->numOfTags = pCreate->numOfTags;
|
pDst->numOfTags = pCreate->numOfTags;
|
||||||
pDst->commentLen = pCreate->commentLen;
|
pDst->commentLen = pCreate->commentLen;
|
||||||
if (pDst->commentLen > 0) {
|
if (pDst->commentLen > 0) {
|
||||||
pDst->comment = taosMemoryCalloc(pDst->commentLen, 1);
|
pDst->comment = taosMemoryCalloc(pDst->commentLen + 1, 1);
|
||||||
if (pDst->comment == NULL) {
|
if (pDst->comment == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(pDst->comment, pCreate->comment, pDst->commentLen);
|
memcpy(pDst->comment, pCreate->comment, pDst->commentLen + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pDst->ast1Len = pCreate->ast1Len;
|
pDst->ast1Len = pCreate->ast1Len;
|
||||||
|
@ -835,7 +836,7 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCheckAlterStbReq(SMAlterStbReq *pAlter) {
|
static int32_t mndCheckAlterStbReq(SMAlterStbReq *pAlter) {
|
||||||
if (pAlter->commentLen != 0 || pAlter->ttl != 0) return 0;
|
if (pAlter->commentLen >= 0 || pAlter->ttl != 0) return 0;
|
||||||
|
|
||||||
if (pAlter->numOfFields < 1 || pAlter->numOfFields != (int32_t)taosArrayGetSize(pAlter->pFields)) {
|
if (pAlter->numOfFields < 1 || pAlter->numOfFields != (int32_t)taosArrayGetSize(pAlter->pFields)) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||||
|
@ -890,13 +891,16 @@ static int32_t mndUpdateStbCommentAndTTL(const SStbObj *pOld, SStbObj *pNew, cha
|
||||||
int32_t ttl) {
|
int32_t ttl) {
|
||||||
if (commentLen > 0) {
|
if (commentLen > 0) {
|
||||||
pNew->commentLen = commentLen;
|
pNew->commentLen = commentLen;
|
||||||
pNew->comment = taosMemoryCalloc(1, commentLen);
|
pNew->comment = taosMemoryCalloc(1, commentLen + 1);
|
||||||
if (pNew->comment == NULL) {
|
if (pNew->comment == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(pNew->comment, pComment, commentLen);
|
memcpy(pNew->comment, pComment, commentLen + 1);
|
||||||
|
} else if(commentLen == 0){
|
||||||
|
pNew->commentLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ttl >= 0) {
|
if (ttl >= 0) {
|
||||||
pNew->ttl = ttl;
|
pNew->ttl = ttl;
|
||||||
}
|
}
|
||||||
|
@ -1206,7 +1210,6 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
action.pCont = pReq;
|
action.pCont = pReq;
|
||||||
|
@ -1841,17 +1844,17 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataAppend(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables
|
colDataAppend(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables
|
||||||
|
|
||||||
char *p = taosMemoryCalloc(1, pStb->commentLen + 1 + VARSTR_HEADER_SIZE); // check malloc failures
|
|
||||||
if (p != NULL) {
|
|
||||||
if (pStb->commentLen != 0) {
|
|
||||||
STR_TO_VARSTR(p, pStb->comment);
|
|
||||||
} else {
|
|
||||||
STR_TO_VARSTR(p, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||||
colDataAppend(pColInfo, numOfRows, (const char *)p, false);
|
if (pStb->commentLen > 0) {
|
||||||
taosMemoryFree(p);
|
char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
STR_TO_VARSTR(comment, pStb->comment);
|
||||||
|
colDataAppend(pColInfo, numOfRows, comment, false);
|
||||||
|
} else if(pStb->commentLen == 0) {
|
||||||
|
char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
STR_TO_VARSTR(comment, "");
|
||||||
|
colDataAppend(pColInfo, numOfRows, comment, false);
|
||||||
|
} else {
|
||||||
|
colDataAppendNULL(pColInfo, numOfRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
|
|
|
@ -210,12 +210,16 @@ struct SMetaEntry {
|
||||||
struct {
|
struct {
|
||||||
int64_t ctime;
|
int64_t ctime;
|
||||||
int32_t ttlDays;
|
int32_t ttlDays;
|
||||||
|
int32_t commentLen;
|
||||||
|
char *comment;
|
||||||
tb_uid_t suid;
|
tb_uid_t suid;
|
||||||
uint8_t *pTags;
|
uint8_t *pTags;
|
||||||
} ctbEntry;
|
} ctbEntry;
|
||||||
struct {
|
struct {
|
||||||
int64_t ctime;
|
int64_t ctime;
|
||||||
int32_t ttlDays;
|
int32_t ttlDays;
|
||||||
|
int32_t commentLen;
|
||||||
|
char *comment;
|
||||||
int32_t ncid; // next column id
|
int32_t ncid; // next column id
|
||||||
SSchemaWrapper schemaRow;
|
SSchemaWrapper schemaRow;
|
||||||
} ntbEntry;
|
} ntbEntry;
|
||||||
|
|
|
@ -87,6 +87,7 @@ int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* p
|
||||||
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
|
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
|
||||||
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq);
|
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq);
|
||||||
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids);
|
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids);
|
||||||
|
int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids);
|
||||||
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
|
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
|
||||||
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||||
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver);
|
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver);
|
||||||
|
@ -105,6 +106,7 @@ int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader);
|
||||||
int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData);
|
int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData);
|
||||||
void* metaGetIdx(SMeta* pMeta);
|
void* metaGetIdx(SMeta* pMeta);
|
||||||
void* metaGetIvtIdx(SMeta* pMeta);
|
void* metaGetIvtIdx(SMeta* pMeta);
|
||||||
|
int metaTtlSmaller(SMeta *pMeta, uint64_t time, SArray *uidList);
|
||||||
|
|
||||||
int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg);
|
int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg);
|
||||||
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
|
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
|
||||||
|
|
|
@ -29,12 +29,20 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
|
||||||
} else if (pME->type == TSDB_CHILD_TABLE) {
|
} else if (pME->type == TSDB_CHILD_TABLE) {
|
||||||
if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1;
|
if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1;
|
||||||
if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1;
|
if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1;
|
||||||
|
if (tEncodeI32(pCoder, pME->ctbEntry.commentLen) < 0) return -1;
|
||||||
|
if (pME->ctbEntry.commentLen > 0){
|
||||||
|
if (tEncodeCStr(pCoder, pME->ctbEntry.comment) < 0) return -1;
|
||||||
|
}
|
||||||
if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1;
|
if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1;
|
||||||
debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug
|
debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug
|
||||||
if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1;
|
if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1;
|
||||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1;
|
if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1;
|
||||||
if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1;
|
if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1;
|
||||||
|
if (tEncodeI32(pCoder, pME->ntbEntry.commentLen) < 0) return -1;
|
||||||
|
if (pME->ntbEntry.commentLen > 0){
|
||||||
|
if (tEncodeCStr(pCoder, pME->ntbEntry.comment) < 0) return -1;
|
||||||
|
}
|
||||||
if (tEncodeI32v(pCoder, pME->ntbEntry.ncid) < 0) return -1;
|
if (tEncodeI32v(pCoder, pME->ntbEntry.ncid) < 0) return -1;
|
||||||
if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1;
|
if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1;
|
||||||
} else if (pME->type == TSDB_TSMA_TABLE) {
|
} else if (pME->type == TSDB_TSMA_TABLE) {
|
||||||
|
@ -61,12 +69,21 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
|
||||||
} else if (pME->type == TSDB_CHILD_TABLE) {
|
} else if (pME->type == TSDB_CHILD_TABLE) {
|
||||||
if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1;
|
if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1;
|
||||||
if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1;
|
if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1;
|
||||||
|
if (tDecodeI32(pCoder, &pME->ctbEntry.commentLen) < 0) return -1;
|
||||||
|
if (pME->ctbEntry.commentLen > 0){
|
||||||
|
if (tDecodeCStr(pCoder, &pME->ctbEntry.comment) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1;
|
if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1;
|
||||||
if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1; // (TODO)
|
if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1; // (TODO)
|
||||||
debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug
|
debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug
|
||||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1;
|
if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1;
|
||||||
if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1;
|
if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1;
|
||||||
|
if (tDecodeI32(pCoder, &pME->ntbEntry.commentLen) < 0) return -1;
|
||||||
|
if (pME->ntbEntry.commentLen > 0){
|
||||||
|
if (tDecodeCStr(pCoder, &pME->ntbEntry.comment) < 0) return -1;
|
||||||
|
}
|
||||||
if (tDecodeI32v(pCoder, &pME->ntbEntry.ncid) < 0) return -1;
|
if (tDecodeI32v(pCoder, &pME->ntbEntry.ncid) < 0) return -1;
|
||||||
if (tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1;
|
if (tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1;
|
||||||
} else if (pME->type == TSDB_TSMA_TABLE) {
|
} else if (pME->type == TSDB_TSMA_TABLE) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) {
|
||||||
|
|
||||||
metaULock(pMeta);
|
metaULock(pMeta);
|
||||||
|
|
||||||
return 0;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaReadNext(SMetaReader *pReader) {
|
int metaReadNext(SMetaReader *pReader) {
|
||||||
|
@ -218,6 +218,40 @@ _err:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){
|
||||||
|
metaRLock(pMeta);
|
||||||
|
TBC * pCur;
|
||||||
|
int ret = tdbTbcOpen(pMeta->pTtlIdx, &pCur, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
metaULock(pMeta);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
STtlIdxKey ttlKey = {0};
|
||||||
|
ttlKey.dtime = ttl;
|
||||||
|
ttlKey.uid = INT64_MAX;
|
||||||
|
int c = 0;
|
||||||
|
tdbTbcMoveTo(pCur, &ttlKey, sizeof(ttlKey), &c);
|
||||||
|
if (c < 0) {
|
||||||
|
tdbTbcMoveToPrev(pCur);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pKey = NULL;
|
||||||
|
int kLen = 0;
|
||||||
|
while(1){
|
||||||
|
ret = tdbTbcPrev(pCur, &pKey, &kLen, NULL, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ttlKey = *(STtlIdxKey*)pKey;
|
||||||
|
taosArrayPush(uidList, &ttlKey.uid);
|
||||||
|
}
|
||||||
|
tdbTbcClose(pCur);
|
||||||
|
|
||||||
|
tdbFree(pKey);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct SMCtbCursor {
|
struct SMCtbCursor {
|
||||||
SMeta * pMeta;
|
SMeta * pMeta;
|
||||||
TBC * pCur;
|
TBC * pCur;
|
||||||
|
|
|
@ -320,11 +320,15 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
|
||||||
if (me.type == TSDB_CHILD_TABLE) {
|
if (me.type == TSDB_CHILD_TABLE) {
|
||||||
me.ctbEntry.ctime = pReq->ctime;
|
me.ctbEntry.ctime = pReq->ctime;
|
||||||
me.ctbEntry.ttlDays = pReq->ttl;
|
me.ctbEntry.ttlDays = pReq->ttl;
|
||||||
|
me.ctbEntry.commentLen = pReq->commentLen;
|
||||||
|
me.ctbEntry.comment = pReq->comment;
|
||||||
me.ctbEntry.suid = pReq->ctb.suid;
|
me.ctbEntry.suid = pReq->ctb.suid;
|
||||||
me.ctbEntry.pTags = pReq->ctb.pTag;
|
me.ctbEntry.pTags = pReq->ctb.pTag;
|
||||||
} else {
|
} else {
|
||||||
me.ntbEntry.ctime = pReq->ctime;
|
me.ntbEntry.ctime = pReq->ctime;
|
||||||
me.ntbEntry.ttlDays = pReq->ttl;
|
me.ntbEntry.ttlDays = pReq->ttl;
|
||||||
|
me.ntbEntry.commentLen = pReq->commentLen;
|
||||||
|
me.ntbEntry.comment = pReq->comment;
|
||||||
me.ntbEntry.schemaRow = pReq->ntb.schemaRow;
|
me.ntbEntry.schemaRow = pReq->ntb.schemaRow;
|
||||||
me.ntbEntry.ncid = me.ntbEntry.schemaRow.pSchema[me.ntbEntry.schemaRow.nCols - 1].colId + 1;
|
me.ntbEntry.ncid = me.ntbEntry.schemaRow.pSchema[me.ntbEntry.schemaRow.nCols - 1].colId + 1;
|
||||||
}
|
}
|
||||||
|
@ -359,7 +363,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
||||||
metaDropTableByUid(pMeta, uid, &type);
|
metaDropTableByUid(pMeta, uid, &type);
|
||||||
metaULock(pMeta);
|
metaULock(pMeta);
|
||||||
|
|
||||||
if (type == TSDB_CHILD_TABLE && tbUids) {
|
if ((type == TSDB_CHILD_TABLE || type == TSDB_NORMAL_TABLE) && tbUids) {
|
||||||
taosArrayPush(tbUids, &uid);
|
taosArrayPush(tbUids, &uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,16 +371,57 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids) {
|
||||||
|
metaWLock(pMeta);
|
||||||
|
int ret = metaTtlSmaller(pMeta, ttl, tbUids);
|
||||||
|
if(ret != 0){
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < taosArrayGetSize(tbUids); ++i) {
|
||||||
|
tb_uid_t *uid = (tb_uid_t *)taosArrayGet(tbUids, i);
|
||||||
|
metaDropTableByUid(pMeta, *uid, NULL);
|
||||||
|
}
|
||||||
|
metaULock(pMeta);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){
|
||||||
|
int32_t ttlDays;
|
||||||
|
int64_t ctime;
|
||||||
|
if (pME->type == TSDB_CHILD_TABLE) {
|
||||||
|
ctime = pME->ctbEntry.ctime;
|
||||||
|
ttlDays = pME->ctbEntry.ttlDays;
|
||||||
|
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
|
ctime = pME->ntbEntry.ctime;
|
||||||
|
ttlDays = pME->ntbEntry.ttlDays;
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ttlDays <= 0) return;
|
||||||
|
|
||||||
|
ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60;
|
||||||
|
// ttlKey->dtime = ctime / 1000 + ttlDays;
|
||||||
|
ttlKey->uid = pME->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
STtlIdxKey ttlKey = {0};
|
||||||
|
metaBuildTtlIdxKey(&ttlKey, pME);
|
||||||
|
if(ttlKey.dtime == 0) return 0;
|
||||||
|
return tdbTbDelete(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), &pMeta->txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
void * pData = NULL;
|
void * pData = NULL;
|
||||||
int nData = 0;
|
int nData = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int64_t version;
|
|
||||||
SMetaEntry e = {0};
|
SMetaEntry e = {0};
|
||||||
SDecoder dc = {0};
|
SDecoder dc = {0};
|
||||||
|
|
||||||
rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
|
rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
|
||||||
version = *(int64_t *)pData;
|
int64_t version = *(int64_t *)pData;
|
||||||
|
|
||||||
tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
|
tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
|
||||||
|
|
||||||
|
@ -388,15 +433,17 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn);
|
tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn);
|
||||||
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
||||||
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
||||||
|
if(e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e);
|
||||||
|
|
||||||
if (e.type == TSDB_CHILD_TABLE) {
|
if (e.type == TSDB_CHILD_TABLE) {
|
||||||
tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn);
|
tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn);
|
||||||
} else if (e.type == TSDB_NORMAL_TABLE) {
|
} else if (e.type == TSDB_NORMAL_TABLE) {
|
||||||
// drop schema.db (todo)
|
// drop schema.db (todo)
|
||||||
// drop ttl.idx (todo)
|
|
||||||
} else if (e.type == TSDB_SUPER_TABLE) {
|
} else if (e.type == TSDB_SUPER_TABLE) {
|
||||||
// drop schema.db (todo)
|
// drop schema.db (todo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metaError("ttl drop table:%s", e.name);
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
tdbFree(pData);
|
tdbFree(pData);
|
||||||
|
|
||||||
|
@ -545,16 +592,20 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
|
|
||||||
metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp);
|
metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp);
|
||||||
|
|
||||||
|
if (entry.pBuf) taosMemoryFree(entry.pBuf);
|
||||||
if (pNewSchema) taosMemoryFree(pNewSchema);
|
if (pNewSchema) taosMemoryFree(pNewSchema);
|
||||||
tDecoderClear(&dc);
|
|
||||||
tdbTbcClose(pTbDbc);
|
tdbTbcClose(pTbDbc);
|
||||||
tdbTbcClose(pUidIdxc);
|
tdbTbcClose(pUidIdxc);
|
||||||
|
tDecoderClear(&dc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
tDecoderClear(&dc);
|
if (entry.pBuf) taosMemoryFree(entry.pBuf);
|
||||||
tdbTbcClose(pTbDbc);
|
tdbTbcClose(pTbDbc);
|
||||||
tdbTbcClose(pUidIdxc);
|
tdbTbcClose(pUidIdxc);
|
||||||
|
tDecoderClear(&dc);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,8 +757,87 @@ _err:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
||||||
// TODO
|
void * pVal = NULL;
|
||||||
ASSERT(0);
|
int nVal = 0;
|
||||||
|
const void * pData = NULL;
|
||||||
|
int nData = 0;
|
||||||
|
int ret = 0;
|
||||||
|
tb_uid_t uid;
|
||||||
|
int64_t oversion;
|
||||||
|
SMetaEntry entry = {0};
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
// search name index
|
||||||
|
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||||
|
if (ret < 0) {
|
||||||
|
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uid = *(tb_uid_t *)pVal;
|
||||||
|
tdbFree(pVal);
|
||||||
|
pVal = NULL;
|
||||||
|
|
||||||
|
// search uid index
|
||||||
|
TBC *pUidIdxc = NULL;
|
||||||
|
|
||||||
|
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn);
|
||||||
|
tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||||
|
ASSERT(c == 0);
|
||||||
|
|
||||||
|
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||||
|
oversion = *(int64_t *)pData;
|
||||||
|
|
||||||
|
// search table.db
|
||||||
|
TBC *pTbDbc = NULL;
|
||||||
|
|
||||||
|
tdbTbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn);
|
||||||
|
tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
|
||||||
|
ASSERT(c == 0);
|
||||||
|
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||||
|
|
||||||
|
// get table entry
|
||||||
|
SDecoder dc = {0};
|
||||||
|
entry.pBuf = taosMemoryMalloc(nData);
|
||||||
|
memcpy(entry.pBuf, pData, nData);
|
||||||
|
tDecoderInit(&dc, entry.pBuf, nData);
|
||||||
|
ret = metaDecodeEntry(&dc, &entry);
|
||||||
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
|
entry.version = version;
|
||||||
|
metaWLock(pMeta);
|
||||||
|
// build SMetaEntry
|
||||||
|
if (entry.type == TSDB_CHILD_TABLE) {
|
||||||
|
if(pAlterTbReq->updateTTL) {
|
||||||
|
metaDeleteTtlIdx(pMeta, &entry);
|
||||||
|
entry.ctbEntry.ttlDays = pAlterTbReq->newTTL;
|
||||||
|
metaUpdateTtlIdx(pMeta, &entry);
|
||||||
|
}
|
||||||
|
if(pAlterTbReq->newCommentLen >= 0) {
|
||||||
|
entry.ctbEntry.commentLen = pAlterTbReq->newCommentLen;
|
||||||
|
entry.ctbEntry.comment = pAlterTbReq->newComment;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(pAlterTbReq->updateTTL) {
|
||||||
|
metaDeleteTtlIdx(pMeta, &entry);
|
||||||
|
entry.ntbEntry.ttlDays = pAlterTbReq->newTTL;
|
||||||
|
metaUpdateTtlIdx(pMeta, &entry);
|
||||||
|
}
|
||||||
|
if(pAlterTbReq->newCommentLen >= 0) {
|
||||||
|
entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen;
|
||||||
|
entry.ntbEntry.comment = pAlterTbReq->newComment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// save to table db
|
||||||
|
metaSaveToTbDb(pMeta, &entry);
|
||||||
|
tdbTbcUpsert(pUidIdxc, &entry.uid, sizeof(tb_uid_t), &version, sizeof(version), 0);
|
||||||
|
metaULock(pMeta);
|
||||||
|
|
||||||
|
tdbTbcClose(pTbDbc);
|
||||||
|
tdbTbcClose(pUidIdxc);
|
||||||
|
tDecoderClear(&dc);
|
||||||
|
if (entry.pBuf) taosMemoryFree(entry.pBuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,25 +916,9 @@ static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
int32_t ttlDays;
|
STtlIdxKey ttlKey = {0};
|
||||||
int64_t ctime;
|
metaBuildTtlIdxKey(&ttlKey, pME);
|
||||||
STtlIdxKey ttlKey;
|
if(ttlKey.dtime == 0) return 0;
|
||||||
|
|
||||||
if (pME->type == TSDB_CHILD_TABLE) {
|
|
||||||
ctime = pME->ctbEntry.ctime;
|
|
||||||
ttlDays = pME->ctbEntry.ttlDays;
|
|
||||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
|
||||||
ctime = pME->ntbEntry.ctime;
|
|
||||||
ttlDays = pME->ntbEntry.ttlDays;
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ttlDays <= 0) return 0;
|
|
||||||
|
|
||||||
ttlKey.dtime = ctime + ttlDays * 24 * 60 * 60;
|
|
||||||
ttlKey.uid = pME->uid;
|
|
||||||
|
|
||||||
return tdbTbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn);
|
return tdbTbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *
|
||||||
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||||
static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||||
static int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp);
|
static int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp);
|
||||||
|
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||||
|
|
||||||
int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) {
|
int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -105,7 +106,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
int32_t len;
|
int32_t len;
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
|
|
||||||
vTrace("vgId:%d, start to process write request %s, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
|
vError("vgId:%d, start to process write request %s, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
|
||||||
version);
|
version);
|
||||||
|
|
||||||
pVnode->state.applied = version;
|
pVnode->state.applied = version;
|
||||||
|
@ -134,6 +135,9 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
case TDMT_VND_DROP_TABLE:
|
case TDMT_VND_DROP_TABLE:
|
||||||
if (vnodeProcessDropTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
if (vnodeProcessDropTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||||
break;
|
break;
|
||||||
|
case TDMT_VND_DROP_TTL_TABLE:
|
||||||
|
if (vnodeProcessDropTtlTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||||
|
break;
|
||||||
case TDMT_VND_CREATE_SMA: {
|
case TDMT_VND_CREATE_SMA: {
|
||||||
if (vnodeProcessCreateTSmaReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
if (vnodeProcessCreateTSmaReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||||
} break;
|
} break;
|
||||||
|
@ -300,6 +304,26 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
|
||||||
pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
|
pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp){
|
||||||
|
|
||||||
|
SArray *tbUids = taosArrayInit(8, sizeof(int64_t));
|
||||||
|
if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
int32_t t = ntohl(*(int32_t*)pReq);
|
||||||
|
vError("rec ttl time:%d", t);
|
||||||
|
int32_t ret = metaTtlDropTable(pVnode->pMeta, t, tbUids);
|
||||||
|
if(ret != 0){
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if(taosArrayGetSize(tbUids) > 0){
|
||||||
|
tqUpdateTbUidList(pVnode->pTq, tbUids, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
taosArrayDestroy(tbUids);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||||
SVCreateStbReq req = {0};
|
SVCreateStbReq req = {0};
|
||||||
SDecoder coder;
|
SDecoder coder;
|
||||||
|
|
|
@ -631,8 +631,8 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
||||||
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
}
|
}
|
||||||
if (pIndefNode->pVectorFuncs) {
|
if (pIndefNode->pFuncs) {
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pIndefNode->pVectorFuncs->length);
|
EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pIndefNode->pFuncs->length);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
}
|
}
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pIndefNode->node.pOutputDataBlockDesc->totalRowSize);
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pIndefNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||||
|
|
|
@ -423,6 +423,7 @@ typedef struct SStreamFinalIntervalOperatorInfo {
|
||||||
SArray* pChildren;
|
SArray* pChildren;
|
||||||
SSDataBlock* pUpdateRes;
|
SSDataBlock* pUpdateRes;
|
||||||
SPhysiNode* pPhyNode; // create new child
|
SPhysiNode* pPhyNode; // create new child
|
||||||
|
bool isFinal;
|
||||||
} SStreamFinalIntervalOperatorInfo;
|
} SStreamFinalIntervalOperatorInfo;
|
||||||
|
|
||||||
typedef struct SAggOperatorInfo {
|
typedef struct SAggOperatorInfo {
|
||||||
|
@ -547,14 +548,18 @@ typedef struct SStreamSessionAggOperatorInfo {
|
||||||
SGroupResInfo groupResInfo;
|
SGroupResInfo groupResInfo;
|
||||||
int64_t gap; // session window gap
|
int64_t gap; // session window gap
|
||||||
int32_t primaryTsIndex; // primary timestamp slot id
|
int32_t primaryTsIndex; // primary timestamp slot id
|
||||||
|
int32_t endTsIndex; // window end timestamp slot id
|
||||||
int32_t order; // current SSDataBlock scan order
|
int32_t order; // current SSDataBlock scan order
|
||||||
STimeWindowAggSupp twAggSup;
|
STimeWindowAggSupp twAggSup;
|
||||||
SSDataBlock* pWinBlock; // window result
|
SSDataBlock* pWinBlock; // window result
|
||||||
SqlFunctionCtx* pDummyCtx; // for combine
|
SqlFunctionCtx* pDummyCtx; // for combine
|
||||||
SSDataBlock* pDelRes;
|
SSDataBlock* pDelRes; // delete result
|
||||||
|
SSDataBlock* pUpdateRes; // update window
|
||||||
SHashObj* pStDeleted;
|
SHashObj* pStDeleted;
|
||||||
void* pDelIterator;
|
void* pDelIterator;
|
||||||
SArray* pChildren; // cache for children's result; final stream operator
|
SArray* pChildren; // cache for children's result; final stream operator
|
||||||
|
SPhysiNode* pPhyNode; // create new child
|
||||||
|
bool isFinal;
|
||||||
} SStreamSessionAggOperatorInfo;
|
} SStreamSessionAggOperatorInfo;
|
||||||
|
|
||||||
typedef struct STimeSliceOperatorInfo {
|
typedef struct STimeSliceOperatorInfo {
|
||||||
|
@ -813,10 +818,10 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
|
||||||
int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput,
|
int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput,
|
||||||
int32_t size);
|
int32_t size);
|
||||||
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize);
|
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize);
|
||||||
SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t groupId, int64_t gap, int32_t* pIndex);
|
SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY startTs,
|
||||||
int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pTs, int32_t rows, int32_t start, int64_t gap,
|
TSKEY endTs, uint64_t groupId, int64_t gap, int32_t* pIndex);
|
||||||
SHashObj* pStDeleted);
|
int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pStartTs,
|
||||||
|
TSKEY* pEndTs, int32_t rows, int32_t start, int64_t gap, SHashObj* pStDeleted);
|
||||||
bool functionNeedToExecute(SqlFunctionCtx* pCtx);
|
bool functionNeedToExecute(SqlFunctionCtx* pCtx);
|
||||||
|
|
||||||
int32_t compareTimeWindow(const void* p1, const void* p2, const void* param);
|
int32_t compareTimeWindow(const void* p1, const void* p2, const void* param);
|
||||||
|
|
|
@ -3716,7 +3716,7 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy
|
||||||
SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode;
|
SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode;
|
||||||
|
|
||||||
int32_t numOfExpr = 0;
|
int32_t numOfExpr = 0;
|
||||||
SExprInfo* pExprInfo = createExprInfo(pPhyNode->pVectorFuncs, NULL, &numOfExpr);
|
SExprInfo* pExprInfo = createExprInfo(pPhyNode->pFuncs, NULL, &numOfExpr);
|
||||||
|
|
||||||
if (pPhyNode->pExprs != NULL) {
|
if (pPhyNode->pExprs != NULL) {
|
||||||
SExprSupp* pSup1 = &pInfo->scalarSup;
|
SExprSupp* pSup1 = &pInfo->scalarSup;
|
||||||
|
|
|
@ -707,10 +707,11 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo) {
|
||||||
int64_t gap = pInfo->sessionSup.gap;
|
int64_t gap = pInfo->sessionSup.gap;
|
||||||
int32_t winIndex = 0;
|
int32_t winIndex = 0;
|
||||||
SResultWindowInfo* pCurWin =
|
SResultWindowInfo* pCurWin =
|
||||||
getSessionTimeWindow(pAggSup, tsCols[pInfo->updateResIndex], pSDB->info.groupId, gap, &winIndex);
|
getSessionTimeWindow(pAggSup, tsCols[pInfo->updateResIndex], INT64_MIN,
|
||||||
|
pSDB->info.groupId, gap, &winIndex);
|
||||||
win = pCurWin->win;
|
win = pCurWin->win;
|
||||||
pInfo->updateResIndex +=
|
pInfo->updateResIndex +=
|
||||||
updateSessionWindowInfo(pCurWin, tsCols, pSDB->info.rows, pInfo->updateResIndex, gap, NULL);
|
updateSessionWindowInfo(pCurWin, tsCols, NULL, pSDB->info.rows, pInfo->updateResIndex, gap, NULL);
|
||||||
} else {
|
} else {
|
||||||
win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[pInfo->updateResIndex], &pInfo->interval,
|
win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[pInfo->updateResIndex], &pInfo->interval,
|
||||||
pInfo->interval.precision, NULL);
|
pInfo->interval.precision, NULL);
|
||||||
|
@ -1368,12 +1369,6 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 6);
|
pColInfoData = taosArrayGet(p->pDataBlock, 6);
|
||||||
colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false);
|
colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false);
|
||||||
|
|
||||||
// table comment
|
|
||||||
// todo: set the correct comment
|
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 8);
|
|
||||||
colDataAppendNULL(pColInfoData, numOfRows);
|
|
||||||
|
|
||||||
char str[256] = {0};
|
|
||||||
int32_t tableType = pInfo->pCur->mr.me.type;
|
int32_t tableType = pInfo->pCur->mr.me.type;
|
||||||
if (tableType == TSDB_CHILD_TABLE) {
|
if (tableType == TSDB_CHILD_TABLE) {
|
||||||
// create time
|
// create time
|
||||||
|
@ -1390,11 +1385,25 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||||
colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schemaRow.nCols, false);
|
colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schemaRow.nCols, false);
|
||||||
|
|
||||||
// super table name
|
// super table name
|
||||||
STR_TO_VARSTR(str, mr.me.name);
|
STR_TO_VARSTR(n, mr.me.name);
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 4);
|
pColInfoData = taosArrayGet(p->pDataBlock, 4);
|
||||||
colDataAppend(pColInfoData, numOfRows, str, false);
|
colDataAppend(pColInfoData, numOfRows, n, false);
|
||||||
metaReaderClear(&mr);
|
metaReaderClear(&mr);
|
||||||
|
|
||||||
|
// table comment
|
||||||
|
pColInfoData = taosArrayGet(p->pDataBlock, 8);
|
||||||
|
if(pInfo->pCur->mr.me.ctbEntry.commentLen > 0) {
|
||||||
|
char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ctbEntry.comment);
|
||||||
|
colDataAppend(pColInfoData, numOfRows, comment, false);
|
||||||
|
}else if(pInfo->pCur->mr.me.ctbEntry.commentLen == 0) {
|
||||||
|
char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
STR_TO_VARSTR(comment, "");
|
||||||
|
colDataAppend(pColInfoData, numOfRows, comment, false);
|
||||||
|
}else{
|
||||||
|
colDataAppendNULL(pColInfoData, numOfRows);
|
||||||
|
}
|
||||||
|
|
||||||
// uid
|
// uid
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 5);
|
pColInfoData = taosArrayGet(p->pDataBlock, 5);
|
||||||
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false);
|
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false);
|
||||||
|
@ -1403,7 +1412,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 7);
|
pColInfoData = taosArrayGet(p->pDataBlock, 7);
|
||||||
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false);
|
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false);
|
||||||
|
|
||||||
STR_TO_VARSTR(str, "CHILD_TABLE");
|
STR_TO_VARSTR(n, "CHILD_TABLE");
|
||||||
} else if (tableType == TSDB_NORMAL_TABLE) {
|
} else if (tableType == TSDB_NORMAL_TABLE) {
|
||||||
// create time
|
// create time
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 2);
|
pColInfoData = taosArrayGet(p->pDataBlock, 2);
|
||||||
|
@ -1417,6 +1426,20 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 4);
|
pColInfoData = taosArrayGet(p->pDataBlock, 4);
|
||||||
colDataAppendNULL(pColInfoData, numOfRows);
|
colDataAppendNULL(pColInfoData, numOfRows);
|
||||||
|
|
||||||
|
// table comment
|
||||||
|
pColInfoData = taosArrayGet(p->pDataBlock, 8);
|
||||||
|
if(pInfo->pCur->mr.me.ntbEntry.commentLen > 0) {
|
||||||
|
char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ntbEntry.comment);
|
||||||
|
colDataAppend(pColInfoData, numOfRows, comment, false);
|
||||||
|
}else if(pInfo->pCur->mr.me.ntbEntry.commentLen == 0) {
|
||||||
|
char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
STR_TO_VARSTR(comment, "");
|
||||||
|
colDataAppend(pColInfoData, numOfRows, comment, false);
|
||||||
|
}else{
|
||||||
|
colDataAppendNULL(pColInfoData, numOfRows);
|
||||||
|
}
|
||||||
|
|
||||||
// uid
|
// uid
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 5);
|
pColInfoData = taosArrayGet(p->pDataBlock, 5);
|
||||||
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false);
|
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false);
|
||||||
|
@ -1425,11 +1448,11 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 7);
|
pColInfoData = taosArrayGet(p->pDataBlock, 7);
|
||||||
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false);
|
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false);
|
||||||
|
|
||||||
STR_TO_VARSTR(str, "NORMAL_TABLE");
|
STR_TO_VARSTR(n, "NORMAL_TABLE");
|
||||||
}
|
}
|
||||||
|
|
||||||
pColInfoData = taosArrayGet(p->pDataBlock, 9);
|
pColInfoData = taosArrayGet(p->pDataBlock, 9);
|
||||||
colDataAppend(pColInfoData, numOfRows, str, false);
|
colDataAppend(pColInfoData, numOfRows, n, false);
|
||||||
|
|
||||||
if (++numOfRows >= pOperator->resultInfo.capacity) {
|
if (++numOfRows >= pOperator->resultInfo.capacity) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -24,6 +24,8 @@ typedef enum SResultTsInterpType {
|
||||||
RESULT_ROW_END_INTERP = 2,
|
RESULT_ROW_END_INTERP = 2,
|
||||||
} SResultTsInterpType;
|
} SResultTsInterpType;
|
||||||
|
|
||||||
|
#define IS_FINAL_OP(op) ((op)->isFinal)
|
||||||
|
|
||||||
static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator);
|
static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator);
|
||||||
|
|
||||||
static int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo);
|
static int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo);
|
||||||
|
@ -682,6 +684,13 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printDataBlock(SSDataBlock* pBlock, const char* flag) {
|
||||||
|
SArray* blocks = taosArrayInit(1, sizeof(SSDataBlock));
|
||||||
|
taosArrayPush(blocks, pBlock);
|
||||||
|
blockDebugShowData(blocks, flag);
|
||||||
|
taosArrayDestroy(blocks);
|
||||||
|
}
|
||||||
|
|
||||||
typedef int64_t (*__get_value_fn_t)(void* data, int32_t index);
|
typedef int64_t (*__get_value_fn_t)(void* data, int32_t index);
|
||||||
|
|
||||||
int32_t binarySearch(void* keyList, int num, TSKEY key, int order, __get_value_fn_t getValuefn) {
|
int32_t binarySearch(void* keyList, int num, TSKEY key, int order, __get_value_fn_t getValuefn) {
|
||||||
|
@ -2054,8 +2063,6 @@ _error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFinalInterval(SStreamFinalIntervalOperatorInfo* pInfo) { return pInfo->pChildren != NULL; }
|
|
||||||
|
|
||||||
void compactFunctions(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx, int32_t numOfOutput,
|
void compactFunctions(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx, int32_t numOfOutput,
|
||||||
SExecTaskInfo* pTaskInfo) {
|
SExecTaskInfo* pTaskInfo) {
|
||||||
for (int32_t k = 0; k < numOfOutput; ++k) {
|
for (int32_t k = 0; k < numOfOutput; ++k) {
|
||||||
|
@ -2129,7 +2136,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
|
||||||
STimeWindow nextWin = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval,
|
STimeWindow nextWin = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval,
|
||||||
pInfo->interval.precision, NULL);
|
pInfo->interval.precision, NULL);
|
||||||
while (1) {
|
while (1) {
|
||||||
if (isFinalInterval(pInfo) && isCloseWindow(&nextWin, &pInfo->twAggSup) &&
|
if (IS_FINAL_OP(pInfo) && isCloseWindow(&nextWin, &pInfo->twAggSup) &&
|
||||||
isDeletedWindow(&nextWin, tableGroupId, &pInfo->aggSup)) {
|
isDeletedWindow(&nextWin, tableGroupId, &pInfo->aggSup)) {
|
||||||
SArray* pUpWins = taosArrayInit(8, sizeof(STimeWindow));
|
SArray* pUpWins = taosArrayInit(8, sizeof(STimeWindow));
|
||||||
taosArrayPush(pUpWins, &nextWin);
|
taosArrayPush(pUpWins, &nextWin);
|
||||||
|
@ -2150,9 +2157,6 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
|
||||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdated) {
|
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdated) {
|
||||||
saveResultRow(pResult, tableGroupId, pUpdated);
|
saveResultRow(pResult, tableGroupId, pUpdated);
|
||||||
}
|
}
|
||||||
// window start(end) key interpolation
|
|
||||||
// doWindowBorderInterpolation(pInfo, pSDataBlock, numOfOutput, pSup->pCtx, pResult, &nextWin, startPos,
|
|
||||||
// forwardRows);
|
|
||||||
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true);
|
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true);
|
||||||
doApplyFunctions(pTaskInfo, pSup->pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardRows,
|
doApplyFunctions(pTaskInfo, pSup->pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardRows,
|
||||||
tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
|
tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
|
||||||
|
@ -2214,8 +2218,8 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||||
if (pInfo->binfo.pRes->info.rows == 0) {
|
if (pInfo->binfo.pRes->info.rows == 0) {
|
||||||
pOperator->status = OP_EXEC_DONE;
|
pOperator->status = OP_EXEC_DONE;
|
||||||
if (isFinalInterval(pInfo) || pInfo->pUpdateRes->info.rows == 0) {
|
if (IS_FINAL_OP(pInfo) || pInfo->pUpdateRes->info.rows == 0) {
|
||||||
if (!isFinalInterval(pInfo)) {
|
if (!IS_FINAL_OP(pInfo)) {
|
||||||
// semi interval operator clear disk buffer
|
// semi interval operator clear disk buffer
|
||||||
clearStreamIntervalOperator(pInfo);
|
clearStreamIntervalOperator(pInfo);
|
||||||
}
|
}
|
||||||
|
@ -2239,7 +2243,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
SArray* pUpWins = taosArrayInit(8, sizeof(STimeWindow));
|
SArray* pUpWins = taosArrayInit(8, sizeof(STimeWindow));
|
||||||
doClearWindows(&pInfo->aggSup, pSup, &pInfo->interval, pInfo->primaryTsIndex, pOperator->exprSupp.numOfExprs,
|
doClearWindows(&pInfo->aggSup, pSup, &pInfo->interval, pInfo->primaryTsIndex, pOperator->exprSupp.numOfExprs,
|
||||||
pBlock, pUpWins);
|
pBlock, pUpWins);
|
||||||
if (isFinalInterval(pInfo)) {
|
if (IS_FINAL_OP(pInfo)) {
|
||||||
int32_t childIndex = getChildIndex(pBlock);
|
int32_t childIndex = getChildIndex(pBlock);
|
||||||
SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex);
|
SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex);
|
||||||
SIntervalAggOperatorInfo* pChildInfo = pChildOp->info;
|
SIntervalAggOperatorInfo* pChildInfo = pChildOp->info;
|
||||||
|
@ -2256,14 +2260,14 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
copyUpdateDataBlock(pInfo->pUpdateRes, pBlock, pInfo->primaryTsIndex);
|
copyUpdateDataBlock(pInfo->pUpdateRes, pBlock, pInfo->primaryTsIndex);
|
||||||
taosArrayDestroy(pUpWins);
|
taosArrayDestroy(pUpWins);
|
||||||
break;
|
break;
|
||||||
} else if (pBlock->info.type == STREAM_GET_ALL && isFinalInterval(pInfo)) {
|
} else if (pBlock->info.type == STREAM_GET_ALL && IS_FINAL_OP(pInfo)) {
|
||||||
getAllIntervalWindow(pInfo->aggSup.pResultRowHashTable, pUpdated);
|
getAllIntervalWindow(pInfo->aggSup.pResultRowHashTable, pUpdated);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->order, MAIN_SCAN, true);
|
setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->order, MAIN_SCAN, true);
|
||||||
doHashInterval(pOperator, pBlock, pBlock->info.groupId, pUpdated);
|
doHashInterval(pOperator, pBlock, pBlock->info.groupId, pUpdated);
|
||||||
if (isFinalInterval(pInfo)) {
|
if (IS_FINAL_OP(pInfo)) {
|
||||||
int32_t chIndex = getChildIndex(pBlock);
|
int32_t chIndex = getChildIndex(pBlock);
|
||||||
int32_t size = taosArrayGetSize(pInfo->pChildren);
|
int32_t size = taosArrayGetSize(pInfo->pChildren);
|
||||||
// if chIndex + 1 - size > 0, add new child
|
// if chIndex + 1 - size > 0, add new child
|
||||||
|
@ -2283,7 +2287,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs);
|
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs);
|
||||||
if (isFinalInterval(pInfo)) {
|
if (IS_FINAL_OP(pInfo)) {
|
||||||
closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, pUpdated);
|
closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, pUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2356,7 +2360,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// semi interval operator does not catch result
|
// semi interval operator does not catch result
|
||||||
if (!isFinalInterval(pInfo)) {
|
if (!IS_FINAL_OP(pInfo)) {
|
||||||
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
||||||
}
|
}
|
||||||
pInfo->pUpdateRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
pInfo->pUpdateRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||||
|
@ -2364,8 +2368,15 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
blockDataEnsureCapacity(pInfo->pUpdateRes, 128);
|
blockDataEnsureCapacity(pInfo->pUpdateRes, 128);
|
||||||
pInfo->pPhyNode = (SPhysiNode*)nodesCloneNode((SNode*)pPhyNode);
|
pInfo->pPhyNode = (SPhysiNode*)nodesCloneNode((SNode*)pPhyNode);
|
||||||
|
|
||||||
|
if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) {
|
||||||
|
pInfo->isFinal = true;
|
||||||
pOperator->name = "StreamFinalIntervalOperator";
|
pOperator->name = "StreamFinalIntervalOperator";
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL;
|
} else {
|
||||||
|
pInfo->isFinal = false;
|
||||||
|
pOperator->name = "StreamSemiIntervalOperator";
|
||||||
|
}
|
||||||
|
|
||||||
|
pOperator->operatorType = pPhyNode->type;
|
||||||
pOperator->blocking = true;
|
pOperator->blocking = true;
|
||||||
pOperator->status = OP_NOT_OPENED;
|
pOperator->status = OP_NOT_OPENED;
|
||||||
pOperator->exprSupp.pExprInfo = pExprInfo;
|
pOperator->exprSupp.pExprInfo = pExprInfo;
|
||||||
|
@ -2455,7 +2466,6 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
SExprInfo* pExprInfo = createExprInfo(pSessionNode->window.pFuncs, NULL, &numOfCols);
|
SExprInfo* pExprInfo = createExprInfo(pSessionNode->window.pFuncs, NULL, &numOfCols);
|
||||||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||||
int32_t tsSlotId = ((SColumnNode*)pSessionNode->window.pTspk)->slotId;
|
|
||||||
int32_t code = TSDB_CODE_OUT_OF_MEMORY;
|
int32_t code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
SStreamSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamSessionAggOperatorInfo));
|
SStreamSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamSessionAggOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
|
@ -2491,7 +2501,10 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh
|
||||||
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
||||||
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
||||||
|
|
||||||
pInfo->primaryTsIndex = tsSlotId;
|
pInfo->primaryTsIndex = ((SColumnNode*)pSessionNode->window.pTspk)->slotId;
|
||||||
|
if (pSessionNode->window.pTsEnd) {
|
||||||
|
pInfo->endTsIndex = ((SColumnNode*)pSessionNode->window.pTsEnd)->slotId;
|
||||||
|
}
|
||||||
pInfo->gap = pSessionNode->gap;
|
pInfo->gap = pSessionNode->gap;
|
||||||
pInfo->binfo.pRes = pResBlock;
|
pInfo->binfo.pRes = pResBlock;
|
||||||
pInfo->order = TSDB_ORDER_ASC;
|
pInfo->order = TSDB_ORDER_ASC;
|
||||||
|
@ -2501,6 +2514,8 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh
|
||||||
pInfo->pDelRes = createOneDataBlock(pResBlock, false);
|
pInfo->pDelRes = createOneDataBlock(pResBlock, false);
|
||||||
blockDataEnsureCapacity(pInfo->pDelRes, 64);
|
blockDataEnsureCapacity(pInfo->pDelRes, 64);
|
||||||
pInfo->pChildren = NULL;
|
pInfo->pChildren = NULL;
|
||||||
|
pInfo->isFinal = false;
|
||||||
|
pInfo->pPhyNode = pPhyNode;
|
||||||
|
|
||||||
pOperator->name = "StreamSessionWindowAggOperator";
|
pOperator->name = "StreamSessionWindowAggOperator";
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION;
|
||||||
|
@ -2513,8 +2528,10 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh
|
||||||
createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo,
|
createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo,
|
||||||
aggEncodeResultRow, aggDecodeResultRow, NULL);
|
aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
if (downstream) {
|
||||||
initDownStream(downstream, &pInfo->streamAggSup, pInfo->gap, pInfo->twAggSup.waterMark, pOperator->operatorType);
|
initDownStream(downstream, &pInfo->streamAggSup, pInfo->gap, pInfo->twAggSup.waterMark, pOperator->operatorType);
|
||||||
code = appendDownstream(pOperator, &downstream, 1);
|
code = appendDownstream(pOperator, &downstream, 1);
|
||||||
|
}
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
||||||
_error:
|
_error:
|
||||||
|
@ -2564,21 +2581,22 @@ SArray* getWinInfos(SStreamAggSupporter* pAggSup, uint64_t groupId) {
|
||||||
return pWinInfos;
|
return pWinInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t groupId, int64_t gap, int32_t* pIndex) {
|
SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY startTs,
|
||||||
|
TSKEY endTs, uint64_t groupId, int64_t gap, int32_t* pIndex) {
|
||||||
SArray* pWinInfos = getWinInfos(pAggSup, groupId);
|
SArray* pWinInfos = getWinInfos(pAggSup, groupId);
|
||||||
pAggSup->pCurWins = pWinInfos;
|
pAggSup->pCurWins = pWinInfos;
|
||||||
|
|
||||||
int32_t size = taosArrayGetSize(pWinInfos);
|
int32_t size = taosArrayGetSize(pWinInfos);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
*pIndex = 0;
|
*pIndex = 0;
|
||||||
return addNewSessionWindow(pWinInfos, ts);
|
return addNewSessionWindow(pWinInfos, startTs);
|
||||||
}
|
}
|
||||||
// find the first position which is smaller than the key
|
// find the first position which is smaller than the key
|
||||||
int32_t index = binarySearch(pWinInfos, size, ts, TSDB_ORDER_DESC, getSessionWindowEndkey);
|
int32_t index = binarySearch(pWinInfos, size, startTs, TSDB_ORDER_DESC, getSessionWindowEndkey);
|
||||||
SResultWindowInfo* pWin = NULL;
|
SResultWindowInfo* pWin = NULL;
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
pWin = taosArrayGet(pWinInfos, index);
|
pWin = taosArrayGet(pWinInfos, index);
|
||||||
if (isInWindow(pWin, ts, gap)) {
|
if (isInWindow(pWin, startTs, gap)) {
|
||||||
*pIndex = index;
|
*pIndex = index;
|
||||||
return pWin;
|
return pWin;
|
||||||
}
|
}
|
||||||
|
@ -2586,34 +2604,40 @@ SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY ts,
|
||||||
|
|
||||||
if (index + 1 < size) {
|
if (index + 1 < size) {
|
||||||
pWin = taosArrayGet(pWinInfos, index + 1);
|
pWin = taosArrayGet(pWinInfos, index + 1);
|
||||||
if (isInWindow(pWin, ts, gap)) {
|
if (isInWindow(pWin, startTs, gap)) {
|
||||||
*pIndex = index + 1;
|
*pIndex = index + 1;
|
||||||
return pWin;
|
return pWin;
|
||||||
|
} else if (endTs != INT64_MIN && isInWindow(pWin, endTs, gap)) {
|
||||||
|
*pIndex = index;
|
||||||
|
return pWin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == size - 1) {
|
if (index == size - 1) {
|
||||||
*pIndex = taosArrayGetSize(pWinInfos);
|
*pIndex = taosArrayGetSize(pWinInfos);
|
||||||
return addNewSessionWindow(pWinInfos, ts);
|
return addNewSessionWindow(pWinInfos, startTs);
|
||||||
}
|
}
|
||||||
*pIndex = index + 1;
|
*pIndex = index + 1;
|
||||||
return insertNewSessionWindow(pWinInfos, ts, index + 1);
|
return insertNewSessionWindow(pWinInfos, startTs, index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pTs, int32_t rows, int32_t start, int64_t gap,
|
int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pStartTs,
|
||||||
SHashObj* pStDeleted) {
|
TSKEY* pEndTs, int32_t rows, int32_t start, int64_t gap, SHashObj* pStDeleted) {
|
||||||
for (int32_t i = start; i < rows; ++i) {
|
for (int32_t i = start; i < rows; ++i) {
|
||||||
if (!isInWindow(pWinInfo, pTs[i], gap)) {
|
if (!isInWindow(pWinInfo, pStartTs[i], gap) && (!pEndTs || !isInWindow(pWinInfo, pEndTs[i], gap)) ) {
|
||||||
return i - start;
|
return i - start;
|
||||||
}
|
}
|
||||||
if (pWinInfo->win.skey > pTs[i]) {
|
if (pWinInfo->win.skey > pStartTs[i]) {
|
||||||
if (pStDeleted && pWinInfo->isOutput) {
|
if (pStDeleted && pWinInfo->isOutput) {
|
||||||
taosHashPut(pStDeleted, &pWinInfo->pos, sizeof(SResultRowPosition), &pWinInfo->win.skey, sizeof(TSKEY));
|
taosHashPut(pStDeleted, &pWinInfo->pos, sizeof(SResultRowPosition), &pWinInfo->win.skey, sizeof(TSKEY));
|
||||||
pWinInfo->isOutput = false;
|
pWinInfo->isOutput = false;
|
||||||
}
|
}
|
||||||
pWinInfo->win.skey = pTs[i];
|
pWinInfo->win.skey = pStartTs[i];
|
||||||
|
}
|
||||||
|
pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pStartTs[i]);
|
||||||
|
if (pEndTs) {
|
||||||
|
pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pEndTs[i]);
|
||||||
}
|
}
|
||||||
pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pTs[i]);
|
|
||||||
}
|
}
|
||||||
return rows - start;
|
return rows - start;
|
||||||
}
|
}
|
||||||
|
@ -2666,7 +2690,7 @@ static int32_t doOneWindowAggImpl(int32_t tsColId, SOptrBasicInfo* pBinfo, SStre
|
||||||
if (code != TSDB_CODE_SUCCESS || (*pResult) == NULL) {
|
if (code != TSDB_CODE_SUCCESS || (*pResult) == NULL) {
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
updateTimeWindowInfo(pTimeWindowData, &pCurWin->win, true);
|
updateTimeWindowInfo(pTimeWindowData, &pCurWin->win, false);
|
||||||
doApplyFunctions(pTaskInfo, pSup->pCtx, &pCurWin->win, pTimeWindowData, startIndex, winRows, tsCols,
|
doApplyFunctions(pTaskInfo, pSup->pCtx, &pCurWin->win, pTimeWindowData, startIndex, winRows, tsCols,
|
||||||
pSDataBlock->info.rows, numOutput, TSDB_ORDER_ASC);
|
pSDataBlock->info.rows, numOutput, TSDB_ORDER_ASC);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -2733,8 +2757,8 @@ typedef struct SWinRes {
|
||||||
uint64_t groupId;
|
uint64_t groupId;
|
||||||
} SWinRes;
|
} SWinRes;
|
||||||
|
|
||||||
static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SHashObj* pStUpdated,
|
static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock,
|
||||||
SHashObj* pStDeleted) {
|
SHashObj* pStUpdated, SHashObj* pStDeleted, bool hasEndTs) {
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
||||||
bool masterScan = true;
|
bool masterScan = true;
|
||||||
|
@ -2745,13 +2769,21 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData
|
||||||
|
|
||||||
int32_t step = 1;
|
int32_t step = 1;
|
||||||
bool ascScan = true;
|
bool ascScan = true;
|
||||||
TSKEY* tsCols = NULL;
|
TSKEY* startTsCols = NULL;
|
||||||
|
TSKEY* endTsCols = NULL;
|
||||||
SResultRow* pResult = NULL;
|
SResultRow* pResult = NULL;
|
||||||
int32_t winRows = 0;
|
int32_t winRows = 0;
|
||||||
|
|
||||||
if (pSDataBlock->pDataBlock != NULL) {
|
if (pSDataBlock->pDataBlock != NULL) {
|
||||||
SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
|
SColumnInfoData* pStartTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
|
||||||
tsCols = (int64_t*)pColDataInfo->pData;
|
startTsCols = (int64_t*) pStartTsCol->pData;
|
||||||
|
SColumnInfoData* pEndTsCol = NULL;
|
||||||
|
if (hasEndTs) {
|
||||||
|
pEndTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->endTsIndex);
|
||||||
|
} else {
|
||||||
|
pEndTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
|
||||||
|
}
|
||||||
|
endTsCols = (int64_t*) pEndTsCol->pData;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2759,22 +2791,21 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData
|
||||||
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
||||||
for (int32_t i = 0; i < pSDataBlock->info.rows;) {
|
for (int32_t i = 0; i < pSDataBlock->info.rows;) {
|
||||||
int32_t winIndex = 0;
|
int32_t winIndex = 0;
|
||||||
SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, tsCols[i], groupId, gap, &winIndex);
|
SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, startTsCols[i],
|
||||||
winRows = updateSessionWindowInfo(pCurWin, tsCols, pSDataBlock->info.rows, i, pInfo->gap, pStDeleted);
|
endTsCols[i], groupId, gap, &winIndex);
|
||||||
|
winRows = updateSessionWindowInfo(pCurWin, startTsCols, endTsCols,
|
||||||
|
pSDataBlock->info.rows, i, pInfo->gap, pStDeleted);
|
||||||
code = doOneWindowAgg(pInfo, pSDataBlock, pCurWin, &pResult, i, winRows, numOfOutput, pOperator);
|
code = doOneWindowAgg(pInfo, pSDataBlock, pCurWin, &pResult, i, winRows, numOfOutput, pOperator);
|
||||||
if (code != TSDB_CODE_SUCCESS || pResult == NULL) {
|
if (code != TSDB_CODE_SUCCESS || pResult == NULL) {
|
||||||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
// window start(end) key interpolation
|
|
||||||
// doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pSup->pCtx, pResult, &nextWin, startPos,
|
|
||||||
// forwardRows,
|
|
||||||
// pInfo->order, false);
|
|
||||||
int32_t winNum = getNumCompactWindow(pAggSup->pCurWins, winIndex, gap);
|
int32_t winNum = getNumCompactWindow(pAggSup->pCurWins, winIndex, gap);
|
||||||
if (winNum > 0) {
|
if (winNum > 0) {
|
||||||
compactTimeWindow(pInfo, winIndex, winNum, groupId, numOfOutput, pStUpdated, pStDeleted, pOperator);
|
compactTimeWindow(pInfo, winIndex, winNum, groupId, numOfOutput, pStUpdated, pStDeleted, pOperator);
|
||||||
}
|
}
|
||||||
pCurWin->isClosed = false;
|
pCurWin->isClosed = false;
|
||||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pStUpdated) {
|
||||||
SWinRes value = {.ts = pCurWin->win.skey, .groupId = groupId};
|
SWinRes value = {.ts = pCurWin->win.skey, .groupId = groupId};
|
||||||
code = taosHashPut(pStUpdated, &pCurWin->pos, sizeof(SResultRowPosition), &value, sizeof(SWinRes));
|
code = taosHashPut(pStUpdated, &pCurWin->pos, sizeof(SResultRowPosition), &value, sizeof(SWinRes));
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -2793,8 +2824,8 @@ static void doClearSessionWindows(SStreamAggSupporter* pAggSup, SExprSupp* pSup,
|
||||||
int32_t step = 0;
|
int32_t step = 0;
|
||||||
for (int32_t i = 0; i < pBlock->info.rows; i += step) {
|
for (int32_t i = 0; i < pBlock->info.rows; i += step) {
|
||||||
int32_t winIndex = 0;
|
int32_t winIndex = 0;
|
||||||
SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, tsCols[i], pBlock->info.groupId, gap, &winIndex);
|
SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, tsCols[i], INT64_MIN, pBlock->info.groupId, gap, &winIndex);
|
||||||
step = updateSessionWindowInfo(pCurWin, tsCols, pBlock->info.rows, i, gap, NULL);
|
step = updateSessionWindowInfo(pCurWin, tsCols, NULL, pBlock->info.rows, i, gap, NULL);
|
||||||
ASSERT(isInWindow(pCurWin, tsCols[i], gap));
|
ASSERT(isInWindow(pCurWin, tsCols[i], gap));
|
||||||
doClearWindowImpl(&pCurWin->pos, pAggSup->pResultBuf, pSup, numOfOutput);
|
doClearWindowImpl(&pCurWin->pos, pAggSup->pResultBuf, pSup, numOfOutput);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -2876,11 +2907,9 @@ static void rebuildTimeWindow(SStreamSessionAggOperatorInfo* pInfo, SArray* pWin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFinalSession(SStreamSessionAggOperatorInfo* pInfo) { return pInfo->pChildren != NULL; }
|
|
||||||
|
|
||||||
typedef SResultWindowInfo* (*__get_win_info_)(void*);
|
typedef SResultWindowInfo* (*__get_win_info_)(void*);
|
||||||
SResultWindowInfo* getSessionWinInfo(void* pData) { return (SResultWindowInfo*)pData; }
|
SResultWindowInfo* getResWinForSession(void* pData) { return (SResultWindowInfo*)pData; }
|
||||||
SResultWindowInfo* getStateWinInfo(void* pData) { return &((SStateWindowInfo*)pData)->winInfo; }
|
SResultWindowInfo* getResWinForState(void* pData) { return &((SStateWindowInfo*)pData)->winInfo; }
|
||||||
|
|
||||||
int32_t closeSessionWindow(SHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SArray* pClosed,
|
int32_t closeSessionWindow(SHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SArray* pClosed,
|
||||||
__get_win_info_ fn) {
|
__get_win_info_ fn) {
|
||||||
|
@ -2928,14 +2957,13 @@ int32_t getAllSessionWindow(SHashObj* pHashMap, SArray* pClosed, __get_win_info_
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
||||||
if (pOperator->status == OP_EXEC_DONE) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SExprSupp* pSup = &pOperator->exprSupp;
|
SExprSupp* pSup = &pOperator->exprSupp;
|
||||||
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
||||||
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
TSKEY maxTs = INT64_MIN;
|
||||||
|
if (pOperator->status == OP_EXEC_DONE) {
|
||||||
|
return NULL;
|
||||||
|
} else if (pOperator->status == OP_RES_TO_RETURN) {
|
||||||
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
||||||
if (pInfo->pDelRes->info.rows > 0) {
|
if (pInfo->pDelRes->info.rows > 0) {
|
||||||
return pInfo->pDelRes;
|
return pInfo->pDelRes;
|
||||||
|
@ -2960,8 +2988,8 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
||||||
if (pBlock->info.type == STREAM_REPROCESS) {
|
if (pBlock->info.type == STREAM_REPROCESS) {
|
||||||
SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
|
SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
|
||||||
doClearSessionWindows(&pInfo->streamAggSup, &pOperator->exprSupp, pBlock, 0, pOperator->exprSupp.numOfExprs, pInfo->gap, pWins);
|
doClearSessionWindows(&pInfo->streamAggSup, &pOperator->exprSupp, pBlock, 0, pOperator->exprSupp.numOfExprs, pInfo->gap, pWins);
|
||||||
if (isFinalSession(pInfo)) {
|
if (IS_FINAL_OP(pInfo)) {
|
||||||
int32_t childIndex = 0; // Todo(liuyao) get child id from SSDataBlock
|
int32_t childIndex = getChildIndex(pBlock);
|
||||||
SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex);
|
SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex);
|
||||||
SStreamSessionAggOperatorInfo* pChildInfo = pChildOp->info;
|
SStreamSessionAggOperatorInfo* pChildInfo = pChildOp->info;
|
||||||
doClearSessionWindows(&pChildInfo->streamAggSup, &pChildOp->exprSupp, pBlock, 0, pChildOp->exprSupp.numOfExprs,
|
doClearSessionWindows(&pChildInfo->streamAggSup, &pChildOp->exprSupp, pBlock, 0, pChildOp->exprSupp.numOfExprs,
|
||||||
|
@ -2971,25 +2999,139 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
||||||
taosArrayDestroy(pWins);
|
taosArrayDestroy(pWins);
|
||||||
continue;
|
continue;
|
||||||
} else if (pBlock->info.type == STREAM_GET_ALL) {
|
} else if (pBlock->info.type == STREAM_GET_ALL) {
|
||||||
getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getSessionWinInfo);
|
getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForSession);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the pDataBlock are always the same one, no need to call this again
|
// the pDataBlock are always the same one, no need to call this again
|
||||||
setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true);
|
setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true);
|
||||||
if (isFinalSession(pInfo)) {
|
doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, IS_FINAL_OP(pInfo));
|
||||||
int32_t childIndex = 0; // Todo(liuyao) get child id from SSDataBlock
|
if (IS_FINAL_OP(pInfo)) {
|
||||||
SOptrBasicInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex);
|
int32_t chIndex = getChildIndex(pBlock);
|
||||||
doStreamSessionAggImpl(pOperator, pBlock, NULL, NULL);
|
int32_t size = taosArrayGetSize(pInfo->pChildren);
|
||||||
|
// if chIndex + 1 - size > 0, add new child
|
||||||
|
for (int32_t i = 0; i < chIndex + 1 - size; i++) {
|
||||||
|
SOperatorInfo* pChildOp = createStreamFinalSessionAggOperatorInfo(NULL, pInfo->pPhyNode, pOperator->pTaskInfo, 0);
|
||||||
|
if (!pChildOp) {
|
||||||
|
longjmp(pOperator->pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted);
|
taosArrayPush(pInfo->pChildren, &pChildOp);
|
||||||
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey);
|
|
||||||
}
|
}
|
||||||
|
SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, chIndex);
|
||||||
|
setInputDataBlock(pChildOp, pChildOp->exprSupp.pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true);
|
||||||
|
doStreamSessionAggImpl(pChildOp, pBlock, NULL, NULL, true);
|
||||||
|
}
|
||||||
|
maxTs = TMAX(maxTs, pBlock->info.window.ekey);
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs);
|
||||||
// restore the value
|
// restore the value
|
||||||
pOperator->status = OP_RES_TO_RETURN;
|
pOperator->status = OP_RES_TO_RETURN;
|
||||||
|
|
||||||
closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated,
|
closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated,
|
||||||
getSessionWinInfo);
|
getResWinForSession);
|
||||||
|
copyUpdateResult(pStUpdated, pUpdated);
|
||||||
|
taosHashCleanup(pStUpdated);
|
||||||
|
|
||||||
|
finalizeUpdatedResult(pSup->numOfExprs, pInfo->streamAggSup.pResultBuf, pUpdated,
|
||||||
|
pSup->rowEntryInfoOffset);
|
||||||
|
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
||||||
|
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||||
|
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
||||||
|
if (pInfo->pDelRes->info.rows > 0) {
|
||||||
|
return pInfo->pDelRes;
|
||||||
|
}
|
||||||
|
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
|
||||||
|
return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clearStreamSessionOperator(SStreamSessionAggOperatorInfo* pInfo) {
|
||||||
|
void **pIte = NULL;
|
||||||
|
while ((pIte = taosHashIterate(pInfo->streamAggSup.pResultRows, pIte)) != NULL) {
|
||||||
|
SArray *pWins = (SArray *) (*pIte);
|
||||||
|
int32_t size = taosArrayGetSize(pWins);
|
||||||
|
for (int32_t i = 0; i < size; i++) {
|
||||||
|
SResultWindowInfo* pWin = (SResultWindowInfo*)taosArrayGet(pWins, i);
|
||||||
|
pWin->pos.pageId = -1;
|
||||||
|
pWin->pos.offset = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clearDiskbasedBuf(pInfo->streamAggSup.pResultBuf);
|
||||||
|
cleanupResultRowInfo(&pInfo->binfo.resultRowInfo);
|
||||||
|
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void removeSessionResults(SHashObj* pHashMap, SArray* pWins) {
|
||||||
|
int32_t size = taosArrayGetSize(pWins);
|
||||||
|
for (int32_t i = 0; i < size; i++) {
|
||||||
|
SResultWindowInfo* pWin = taosArrayGet(pWins, i);
|
||||||
|
taosHashRemove(pHashMap, &pWin->pos, sizeof(SResultRowPosition));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
|
||||||
|
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
||||||
|
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||||
|
TSKEY maxTs = INT64_MIN;
|
||||||
|
SExprSupp* pSup = &pOperator->exprSupp;
|
||||||
|
|
||||||
|
if (pOperator->status == OP_EXEC_DONE) {
|
||||||
|
return NULL;
|
||||||
|
} else if (pOperator->status == OP_RES_TO_RETURN) {
|
||||||
|
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
||||||
|
if (pInfo->pDelRes->info.rows > 0) {
|
||||||
|
return pInfo->pDelRes;
|
||||||
|
}
|
||||||
|
doBuildResultDatablock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
|
||||||
|
if (pInfo->binfo.pRes->info.rows == 0) {
|
||||||
|
pOperator->status = OP_EXEC_DONE;
|
||||||
|
if (pInfo->pUpdateRes->info.rows == 0) {
|
||||||
|
// semi interval operator clear disk buffer
|
||||||
|
clearStreamSessionOperator(pInfo);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// process the rest of the data
|
||||||
|
pOperator->status = OP_OPENED;
|
||||||
|
return pInfo->pUpdateRes;
|
||||||
|
}
|
||||||
|
return pInfo->binfo.pRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
||||||
|
SHashObj* pStUpdated = taosHashInit(64, hashFn, true, HASH_NO_LOCK);
|
||||||
|
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||||
|
SArray* pUpdated = taosArrayInit(16, POINTER_BYTES);
|
||||||
|
while (1) {
|
||||||
|
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||||
|
if (pBlock == NULL) {
|
||||||
|
clearUpdateDataBlock(pInfo->pUpdateRes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pBlock->info.type == STREAM_REPROCESS) {
|
||||||
|
SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
|
||||||
|
doClearSessionWindows(&pInfo->streamAggSup, pSup, pBlock, 0, pSup->numOfExprs, pInfo->gap, pWins);
|
||||||
|
removeSessionResults(pStUpdated, pWins);
|
||||||
|
taosArrayDestroy(pWins);
|
||||||
|
copyUpdateDataBlock(pInfo->pUpdateRes, pBlock, pInfo->primaryTsIndex);
|
||||||
|
break;
|
||||||
|
} else if (pBlock->info.type == STREAM_GET_ALL) {
|
||||||
|
getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForSession);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the pDataBlock are always the same one, no need to call this again
|
||||||
|
setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true);
|
||||||
|
doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, false);
|
||||||
|
maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey);
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs);
|
||||||
|
// restore the value
|
||||||
|
pOperator->status = OP_RES_TO_RETURN;
|
||||||
|
// semi operator
|
||||||
|
// closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated,
|
||||||
|
// getResWinForSession);
|
||||||
copyUpdateResult(pStUpdated, pUpdated);
|
copyUpdateResult(pStUpdated, pUpdated);
|
||||||
taosHashCleanup(pStUpdated);
|
taosHashCleanup(pStUpdated);
|
||||||
|
|
||||||
|
@ -3002,6 +3144,15 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
||||||
return pInfo->pDelRes;
|
return pInfo->pDelRes;
|
||||||
}
|
}
|
||||||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
|
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
|
||||||
|
if (pInfo->binfo.pRes->info.rows == 0) {
|
||||||
|
pOperator->status = OP_EXEC_DONE;
|
||||||
|
if (pInfo->pUpdateRes->info.rows == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// process the rest of the data
|
||||||
|
pOperator->status = OP_OPENED;
|
||||||
|
return pInfo->pUpdateRes;
|
||||||
|
}
|
||||||
return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
|
return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3012,18 +3163,33 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream
|
||||||
if (pOperator == NULL) {
|
if (pOperator == NULL) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
pOperator->name = "StreamFinalSessionWindowAggOperator";
|
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION;
|
|
||||||
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
||||||
pInfo->pChildren = taosArrayInit(8, sizeof(void*));
|
|
||||||
|
if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
|
||||||
|
pInfo->isFinal = true;
|
||||||
|
pOperator->name = "StreamSessionFinalAggOperator";
|
||||||
|
} else {
|
||||||
|
pInfo->isFinal = false;
|
||||||
|
pInfo->pUpdateRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||||
|
pInfo->pUpdateRes->info.type = STREAM_REPROCESS;
|
||||||
|
blockDataEnsureCapacity(pInfo->pUpdateRes, 128);
|
||||||
|
pOperator->name = "StreamSessionSemiAggOperator";
|
||||||
|
pOperator->fpSet =
|
||||||
|
createOperatorFpSet(operatorDummyOpenFn, doStreamSessionSemiAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo,
|
||||||
|
aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||||
|
}
|
||||||
|
pOperator->operatorType = pPhyNode->type;
|
||||||
|
if (numOfChild > 0) {
|
||||||
|
pInfo->pChildren = taosArrayInit(numOfChild, sizeof(void*));
|
||||||
for (int32_t i = 0; i < numOfChild; i++) {
|
for (int32_t i = 0; i < numOfChild; i++) {
|
||||||
SOperatorInfo* pChild =
|
SOperatorInfo* pChild =
|
||||||
createStreamSessionAggOperatorInfo(NULL, pPhyNode, pTaskInfo);
|
createStreamFinalSessionAggOperatorInfo(NULL, pPhyNode, pTaskInfo, 0);
|
||||||
if (pChild == NULL) {
|
if (pChild == NULL) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
taosArrayPush(pInfo->pChildren, &pChild);
|
taosArrayPush(pInfo->pChildren, &pChild);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
||||||
_error:
|
_error:
|
||||||
|
@ -3331,7 +3497,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
|
||||||
pSeUpdated, pInfo->pSeDeleted);
|
pSeUpdated, pInfo->pSeDeleted);
|
||||||
continue;
|
continue;
|
||||||
} else if (pBlock->info.type == STREAM_GET_ALL) {
|
} else if (pBlock->info.type == STREAM_GET_ALL) {
|
||||||
getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getStateWinInfo);
|
getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForState);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3344,7 +3510,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
|
||||||
pOperator->status = OP_RES_TO_RETURN;
|
pOperator->status = OP_RES_TO_RETURN;
|
||||||
|
|
||||||
closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated,
|
closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated,
|
||||||
getStateWinInfo);
|
getResWinForState);
|
||||||
copyUpdateResult(pSeUpdated, pUpdated);
|
copyUpdateResult(pSeUpdated, pUpdated);
|
||||||
taosHashCleanup(pSeUpdated);
|
taosHashCleanup(pSeUpdated);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
||||||
typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||||
|
typedef int32_t (*FCreateMergeFuncParameters)(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters);
|
||||||
|
|
||||||
typedef struct SBuiltinFuncDefinition {
|
typedef struct SBuiltinFuncDefinition {
|
||||||
const char* name;
|
const char* name;
|
||||||
|
@ -40,6 +41,7 @@ typedef struct SBuiltinFuncDefinition {
|
||||||
FExecCombine combineFunc;
|
FExecCombine combineFunc;
|
||||||
const char* pPartialFunc;
|
const char* pPartialFunc;
|
||||||
const char* pMergeFunc;
|
const char* pMergeFunc;
|
||||||
|
FCreateMergeFuncParameters createMergeParaFuc;
|
||||||
} SBuiltinFuncDefinition;
|
} SBuiltinFuncDefinition;
|
||||||
|
|
||||||
extern const SBuiltinFuncDefinition funcMgtBuiltins[];
|
extern const SBuiltinFuncDefinition funcMgtBuiltins[];
|
||||||
|
|
|
@ -51,8 +51,6 @@ extern "C" {
|
||||||
|
|
||||||
#define FUNC_UDF_ID_START 5000
|
#define FUNC_UDF_ID_START 5000
|
||||||
|
|
||||||
extern const int funcMgtUdfNum;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -419,6 +419,14 @@ static int32_t translateTopBot(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t topCreateMergePara(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters) {
|
||||||
|
int32_t code = nodesListMakeAppend(pParameters, pPartialRes);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesListStrictAppend(*pParameters, nodesCloneNode(nodesListGetNode(pRawParameters, 1)));
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) {
|
static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) {
|
||||||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||||
|
|
||||||
|
@ -1728,7 +1736,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.finalizeFunc = topBotFinalize,
|
.finalizeFunc = topBotFinalize,
|
||||||
.combineFunc = topCombine,
|
.combineFunc = topCombine,
|
||||||
.pPartialFunc = "_top_partial",
|
.pPartialFunc = "_top_partial",
|
||||||
.pMergeFunc = "_top_merge"
|
.pMergeFunc = "_top_merge",
|
||||||
|
// .createMergeParaFuc = topCreateMergePara
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "_top_partial",
|
.name = "_top_partial",
|
||||||
|
@ -1872,7 +1881,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "interp",
|
.name = "interp",
|
||||||
.type = FUNCTION_TYPE_INTERP,
|
.type = FUNCTION_TYPE_INTERP,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_INTERVAL_INTERPO_FUNC,
|
.classification = FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_INTERVAL_INTERPO_FUNC,
|
||||||
.translateFunc = translateFirstLast,
|
.translateFunc = translateFirstLast,
|
||||||
.getEnvFunc = getSelectivityFuncEnv,
|
.getEnvFunc = getSelectivityFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
|
|
|
@ -2360,12 +2360,10 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getFirstLastInfoSize(int32_t resBytes) {
|
int32_t getFirstLastInfoSize(int32_t resBytes) { return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t); }
|
||||||
return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||||
SColumnNode* pNode = (SColumnNode *)nodesListGetNode(pFunc->pParameterList, 0);
|
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
pEnv->calcMemSize = sizeof(SFirstLastRes) + pNode->node.resType.bytes + sizeof(int64_t);
|
pEnv->calcMemSize = sizeof(SFirstLastRes) + pNode->node.resType.bytes + sizeof(int64_t);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2390,7 +2388,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
||||||
int32_t numOfElems = 0;
|
int32_t numOfElems = 0;
|
||||||
|
|
||||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
SFirstLastRes *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||||
|
@ -2488,7 +2486,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
||||||
int32_t numOfElems = 0;
|
int32_t numOfElems = 0;
|
||||||
|
|
||||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
SFirstLastRes *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||||
|
@ -2567,8 +2565,8 @@ static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pOutput->bytes = pInput->bytes;
|
pOutput->bytes = pInput->bytes;
|
||||||
TSKEY *tsIn = (TSKEY*)(pInput->buf + pInput->bytes);
|
TSKEY* tsIn = (TSKEY*)(pInput->buf + pInput->bytes);
|
||||||
TSKEY *tsOut = (TSKEY*)(pOutput->buf + pInput->bytes);
|
TSKEY* tsOut = (TSKEY*)(pOutput->buf + pInput->bytes);
|
||||||
if (pOutput->hasResult) {
|
if (pOutput->hasResult) {
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
if (*tsIn > *tsOut) {
|
if (*tsIn > *tsOut) {
|
||||||
|
@ -2586,7 +2584,7 @@ static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx *pCtx, bool isFirstQuery) {
|
static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuery) {
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
SColumnInfoData* pCol = pInput->pData[0];
|
SColumnInfoData* pCol = pInput->pData[0];
|
||||||
ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY);
|
ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY);
|
||||||
|
@ -2595,7 +2593,7 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx *pCtx, bool isFirstQuer
|
||||||
|
|
||||||
int32_t start = pInput->startRowIndex;
|
int32_t start = pInput->startRowIndex;
|
||||||
char* data = colDataGetData(pCol, start);
|
char* data = colDataGetData(pCol, start);
|
||||||
SFirstLastRes* pInputInfo = (SFirstLastRes *)varDataVal(data);
|
SFirstLastRes* pInputInfo = (SFirstLastRes*)varDataVal(data);
|
||||||
|
|
||||||
firstLastTransferInfo(pInputInfo, pInfo, isFirstQuery);
|
firstLastTransferInfo(pInputInfo, pInfo, isFirstQuery);
|
||||||
|
|
||||||
|
@ -2604,13 +2602,9 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx *pCtx, bool isFirstQuer
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t firstFunctionMerge(SqlFunctionCtx *pCtx) {
|
int32_t firstFunctionMerge(SqlFunctionCtx* pCtx) { return firstLastFunctionMergeImpl(pCtx, true); }
|
||||||
return firstLastFunctionMergeImpl(pCtx, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t lastFunctionMerge(SqlFunctionCtx *pCtx) {
|
int32_t lastFunctionMerge(SqlFunctionCtx* pCtx) { return firstLastFunctionMergeImpl(pCtx, false); }
|
||||||
return firstLastFunctionMergeImpl(pCtx, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||||
|
@ -2629,7 +2623,7 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx);
|
||||||
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
int32_t resultBytes = getFirstLastInfoSize(pRes->bytes);
|
int32_t resultBytes = getFirstLastInfoSize(pRes->bytes);
|
||||||
char *res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char));
|
char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char));
|
||||||
|
|
||||||
memcpy(varDataVal(res), pRes, resultBytes);
|
memcpy(varDataVal(res), pRes, resultBytes);
|
||||||
varDataSetLen(res, resultBytes);
|
varDataSetLen(res, resultBytes);
|
||||||
|
@ -5178,7 +5172,7 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
typedef struct SDerivInfo {
|
typedef struct SDerivInfo {
|
||||||
double prevValue; // previous value
|
double prevValue; // previous value
|
||||||
TSKEY prevTs; // previous timestamp
|
TSKEY prevTs; // previous timestamp
|
||||||
bool ignoreNegative;// ignore the negative value
|
bool ignoreNegative; // ignore the negative value
|
||||||
int64_t tsWindow; // time window for derivative
|
int64_t tsWindow; // time window for derivative
|
||||||
bool valueSet; // the value has been set already
|
bool valueSet; // the value has been set already
|
||||||
} SDerivInfo;
|
} SDerivInfo;
|
||||||
|
@ -5188,7 +5182,7 @@ bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool derivativeFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo) {
|
bool derivativeFuncSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) {
|
||||||
if (!functionSetup(pCtx, pResInfo)) {
|
if (!functionSetup(pCtx, pResInfo)) {
|
||||||
return false; // not initialized since it has been initialized
|
return false; // not initialized since it has been initialized
|
||||||
}
|
}
|
||||||
|
@ -5202,8 +5196,8 @@ bool derivativeFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t derivativeFunction(SqlFunctionCtx *pCtx) {
|
int32_t derivativeFunction(SqlFunctionCtx* pCtx) {
|
||||||
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
|
@ -5277,7 +5271,7 @@ int32_t derivativeFunction(SqlFunctionCtx *pCtx) {
|
||||||
return numOfElems;
|
return numOfElems;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t interpFunction(SqlFunctionCtx *pCtx) {
|
int32_t interpFunction(SqlFunctionCtx* pCtx) {
|
||||||
#if 0
|
#if 0
|
||||||
int32_t fillType = (int32_t) pCtx->param[2].i64;
|
int32_t fillType = (int32_t) pCtx->param[2].i64;
|
||||||
//bool ascQuery = (pCtx->order == TSDB_ORDER_ASC);
|
//bool ascQuery = (pCtx->order == TSDB_ORDER_ASC);
|
||||||
|
|
|
@ -70,6 +70,7 @@ int32_t fmFuncMgtInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen) {
|
int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen) {
|
||||||
|
if (NULL != gFunMgtService.pFuncNameHashTable) {
|
||||||
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
|
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
|
||||||
if (NULL != pVal) {
|
if (NULL != pVal) {
|
||||||
pFunc->funcId = *(int32_t*)pVal;
|
pFunc->funcId = *(int32_t*)pVal;
|
||||||
|
@ -77,6 +78,15 @@ int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen) {
|
||||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
|
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
|
return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
|
||||||
|
if (0 == strcmp(funcMgtBuiltins[i].name, pFunc->functionName)) {
|
||||||
|
pFunc->funcId = i;
|
||||||
|
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
||||||
|
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fmIsBuiltinFunc(const char* pFunc) {
|
bool fmIsBuiltinFunc(const char* pFunc) {
|
||||||
|
@ -169,6 +179,13 @@ bool fmIsForbidWindowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId
|
||||||
|
|
||||||
bool fmIsForbidGroupByFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_GROUP_BY_FUNC); }
|
bool fmIsForbidGroupByFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_GROUP_BY_FUNC); }
|
||||||
|
|
||||||
|
bool fmIsInterpFunc(int32_t funcId) {
|
||||||
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return FUNCTION_TYPE_INTERP == funcMgtBuiltins[funcId].type;
|
||||||
|
}
|
||||||
|
|
||||||
void fmFuncMgtDestroy() {
|
void fmFuncMgtDestroy() {
|
||||||
void* m = gFunMgtService.pFuncNameHashTable;
|
void* m = gFunMgtService.pFuncNameHashTable;
|
||||||
if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
||||||
|
@ -233,17 +250,7 @@ bool fmIsSameInOutType(int32_t funcId) {
|
||||||
|
|
||||||
static int32_t getFuncInfo(SFunctionNode* pFunc) {
|
static int32_t getFuncInfo(SFunctionNode* pFunc) {
|
||||||
char msg[64] = {0};
|
char msg[64] = {0};
|
||||||
if (NULL != gFunMgtService.pFuncNameHashTable) {
|
|
||||||
return fmGetFuncInfo(pFunc, msg, sizeof(msg));
|
return fmGetFuncInfo(pFunc, msg, sizeof(msg));
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
|
|
||||||
if (0 == strcmp(funcMgtBuiltins[i].name, pFunc->functionName)) {
|
|
||||||
pFunc->funcId = i;
|
|
||||||
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
|
||||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, msg, sizeof(msg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterList) {
|
static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterList) {
|
||||||
|
@ -261,14 +268,14 @@ static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterLis
|
||||||
return pFunc;
|
return pFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SColumnNode* createColumnByFunc(const SFunctionNode* pFunc) {
|
static SNode* createColumnByFunc(const SFunctionNode* pFunc) {
|
||||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||||
if (NULL == pCol) {
|
if (NULL == pCol) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcpy(pCol->colName, pFunc->node.aliasName);
|
strcpy(pCol->colName, pFunc->node.aliasName);
|
||||||
pCol->node.resType = pFunc->node.resType;
|
pCol->node.resType = pFunc->node.resType;
|
||||||
return pCol;
|
return (SNode*)pCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fmIsDistExecFunc(int32_t funcId) {
|
bool fmIsDistExecFunc(int32_t funcId) {
|
||||||
|
@ -296,21 +303,47 @@ static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNod
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
||||||
|
SNodeList** pParameterList) {
|
||||||
|
SNode* pRes = createColumnByFunc(pPartialFunc);
|
||||||
|
if (NULL != funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc) {
|
||||||
|
return funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc(pSrcFunc->pParameterList, pRes, pParameterList);
|
||||||
|
} else {
|
||||||
|
return nodesListMakeStrictAppend(pParameterList, pRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
||||||
SFunctionNode** pMergeFunc) {
|
SFunctionNode** pMergeFunc) {
|
||||||
SNodeList* pParameterList = NULL;
|
SNodeList* pParameterList = NULL;
|
||||||
nodesListMakeStrictAppend(&pParameterList, (SNode*)createColumnByFunc(pPartialFunc));
|
SFunctionNode* pFunc = NULL;
|
||||||
*pMergeFunc = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pParameterList);
|
|
||||||
if (NULL == *pMergeFunc) {
|
int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
|
||||||
nodesDestroyList(pParameterList);
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
pFunc = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pParameterList);
|
||||||
|
if (NULL == pFunc) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
// overwrite function restype set by translate function
|
// overwrite function restype set by translate function
|
||||||
if (fmIsSameInOutType(pSrcFunc->funcId)) {
|
if (fmIsSameInOutType(pSrcFunc->funcId)) {
|
||||||
(*pMergeFunc)->node.resType = pSrcFunc->node.resType;
|
pFunc->node.resType = pSrcFunc->node.resType;
|
||||||
}
|
}
|
||||||
strcpy((*pMergeFunc)->node.aliasName, pSrcFunc->node.aliasName);
|
strcpy(pFunc->node.aliasName, pSrcFunc->node.aliasName);
|
||||||
return TSDB_CODE_SUCCESS;
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pMergeFunc = pFunc;
|
||||||
|
} else {
|
||||||
|
if (NULL != pFunc) {
|
||||||
|
pFunc->pParameterList = NULL;
|
||||||
|
nodesDestroyNode((SNode*)pFunc);
|
||||||
|
}
|
||||||
|
nodesDestroyList(pParameterList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc) {
|
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc) {
|
||||||
|
|
|
@ -423,6 +423,7 @@ static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pD
|
||||||
COPY_SCALAR_FIELD(slidingUnit);
|
COPY_SCALAR_FIELD(slidingUnit);
|
||||||
COPY_SCALAR_FIELD(sessionGap);
|
COPY_SCALAR_FIELD(sessionGap);
|
||||||
CLONE_NODE_FIELD(pTspk);
|
CLONE_NODE_FIELD(pTspk);
|
||||||
|
CLONE_NODE_FIELD(pTsEnd);
|
||||||
CLONE_NODE_FIELD(pStateExpr);
|
CLONE_NODE_FIELD(pStateExpr);
|
||||||
COPY_SCALAR_FIELD(triggerType);
|
COPY_SCALAR_FIELD(triggerType);
|
||||||
COPY_SCALAR_FIELD(watermark);
|
COPY_SCALAR_FIELD(watermark);
|
||||||
|
@ -454,7 +455,15 @@ static SNode* logicPartitionCopy(const SPartitionLogicNode* pSrc, SPartitionLogi
|
||||||
|
|
||||||
static SNode* logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) {
|
static SNode* logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) {
|
||||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||||
CLONE_NODE_LIST_FIELD(pVectorFuncs);
|
CLONE_NODE_LIST_FIELD(pFuncs);
|
||||||
|
return (SNode*)pDst;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SNode* logicInterpFuncCopy(const SInterpFuncLogicNode* pSrc, SInterpFuncLogicNode* pDst) {
|
||||||
|
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||||
|
CLONE_NODE_LIST_FIELD(pFuncs);
|
||||||
|
COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow));
|
||||||
|
COPY_SCALAR_FIELD(interval);
|
||||||
return (SNode*)pDst;
|
return (SNode*)pDst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,6 +531,7 @@ static SNode* physiWindowCopy(const SWinodwPhysiNode* pSrc, SWinodwPhysiNode* pD
|
||||||
CLONE_NODE_LIST_FIELD(pExprs);
|
CLONE_NODE_LIST_FIELD(pExprs);
|
||||||
CLONE_NODE_LIST_FIELD(pFuncs);
|
CLONE_NODE_LIST_FIELD(pFuncs);
|
||||||
CLONE_NODE_FIELD(pTspk);
|
CLONE_NODE_FIELD(pTspk);
|
||||||
|
CLONE_NODE_FIELD(pTsEnd);
|
||||||
COPY_SCALAR_FIELD(triggerType);
|
COPY_SCALAR_FIELD(triggerType);
|
||||||
COPY_SCALAR_FIELD(watermark);
|
COPY_SCALAR_FIELD(watermark);
|
||||||
COPY_SCALAR_FIELD(filesFactor);
|
COPY_SCALAR_FIELD(filesFactor);
|
||||||
|
@ -668,6 +678,8 @@ SNode* nodesCloneNode(const SNode* pNode) {
|
||||||
return logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst);
|
return logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst);
|
||||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||||
return logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst);
|
return logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst);
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
|
||||||
|
return logicInterpFuncCopy((const SInterpFuncLogicNode*)pNode, (SInterpFuncLogicNode*)pDst);
|
||||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||||
return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst);
|
return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst);
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
||||||
|
|
|
@ -202,6 +202,8 @@ const char* nodesNodeName(ENodeType type) {
|
||||||
return "LogicPartition";
|
return "LogicPartition";
|
||||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||||
return "LogicIndefRowsFunc";
|
return "LogicIndefRowsFunc";
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
|
||||||
|
return "LogicInterpFunc";
|
||||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||||
return "LogicSubplan";
|
return "LogicSubplan";
|
||||||
case QUERY_NODE_LOGIC_PLAN:
|
case QUERY_NODE_LOGIC_PLAN:
|
||||||
|
@ -258,6 +260,8 @@ const char* nodesNodeName(ENodeType type) {
|
||||||
return "PhysiPartition";
|
return "PhysiPartition";
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||||
return "PhysiIndefRowsFunc";
|
return "PhysiIndefRowsFunc";
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
|
||||||
|
return "PhysiInterpFunc";
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||||
return "PhysiDispatch";
|
return "PhysiDispatch";
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||||
|
@ -935,14 +939,14 @@ static int32_t jsonToLogicPartitionNode(const SJson* pJson, void* pObj) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* jkIndefRowsFuncLogicPlanVectorFuncs = "VectorFuncs";
|
static const char* jkIndefRowsFuncLogicPlanFuncs = "Funcs";
|
||||||
|
|
||||||
static int32_t logicIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t logicIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
const SIndefRowsFuncLogicNode* pNode = (const SIndefRowsFuncLogicNode*)pObj;
|
const SIndefRowsFuncLogicNode* pNode = (const SIndefRowsFuncLogicNode*)pObj;
|
||||||
|
|
||||||
int32_t code = logicPlanNodeToJson(pObj, pJson);
|
int32_t code = logicPlanNodeToJson(pObj, pJson);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, pNode->pVectorFuncs);
|
code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanFuncs, pNode->pFuncs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -953,7 +957,52 @@ static int32_t jsonToLogicIndefRowsFuncNode(const SJson* pJson, void* pObj) {
|
||||||
|
|
||||||
int32_t code = jsonToLogicPlanNode(pJson, pObj);
|
int32_t code = jsonToLogicPlanNode(pJson, pObj);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = jsonToNodeList(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, &pNode->pVectorFuncs);
|
code = jsonToNodeList(pJson, jkIndefRowsFuncLogicPlanFuncs, &pNode->pFuncs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* jkInterpFuncLogicPlanFuncs = "Funcs";
|
||||||
|
static const char* jkInterpFuncLogicPlanStartTime = "StartTime";
|
||||||
|
static const char* jkInterpFuncLogicPlanEndTime = "EndTime";
|
||||||
|
static const char* jkInterpFuncLogicPlanInterval = "Interval";
|
||||||
|
|
||||||
|
static int32_t logicInterpFuncNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
|
const SInterpFuncLogicNode* pNode = (const SInterpFuncLogicNode*)pObj;
|
||||||
|
|
||||||
|
int32_t code = logicPlanNodeToJson(pObj, pJson);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodeListToJson(pJson, jkInterpFuncLogicPlanFuncs, pNode->pFuncs);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanStartTime, pNode->timeRange.skey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanEndTime, pNode->timeRange.ekey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanInterval, pNode->interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t jsonToLogicInterpFuncNode(const SJson* pJson, void* pObj) {
|
||||||
|
SInterpFuncLogicNode* pNode = (SInterpFuncLogicNode*)pObj;
|
||||||
|
|
||||||
|
int32_t code = jsonToLogicPlanNode(pJson, pObj);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = jsonToNodeList(pJson, jkInterpFuncLogicPlanFuncs, &pNode->pFuncs);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanStartTime, &pNode->timeRange.skey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanEndTime, &pNode->timeRange.ekey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanInterval, &pNode->interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -1784,6 +1833,7 @@ static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) {
|
||||||
static const char* jkWindowPhysiPlanExprs = "Exprs";
|
static const char* jkWindowPhysiPlanExprs = "Exprs";
|
||||||
static const char* jkWindowPhysiPlanFuncs = "Funcs";
|
static const char* jkWindowPhysiPlanFuncs = "Funcs";
|
||||||
static const char* jkWindowPhysiPlanTsPk = "TsPk";
|
static const char* jkWindowPhysiPlanTsPk = "TsPk";
|
||||||
|
static const char* jkWindowPhysiPlanTsEnd = "TsEnd";
|
||||||
static const char* jkWindowPhysiPlanTriggerType = "TriggerType";
|
static const char* jkWindowPhysiPlanTriggerType = "TriggerType";
|
||||||
static const char* jkWindowPhysiPlanWatermark = "Watermark";
|
static const char* jkWindowPhysiPlanWatermark = "Watermark";
|
||||||
static const char* jkWindowPhysiPlanFilesFactor = "FilesFactor";
|
static const char* jkWindowPhysiPlanFilesFactor = "FilesFactor";
|
||||||
|
@ -1801,6 +1851,9 @@ static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk);
|
code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddObject(pJson, jkWindowPhysiPlanTsEnd, nodeToJson, pNode->pTsEnd);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType);
|
code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType);
|
||||||
}
|
}
|
||||||
|
@ -1827,6 +1880,9 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk);
|
code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsEnd, (SNode**)&pNode->pTsEnd);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
tjsonGetNumberValue(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType, code);
|
tjsonGetNumberValue(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType, code);
|
||||||
;
|
;
|
||||||
|
@ -2042,7 +2098,7 @@ static int32_t jsonToPhysiPartitionNode(const SJson* pJson, void* pObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* jkIndefRowsFuncPhysiPlanExprs = "Exprs";
|
static const char* jkIndefRowsFuncPhysiPlanExprs = "Exprs";
|
||||||
static const char* jkIndefRowsFuncPhysiPlanVectorFuncs = "VectorFuncs";
|
static const char* jkIndefRowsFuncPhysiPlanFuncs = "Funcs";
|
||||||
|
|
||||||
static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
const SIndefRowsFuncPhysiNode* pNode = (const SIndefRowsFuncPhysiNode*)pObj;
|
const SIndefRowsFuncPhysiNode* pNode = (const SIndefRowsFuncPhysiNode*)pObj;
|
||||||
|
@ -2052,7 +2108,7 @@ static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanExprs, pNode->pExprs);
|
code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanExprs, pNode->pExprs);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, pNode->pVectorFuncs);
|
code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanFuncs, pNode->pFuncs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -2066,7 +2122,59 @@ static int32_t jsonToPhysiIndefRowsFuncNode(const SJson* pJson, void* pObj) {
|
||||||
code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanExprs, &pNode->pExprs);
|
code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanExprs, &pNode->pExprs);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, &pNode->pVectorFuncs);
|
code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanFuncs, &pNode->pFuncs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* jkInterpFuncPhysiPlanExprs = "Exprs";
|
||||||
|
static const char* jkInterpFuncPhysiPlanFuncs = "Funcs";
|
||||||
|
static const char* jkInterpFuncPhysiPlanStartTime = "StartTime";
|
||||||
|
static const char* jkInterpFuncPhysiPlanEndTime = "EndTime";
|
||||||
|
static const char* jkInterpFuncPhysiPlanInterval = "Interval";
|
||||||
|
|
||||||
|
static int32_t physiInterpFuncNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
|
const SInterpFuncPhysiNode* pNode = (const SInterpFuncPhysiNode*)pObj;
|
||||||
|
|
||||||
|
int32_t code = physicPlanNodeToJson(pObj, pJson);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodeListToJson(pJson, jkInterpFuncPhysiPlanExprs, pNode->pExprs);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodeListToJson(pJson, jkInterpFuncPhysiPlanFuncs, pNode->pFuncs);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanStartTime, pNode->timeRange.skey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanEndTime, pNode->timeRange.ekey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanInterval, pNode->interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t jsonToPhysiInterpFuncNode(const SJson* pJson, void* pObj) {
|
||||||
|
SInterpFuncPhysiNode* pNode = (SInterpFuncPhysiNode*)pObj;
|
||||||
|
|
||||||
|
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = jsonToNodeList(pJson, jkInterpFuncPhysiPlanExprs, &pNode->pExprs);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = jsonToNodeList(pJson, jkInterpFuncPhysiPlanFuncs, &pNode->pFuncs);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanStartTime, &pNode->timeRange.skey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanEndTime, &pNode->timeRange.ekey);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanInterval, &pNode->interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -3968,6 +4076,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
return logicPartitionNodeToJson(pObj, pJson);
|
return logicPartitionNodeToJson(pObj, pJson);
|
||||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||||
return logicIndefRowsFuncNodeToJson(pObj, pJson);
|
return logicIndefRowsFuncNodeToJson(pObj, pJson);
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
|
||||||
|
return logicInterpFuncNodeToJson(pObj, pJson);
|
||||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||||
return logicSubplanToJson(pObj, pJson);
|
return logicSubplanToJson(pObj, pJson);
|
||||||
case QUERY_NODE_LOGIC_PLAN:
|
case QUERY_NODE_LOGIC_PLAN:
|
||||||
|
@ -4013,6 +4123,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
return physiPartitionNodeToJson(pObj, pJson);
|
return physiPartitionNodeToJson(pObj, pJson);
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||||
return physiIndefRowsFuncNodeToJson(pObj, pJson);
|
return physiIndefRowsFuncNodeToJson(pObj, pJson);
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
|
||||||
|
return physiInterpFuncNodeToJson(pObj, pJson);
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||||
return physiDispatchNodeToJson(pObj, pJson);
|
return physiDispatchNodeToJson(pObj, pJson);
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||||
|
@ -4104,6 +4216,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
||||||
return jsonToLogicPartitionNode(pJson, pObj);
|
return jsonToLogicPartitionNode(pJson, pObj);
|
||||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||||
return jsonToLogicIndefRowsFuncNode(pJson, pObj);
|
return jsonToLogicIndefRowsFuncNode(pJson, pObj);
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
|
||||||
|
return jsonToLogicInterpFuncNode(pJson, pObj);
|
||||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||||
return jsonToLogicSubplan(pJson, pObj);
|
return jsonToLogicSubplan(pJson, pObj);
|
||||||
case QUERY_NODE_LOGIC_PLAN:
|
case QUERY_NODE_LOGIC_PLAN:
|
||||||
|
@ -4149,6 +4263,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
||||||
return jsonToPhysiPartitionNode(pJson, pObj);
|
return jsonToPhysiPartitionNode(pJson, pObj);
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||||
return jsonToPhysiIndefRowsFuncNode(pJson, pObj);
|
return jsonToPhysiIndefRowsFuncNode(pJson, pObj);
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
|
||||||
|
return jsonToPhysiInterpFuncNode(pJson, pObj);
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||||
return jsonToPhysiDispatchNode(pJson, pObj);
|
return jsonToPhysiDispatchNode(pJson, pObj);
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_DELETE:
|
case QUERY_NODE_PHYSICAL_PLAN_DELETE:
|
||||||
|
|
|
@ -250,6 +250,8 @@ SNode* nodesMakeNode(ENodeType type) {
|
||||||
return makeNode(type, sizeof(SPartitionLogicNode));
|
return makeNode(type, sizeof(SPartitionLogicNode));
|
||||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||||
return makeNode(type, sizeof(SIndefRowsFuncLogicNode));
|
return makeNode(type, sizeof(SIndefRowsFuncLogicNode));
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
|
||||||
|
return makeNode(type, sizeof(SInterpFuncLogicNode));
|
||||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||||
return makeNode(type, sizeof(SLogicSubplan));
|
return makeNode(type, sizeof(SLogicSubplan));
|
||||||
case QUERY_NODE_LOGIC_PLAN:
|
case QUERY_NODE_LOGIC_PLAN:
|
||||||
|
@ -308,6 +310,8 @@ SNode* nodesMakeNode(ENodeType type) {
|
||||||
return makeNode(type, sizeof(SPartitionPhysiNode));
|
return makeNode(type, sizeof(SPartitionPhysiNode));
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||||
return makeNode(type, sizeof(SIndefRowsFuncPhysiNode));
|
return makeNode(type, sizeof(SIndefRowsFuncPhysiNode));
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
|
||||||
|
return makeNode(type, sizeof(SInterpFuncLogicNode));
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||||
return makeNode(type, sizeof(SDataDispatcherNode));
|
return makeNode(type, sizeof(SDataDispatcherNode));
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||||
|
@ -352,6 +356,7 @@ static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) {
|
||||||
nodesDestroyList(pNode->pExprs);
|
nodesDestroyList(pNode->pExprs);
|
||||||
nodesDestroyList(pNode->pFuncs);
|
nodesDestroyList(pNode->pFuncs);
|
||||||
nodesDestroyNode(pNode->pTspk);
|
nodesDestroyNode(pNode->pTspk);
|
||||||
|
nodesDestroyNode(pNode->pTsEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
|
static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
|
||||||
|
@ -525,6 +530,7 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
SCreateSubTableClause* pStmt = (SCreateSubTableClause*)pNode;
|
SCreateSubTableClause* pStmt = (SCreateSubTableClause*)pNode;
|
||||||
nodesDestroyList(pStmt->pSpecificTags);
|
nodesDestroyList(pStmt->pSpecificTags);
|
||||||
nodesDestroyList(pStmt->pValsOfTags);
|
nodesDestroyList(pStmt->pValsOfTags);
|
||||||
|
nodesDestroyNode((SNode*)pStmt->pOptions);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||||
|
@ -718,6 +724,7 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
destroyLogicNode((SLogicNode*)pLogicNode);
|
destroyLogicNode((SLogicNode*)pLogicNode);
|
||||||
nodesDestroyList(pLogicNode->pFuncs);
|
nodesDestroyList(pLogicNode->pFuncs);
|
||||||
nodesDestroyNode(pLogicNode->pTspk);
|
nodesDestroyNode(pLogicNode->pTspk);
|
||||||
|
nodesDestroyNode(pLogicNode->pTsEnd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QUERY_NODE_LOGIC_PLAN_FILL: {
|
case QUERY_NODE_LOGIC_PLAN_FILL: {
|
||||||
|
@ -742,7 +749,13 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: {
|
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: {
|
||||||
SIndefRowsFuncLogicNode* pLogicNode = (SIndefRowsFuncLogicNode*)pNode;
|
SIndefRowsFuncLogicNode* pLogicNode = (SIndefRowsFuncLogicNode*)pNode;
|
||||||
destroyLogicNode((SLogicNode*)pLogicNode);
|
destroyLogicNode((SLogicNode*)pLogicNode);
|
||||||
nodesDestroyList(pLogicNode->pVectorFuncs);
|
nodesDestroyList(pLogicNode->pFuncs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: {
|
||||||
|
SInterpFuncLogicNode* pLogicNode = (SInterpFuncLogicNode*)pNode;
|
||||||
|
destroyLogicNode((SLogicNode*)pLogicNode);
|
||||||
|
nodesDestroyList(pLogicNode->pFuncs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QUERY_NODE_LOGIC_SUBPLAN: {
|
case QUERY_NODE_LOGIC_SUBPLAN: {
|
||||||
|
@ -845,7 +858,14 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode;
|
SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode;
|
||||||
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
||||||
nodesDestroyList(pPhyNode->pExprs);
|
nodesDestroyList(pPhyNode->pExprs);
|
||||||
nodesDestroyList(pPhyNode->pVectorFuncs);
|
nodesDestroyList(pPhyNode->pFuncs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: {
|
||||||
|
SInterpFuncPhysiNode* pPhyNode = (SInterpFuncPhysiNode*)pNode;
|
||||||
|
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
||||||
|
nodesDestroyList(pPhyNode->pExprs);
|
||||||
|
nodesDestroyList(pPhyNode->pFuncs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||||
|
|
|
@ -109,6 +109,7 @@ SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode
|
||||||
SNode* pFill);
|
SNode* pFill);
|
||||||
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues);
|
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues);
|
||||||
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode);
|
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode);
|
||||||
|
SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* pEnd);
|
||||||
|
|
||||||
SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere);
|
SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere);
|
||||||
SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList);
|
SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList);
|
||||||
|
@ -118,6 +119,9 @@ SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving);
|
||||||
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList);
|
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList);
|
||||||
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit);
|
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit);
|
||||||
SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
|
SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
|
||||||
|
SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange);
|
||||||
|
SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery);
|
||||||
|
SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill);
|
||||||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
||||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
||||||
|
|
||||||
|
|
|
@ -791,7 +791,7 @@ join_type(A) ::= INNER.
|
||||||
/************************************************ query_specification *************************************************/
|
/************************************************ query_specification *************************************************/
|
||||||
query_specification(A) ::=
|
query_specification(A) ::=
|
||||||
SELECT set_quantifier_opt(B) select_list(C) from_clause(D) where_clause_opt(E)
|
SELECT set_quantifier_opt(B) select_list(C) from_clause(D) where_clause_opt(E)
|
||||||
partition_by_clause_opt(F) twindow_clause_opt(G)
|
partition_by_clause_opt(F) range_opt(J) every_opt(K) fill_opt(L) twindow_clause_opt(G)
|
||||||
group_by_clause_opt(H) having_clause_opt(I). {
|
group_by_clause_opt(H) having_clause_opt(I). {
|
||||||
A = createSelectStmt(pCxt, B, C, D);
|
A = createSelectStmt(pCxt, B, C, D);
|
||||||
A = addWhereClause(pCxt, A, E);
|
A = addWhereClause(pCxt, A, E);
|
||||||
|
@ -799,6 +799,9 @@ query_specification(A) ::=
|
||||||
A = addWindowClauseClause(pCxt, A, G);
|
A = addWindowClauseClause(pCxt, A, G);
|
||||||
A = addGroupByClause(pCxt, A, H);
|
A = addGroupByClause(pCxt, A, H);
|
||||||
A = addHavingClause(pCxt, A, I);
|
A = addHavingClause(pCxt, A, I);
|
||||||
|
A = addRangeClause(pCxt, A, J);
|
||||||
|
A = addEveryClause(pCxt, A, K);
|
||||||
|
A = addFillClause(pCxt, A, L);
|
||||||
}
|
}
|
||||||
|
|
||||||
%type set_quantifier_opt { bool }
|
%type set_quantifier_opt { bool }
|
||||||
|
@ -868,6 +871,12 @@ group_by_list(A) ::= group_by_list(B) NK_COMMA expression(C).
|
||||||
having_clause_opt(A) ::= . { A = NULL; }
|
having_clause_opt(A) ::= . { A = NULL; }
|
||||||
having_clause_opt(A) ::= HAVING search_condition(B). { A = B; }
|
having_clause_opt(A) ::= HAVING search_condition(B). { A = B; }
|
||||||
|
|
||||||
|
range_opt(A) ::= . { A = NULL; }
|
||||||
|
range_opt(A) ::= RANGE NK_LP expression(B) NK_COMMA expression(C) NK_RP. { A = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)); }
|
||||||
|
|
||||||
|
every_opt(A) ::= . { A = NULL; }
|
||||||
|
every_opt(A) ::= EVERY NK_LP duration_literal(B) NK_RP. { A = releaseRawExprNode(pCxt, B); }
|
||||||
|
|
||||||
/************************************************ query_expression ****************************************************/
|
/************************************************ query_expression ****************************************************/
|
||||||
query_expression(A) ::=
|
query_expression(A) ::=
|
||||||
query_expression_body(B)
|
query_expression_body(B)
|
||||||
|
|
|
@ -599,6 +599,11 @@ SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
return (SNode*)groupingSet;
|
return (SNode*)groupingSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* pEnd) {
|
||||||
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
return createBetweenAnd(pCxt, createPrimaryKeyCol(pCxt), pStart, pEnd);
|
||||||
|
}
|
||||||
|
|
||||||
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) {
|
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n);
|
int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n);
|
||||||
|
@ -671,6 +676,32 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit;
|
((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit;
|
||||||
|
} else {
|
||||||
|
((SSetOperator*)pStmt)->pLimit = pLimit;
|
||||||
|
}
|
||||||
|
return pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange) {
|
||||||
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
|
((SSelectStmt*)pStmt)->pRange = pRange;
|
||||||
|
}
|
||||||
|
return pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery) {
|
||||||
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
|
((SSelectStmt*)pStmt)->pEvery = pEvery;
|
||||||
|
}
|
||||||
|
return pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill) {
|
||||||
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
|
((SSelectStmt*)pStmt)->pFill = pFill;
|
||||||
}
|
}
|
||||||
return pStmt;
|
return pStmt;
|
||||||
}
|
}
|
||||||
|
@ -878,6 +909,7 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
|
||||||
pOptions->watermark1 = TSDB_DEFAULT_ROLLUP_WATERMARK;
|
pOptions->watermark1 = TSDB_DEFAULT_ROLLUP_WATERMARK;
|
||||||
pOptions->watermark2 = TSDB_DEFAULT_ROLLUP_WATERMARK;
|
pOptions->watermark2 = TSDB_DEFAULT_ROLLUP_WATERMARK;
|
||||||
pOptions->ttl = TSDB_DEFAULT_TABLE_TTL;
|
pOptions->ttl = TSDB_DEFAULT_TABLE_TTL;
|
||||||
|
pOptions->commentNull = true; // mark null
|
||||||
return (SNode*)pOptions;
|
return (SNode*)pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,6 +918,7 @@ SNode* createAlterTableOptions(SAstCreateContext* pCxt) {
|
||||||
STableOptions* pOptions = (STableOptions*)nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
|
STableOptions* pOptions = (STableOptions*)nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
|
||||||
CHECK_OUT_OF_MEM(pOptions);
|
CHECK_OUT_OF_MEM(pOptions);
|
||||||
pOptions->ttl = -1;
|
pOptions->ttl = -1;
|
||||||
|
pOptions->commentNull = true; // mark null
|
||||||
return (SNode*)pOptions;
|
return (SNode*)pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -894,6 +927,7 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TABLE_OPTION_COMMENT:
|
case TABLE_OPTION_COMMENT:
|
||||||
if (checkComment(pCxt, (SToken*)pVal, true)) {
|
if (checkComment(pCxt, (SToken*)pVal, true)) {
|
||||||
|
((STableOptions*)pOptions)->commentNull = false;
|
||||||
COPY_STRING_FORM_STR_TOKEN(((STableOptions*)pOptions)->comment, (SToken*)pVal);
|
COPY_STRING_FORM_STR_TOKEN(((STableOptions*)pOptions)->comment, (SToken*)pVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -906,9 +940,15 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType
|
||||||
case TABLE_OPTION_ROLLUP:
|
case TABLE_OPTION_ROLLUP:
|
||||||
((STableOptions*)pOptions)->pRollupFuncs = pVal;
|
((STableOptions*)pOptions)->pRollupFuncs = pVal;
|
||||||
break;
|
break;
|
||||||
case TABLE_OPTION_TTL:
|
case TABLE_OPTION_TTL:{
|
||||||
((STableOptions*)pOptions)->ttl = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
|
int64_t ttl = taosStr2Int64(((SToken*)pVal)->z, NULL, 10);
|
||||||
|
if (ttl > INT32_MAX){
|
||||||
|
ttl = INT32_MAX;
|
||||||
|
}
|
||||||
|
// ttl can not be smaller than 0, because there is a limitation in sql.y (TTL NK_INTEGER)
|
||||||
|
((STableOptions*)pOptions)->ttl = ttl;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case TABLE_OPTION_SMA:
|
case TABLE_OPTION_SMA:
|
||||||
((STableOptions*)pOptions)->pSma = pVal;
|
((STableOptions*)pOptions)->pSma = pVal;
|
||||||
break;
|
break;
|
||||||
|
@ -971,9 +1011,9 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN
|
||||||
pStmt->ignoreExists = ignoreExists;
|
pStmt->ignoreExists = ignoreExists;
|
||||||
pStmt->pSpecificTags = pSpecificTags;
|
pStmt->pSpecificTags = pSpecificTags;
|
||||||
pStmt->pValsOfTags = pValsOfTags;
|
pStmt->pValsOfTags = pValsOfTags;
|
||||||
|
pStmt->pOptions = (STableOptions*)pOptions;
|
||||||
nodesDestroyNode(pRealTable);
|
nodesDestroyNode(pRealTable);
|
||||||
nodesDestroyNode(pUseRealTable);
|
nodesDestroyNode(pUseRealTable);
|
||||||
nodesDestroyNode(pOptions);
|
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -803,6 +803,7 @@ static void buildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTa
|
||||||
pTbReq->name = strdup(tname);
|
pTbReq->name = strdup(tname);
|
||||||
pTbReq->ctb.suid = suid;
|
pTbReq->ctb.suid = suid;
|
||||||
pTbReq->ctb.pTag = (uint8_t*)pTag;
|
pTbReq->ctb.pTag = (uint8_t*)pTag;
|
||||||
|
pTbReq->commentLen = -1;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"DURATION", TK_DURATION},
|
{"DURATION", TK_DURATION},
|
||||||
{"EXISTS", TK_EXISTS},
|
{"EXISTS", TK_EXISTS},
|
||||||
{"EXPLAIN", TK_EXPLAIN},
|
{"EXPLAIN", TK_EXPLAIN},
|
||||||
|
{"EVERY", TK_EVERY},
|
||||||
{"FILL", TK_FILL},
|
{"FILL", TK_FILL},
|
||||||
{"FIRST", TK_FIRST},
|
{"FIRST", TK_FIRST},
|
||||||
{"FLOAT", TK_FLOAT},
|
{"FLOAT", TK_FLOAT},
|
||||||
|
@ -152,6 +153,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"QTIME", TK_QTIME},
|
{"QTIME", TK_QTIME},
|
||||||
{"QUERIES", TK_QUERIES},
|
{"QUERIES", TK_QUERIES},
|
||||||
{"QUERY", TK_QUERY},
|
{"QUERY", TK_QUERY},
|
||||||
|
{"RANGE", TK_RANGE},
|
||||||
{"RATIO", TK_RATIO},
|
{"RATIO", TK_RATIO},
|
||||||
{"READ", TK_READ},
|
{"READ", TK_READ},
|
||||||
{"REDISTRIBUTE", TK_REDISTRIBUTE},
|
{"REDISTRIBUTE", TK_REDISTRIBUTE},
|
||||||
|
@ -258,7 +260,6 @@ static SKeyword keywordTable[] = {
|
||||||
// {"LP", TK_LP},
|
// {"LP", TK_LP},
|
||||||
// {"RP", TK_RP},
|
// {"RP", TK_RP},
|
||||||
// {"COMMA", TK_COMMA},
|
// {"COMMA", TK_COMMA},
|
||||||
// {"EVERY", TK_EVERY},
|
|
||||||
// {"VARIABLE", TK_VARIABLE},
|
// {"VARIABLE", TK_VARIABLE},
|
||||||
// {"UPDATE", TK_UPDATE},
|
// {"UPDATE", TK_UPDATE},
|
||||||
// {"CHANGE", TK_CHANGE},
|
// {"CHANGE", TK_CHANGE},
|
||||||
|
|
|
@ -1157,6 +1157,7 @@ static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
||||||
pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId);
|
pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId);
|
||||||
pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType);
|
pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType);
|
||||||
pSelect->hasTailFunc = pSelect->hasTailFunc ? true : (FUNCTION_TYPE_TAIL == pFunc->funcType);
|
pSelect->hasTailFunc = pSelect->hasTailFunc ? true : (FUNCTION_TYPE_TAIL == pFunc->funcType);
|
||||||
|
pSelect->hasInterpFunc = pSelect->hasInterpFunc ? true : (FUNCTION_TYPE_INTERP == pFunc->funcType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3147,9 +3148,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = checkTableRollupOption(pCxt, pStmt->pOptions->pRollupFuncs);
|
code = checkTableRollupOption(pCxt, pStmt->pOptions->pRollupFuncs);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = checkTableSmaOption(pCxt, pStmt);
|
code = checkTableSmaOption(pCxt, pStmt);
|
||||||
}
|
}
|
||||||
|
@ -3390,17 +3388,19 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm
|
||||||
pReq->delay2 = pStmt->pOptions->maxDelay2;
|
pReq->delay2 = pStmt->pOptions->maxDelay2;
|
||||||
pReq->watermark1 = pStmt->pOptions->watermark1;
|
pReq->watermark1 = pStmt->pOptions->watermark1;
|
||||||
pReq->watermark2 = pStmt->pOptions->watermark2;
|
pReq->watermark2 = pStmt->pOptions->watermark2;
|
||||||
pReq->ttl = pStmt->pOptions->ttl;
|
// pReq->ttl = pStmt->pOptions->ttl;
|
||||||
columnDefNodeToField(pStmt->pCols, &pReq->pColumns);
|
columnDefNodeToField(pStmt->pCols, &pReq->pColumns);
|
||||||
columnDefNodeToField(pStmt->pTags, &pReq->pTags);
|
columnDefNodeToField(pStmt->pTags, &pReq->pTags);
|
||||||
pReq->numOfColumns = LIST_LENGTH(pStmt->pCols);
|
pReq->numOfColumns = LIST_LENGTH(pStmt->pCols);
|
||||||
pReq->numOfTags = LIST_LENGTH(pStmt->pTags);
|
pReq->numOfTags = LIST_LENGTH(pStmt->pTags);
|
||||||
if ('\0' != pStmt->pOptions->comment[0]) {
|
if(pStmt->pOptions->commentNull == false){
|
||||||
pReq->comment = strdup(pStmt->pOptions->comment);
|
pReq->comment = strdup(pStmt->pOptions->comment);
|
||||||
if (NULL == pReq->comment) {
|
if (NULL == pReq->comment) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pReq->commentLen = strlen(pStmt->pOptions->comment) + 1;
|
pReq->commentLen = strlen(pStmt->pOptions->comment);
|
||||||
|
}else{
|
||||||
|
pReq->commentLen = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SName tableName;
|
SName tableName;
|
||||||
|
@ -3452,14 +3452,17 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt*
|
||||||
pAlterReq->alterType = pStmt->alterType;
|
pAlterReq->alterType = pStmt->alterType;
|
||||||
|
|
||||||
if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) {
|
if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) {
|
||||||
pAlterReq->ttl = pStmt->pOptions->ttl;
|
// pAlterReq->ttl = pStmt->pOptions->ttl;
|
||||||
if ('\0' != pStmt->pOptions->comment[0]) {
|
if (pStmt->pOptions->commentNull == false) {
|
||||||
pAlterReq->comment = strdup(pStmt->pOptions->comment);
|
pAlterReq->comment = strdup(pStmt->pOptions->comment);
|
||||||
if (NULL == pAlterReq->comment) {
|
if (NULL == pAlterReq->comment) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pAlterReq->commentLen = strlen(pStmt->pOptions->comment) + 1;
|
pAlterReq->commentLen = strlen(pStmt->pOptions->comment);
|
||||||
|
}else{
|
||||||
|
pAlterReq->commentLen = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4715,6 +4718,16 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
|
||||||
SVCreateTbReq req = {0};
|
SVCreateTbReq req = {0};
|
||||||
req.type = TD_NORMAL_TABLE;
|
req.type = TD_NORMAL_TABLE;
|
||||||
req.name = strdup(pStmt->tableName);
|
req.name = strdup(pStmt->tableName);
|
||||||
|
req.ttl = pStmt->pOptions->ttl;
|
||||||
|
if (pStmt->pOptions->commentNull == false) {
|
||||||
|
req.comment = strdup(pStmt->pOptions->comment);
|
||||||
|
if (NULL == req.comment) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
req.commentLen = strlen(pStmt->pOptions->comment);
|
||||||
|
}else{
|
||||||
|
req.commentLen = -1;
|
||||||
|
}
|
||||||
req.ntb.schemaRow.nCols = LIST_LENGTH(pStmt->pCols);
|
req.ntb.schemaRow.nCols = LIST_LENGTH(pStmt->pCols);
|
||||||
req.ntb.schemaRow.version = 1;
|
req.ntb.schemaRow.version = 1;
|
||||||
req.ntb.schemaRow.pSchema = taosMemoryCalloc(req.ntb.schemaRow.nCols, sizeof(SSchema));
|
req.ntb.schemaRow.pSchema = taosMemoryCalloc(req.ntb.schemaRow.nCols, sizeof(SSchema));
|
||||||
|
@ -4865,6 +4878,13 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S
|
||||||
struct SVCreateTbReq req = {0};
|
struct SVCreateTbReq req = {0};
|
||||||
req.type = TD_CHILD_TABLE;
|
req.type = TD_CHILD_TABLE;
|
||||||
req.name = strdup(pStmt->tableName);
|
req.name = strdup(pStmt->tableName);
|
||||||
|
req.ttl = pStmt->pOptions->ttl;
|
||||||
|
if (pStmt->pOptions->commentNull == false) {
|
||||||
|
req.comment = strdup(pStmt->pOptions->comment);
|
||||||
|
req.commentLen = strlen(pStmt->pOptions->comment);
|
||||||
|
} else{
|
||||||
|
req.commentLen = -1;
|
||||||
|
}
|
||||||
req.ctb.suid = suid;
|
req.ctb.suid = suid;
|
||||||
req.ctb.pTag = (uint8_t*)pTag;
|
req.ctb.pTag = (uint8_t*)pTag;
|
||||||
if (pStmt->ignoreExists) {
|
if (pStmt->ignoreExists) {
|
||||||
|
@ -5436,19 +5456,21 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
if (-1 != pStmt->pOptions->ttl) {
|
if (-1 != pStmt->pOptions->ttl) {
|
||||||
code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
pReq->updateTTL = true;
|
pReq->updateTTL = true;
|
||||||
pReq->newTTL = pStmt->pOptions->ttl;
|
pReq->newTTL = pStmt->pOptions->ttl;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && '\0' != pStmt->pOptions->comment[0]) {
|
if (TSDB_CODE_SUCCESS == code){
|
||||||
pReq->updateComment = true;
|
if(pStmt->pOptions->commentNull == false) {
|
||||||
pReq->newComment = strdup(pStmt->pOptions->comment);
|
pReq->newComment = strdup(pStmt->pOptions->comment);
|
||||||
if (NULL == pReq->newComment) {
|
if (NULL == pReq->newComment) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
pReq->newCommentLen = strlen(pReq->newComment);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
pReq->newCommentLen = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -5566,6 +5588,9 @@ static int32_t rewriteAlterTableImpl(STranslateContext* pCxt, SAlterTableStmt* p
|
||||||
pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_TAG_BYTES)) {
|
pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_TAG_BYTES)) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG);
|
||||||
}
|
}
|
||||||
|
if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_OPTIONS && -1 != pStmt->pOptions->ttl) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||||
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else if (TSDB_CHILD_TABLE != pTableMeta->tableType && TSDB_NORMAL_TABLE != pTableMeta->tableType) {
|
} else if (TSDB_CHILD_TABLE != pTableMeta->tableType && TSDB_NORMAL_TABLE != pTableMeta->tableType) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -121,10 +121,10 @@ TEST_F(ParserInitialATest, alterSTable) {
|
||||||
int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname);
|
int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname);
|
||||||
expect.name[len] = '\0';
|
expect.name[len] = '\0';
|
||||||
expect.alterType = alterType;
|
expect.alterType = alterType;
|
||||||
expect.ttl = ttl;
|
// expect.ttl = ttl;
|
||||||
if (nullptr != pComment) {
|
if (nullptr != pComment) {
|
||||||
expect.comment = strdup(pComment);
|
expect.comment = strdup(pComment);
|
||||||
expect.commentLen = strlen(pComment) + 1;
|
expect.commentLen = strlen(pComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect.numOfFields = numOfFields;
|
expect.numOfFields = numOfFields;
|
||||||
|
@ -180,9 +180,9 @@ TEST_F(ParserInitialATest, alterSTable) {
|
||||||
tFreeSMAltertbReq(&req);
|
tFreeSMAltertbReq(&req);
|
||||||
});
|
});
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10);
|
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10);
|
||||||
run("ALTER TABLE st1 TTL 10");
|
// run("ALTER TABLE st1 TTL 10");
|
||||||
clearAlterStbReq();
|
// clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test");
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test");
|
||||||
run("ALTER TABLE st1 COMMENT 'test'");
|
run("ALTER TABLE st1 COMMENT 'test'");
|
||||||
|
@ -289,7 +289,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
||||||
expect.newTTL = ttl;
|
expect.newTTL = ttl;
|
||||||
}
|
}
|
||||||
if (nullptr != pComment) {
|
if (nullptr != pComment) {
|
||||||
expect.updateComment = true;
|
expect.newCommentLen = strlen(pComment);
|
||||||
expect.newComment = pComment;
|
expect.newComment = pComment;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -328,9 +328,10 @@ TEST_F(ParserInitialATest, alterTable) {
|
||||||
ASSERT_EQ(memcmp(req.pTagVal, expect.pTagVal, expect.nTagVal), 0);
|
ASSERT_EQ(memcmp(req.pTagVal, expect.pTagVal, expect.nTagVal), 0);
|
||||||
ASSERT_EQ(req.updateTTL, expect.updateTTL);
|
ASSERT_EQ(req.updateTTL, expect.updateTTL);
|
||||||
ASSERT_EQ(req.newTTL, expect.newTTL);
|
ASSERT_EQ(req.newTTL, expect.newTTL);
|
||||||
ASSERT_EQ(req.updateComment, expect.updateComment);
|
|
||||||
if (nullptr != expect.newComment) {
|
if (nullptr != expect.newComment) {
|
||||||
ASSERT_EQ(std::string(req.newComment), std::string(expect.newComment));
|
ASSERT_EQ(std::string(req.newComment), std::string(expect.newComment));
|
||||||
|
ASSERT_EQ(req.newCommentLen, strlen(req.newComment));
|
||||||
|
ASSERT_EQ(expect.newCommentLen, strlen(expect.newComment));
|
||||||
}
|
}
|
||||||
|
|
||||||
tDecoderClear(&coder);
|
tDecoderClear(&coder);
|
||||||
|
|
|
@ -370,10 +370,10 @@ TEST_F(ParserInitialCTest, createStable) {
|
||||||
expect.delay2 = delay2;
|
expect.delay2 = delay2;
|
||||||
expect.watermark1 = watermark1;
|
expect.watermark1 = watermark1;
|
||||||
expect.watermark2 = watermark2;
|
expect.watermark2 = watermark2;
|
||||||
expect.ttl = ttl;
|
// expect.ttl = ttl;
|
||||||
if (nullptr != pComment) {
|
if (nullptr != pComment) {
|
||||||
expect.comment = strdup(pComment);
|
expect.comment = strdup(pComment);
|
||||||
expect.commentLen = strlen(pComment) + 1;
|
expect.commentLen = strlen(pComment);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ TEST_F(ParserInitialCTest, createStable) {
|
||||||
ASSERT_EQ(req.ttl, expect.ttl);
|
ASSERT_EQ(req.ttl, expect.ttl);
|
||||||
ASSERT_EQ(req.numOfColumns, expect.numOfColumns);
|
ASSERT_EQ(req.numOfColumns, expect.numOfColumns);
|
||||||
ASSERT_EQ(req.numOfTags, expect.numOfTags);
|
ASSERT_EQ(req.numOfTags, expect.numOfTags);
|
||||||
ASSERT_EQ(req.commentLen, expect.commentLen);
|
// ASSERT_EQ(req.commentLen, expect.commentLen);
|
||||||
ASSERT_EQ(req.ast1Len, expect.ast1Len);
|
ASSERT_EQ(req.ast1Len, expect.ast1Len);
|
||||||
ASSERT_EQ(req.ast2Len, expect.ast2Len);
|
ASSERT_EQ(req.ast2Len, expect.ast2Len);
|
||||||
|
|
||||||
|
|
|
@ -256,6 +256,24 @@ TEST_F(ParserSelectTest, intervalSemanticCheck) {
|
||||||
run("SELECT _WSTARTTS, _WENDTS, _WDURATION, sum(c1) FROM t1", TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
run("SELECT _WSTARTTS, _WENDTS, _WDURATION, sum(c1) FROM t1", TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserSelectTest, interp) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00')");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') FILL(LINEAR)");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1 EVERY(5s)");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1 EVERY(5s) FILL(LINEAR)");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s)");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ParserSelectTest, subquery) {
|
TEST_F(ParserSelectTest, subquery) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t rewriteExprForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) {
|
static int32_t rewriteExprsForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) {
|
||||||
nodesWalkExprs(pExprs, doNameExpr, NULL);
|
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);
|
nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt);
|
||||||
|
@ -266,7 +266,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
||||||
|
|
||||||
// rewrite the expression in subsequent clauses
|
// rewrite the expression in subsequent clauses
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pScan->pScanPseudoCols, pSelect, SQL_CLAUSE_FROM);
|
code = rewriteExprsForSelect(pScan->pScanPseudoCols, pSelect, SQL_CLAUSE_FROM);
|
||||||
}
|
}
|
||||||
|
|
||||||
pScan->scanType = getScanType(pCxt, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType);
|
pScan->scanType = getScanType(pCxt, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType);
|
||||||
|
@ -425,7 +425,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
||||||
|
|
||||||
// rewrite the expression in subsequent clauses
|
// rewrite the expression in subsequent clauses
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
code = rewriteExprsForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) {
|
if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) {
|
||||||
|
@ -434,7 +434,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
||||||
|
|
||||||
// rewrite the expression in subsequent clauses
|
// rewrite the expression in subsequent clauses
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
code = rewriteExprsForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pHaving) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pHaving) {
|
||||||
|
@ -473,14 +473,15 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pIdfRowsFunc->pVectorFuncs);
|
// indefinite rows functions and _select_values functions
|
||||||
|
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pIdfRowsFunc->pFuncs);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pIdfRowsFunc->pVectorFuncs, pSelect, SQL_CLAUSE_SELECT);
|
code = rewriteExprsForSelect(pIdfRowsFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the output
|
// set the output
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = createColumnByRewriteExprs(pIdfRowsFunc->pVectorFuncs, &pIdfRowsFunc->node.pTargets);
|
code = createColumnByRewriteExprs(pIdfRowsFunc->pFuncs, &pIdfRowsFunc->node.pTargets);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -492,6 +493,45 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||||
|
if (!pSelect->hasInterpFunc) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SInterpFuncLogicNode* pInterpFunc = (SInterpFuncLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_INTERP_FUNC);
|
||||||
|
if (NULL == pInterpFunc) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsInterpFunc, &pInterpFunc->pFuncs);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = rewriteExprsForSelect(pInterpFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pRange) {
|
||||||
|
// SRangeNode* pRange = (SRangeNode*)pSelect->pRange;
|
||||||
|
// pInterpFunc->timeRange.skey = ((SValueNode*)pRange->pStart)->datum.i;
|
||||||
|
// pInterpFunc->timeRange.ekey = ((SValueNode*)pRange->pEnd)->datum.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pEvery) {
|
||||||
|
pInterpFunc->interval = ((SValueNode*)pSelect->pEvery)->datum.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the output
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = createColumnByRewriteExprs(pInterpFunc->pFuncs, &pInterpFunc->node.pTargets);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pLogicNode = (SLogicNode*)pInterpFunc;
|
||||||
|
} else {
|
||||||
|
nodesDestroyNode((SNode*)pInterpFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow,
|
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow,
|
||||||
SLogicNode** pLogicNode) {
|
SLogicNode** pLogicNode) {
|
||||||
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_WINDOW, fmIsWindowClauseFunc, &pWindow->pFuncs);
|
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_WINDOW, fmIsWindowClauseFunc, &pWindow->pFuncs);
|
||||||
|
@ -506,7 +546,7 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW);
|
code = rewriteExprsForSelect(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -559,6 +599,7 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW
|
||||||
nodesDestroyNode((SNode*)pWindow);
|
nodesDestroyNode((SNode*)pWindow);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
pWindow->pTsEnd = nodesCloneNode((SNode*)pSession->pCol);
|
||||||
|
|
||||||
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||||
}
|
}
|
||||||
|
@ -777,7 +818,7 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe
|
||||||
|
|
||||||
// rewrite the expression in subsequent clauses
|
// rewrite the expression in subsequent clauses
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_DISTINCT);
|
code = rewriteExprsForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_DISTINCT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the output
|
// set the output
|
||||||
|
@ -812,6 +853,9 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = createSelectRootLogicNode(pCxt, pSelect, createIndefRowsFuncLogicNode, &pRoot);
|
code = createSelectRootLogicNode(pCxt, pSelect, createIndefRowsFuncLogicNode, &pRoot);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = createSelectRootLogicNode(pCxt, pSelect, createInterpFuncLogicNode, &pRoot);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = createSelectRootLogicNode(pCxt, pSelect, createDistinctLogicNode, &pRoot);
|
code = createSelectRootLogicNode(pCxt, pSelect, createDistinctLogicNode, &pRoot);
|
||||||
}
|
}
|
||||||
|
|
|
@ -825,8 +825,8 @@ static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
}
|
}
|
||||||
|
|
||||||
SNodeList* pPrecalcExprs = NULL;
|
SNodeList* pPrecalcExprs = NULL;
|
||||||
SNodeList* pVectorFuncs = NULL;
|
SNodeList* pFuncs = NULL;
|
||||||
int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pVectorFuncs, &pPrecalcExprs, &pVectorFuncs);
|
int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pFuncs, &pPrecalcExprs, &pFuncs);
|
||||||
|
|
||||||
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
||||||
// push down expression to pOutputDataBlockDesc of child node
|
// push down expression to pOutputDataBlockDesc of child node
|
||||||
|
@ -837,10 +837,10 @@ static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pVectorFuncs) {
|
|
||||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pVectorFuncs, &pIdfRowsFunc->pVectorFuncs);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = addDataBlockSlots(pCxt, pIdfRowsFunc->pVectorFuncs, pIdfRowsFunc->node.pOutputDataBlockDesc);
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pIdfRowsFunc->pFuncs);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = addDataBlockSlots(pCxt, pIdfRowsFunc->pFuncs, pIdfRowsFunc->node.pOutputDataBlockDesc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,6 +853,48 @@ static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t createInterpFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
|
SInterpFuncLogicNode* pFuncLogicNode, SPhysiNode** pPhyNode) {
|
||||||
|
SInterpFuncPhysiNode* pInterpFunc =
|
||||||
|
(SInterpFuncPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pFuncLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC);
|
||||||
|
if (NULL == pInterpFunc) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNodeList* pPrecalcExprs = NULL;
|
||||||
|
SNodeList* pFuncs = NULL;
|
||||||
|
int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pFuncs, &pPrecalcExprs, &pFuncs);
|
||||||
|
|
||||||
|
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
||||||
|
// push down expression to pOutputDataBlockDesc of child node
|
||||||
|
if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) {
|
||||||
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pInterpFunc->pExprs);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = pushdownDataBlockSlots(pCxt, pInterpFunc->pExprs, pChildTupe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pInterpFunc->pFuncs);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = addDataBlockSlots(pCxt, pInterpFunc->pFuncs, pInterpFunc->node.pOutputDataBlockDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pInterpFunc->timeRange = pFuncLogicNode->timeRange;
|
||||||
|
pInterpFunc->interval = pFuncLogicNode->interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pPhyNode = (SPhysiNode*)pInterpFunc;
|
||||||
|
} else {
|
||||||
|
nodesDestroyNode((SNode*)pInterpFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||||
SProjectPhysiNode* pProject =
|
SProjectPhysiNode* pProject =
|
||||||
|
@ -961,6 +1003,9 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pWindow->pTspk);
|
code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pWindow->pTspk);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code && pWindowLogicNode->pTsEnd) {
|
||||||
|
code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTsEnd, &pWindow->pTsEnd);
|
||||||
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) {
|
||||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs);
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs);
|
||||||
|
@ -1295,6 +1340,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
||||||
return createFillPhysiNode(pCxt, pChildren, (SFillLogicNode*)pLogicNode, pPhyNode);
|
return createFillPhysiNode(pCxt, pChildren, (SFillLogicNode*)pLogicNode, pPhyNode);
|
||||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||||
return createIndefRowsFuncPhysiNode(pCxt, pChildren, (SIndefRowsFuncLogicNode*)pLogicNode, pPhyNode);
|
return createIndefRowsFuncPhysiNode(pCxt, pChildren, (SIndefRowsFuncLogicNode*)pLogicNode, pPhyNode);
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
|
||||||
|
return createInterpFuncPhysiNode(pCxt, pChildren, (SInterpFuncLogicNode*)pLogicNode, pPhyNode);
|
||||||
case QUERY_NODE_LOGIC_PLAN_MERGE:
|
case QUERY_NODE_LOGIC_PLAN_MERGE:
|
||||||
return createMergePhysiNode(pCxt, (SMergeLogicNode*)pLogicNode, pPhyNode);
|
return createMergePhysiNode(pCxt, (SMergeLogicNode*)pLogicNode, pPhyNode);
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -176,7 +176,7 @@ static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) {
|
||||||
return !stbSplHasGatherExecFunc(((SAggLogicNode*)pNode)->pAggFuncs) && stbSplHasMultiTbScan(streamQuery, pNode);
|
return !stbSplHasGatherExecFunc(((SAggLogicNode*)pNode)->pAggFuncs) && stbSplHasMultiTbScan(streamQuery, pNode);
|
||||||
case QUERY_NODE_LOGIC_PLAN_WINDOW: {
|
case QUERY_NODE_LOGIC_PLAN_WINDOW: {
|
||||||
SWindowLogicNode* pWindow = (SWindowLogicNode*)pNode;
|
SWindowLogicNode* pWindow = (SWindowLogicNode*)pNode;
|
||||||
if (WINDOW_TYPE_INTERVAL != pWindow->winType) {
|
if (WINDOW_TYPE_STATE == pWindow->winType || (!streamQuery && WINDOW_TYPE_SESSION == pWindow->winType) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode);
|
return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode);
|
||||||
|
@ -257,6 +257,34 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) {
|
||||||
|
int32_t index = 0;
|
||||||
|
SNode* pFunc = NULL;
|
||||||
|
FOREACH(pFunc, pWin->pFuncs) {
|
||||||
|
if (FUNCTION_TYPE_WENDTS == ((SFunctionNode*)pFunc)->funcType) {
|
||||||
|
*pIndex = index;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
|
SFunctionNode* pWEnd = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
|
if (NULL == pWEnd) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
strcpy(pWEnd->functionName, "_wendts");
|
||||||
|
snprintf(pWEnd->node.aliasName, sizeof(pWEnd->node.aliasName), "%s.%p", pWEnd->functionName, pWEnd);
|
||||||
|
int32_t code = fmGetFuncInfo(pWEnd, NULL, 0);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesListStrictAppend(pWin->pFuncs, (SNode*)pWEnd);
|
||||||
|
}
|
||||||
|
*pIndex = index;
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = createColumnByRewriteExpr(nodesListGetNode(pWin->pFuncs, index), &pWin->node.pTargets);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t stbSplCreatePartWindowNode(SWindowLogicNode* pMergeWindow, SLogicNode** pPartWindow) {
|
static int32_t stbSplCreatePartWindowNode(SWindowLogicNode* pMergeWindow, SLogicNode** pPartWindow) {
|
||||||
SNodeList* pFunc = pMergeWindow->pFuncs;
|
SNodeList* pFunc = pMergeWindow->pFuncs;
|
||||||
pMergeWindow->pFuncs = NULL;
|
pMergeWindow->pFuncs = NULL;
|
||||||
|
@ -425,8 +453,18 @@ static int32_t stbSplSplitSessionForStream(SSplitContext* pCxt, SStableSplitInfo
|
||||||
SLogicNode* pPartWindow = NULL;
|
SLogicNode* pPartWindow = NULL;
|
||||||
int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow);
|
int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
((SWindowLogicNode*)pPartWindow)->windowAlgo = SESSION_ALGO_STREAM_SEMI;
|
SWindowLogicNode* pPartWin = (SWindowLogicNode*)pPartWindow;
|
||||||
((SWindowLogicNode*)pInfo->pSplitNode)->windowAlgo = SESSION_ALGO_STREAM_FINAL;
|
SWindowLogicNode* pMergeWin = (SWindowLogicNode*)pInfo->pSplitNode;
|
||||||
|
pPartWin->windowAlgo = SESSION_ALGO_STREAM_SEMI;
|
||||||
|
pMergeWin->windowAlgo = SESSION_ALGO_STREAM_FINAL;
|
||||||
|
int32_t index = 0;
|
||||||
|
int32_t code = stbSplAppendWEnd(pPartWin, &index);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pMergeWin->pTsEnd = nodesCloneNode(nodesListGetNode(pPartWin->node.pTargets, index));
|
||||||
|
if (NULL == pMergeWin->pTsEnd) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartWindow);
|
code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartWindow);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
|
|
@ -52,6 +52,8 @@ TEST_F(PlanBasicTest, func) {
|
||||||
run("SELECT PERCENTILE(c1, 60) FROM t1");
|
run("SELECT PERCENTILE(c1, 60) FROM t1");
|
||||||
|
|
||||||
run("SELECT TOP(c1, 60) FROM t1");
|
run("SELECT TOP(c1, 60) FROM t1");
|
||||||
|
|
||||||
|
run("SELECT TOP(c1, 60) FROM st1");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanBasicTest, uniqueFunc) {
|
TEST_F(PlanBasicTest, uniqueFunc) {
|
||||||
|
@ -73,3 +75,11 @@ TEST_F(PlanBasicTest, tailFunc) {
|
||||||
|
|
||||||
run("SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10");
|
run("SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PlanBasicTest, interpFunc) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1");
|
||||||
|
|
||||||
|
run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)");
|
||||||
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ int32_t tdbTbcMoveToPrev(TBC *pTbc);
|
||||||
int32_t tdbTbcGet(TBC *pTbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen);
|
int32_t tdbTbcGet(TBC *pTbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen);
|
||||||
int32_t tdbTbcDelete(TBC *pTbc);
|
int32_t tdbTbcDelete(TBC *pTbc);
|
||||||
int32_t tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
int32_t tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||||
|
int32_t tdbTbcPrev(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||||
int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert);
|
int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert);
|
||||||
|
|
||||||
// TXN
|
// TXN
|
||||||
|
|
|
@ -1245,6 +1245,52 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||||
|
SCell *pCell;
|
||||||
|
SCellDecoder cd;
|
||||||
|
void *pKey, *pVal;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
// current cursor points to an invalid position
|
||||||
|
if (pBtc->idx < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
|
||||||
|
|
||||||
|
tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd);
|
||||||
|
|
||||||
|
pKey = tdbRealloc(*ppKey, cd.kLen);
|
||||||
|
if (pKey == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ppKey = pKey;
|
||||||
|
*kLen = cd.kLen;
|
||||||
|
memcpy(pKey, cd.pKey, cd.kLen);
|
||||||
|
|
||||||
|
if (ppVal) {
|
||||||
|
// TODO: vLen may be zero
|
||||||
|
pVal = tdbRealloc(*ppVal, cd.vLen);
|
||||||
|
if (pVal == NULL) {
|
||||||
|
tdbFree(pKey);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ppVal = pVal;
|
||||||
|
*vLen = cd.vLen;
|
||||||
|
memcpy(pVal, cd.pVal, cd.vLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = tdbBtcMoveToPrev(pBtc);
|
||||||
|
if (ret < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int tdbBtcMoveToNext(SBTC *pBtc) {
|
int tdbBtcMoveToNext(SBTC *pBtc) {
|
||||||
int nCells;
|
int nCells;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
|
@ -132,6 +132,10 @@ int tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||||
return tdbBtreeNext(&pTbc->btc, ppKey, kLen, ppVal, vLen);
|
return tdbBtreeNext(&pTbc->btc, ppKey, kLen, ppVal, vLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tdbTbcPrev(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||||
|
return tdbBtreePrev(&pTbc->btc, ppKey, kLen, ppVal, vLen);
|
||||||
|
}
|
||||||
|
|
||||||
int tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert) {
|
int tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert) {
|
||||||
return tdbBtcUpsert(&pTbc->btc, pKey, nKey, pData, nData, insert);
|
return tdbBtcUpsert(&pTbc->btc, pKey, nKey, pData, nData, insert);
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,7 @@ int tdbBtcMoveToLast(SBTC *pBtc);
|
||||||
int tdbBtcMoveToNext(SBTC *pBtc);
|
int tdbBtcMoveToNext(SBTC *pBtc);
|
||||||
int tdbBtcMoveToPrev(SBTC *pBtc);
|
int tdbBtcMoveToPrev(SBTC *pBtc);
|
||||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||||
|
int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||||
int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen);
|
int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen);
|
||||||
int tdbBtcDelete(SBTC *pBtc);
|
int tdbBtcDelete(SBTC *pBtc);
|
||||||
int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int nData, int insert);
|
int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int nData, int insert);
|
||||||
|
|
|
@ -159,7 +159,7 @@ sql alter table db.stb rename tag t1 tx
|
||||||
|
|
||||||
print ========== alter common
|
print ========== alter common
|
||||||
sql alter table db.stb comment 'abcde' ;
|
sql alter table db.stb comment 'abcde' ;
|
||||||
sql alter table db.stb ttl 10 ;
|
sql_error alter table db.stb ttl 10 ;
|
||||||
|
|
||||||
sql show db.stables;
|
sql show db.stables;
|
||||||
if $data[0][6] != abcde then
|
if $data[0][6] != abcde then
|
||||||
|
|
|
@ -231,9 +231,10 @@ sql use test3;
|
||||||
sql create table t1(ts timestamp, a int, b int , c int, d double);
|
sql create table t1(ts timestamp, a int, b int , c int, d double);
|
||||||
sql create stream streams3 trigger at_once watermark 1d into streamt3 as select _wstartts, min(b), a,c from t1 session(ts,10s);
|
sql create stream streams3 trigger at_once watermark 1d into streamt3 as select _wstartts, min(b), a,c from t1 session(ts,10s);
|
||||||
sql create stream streams4 trigger at_once watermark 1d into streamt4 as select _wstartts, max(b), a,c from t1 session(ts,10s);
|
sql create stream streams4 trigger at_once watermark 1d into streamt4 as select _wstartts, max(b), a,c from t1 session(ts,10s);
|
||||||
sql create stream streams5 trigger at_once watermark 1d into streamt5 as select _wstartts, top(b,3), a,c from t1 session(ts,10s);
|
# sql create stream streams5 trigger at_once watermark 1d into streamt5 as select _wstartts, top(b,3), a,c from t1 session(ts,10s);
|
||||||
sql create stream streams6 trigger at_once watermark 1d into streamt6 as select _wstartts, bottom(b,3), a,c from t1 session(ts,10s);
|
# sql create stream streams6 trigger at_once watermark 1d into streamt6 as select _wstartts, bottom(b,3), a,c from t1 session(ts,10s);
|
||||||
sql create stream streams7 trigger at_once watermark 1d into streamt7 as select _wstartts, spread(a), elapsed(ts), hyperloglog(a) from t1 session(ts,10s);
|
# sql create stream streams7 trigger at_once watermark 1d into streamt7 as select _wstartts, spread(a), elapsed(ts), hyperloglog(a) from t1 session(ts,10s);
|
||||||
|
sql create stream streams7 trigger at_once watermark 1d into streamt7 as select _wstartts, spread(a), hyperloglog(a) from t1 session(ts,10s);
|
||||||
sql create stream streams8 trigger at_once watermark 1d into streamt8 as select _wstartts, histogram(a,"user_input", "[1,3,5,7]", 1), histogram(a,"user_input", "[1,3,5,7]", 0) from t1 session(ts,10s);
|
sql create stream streams8 trigger at_once watermark 1d into streamt8 as select _wstartts, histogram(a,"user_input", "[1,3,5,7]", 1), histogram(a,"user_input", "[1,3,5,7]", 0) from t1 session(ts,10s);
|
||||||
sql insert into t1 values(1648791213001,1,1,1,1.0);
|
sql insert into t1 values(1648791213001,1,1,1,1.0);
|
||||||
sql insert into t1 values(1648791213002,2,3,2,3.4);
|
sql insert into t1 values(1648791213002,2,3,2,3.4);
|
||||||
|
@ -269,13 +270,13 @@ if $rows == 0 then
|
||||||
goto loop3
|
goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select * from streamt5;
|
#sql select * from streamt5;
|
||||||
if $rows == 0 then
|
if $rows == 0 then
|
||||||
print ======$rows
|
print ======$rows
|
||||||
goto loop3
|
# goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select * from streamt6;
|
# sql select * from streamt6;
|
||||||
if $rows == 0 then
|
if $rows == 0 then
|
||||||
print ======$rows
|
print ======$rows
|
||||||
goto loop3
|
goto loop3
|
||||||
|
|
|
@ -85,7 +85,7 @@ sql insert into t2 values(1648791243003,1,2,3,1.0) (1648791243002,1,2,3,1.0) (16
|
||||||
sleep 500
|
sleep 500
|
||||||
sql select * from streamt2;
|
sql select * from streamt2;
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
print ======$rows
|
print =====rows=$rows
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,206 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, db_test.stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import taos
|
||||||
|
from util.log import tdLog
|
||||||
|
from util.cases import tdCases
|
||||||
|
from util.sql import tdSql
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def caseDescription(self):
|
||||||
|
'''
|
||||||
|
ttl/comment test
|
||||||
|
'''
|
||||||
|
return
|
||||||
|
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tdSql.prepare()
|
||||||
|
|
||||||
|
tdSql.error("create table ttl_table1(ts timestamp, i int) ttl 1.1")
|
||||||
|
tdSql.error("create table ttl_table2(ts timestamp, i int) ttl 1e1")
|
||||||
|
tdSql.error("create table ttl_table3(ts timestamp, i int) ttl -1")
|
||||||
|
|
||||||
|
print("============== STEP 1 ===== test normal table")
|
||||||
|
|
||||||
|
tdSql.execute("create table normal_table1(ts timestamp, i int)")
|
||||||
|
tdSql.execute("create table normal_table2(ts timestamp, i int) comment '' ttl 3")
|
||||||
|
tdSql.execute("create table normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'")
|
||||||
|
|
||||||
|
tdSql.query("show tables like 'normal_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table1')
|
||||||
|
tdSql.checkData(0, 7, 0)
|
||||||
|
tdSql.checkData(0, 8, None)
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.query("show tables like 'normal_table2'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table2')
|
||||||
|
tdSql.checkData(0, 7, 3)
|
||||||
|
tdSql.checkData(0, 8, '')
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.query("show tables like 'normal_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table3')
|
||||||
|
tdSql.checkData(0, 7, 2147483647)
|
||||||
|
tdSql.checkData(0, 8, 'hello')
|
||||||
|
|
||||||
|
tdSql.execute("alter table normal_table1 comment 'nihao'")
|
||||||
|
tdSql.query("show tables like 'normal_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table1')
|
||||||
|
tdSql.checkData(0, 8, 'nihao')
|
||||||
|
|
||||||
|
tdSql.execute("alter table normal_table1 comment ''")
|
||||||
|
tdSql.query("show tables like 'normal_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table1')
|
||||||
|
tdSql.checkData(0, 8, '')
|
||||||
|
|
||||||
|
tdSql.execute("alter table normal_table2 comment 'fly'")
|
||||||
|
tdSql.query("show tables like 'normal_table2'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table2')
|
||||||
|
tdSql.checkData(0, 8, 'fly')
|
||||||
|
|
||||||
|
tdSql.execute("alter table normal_table3 comment 'fly'")
|
||||||
|
tdSql.query("show tables like 'normal_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table3')
|
||||||
|
tdSql.checkData(0, 8, 'fly')
|
||||||
|
|
||||||
|
tdSql.execute("alter table normal_table1 ttl 1")
|
||||||
|
tdSql.query("show tables like 'normal_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table1')
|
||||||
|
tdSql.checkData(0, 7, 1)
|
||||||
|
|
||||||
|
tdSql.execute("alter table normal_table3 ttl 0")
|
||||||
|
tdSql.query("show tables like 'normal_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'normal_table3')
|
||||||
|
tdSql.checkData(0, 7, 0)
|
||||||
|
|
||||||
|
|
||||||
|
print("============== STEP 2 ===== test super table")
|
||||||
|
|
||||||
|
tdSql.execute("create table super_table1(ts timestamp, i int) tags(t int)")
|
||||||
|
tdSql.execute("create table super_table2(ts timestamp, i int) tags(t int) comment ''")
|
||||||
|
tdSql.execute("create table super_table3(ts timestamp, i int) tags(t int) comment 'super'")
|
||||||
|
|
||||||
|
tdSql.query("show stables like 'super_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'super_table1')
|
||||||
|
tdSql.checkData(0, 6, None)
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.query("show stables like 'super_table2'")
|
||||||
|
tdSql.checkData(0, 0, 'super_table2')
|
||||||
|
tdSql.checkData(0, 6, '')
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.query("show stables like 'super_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'super_table3')
|
||||||
|
tdSql.checkData(0, 6, 'super')
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.execute("alter table super_table1 comment 'nihao'")
|
||||||
|
tdSql.query("show stables like 'super_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'super_table1')
|
||||||
|
tdSql.checkData(0, 6, 'nihao')
|
||||||
|
|
||||||
|
tdSql.execute("alter table super_table1 comment ''")
|
||||||
|
tdSql.query("show stables like 'super_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'super_table1')
|
||||||
|
tdSql.checkData(0, 6, '')
|
||||||
|
|
||||||
|
tdSql.execute("alter table super_table2 comment 'fly'")
|
||||||
|
tdSql.query("show stables like 'super_table2'")
|
||||||
|
tdSql.checkData(0, 0, 'super_table2')
|
||||||
|
tdSql.checkData(0, 6, 'fly')
|
||||||
|
|
||||||
|
tdSql.execute("alter table super_table3 comment 'tdengine'")
|
||||||
|
tdSql.query("show stables like 'super_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'super_table3')
|
||||||
|
tdSql.checkData(0, 6, 'tdengine')
|
||||||
|
|
||||||
|
print("============== STEP 3 ===== test child table")
|
||||||
|
|
||||||
|
tdSql.execute("create table child_table1 using super_table1 tags(1) ttl 10")
|
||||||
|
tdSql.execute("create table child_table2 using super_table1 tags(1) comment ''")
|
||||||
|
tdSql.execute("create table child_table3 using super_table1 tags(1) comment 'child'")
|
||||||
|
tdSql.execute("insert into child_table4 using super_table1 tags(1) values(now, 1)")
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.query("show tables like 'child_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table1')
|
||||||
|
tdSql.checkData(0, 7, 10)
|
||||||
|
tdSql.checkData(0, 8, None)
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.query("show tables like 'child_table2'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table2')
|
||||||
|
tdSql.checkData(0, 7, 0)
|
||||||
|
tdSql.checkData(0, 8, '')
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.query("show tables like 'child_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table3')
|
||||||
|
tdSql.checkData(0, 8, 'child')
|
||||||
|
|
||||||
|
tdSql.query("show tables like 'child_table4'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table4')
|
||||||
|
tdSql.checkData(0, 7, 0)
|
||||||
|
tdSql.checkData(0, 8, None)
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.execute("alter table child_table1 comment 'nihao'")
|
||||||
|
tdSql.query("show tables like 'child_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table1')
|
||||||
|
tdSql.checkData(0, 8, 'nihao')
|
||||||
|
|
||||||
|
tdSql.execute("alter table child_table1 comment ''")
|
||||||
|
tdSql.query("show tables like 'child_table1'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table1')
|
||||||
|
tdSql.checkData(0, 8, '')
|
||||||
|
|
||||||
|
tdSql.execute("alter table child_table2 comment 'fly'")
|
||||||
|
tdSql.query("show tables like 'child_table2'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table2')
|
||||||
|
tdSql.checkData(0, 8, 'fly')
|
||||||
|
|
||||||
|
tdSql.execute("alter table child_table3 comment 'tdengine'")
|
||||||
|
tdSql.query("show tables like 'child_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table3')
|
||||||
|
tdSql.checkData(0, 8, 'tdengine')
|
||||||
|
|
||||||
|
|
||||||
|
tdSql.execute("alter table child_table4 comment 'tdengine'")
|
||||||
|
tdSql.query("show tables like 'child_table4'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table4')
|
||||||
|
tdSql.checkData(0, 8, 'tdengine')
|
||||||
|
|
||||||
|
tdSql.execute("alter table child_table4 ttl 9")
|
||||||
|
tdSql.query("show tables like 'child_table4'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table4')
|
||||||
|
tdSql.checkData(0, 7, 9)
|
||||||
|
|
||||||
|
tdSql.execute("alter table child_table3 ttl 9")
|
||||||
|
tdSql.query("show tables like 'child_table3'")
|
||||||
|
tdSql.checkData(0, 0, 'child_table3')
|
||||||
|
tdSql.checkData(0, 7, 9)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
||||||
|
|
|
@ -98,6 +98,7 @@ python3 ./test.py -f 2-query/stateduration.py
|
||||||
python3 ./test.py -f 2-query/function_stateduration.py
|
python3 ./test.py -f 2-query/function_stateduration.py
|
||||||
python3 ./test.py -f 2-query/statecount.py
|
python3 ./test.py -f 2-query/statecount.py
|
||||||
python3 ./test.py -f 2-query/tail.py
|
python3 ./test.py -f 2-query/tail.py
|
||||||
|
python3 ./test.py -f 2-query/ttl_comment.py
|
||||||
python3 ./test.py -f 2-query/distribute_agg_count.py
|
python3 ./test.py -f 2-query/distribute_agg_count.py
|
||||||
python3 ./test.py -f 2-query/distribute_agg_max.py
|
python3 ./test.py -f 2-query/distribute_agg_max.py
|
||||||
python3 ./test.py -f 2-query/distribute_agg_min.py
|
python3 ./test.py -f 2-query/distribute_agg_min.py
|
||||||
|
|
Loading…
Reference in New Issue