Merge branch '3.0' into feature/TD-13066-3.0
This commit is contained in:
commit
71b723e8dc
|
@ -17,6 +17,7 @@
|
|||
#define _TD_INDEX_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "tarray.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -41,11 +42,12 @@ typedef enum {
|
|||
UPDATE_VALUE, // update index column value
|
||||
ADD_INDEX, // add index on specify column
|
||||
DROP_INDEX, // drop existed index
|
||||
DROP_SATBLE // drop stable
|
||||
DROP_SATBLE, // drop stable
|
||||
DEFAULT // query
|
||||
} SIndexOperOnColumn;
|
||||
|
||||
typedef enum { MUST = 0, SHOULD = 1, NOT = 2 } EIndexOperatorType;
|
||||
typedef enum { QUERY_TERM = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2, QUERY_REGEX = 3, QUERY_RANGE = 4 } EIndexQueryType;
|
||||
typedef enum { MUST = 0, SHOULD, NOT } EIndexOperatorType;
|
||||
typedef enum { QUERY_TERM = 0, QUERY_PREFIX, QUERY_SUFFIX, QUERY_REGEX, QUERY_RANGE } EIndexQueryType;
|
||||
|
||||
/*
|
||||
* create multi query
|
||||
|
@ -166,8 +168,8 @@ void indexOptsDestroy(SIndexOpts* opts);
|
|||
* @param:
|
||||
*/
|
||||
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t colType, const char* colName,
|
||||
int32_t nColName, const char* colVal, int32_t nColVal);
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, int8_t qType, uint8_t colType,
|
||||
const char* colName, int32_t nColName, const char* colVal, int32_t nColVal);
|
||||
void indexTermDestroy(SIndexTerm* p);
|
||||
|
||||
/*
|
||||
|
|
|
@ -264,7 +264,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TRANS_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D0)
|
||||
#define TSDB_CODE_MND_TRANS_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D1)
|
||||
#define TSDB_CODE_MND_TRANS_INVALID_STAGE TAOS_DEF_ERROR_CODE(0, 0x03D2)
|
||||
#define TSDB_CODE_MND_TRANS_CANT_PARALLEL TAOS_DEF_ERROR_CODE(0, 0x03D4)
|
||||
#define TSDB_CODE_MND_TRANS_CAN_NOT_PARALLEL TAOS_DEF_ERROR_CODE(0, 0x03D4)
|
||||
|
||||
// mnode-mq
|
||||
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
|
||||
|
|
|
@ -57,11 +57,11 @@ typedef enum {
|
|||
TRN_STAGE_PREPARE = 0,
|
||||
TRN_STAGE_REDO_LOG = 1,
|
||||
TRN_STAGE_REDO_ACTION = 2,
|
||||
TRN_STAGE_COMMIT = 3,
|
||||
TRN_STAGE_COMMIT_LOG = 4,
|
||||
TRN_STAGE_UNDO_ACTION = 5,
|
||||
TRN_STAGE_UNDO_LOG = 6,
|
||||
TRN_STAGE_ROLLBACK = 7,
|
||||
TRN_STAGE_ROLLBACK = 3,
|
||||
TRN_STAGE_UNDO_ACTION = 4,
|
||||
TRN_STAGE_UNDO_LOG = 5,
|
||||
TRN_STAGE_COMMIT = 6,
|
||||
TRN_STAGE_COMMIT_LOG = 7,
|
||||
TRN_STAGE_FINISHED = 8
|
||||
} ETrnStage;
|
||||
|
||||
|
@ -72,6 +72,7 @@ typedef enum {
|
|||
TRN_TYPE_DROP_USER = 1003,
|
||||
TRN_TYPE_CREATE_FUNC = 1004,
|
||||
TRN_TYPE_DROP_FUNC = 1005,
|
||||
|
||||
TRN_TYPE_CREATE_SNODE = 1006,
|
||||
TRN_TYPE_DROP_SNODE = 1007,
|
||||
TRN_TYPE_CREATE_QNODE = 1008,
|
||||
|
@ -91,10 +92,12 @@ typedef enum {
|
|||
TRN_TYPE_CONSUMER_LOST = 1022,
|
||||
TRN_TYPE_CONSUMER_RECOVER = 1023,
|
||||
TRN_TYPE_BASIC_SCOPE_END,
|
||||
|
||||
TRN_TYPE_GLOBAL_SCOPE = 2000,
|
||||
TRN_TYPE_CREATE_DNODE = 2001,
|
||||
TRN_TYPE_DROP_DNODE = 2002,
|
||||
TRN_TYPE_GLOBAL_SCOPE_END,
|
||||
|
||||
TRN_TYPE_DB_SCOPE = 3000,
|
||||
TRN_TYPE_CREATE_DB = 3001,
|
||||
TRN_TYPE_ALTER_DB = 3002,
|
||||
|
@ -102,6 +105,7 @@ typedef enum {
|
|||
TRN_TYPE_SPLIT_VGROUP = 3004,
|
||||
TRN_TYPE_MERGE_VGROUP = 3015,
|
||||
TRN_TYPE_DB_SCOPE_END,
|
||||
|
||||
TRN_TYPE_STB_SCOPE = 4000,
|
||||
TRN_TYPE_CREATE_STB = 4001,
|
||||
TRN_TYPE_ALTER_STB = 4002,
|
||||
|
@ -131,7 +135,7 @@ typedef struct {
|
|||
int32_t id;
|
||||
ETrnStage stage;
|
||||
ETrnPolicy policy;
|
||||
ETrnType transType;
|
||||
ETrnType type;
|
||||
int32_t code;
|
||||
int32_t failedTimes;
|
||||
void* rpcHandle;
|
||||
|
|
|
@ -24,9 +24,12 @@ extern "C" {
|
|||
|
||||
int32_t mndInitUser(SMnode *pMnode);
|
||||
void mndCleanupUser(SMnode *pMnode);
|
||||
SUserObj *mndAcquireUser(SMnode *pMnode, char *userName);
|
||||
SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName);
|
||||
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
||||
|
||||
// for trans test
|
||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include "mndSync.h"
|
||||
#include "mndUser.h"
|
||||
|
||||
#define MND_TRANS_VER_NUMBER 1
|
||||
#define MND_TRANS_ARRAY_SIZE 8
|
||||
#define MND_TRANS_RESERVE_SIZE 64
|
||||
#define TRANS_VER_NUMBER 1
|
||||
#define TRANS_ARRAY_SIZE 8
|
||||
#define TRANS_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
|
||||
|
@ -63,13 +63,15 @@ static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
|||
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitTrans(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_TRANS,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
.encodeFp = (SdbEncodeFp)mndTransActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndTransActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndTransActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndTransActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndTransActionDelete};
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_TRANS,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
.encodeFp = (SdbEncodeFp)mndTransActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndTransActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndTransActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndTransActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndTransActionDelete,
|
||||
};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TRANS_TIMER, mndProcessTransReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_KILL_TRANS, mndProcessKillTransReq);
|
||||
|
@ -84,7 +86,7 @@ void mndCleanupTrans(SMnode *pMnode) {}
|
|||
static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t rawDataLen = sizeof(STrans) + MND_TRANS_RESERVE_SIZE;
|
||||
int32_t rawDataLen = sizeof(STrans) + TRANS_RESERVE_SIZE;
|
||||
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
||||
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
||||
int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs);
|
||||
|
@ -116,78 +118,89 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
rawDataLen += (sizeof(STransAction) + pAction->contLen);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, MND_TRANS_VER_NUMBER, rawDataLen);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TRANS_VER_NUMBER, rawDataLen);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->id, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pTrans->policy, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pTrans->stage, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pTrans->transType, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pTrans->createdTime, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pTrans->dbUid, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_DB_FNAME_LEN, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoLogNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoLogNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, commitLogNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoActionNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoActionNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->id, _OVER)
|
||||
|
||||
ETrnStage stage = pTrans->stage;
|
||||
if (stage == TRN_STAGE_REDO_LOG || stage == TRN_STAGE_REDO_ACTION) {
|
||||
stage = TRN_STAGE_PREPARE;
|
||||
} else if (stage == TRN_STAGE_UNDO_ACTION || stage == TRN_STAGE_UNDO_LOG) {
|
||||
stage = TRN_STAGE_ROLLBACK;
|
||||
} else if (stage == TRN_STAGE_COMMIT_LOG || stage == TRN_STAGE_FINISHED) {
|
||||
stage = TRN_STAGE_COMMIT;
|
||||
} else {
|
||||
}
|
||||
|
||||
SDB_SET_INT16(pRaw, dataPos, stage, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pTrans->policy, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pTrans->type, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pTrans->createdTime, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pTrans->dbUid, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_DB_FNAME_LEN, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoLogNum, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoLogNum, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, commitLogNum, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoActionNum, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoActionNum, _OVER)
|
||||
|
||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->redoLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, _OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->undoLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, _OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->commitLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, _OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, _OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen, _OVER)
|
||||
}
|
||||
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->startFunc, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->stopFunc, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->paramLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->startFunc, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->stopFunc, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->paramLen, _OVER)
|
||||
if (pTrans->param != NULL) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, _OVER)
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, TRANS_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
TRANS_ENCODE_OVER:
|
||||
_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("trans:%d, failed to encode to raw:%p len:%d since %s", pTrans->id, pRaw, dataPos, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
|
@ -214,38 +227,38 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
int32_t dataPos = 0;
|
||||
STransAction action = {0};
|
||||
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TRANS_DECODE_OVER;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != MND_TRANS_VER_NUMBER) {
|
||||
if (sver != TRANS_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto TRANS_DECODE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pRow = sdbAllocRow(sizeof(STrans));
|
||||
if (pRow == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pRow == NULL) goto _OVER;
|
||||
|
||||
pTrans = sdbGetRowObj(pRow);
|
||||
if (pTrans == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->id, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->id, _OVER)
|
||||
|
||||
int16_t type = 0;
|
||||
int16_t policy = 0;
|
||||
int16_t stage = 0;
|
||||
SDB_GET_INT16(pRaw, dataPos, &policy, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &stage, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &type, TRANS_DECODE_OVER)
|
||||
pTrans->policy = policy;
|
||||
int16_t policy = 0;
|
||||
int16_t type = 0;
|
||||
SDB_GET_INT16(pRaw, dataPos, &stage, _OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &policy, _OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &type, _OVER)
|
||||
pTrans->stage = stage;
|
||||
pTrans->transType = type;
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTrans->createdTime, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTrans->dbUid, TRANS_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_DB_FNAME_LEN, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &redoLogNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &undoLogNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &commitLogNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &redoActionNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &undoActionNum, TRANS_DECODE_OVER)
|
||||
pTrans->policy = policy;
|
||||
pTrans->type = type;
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTrans->createdTime, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTrans->dbUid, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_DB_FNAME_LEN, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &redoLogNum, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &undoLogNum, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &commitLogNum, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &redoActionNum, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &undoActionNum, _OVER)
|
||||
|
||||
pTrans->redoLogs = taosArrayInit(redoLogNum, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(undoLogNum, sizeof(void *));
|
||||
|
@ -253,79 +266,79 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
pTrans->redoActions = taosArrayInit(redoActionNum, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(undoActionNum, sizeof(STransAction));
|
||||
|
||||
if (pTrans->redoLogs == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->undoLogs == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->commitLogs == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->redoActions == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->undoActions == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->redoLogs == NULL) goto _OVER;
|
||||
if (pTrans->undoLogs == NULL) goto _OVER;
|
||||
if (pTrans->commitLogs == NULL) goto _OVER;
|
||||
if (pTrans->redoActions == NULL) goto _OVER;
|
||||
if (pTrans->undoActions == NULL) goto _OVER;
|
||||
|
||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
|
||||
pData = taosMemoryMalloc(dataLen);
|
||||
if (pData == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pData == NULL) goto _OVER;
|
||||
mTrace("raw:%p, is created", pData);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->redoLogs, &pData) == NULL) goto TRANS_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, _OVER);
|
||||
if (taosArrayPush(pTrans->redoLogs, &pData) == NULL) goto _OVER;
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
|
||||
pData = taosMemoryMalloc(dataLen);
|
||||
if (pData == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pData == NULL) goto _OVER;
|
||||
mTrace("raw:%p, is created", pData);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->undoLogs, &pData) == NULL) goto TRANS_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, _OVER);
|
||||
if (taosArrayPush(pTrans->undoLogs, &pData) == NULL) goto _OVER;
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
|
||||
pData = taosMemoryMalloc(dataLen);
|
||||
if (pData == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pData == NULL) goto _OVER;
|
||||
mTrace("raw:%p, is created", pData);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->commitLogs, &pData) == NULL) goto TRANS_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, _OVER);
|
||||
if (taosArrayPush(pTrans->commitLogs, &pData) == NULL) goto _OVER;
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
|
||||
action.pCont = taosMemoryMalloc(action.contLen);
|
||||
if (action.pCont == NULL) goto TRANS_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto TRANS_DECODE_OVER;
|
||||
if (action.pCont == NULL) goto _OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
|
||||
if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto _OVER;
|
||||
action.pCont = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
|
||||
action.pCont = taosMemoryMalloc(action.contLen);
|
||||
if (action.pCont == NULL) goto TRANS_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto TRANS_DECODE_OVER;
|
||||
if (action.pCont == NULL) goto _OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
|
||||
if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto _OVER;
|
||||
action.pCont = NULL;
|
||||
}
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->startFunc, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->stopFunc, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->paramLen, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->startFunc, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->stopFunc, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->paramLen, _OVER)
|
||||
if (pTrans->paramLen != 0) {
|
||||
pTrans->param = taosMemoryMalloc(pTrans->paramLen);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, TRANS_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, _OVER);
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
TRANS_DECODE_OVER:
|
||||
_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr());
|
||||
mndTransDropData(pTrans);
|
||||
|
@ -400,6 +413,16 @@ static const char *mndTransType(ETrnType type) {
|
|||
return "subscribe";
|
||||
case TRN_TYPE_REBALANCE:
|
||||
return "rebalance";
|
||||
case TRN_TYPE_COMMIT_OFFSET:
|
||||
return "commit-offset";
|
||||
case TRN_TYPE_CREATE_STREAM:
|
||||
return "create-stream";
|
||||
case TRN_TYPE_DROP_STREAM:
|
||||
return "drop-stream";
|
||||
case TRN_TYPE_CONSUMER_LOST:
|
||||
return "consumer-lost";
|
||||
case TRN_TYPE_CONSUMER_RECOVER:
|
||||
return "consumer-recover";
|
||||
case TRN_TYPE_CREATE_DNODE:
|
||||
return "create-qnode";
|
||||
case TRN_TYPE_DROP_DNODE:
|
||||
|
@ -453,7 +476,6 @@ static TransCbFp mndTransGetCbFp(ETrnFuncType ftype) {
|
|||
}
|
||||
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
||||
// pTrans->stage = TRN_STAGE_PREPARE;
|
||||
mTrace("trans:%d, perform insert action, row:%p stage:%s", pTrans->id, pTrans, mndTransStr(pTrans->stage));
|
||||
|
||||
if (pTrans->startFunc > 0) {
|
||||
|
@ -516,8 +538,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
|||
}
|
||||
|
||||
static STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &transId);
|
||||
STrans *pTrans = sdbAcquire(pMnode->pSdb, SDB_TRANS, &transId);
|
||||
if (pTrans == NULL) {
|
||||
terrno = TSDB_CODE_MND_TRANS_NOT_EXIST;
|
||||
}
|
||||
|
@ -540,16 +561,16 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnType type, const S
|
|||
pTrans->id = sdbGetMaxId(pMnode->pSdb, SDB_TRANS);
|
||||
pTrans->stage = TRN_STAGE_PREPARE;
|
||||
pTrans->policy = policy;
|
||||
pTrans->transType = type;
|
||||
pTrans->type = type;
|
||||
pTrans->createdTime = taosGetTimestampMs();
|
||||
pTrans->rpcHandle = pReq->handle;
|
||||
pTrans->rpcAHandle = pReq->ahandle;
|
||||
pTrans->rpcRefId = pReq->refId;
|
||||
pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->redoLogs = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
|
@ -558,7 +579,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnType type, const S
|
|||
return NULL;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, local var is created, data:%p", pTrans->id, pTrans);
|
||||
mDebug("trans:%d, local object is created, data:%p", pTrans->id, pTrans);
|
||||
return pTrans;
|
||||
}
|
||||
|
||||
|
@ -585,14 +606,14 @@ static void mndTransDropActions(SArray *pArray) {
|
|||
void mndTransDrop(STrans *pTrans) {
|
||||
if (pTrans != NULL) {
|
||||
mndTransDropData(pTrans);
|
||||
mDebug("trans:%d, local var is freed, data:%p", pTrans->id, pTrans);
|
||||
mDebug("trans:%d, local object is freed, data:%p", pTrans->id, pTrans);
|
||||
taosMemoryFreeClear(pTrans);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw) {
|
||||
if (pArray == NULL || pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -674,27 +695,27 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
static bool mndIsBasicTrans(STrans *pTrans) {
|
||||
return pTrans->stage > TRN_TYPE_BASIC_SCOPE && pTrans->stage < TRN_TYPE_BASIC_SCOPE_END;
|
||||
return pTrans->type > TRN_TYPE_BASIC_SCOPE && pTrans->type < TRN_TYPE_BASIC_SCOPE_END;
|
||||
}
|
||||
|
||||
static bool mndIsGlobalTrans(STrans *pTrans) {
|
||||
return pTrans->stage > TRN_TYPE_GLOBAL_SCOPE && pTrans->stage < TRN_TYPE_GLOBAL_SCOPE_END;
|
||||
return pTrans->type > TRN_TYPE_GLOBAL_SCOPE && pTrans->type < TRN_TYPE_GLOBAL_SCOPE_END;
|
||||
}
|
||||
|
||||
static bool mndIsDbTrans(STrans *pTrans) {
|
||||
return pTrans->stage > TRN_TYPE_DB_SCOPE && pTrans->stage < TRN_TYPE_DB_SCOPE_END;
|
||||
return pTrans->type > TRN_TYPE_DB_SCOPE && pTrans->type < TRN_TYPE_DB_SCOPE_END;
|
||||
}
|
||||
|
||||
static bool mndIsStbTrans(STrans *pTrans) {
|
||||
return pTrans->stage > TRN_TYPE_STB_SCOPE && pTrans->stage < TRN_TYPE_STB_SCOPE_END;
|
||||
return pTrans->type > TRN_TYPE_STB_SCOPE && pTrans->type < TRN_TYPE_STB_SCOPE_END;
|
||||
}
|
||||
|
||||
static int32_t mndCheckTransCanBeStartedInParallel(SMnode *pMnode, STrans *pNewTrans) {
|
||||
if (mndIsBasicTrans(pNewTrans)) return 0;
|
||||
|
||||
static bool mndCheckTransCanParallel(SMnode *pMnode, STrans *pNewTrans) {
|
||||
STrans *pTrans = NULL;
|
||||
void *pIter = NULL;
|
||||
int32_t code = 0;
|
||||
bool canParallel = true;
|
||||
|
||||
if (mndIsBasicTrans(pNewTrans)) return canParallel;
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans);
|
||||
|
@ -703,42 +724,35 @@ static int32_t mndCheckTransCanBeStartedInParallel(SMnode *pMnode, STrans *pNewT
|
|||
if (mndIsGlobalTrans(pNewTrans)) {
|
||||
if (mndIsDbTrans(pTrans) || mndIsStbTrans(pTrans)) {
|
||||
mError("trans:%d, can't execute since trans:%d in progress db:%s", pNewTrans->id, pTrans->id, pTrans->dbname);
|
||||
code = -1;
|
||||
break;
|
||||
canParallel = false;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
if (mndIsDbTrans(pNewTrans)) {
|
||||
if (mndIsBasicTrans(pTrans)) continue;
|
||||
else if (mndIsDbTrans(pNewTrans)) {
|
||||
if (mndIsGlobalTrans(pTrans)) {
|
||||
mError("trans:%d, can't execute since trans:%d in progress", pNewTrans->id, pTrans->id);
|
||||
code = -1;
|
||||
break;
|
||||
}
|
||||
if (mndIsDbTrans(pTrans) || mndIsStbTrans(pTrans)) {
|
||||
canParallel = false;
|
||||
} else if (mndIsDbTrans(pTrans) || mndIsStbTrans(pTrans)) {
|
||||
if (pNewTrans->dbUid == pTrans->dbUid) {
|
||||
mError("trans:%d, can't execute since trans:%d in progress db:%s", pNewTrans->id, pTrans->id, pTrans->dbname);
|
||||
code = -1;
|
||||
break;
|
||||
canParallel = false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
if (mndIsStbTrans(pNewTrans)) {
|
||||
if (mndIsBasicTrans(pTrans)) continue;
|
||||
else if (mndIsStbTrans(pNewTrans)) {
|
||||
if (mndIsGlobalTrans(pTrans)) {
|
||||
mError("trans:%d, can't execute since trans:%d in progress", pNewTrans->id, pTrans->id);
|
||||
code = -1;
|
||||
break;
|
||||
}
|
||||
if (mndIsDbTrans(pTrans)) {
|
||||
canParallel = false;
|
||||
} else if (mndIsDbTrans(pTrans)) {
|
||||
if (pNewTrans->dbUid == pTrans->dbUid) {
|
||||
mError("trans:%d, can't execute since trans:%d in progress db:%s", pNewTrans->id, pTrans->id, pTrans->dbname);
|
||||
code = -1;
|
||||
break;
|
||||
canParallel = false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (mndIsStbTrans(pTrans)) continue;
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pTrans);
|
||||
|
@ -746,12 +760,12 @@ static int32_t mndCheckTransCanBeStartedInParallel(SMnode *pMnode, STrans *pNewT
|
|||
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pTrans);
|
||||
return code;
|
||||
return canParallel;
|
||||
}
|
||||
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
||||
if (mndCheckTransCanBeStartedInParallel(pMnode, pTrans) != 0) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CANT_PARALLEL;
|
||||
if (!mndCheckTransCanParallel(pMnode, pTrans)) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CAN_NOT_PARALLEL;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -833,12 +847,14 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
|
||||
mDebug("trans:%d, send rsp, code:0x%04x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage,
|
||||
pTrans->rpcAHandle);
|
||||
SRpcMsg rspMsg = {.handle = pTrans->rpcHandle,
|
||||
.code = pTrans->code,
|
||||
.ahandle = pTrans->rpcAHandle,
|
||||
.refId = pTrans->rpcRefId,
|
||||
.pCont = rpcCont,
|
||||
.contLen = pTrans->rpcRspLen};
|
||||
SRpcMsg rspMsg = {
|
||||
.handle = pTrans->rpcHandle,
|
||||
.ahandle = pTrans->rpcAHandle,
|
||||
.refId = pTrans->rpcRefId,
|
||||
.code = pTrans->code,
|
||||
.pCont = rpcCont,
|
||||
.contLen = pTrans->rpcRspLen,
|
||||
};
|
||||
tmsgSendRsp(&rspMsg);
|
||||
pTrans->rpcHandle = NULL;
|
||||
pTrans->rpcRsp = NULL;
|
||||
|
@ -855,7 +871,7 @@ void mndTransProcessRsp(SNodeMsg *pRsp) {
|
|||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans == NULL) {
|
||||
mError("trans:%d, failed to get transId from vnode rsp since %s", transId, terrstr());
|
||||
goto HANDLE_ACTION_RSP_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SArray *pArray = NULL;
|
||||
|
@ -865,18 +881,18 @@ void mndTransProcessRsp(SNodeMsg *pRsp) {
|
|||
pArray = pTrans->undoActions;
|
||||
} else {
|
||||
mError("trans:%d, invalid trans stage:%d while recv action rsp", pTrans->id, pTrans->stage);
|
||||
goto HANDLE_ACTION_RSP_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pArray == NULL) {
|
||||
mError("trans:%d, invalid trans stage:%d", transId, pTrans->stage);
|
||||
goto HANDLE_ACTION_RSP_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t actionNum = taosArrayGetSize(pTrans->redoActions);
|
||||
if (action < 0 || action >= actionNum) {
|
||||
mError("trans:%d, invalid action:%d", transId, action);
|
||||
goto HANDLE_ACTION_RSP_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
STransAction *pAction = taosArrayGet(pArray, action);
|
||||
|
@ -892,7 +908,7 @@ void mndTransProcessRsp(SNodeMsg *pRsp) {
|
|||
pAction->acceptableCode);
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
|
||||
HANDLE_ACTION_RSP_OVER:
|
||||
_OVER:
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
}
|
||||
|
||||
|
@ -1281,19 +1297,19 @@ static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
|
|||
|
||||
if (tDeserializeSKillTransReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &killReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto KILL_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, start to kill", killReq.transId);
|
||||
|
||||
pUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pUser == NULL) {
|
||||
goto KILL_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!pUser->superUser) {
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
goto KILL_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pTrans = mndAcquireTrans(pMnode, killReq.transId);
|
||||
|
@ -1305,7 +1321,7 @@ static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
|
|||
|
||||
code = mndKillTrans(pMnode, pTrans);
|
||||
|
||||
KILL_OVER:
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to kill since %s", killReq.transId, terrstr());
|
||||
return -1;
|
||||
|
@ -1360,10 +1376,10 @@ static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)dbname, false);
|
||||
|
||||
char transType[TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndTransType(pTrans->transType), pShow->pMeta->pSchemas[cols].bytes);
|
||||
char type[TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndTransType(pTrans->type), pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)transType, false);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)type, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pTrans->lastExecTime, false);
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#define USER_RESERVE_SIZE 64
|
||||
|
||||
static int32_t mndCreateDefaultUsers(SMnode *pMnode);
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser);
|
||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser);
|
||||
|
@ -90,7 +89,7 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
||||
|
@ -238,7 +237,7 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SUserObj *mndAcquireUser(SMnode *pMnode, char *userName) {
|
||||
SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SUserObj *pUser = sdbAcquire(pSdb, SDB_USER, userName);
|
||||
if (pUser == NULL) {
|
||||
|
|
|
@ -1,11 +1,37 @@
|
|||
aux_source_directory(. MNODE_TRANS_TEST_SRC)
|
||||
add_executable(transTest ${MNODE_TRANS_TEST_SRC})
|
||||
add_executable(transTest1 "")
|
||||
target_sources(transTest1
|
||||
PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/trans1.cpp"
|
||||
)
|
||||
target_link_libraries(
|
||||
transTest
|
||||
transTest1
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME transTest
|
||||
COMMAND transTest
|
||||
target_include_directories(
|
||||
transTest1
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/dnode/mnode"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
)
|
||||
add_test(
|
||||
NAME transTest1
|
||||
COMMAND transTest1
|
||||
)
|
||||
|
||||
add_executable(transTest2 "")
|
||||
target_sources(transTest2
|
||||
PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/trans2.cpp"
|
||||
)
|
||||
target_link_libraries(
|
||||
transTest2
|
||||
PUBLIC dnode mnode gtest_main
|
||||
)
|
||||
target_include_directories(
|
||||
transTest2
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/dnode/mnode"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
)
|
||||
add_test(
|
||||
NAME transTest2
|
||||
COMMAND transTest2
|
||||
)
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestTrans : public ::testing::Test {
|
||||
class MndTestTrans1 : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_trans", 9013);
|
||||
test.Init("/tmp/mnode_test_trans1", 9013);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9013";
|
||||
server2.Start("/tmp/mnode_test_trans2", fqdn, 9020, firstEp);
|
||||
|
@ -26,7 +26,7 @@ class MndTestTrans : public ::testing::Test {
|
|||
}
|
||||
|
||||
static void KillThenRestartServer() {
|
||||
char file[PATH_MAX] = "/tmp/mnode_test_trans/mnode/data/sdb.data";
|
||||
char file[PATH_MAX] = "/tmp/mnode_test_trans1/mnode/data/sdb.data";
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
int32_t size = 3 * 1024 * 1024;
|
||||
void* buffer = taosMemoryMalloc(size);
|
||||
|
@ -60,10 +60,10 @@ class MndTestTrans : public ::testing::Test {
|
|||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase MndTestTrans::test;
|
||||
TestServer MndTestTrans::server2;
|
||||
Testbase MndTestTrans1::test;
|
||||
TestServer MndTestTrans1::server2;
|
||||
|
||||
TEST_F(MndTestTrans, 00_Create_User_Crash) {
|
||||
TEST_F(MndTestTrans1, 00_Create_User_Crash) {
|
||||
{
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_TRANS, "trans", "");
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
|
@ -83,7 +83,7 @@ TEST_F(MndTestTrans, 00_Create_User_Crash) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestTrans, 01_Create_User_Crash) {
|
||||
TEST_F(MndTestTrans1, 01_Create_User_Crash) {
|
||||
{
|
||||
SCreateUserReq createReq = {0};
|
||||
strcpy(createReq.user, "u1");
|
||||
|
@ -107,7 +107,7 @@ TEST_F(MndTestTrans, 01_Create_User_Crash) {
|
|||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
TEST_F(MndTestTrans, 02_Create_Qnode1_Crash) {
|
||||
TEST_F(MndTestTrans1, 02_Create_Qnode1_Crash) {
|
||||
{
|
||||
SMCreateQnodeReq createReq = {0};
|
||||
createReq.dnodeId = 1;
|
||||
|
@ -142,7 +142,7 @@ TEST_F(MndTestTrans, 02_Create_Qnode1_Crash) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestTrans, 03_Create_Qnode2_Crash) {
|
||||
TEST_F(MndTestTrans1, 03_Create_Qnode2_Crash) {
|
||||
{
|
||||
SCreateDnodeReq createReq = {0};
|
||||
strcpy(createReq.fqdn, "localhost");
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* @file trans.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module trans tests
|
||||
* @version 1.0
|
||||
* @date 2022-05-02
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "tcache.h"
|
||||
|
||||
void reportStartup(SMgmtWrapper *pWrapper, const char *name, const char *desc) {}
|
||||
|
||||
class MndTestTrans2 : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
dDebugFlag = 143;
|
||||
vDebugFlag = 0;
|
||||
mDebugFlag = 207;
|
||||
cDebugFlag = 0;
|
||||
jniDebugFlag = 0;
|
||||
tmrDebugFlag = 135;
|
||||
uDebugFlag = 135;
|
||||
rpcDebugFlag = 143;
|
||||
qDebugFlag = 0;
|
||||
wDebugFlag = 0;
|
||||
sDebugFlag = 0;
|
||||
tsdbDebugFlag = 0;
|
||||
tsLogEmbedded = 1;
|
||||
tsAsyncLog = 0;
|
||||
|
||||
const char *logpath = "/tmp/td";
|
||||
taosRemoveDir(logpath);
|
||||
taosMkDir(logpath);
|
||||
tstrncpy(tsLogDir, logpath, PATH_MAX);
|
||||
if (taosInitLog("taosdlog", 1) != 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
|
||||
walInit();
|
||||
|
||||
static SMsgCb msgCb = {0};
|
||||
msgCb.reportStartupFp = reportStartup;
|
||||
msgCb.pWrapper = (SMgmtWrapper *)(&msgCb); // hack
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
SMnodeOpt opt = {0};
|
||||
opt.deploy = 1;
|
||||
opt.replica = 1;
|
||||
opt.replicas[0].id = 1;
|
||||
opt.replicas[0].port = 9040;
|
||||
strcpy(opt.replicas[0].fqdn, "localhost");
|
||||
opt.msgCb = msgCb;
|
||||
|
||||
const char *mnodepath = "/tmp/mnode_test_trans";
|
||||
taosRemoveDir(mnodepath);
|
||||
pMnode = mndOpen(mnodepath, &opt);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
mndClose(pMnode);
|
||||
walCleanUp();
|
||||
taosCloseLog();
|
||||
taosStopCacheRefreshWorker();
|
||||
}
|
||||
|
||||
static SMnode *pMnode;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void CreateUser(const char *user) {
|
||||
SUserObj userObj = {0};
|
||||
taosEncryptPass_c((uint8_t *)"taosdata", strlen("taosdata"), userObj.pass);
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, "root", TSDB_USER_LEN);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.superUser = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_USER, &rpcMsg);
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj);
|
||||
mndTransAppendRedolog(pTrans, pRedoRaw);
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
char *param = strdup("====> test param <=====");
|
||||
mndTransSetCb(pTrans, TEST_TRANS_START_FUNC, TEST_TRANS_STOP_FUNC, param, strlen(param) + 1);
|
||||
|
||||
mndTransPrepare(pMnode, pTrans);
|
||||
mndTransDrop(pTrans);
|
||||
}
|
||||
};
|
||||
|
||||
SMnode *MndTestTrans2::pMnode;
|
||||
|
||||
TEST_F(MndTestTrans2, 01_CbFunc) {
|
||||
ASSERT_NE(pMnode, nullptr);
|
||||
|
||||
const char *user1 = "test1";
|
||||
CreateUser(user1);
|
||||
|
||||
SUserObj *pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser1, nullptr);
|
||||
}
|
|
@ -155,7 +155,6 @@ static int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle);
|
|||
|
||||
static void changeQueryHandleForInterpQuery(tsdbReaderT pHandle);
|
||||
static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock);
|
||||
static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
|
||||
static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win,
|
||||
STsdbReadHandle* pTsdbReadHandle);
|
||||
static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2);
|
||||
|
@ -1337,6 +1336,8 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
|
||||
|
||||
static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo,
|
||||
bool* exists) {
|
||||
SQueryFilePos* cur = &pTsdbReadHandle->cur;
|
||||
|
|
|
@ -73,7 +73,7 @@ typedef struct SResKeyPos {
|
|||
} SResKeyPos;
|
||||
|
||||
typedef struct SResultRowInfo {
|
||||
SResultRowPosition *pPosition;
|
||||
SResultRowPosition *pPosition; // todo remove this
|
||||
int32_t size; // number of result set
|
||||
int32_t capacity; // max capacity
|
||||
SResultRowPosition cur;
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char* pData;
|
||||
bool isNull;
|
||||
int16_t type;
|
||||
int32_t bytes;
|
||||
} SGroupKeys, SStateKeys;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
|||
#include "tpagedbuf.h"
|
||||
|
||||
#include "vnode.h"
|
||||
#include "executorInt.h"
|
||||
|
||||
typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int32_t order);
|
||||
|
||||
|
@ -118,6 +119,17 @@ typedef struct SLimit {
|
|||
int64_t offset;
|
||||
} SLimit;
|
||||
|
||||
typedef struct SFileBlockLoadRecorder {
|
||||
uint64_t totalRows;
|
||||
uint64_t totalCheckedRows;
|
||||
uint32_t totalBlocks;
|
||||
uint32_t loadBlocks;
|
||||
uint32_t loadBlockStatis;
|
||||
uint32_t skipBlocks;
|
||||
uint32_t filterOutBlocks;
|
||||
uint64_t elapsedTime;
|
||||
} SFileBlockLoadRecorder;
|
||||
|
||||
typedef struct STaskCostInfo {
|
||||
int64_t created;
|
||||
int64_t start;
|
||||
|
@ -131,14 +143,10 @@ typedef struct STaskCostInfo {
|
|||
uint64_t loadDataInCacheSize;
|
||||
|
||||
uint64_t loadDataTime;
|
||||
uint64_t totalRows;
|
||||
uint64_t totalCheckedRows;
|
||||
uint32_t totalBlocks;
|
||||
uint32_t loadBlocks;
|
||||
uint32_t loadBlockStatis;
|
||||
uint32_t skipBlocks;
|
||||
uint32_t filterOutBlocks;
|
||||
|
||||
SFileBlockLoadRecorder* pRecoder;
|
||||
uint64_t elapsedTime;
|
||||
|
||||
uint64_t firstStageMergeTime;
|
||||
uint64_t winInfoSize;
|
||||
uint64_t tableInfoSize;
|
||||
|
@ -196,7 +204,7 @@ typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, struct SAggS
|
|||
struct SOptrBasicInfo* pInfo, char* result, int32_t length);
|
||||
|
||||
typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr);
|
||||
typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup);
|
||||
typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr);
|
||||
typedef void (*__optr_close_fn_t)(void* param, int32_t num);
|
||||
typedef int32_t (*__optr_get_explain_fn_t)(struct SOperatorInfo* pOptr, void** pOptrExplain);
|
||||
|
||||
|
@ -267,7 +275,7 @@ typedef struct SOperatorFpSet {
|
|||
|
||||
typedef struct SOperatorInfo {
|
||||
uint8_t operatorType;
|
||||
bool blockingOptr; // block operator or not
|
||||
bool blocking; // block operator or not
|
||||
uint8_t status; // denote if current operator is completed
|
||||
int32_t numOfOutput; // number of columns of the current operator results
|
||||
char* name; // name, used to show the query execution plan
|
||||
|
@ -332,17 +340,14 @@ typedef struct SScanInfo {
|
|||
|
||||
typedef struct STableScanInfo {
|
||||
void* dataReader;
|
||||
|
||||
int32_t numOfBlocks; // extract basic running information.
|
||||
int32_t numOfSkipped;
|
||||
int32_t numOfBlockStatis;
|
||||
SFileBlockLoadRecorder readRecorder;
|
||||
int64_t numOfRows;
|
||||
int64_t elapsedTime;
|
||||
int32_t prevGroupId; // previous table group id
|
||||
// int32_t prevGroupId; // previous table group id
|
||||
SScanInfo scanInfo;
|
||||
int32_t current;
|
||||
SNode* pFilterNode; // filter operator info
|
||||
SqlFunctionCtx* pCtx; // next operator query context
|
||||
int32_t scanTimes;
|
||||
SNode* pFilterNode; // filter info, which is push down by optimizer
|
||||
SqlFunctionCtx* pCtx; // which belongs to the direct upstream operator operator query context
|
||||
SResultRowInfo* pResultRowInfo;
|
||||
int32_t* rowCellInfoOffset;
|
||||
SExprInfo* pExpr;
|
||||
|
@ -396,7 +401,6 @@ typedef struct SSysTableScanInfo {
|
|||
SArray* scanCols; // SArray<int16_t> scan column id list
|
||||
SName name;
|
||||
SSDataBlock* pRes;
|
||||
int32_t capacity;
|
||||
int64_t numOfBlocks; // extract basic running information.
|
||||
SLoadRemoteDataInfo loadInfo;
|
||||
} SSysTableScanInfo;
|
||||
|
@ -424,7 +428,7 @@ typedef struct STimeWindowSupp {
|
|||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||
} STimeWindowAggSupp;
|
||||
|
||||
typedef struct STableIntervalOperatorInfo {
|
||||
typedef struct SIntervalAggOperatorInfo {
|
||||
SOptrBasicInfo binfo; // basic info
|
||||
SGroupResInfo groupResInfo; // multiple results build supporter
|
||||
SInterval interval; // interval info
|
||||
|
@ -439,7 +443,7 @@ typedef struct STableIntervalOperatorInfo {
|
|||
SArray* pUpdatedWindow; // updated time window due to the input data block from the downstream operator.
|
||||
STimeWindowAggSupp twAggSup;
|
||||
struct SFillInfo* pFillInfo; // fill info
|
||||
} STableIntervalOperatorInfo;
|
||||
} SIntervalAggOperatorInfo;
|
||||
|
||||
typedef struct SAggOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
|
@ -478,16 +482,8 @@ typedef struct SFillOperatorInfo {
|
|||
void** p;
|
||||
SSDataBlock* existNewGroupBlock;
|
||||
bool multigroupResult;
|
||||
SInterval intervalInfo;
|
||||
} SFillOperatorInfo;
|
||||
|
||||
typedef struct {
|
||||
char* pData;
|
||||
bool isNull;
|
||||
int16_t type;
|
||||
int32_t bytes;
|
||||
} SGroupKeys, SStateKeys;
|
||||
|
||||
typedef struct SGroupbyOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pGroupCols; // group by columns, SArray<SColumn>
|
||||
|
@ -540,6 +536,7 @@ typedef struct SSessionAggOperatorInfo {
|
|||
SWindowRowsSup winSup;
|
||||
bool reptScan; // next round scan
|
||||
int64_t gap; // session window gap
|
||||
int32_t tsSlotId; // primary timestamp slot id
|
||||
STimeWindowAggSupp twAggSup;
|
||||
} SSessionAggOperatorInfo;
|
||||
|
||||
|
@ -557,6 +554,7 @@ typedef struct SStateWindowOperatorInfo {
|
|||
int32_t colIndex; // start row index
|
||||
bool hasKey;
|
||||
SStateKeys stateKey;
|
||||
int32_t tsSlotId; // primary timestamp column slot id
|
||||
STimeWindowAggSupp twAggSup;
|
||||
// bool reptScan;
|
||||
} SStateWindowOperatorInfo;
|
||||
|
@ -613,6 +611,9 @@ typedef struct SJoinOperatorInfo {
|
|||
SNode *pOnCondition;
|
||||
} SJoinOperatorInfo;
|
||||
|
||||
#define OPTR_IS_OPENED(_optr) (((_optr)->status & OP_OPENED) == OP_OPENED)
|
||||
#define OPTR_SET_OPENED(_optr) ((_optr)->status |= OP_OPENED)
|
||||
|
||||
SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn,
|
||||
__optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_encode_fn_t encode,
|
||||
__optr_decode_fn_t decode, __optr_get_explain_fn_t explain);
|
||||
|
@ -623,8 +624,8 @@ int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t
|
|||
int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey);
|
||||
void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows);
|
||||
void doBuildResultDatablock(SSDataBlock* pBlock, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo,
|
||||
SDiskbasedBuf* pBuf, int32_t* rowCellOffset, SqlFunctionCtx* pCtx);
|
||||
void doBuildResultDatablock(SOptrBasicInfo *pbInfo, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf);
|
||||
|
||||
void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf,
|
||||
SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset);
|
||||
void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset,
|
||||
|
@ -642,6 +643,16 @@ void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
|||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock);
|
||||
SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset);
|
||||
void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols);
|
||||
void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow);
|
||||
void cleanupAggSup(SAggSupporter* pAggSup);
|
||||
void destroyBasicOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
||||
void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
|
||||
int32_t* rowCellInfoOffset);
|
||||
|
||||
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo,
|
||||
char* pData, int16_t bytes, bool masterscan, uint64_t groupId,
|
||||
SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup);
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
|
@ -663,10 +674,12 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId,
|
||||
STimeWindowAggSupp *pTwAggSupp, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
|
||||
SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId,
|
||||
STimeWindowAggSupp *pTwAggSupp, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResBlock, int64_t gap, STimeWindowAggSupp *pTwAggSupp, SExecTaskInfo* pTaskInfo);
|
||||
SSDataBlock* pResBlock, int64_t gap, int32_t tsSlotId, STimeWindowAggSupp* pTwAggSupp,
|
||||
SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition,
|
||||
SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo,
|
||||
|
@ -676,14 +689,15 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
|
|||
SArray* pTableIdList, SExecTaskInfo* pTaskInfo, SNode* pConditions);
|
||||
|
||||
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols,
|
||||
SInterval* pInterval, SSDataBlock* pResBlock, int32_t fillType, char* fillVal,
|
||||
SInterval* pInterval, STimeWindow* pWindow, SSDataBlock* pResBlock, int32_t fillType, SNodeListNode* fillVal,
|
||||
bool multigroupResult, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols,
|
||||
SSDataBlock* pResBlock, STimeWindowAggSupp *pTwAggSupp, SExecTaskInfo* pTaskInfo);
|
||||
SSDataBlock* pResBlock, STimeWindowAggSupp *pTwAggSupp, int32_t tsSlotId, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo,
|
||||
const STableGroupInfo* pTableGroupInfo);
|
||||
|
||||
SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
|
@ -704,7 +718,7 @@ void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlo
|
|||
void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
|
||||
STableQueryInfo* createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow win);
|
||||
STableQueryInfo* createTableQueryInfo(void* buf, STimeWindow win);
|
||||
|
||||
bool isTaskKilled(SExecTaskInfo* pTaskInfo);
|
||||
int32_t checkForQueryBuf(size_t numOfTables);
|
||||
|
|
|
@ -27,13 +27,12 @@ extern "C" {
|
|||
struct SSDataBlock;
|
||||
|
||||
typedef struct SFillColInfo {
|
||||
// STColumn col; // column info
|
||||
SResSchema col;
|
||||
int16_t functionId; // sql function id
|
||||
int16_t flag; // column flag: TAG COLUMN|NORMAL COLUMN
|
||||
int16_t tagIndex; // index of current tag in SFillTagColInfo array list
|
||||
int32_t offset;
|
||||
union {int64_t i; double d;} val;
|
||||
SExprInfo *pExpr;
|
||||
// SResSchema schema;
|
||||
// int16_t functionId; // sql function id
|
||||
int16_t flag; // column flag: TAG COLUMN|NORMAL COLUMN
|
||||
int16_t tagIndex; // index of current tag in SFillTagColInfo array list
|
||||
SVariant fillVal;
|
||||
} SFillColInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -56,9 +55,10 @@ typedef struct SFillInfo {
|
|||
int32_t numOfCols; // number of columns, including the tags columns
|
||||
int32_t rowSize; // size of each row
|
||||
SInterval interval;
|
||||
char * prevValues; // previous row of data, to generate the interpolation results
|
||||
char * nextValues; // next row of data
|
||||
char** pData; // original result data block involved in filling data
|
||||
|
||||
SArray *prev;
|
||||
SArray *next;
|
||||
SSDataBlock *pSrcBlock;
|
||||
int32_t alloc; // data buffer size in rows
|
||||
|
||||
SFillColInfo* pFillCol; // column info for fill operations
|
||||
|
@ -72,7 +72,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t
|
|||
void taosFillSetStartInfo(struct SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey);
|
||||
void taosResetFillInfo(struct SFillInfo* pFillInfo, TSKEY startTimestamp);
|
||||
void taosFillSetInputDataBlock(struct SFillInfo* pFillInfo, const struct SSDataBlock* pInput);
|
||||
struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, const struct SValueNode* val);
|
||||
struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, const struct SNodeListNode* val);
|
||||
bool taosFillHasMoreResults(struct SFillInfo* pFillInfo);
|
||||
|
||||
SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols,
|
||||
|
@ -80,7 +80,7 @@ SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int3
|
|||
struct SFillColInfo* pCol, const char* id);
|
||||
|
||||
void* taosDestroyFillInfo(struct SFillInfo *pFillInfo);
|
||||
int64_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, void** output, int32_t capacity);
|
||||
int64_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity);
|
||||
int64_t getFillInfoStart(struct SFillInfo *pFillInfo);
|
||||
|
||||
|
||||
|
|
|
@ -154,14 +154,12 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
|
|||
|
||||
qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
|
||||
|
||||
bool newgroup = false;
|
||||
publishOperatorProfEvent(pTaskInfo->pRoot, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
int64_t st = 0;
|
||||
|
||||
st = taosGetTimestampUs();
|
||||
*pRes = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &newgroup);
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
*pRes = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot);
|
||||
uint64_t el = (taosGetTimestampUs() - st);
|
||||
|
||||
pTaskInfo->cost.elapsedTime += el;
|
||||
|
||||
publishOperatorProfEvent(pTaskInfo->pRoot, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -256,7 +256,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
SSDataBlock* pRes = pInfo->binfo.pRes;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
doBuildResultDatablock(pRes, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset, pInfo->binfo.pCtx);
|
||||
doBuildResultDatablock(&pInfo->binfo, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf);
|
||||
if (pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
|
||||
while (1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
if (pBlock == NULL) {
|
||||
break;
|
||||
|
@ -311,7 +311,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, false);
|
||||
|
||||
while(1) {
|
||||
doBuildResultDatablock(pRes, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset, pInfo->binfo.pCtx);
|
||||
doBuildResultDatablock(&pInfo->binfo, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf);
|
||||
doFilter(pInfo->pCondition, pRes);
|
||||
|
||||
bool hasRemain = hasRemainDataInCurrentGroup(&pInfo->groupResInfo);
|
||||
|
@ -353,7 +353,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx
|
|||
initResultRowInfo(&pInfo->binfo.resultRowInfo, 8);
|
||||
|
||||
pOperator->name = "GroupbyAggOperator";
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
// pOperator->operatorType = OP_Groupby;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
|
@ -537,11 +537,12 @@ static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) {
|
|||
|
||||
pInfo->pageIndex += 1;
|
||||
|
||||
blockDataUpdateTsWindow(pInfo->binfo.pRes);
|
||||
pInfo->binfo.pRes->info.groupId = pGroupInfo->groupId;
|
||||
return pInfo->binfo.pRes;
|
||||
}
|
||||
|
||||
static SSDataBlock* hashPartition(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -558,7 +559,7 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
|
||||
while (1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
if (pBlock == NULL) {
|
||||
break;
|
||||
|
@ -611,7 +612,7 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
}
|
||||
|
||||
pOperator->name = "PartitionOperator";
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PARTITION;
|
||||
pInfo->binfo.pRes = pResultBlock;
|
||||
|
|
|
@ -55,13 +55,27 @@ typedef struct SIFParam {
|
|||
SArray *result;
|
||||
char * condValue;
|
||||
|
||||
uint8_t colValType;
|
||||
col_id_t colId;
|
||||
|
||||
int64_t suid; // add later
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
int64_t suid; // add later
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
} SIFParam;
|
||||
|
||||
static int32_t sifGetFuncFromSql(EOperatorType src, EIndexQueryType *dst) {
|
||||
if (src == OP_TYPE_GREATER_THAN || src == OP_TYPE_GREATER_EQUAL || src == OP_TYPE_LOWER_THAN ||
|
||||
src == OP_TYPE_LOWER_EQUAL) {
|
||||
*dst = QUERY_RANGE;
|
||||
} else if (src == OP_TYPE_EQUAL) {
|
||||
*dst = QUERY_TERM;
|
||||
} else if (src == OP_TYPE_LIKE || src == OP_TYPE_MATCH || src == OP_TYPE_NMATCH) {
|
||||
*dst = QUERY_REGEX;
|
||||
} else {
|
||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef int32_t (*sif_func_t)(SIFParam *left, SIFParam *rigth, SIFParam *output);
|
||||
// construct tag filter operator later
|
||||
static void destroyTagFilterOperatorInfo(void *param) {
|
||||
|
@ -145,10 +159,11 @@ static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
|||
SColumnNode *cn = (SColumnNode *)node;
|
||||
/*only support tag column*/
|
||||
SIF_ERR_RET(sifValidateColumn(cn));
|
||||
|
||||
param->colId = cn->colId;
|
||||
param->colValType = cn->node.resType.type;
|
||||
memcpy(param->dbName, cn->dbName, sizeof(cn->dbName));
|
||||
memcpy(param->colName, cn->colName, sizeof(cn->colName));
|
||||
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_NODE_LIST: {
|
||||
|
@ -231,61 +246,76 @@ static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *outpu
|
|||
qError("index-filter not support buildin function");
|
||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
static int32_t sifIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) {
|
||||
SIndexMultiTermQuery *mq = indexMultiTermQueryCreate(MUST);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) {
|
||||
SIndexTerm *tm = indexTermCreate(left->suid, DEFAULT, operType, left->colValType, left->colName,
|
||||
strlen(left->colName), right->condValue, strlen(right->condValue));
|
||||
if (operType == OP_TYPE_LOWER_EQUAL || operType == OP_TYPE_GREATER_EQUAL || operType == OP_TYPE_GREATER_THAN ||
|
||||
operType == OP_TYPE_LOWER_THAN) {
|
||||
}
|
||||
if (tm == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
SIndexMultiTermQuery *mtm = indexMultiTermQueryCreate(MUST);
|
||||
|
||||
EIndexQueryType qtype = 0;
|
||||
SIF_ERR_RET(sifGetFuncFromSql(operType, &qtype));
|
||||
|
||||
indexMultiTermQueryAdd(mtm, tm, qtype);
|
||||
int ret = indexSearch(NULL, mtm, output->result);
|
||||
indexMultiTermQueryDestroy(mtm);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t sifLessThanFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_LOWER_THAN;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifLessEqualFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_LOWER_EQUAL;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
|
||||
static int32_t sifGreaterThanFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_GREATER_THAN;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifGreaterEqualFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_GREATER_EQUAL;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
|
||||
static int32_t sifEqualFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_EQUAL;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifNotEqualFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_NOT_EQUAL;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifInFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_IN;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifNotInFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_NOT_IN;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifLikeFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_LIKE;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifNotLikeFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_NOT_LIKE;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
|
||||
static int32_t sifMatchFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_MATCH;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifNotMatchFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
int id = OP_TYPE_NMATCH;
|
||||
return sifIndex(left, right, id, output);
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifDefaultFunc(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
// add more except
|
||||
|
@ -460,6 +490,7 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) {
|
|||
qError("index-filter failed to taosHashInit");
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nodesWalkExprPostOrder(pNode, sifCalcWalker, &ctx);
|
||||
SIF_ERR_RET(ctx.code);
|
||||
|
||||
|
@ -498,6 +529,7 @@ SIdxFltStatus idxGetFltStatus(SNode *pFilterNode) {
|
|||
if (pFilterNode == NULL) {
|
||||
return SFLT_NOT_INDEX;
|
||||
}
|
||||
|
||||
// impl later
|
||||
return SFLT_ACCURATE_INDEX;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "common/ttime.h"
|
||||
#include "ttime.h"
|
||||
#include "filter.h"
|
||||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
|
@ -36,10 +36,10 @@
|
|||
#define SET_REVERSE_SCAN_FLAG(_info) ((_info)->scanFlag = REVERSE_SCAN)
|
||||
#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC))
|
||||
|
||||
int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo);
|
||||
static int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity);
|
||||
static int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName);
|
||||
|
||||
int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName);
|
||||
void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||
static void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SWITCH_ORDER(pCtx[i].order);
|
||||
}
|
||||
|
@ -158,11 +158,11 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) {
|
||||
static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) {
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
STableScanInfo* pInfo = pOperator->info;
|
||||
|
||||
STaskCostInfo* pCost = &pTaskInfo->cost;
|
||||
SFileBlockLoadRecorder* pCost = &pTableScanInfo->readRecorder;
|
||||
|
||||
pCost->totalBlocks += 1;
|
||||
pCost->totalRows += pBlock->info.rows;
|
||||
|
@ -188,11 +188,11 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo,
|
|||
} else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) {
|
||||
pCost->loadBlockStatis += 1;
|
||||
|
||||
bool allHave = true;
|
||||
bool allColumnsHaveAgg = true;
|
||||
SColumnDataAgg** pColAgg = NULL;
|
||||
tsdbRetrieveDataBlockStatisInfo(pTableScanInfo->dataReader, &pColAgg, &allHave);
|
||||
tsdbRetrieveDataBlockStatisInfo(pTableScanInfo->dataReader, &pColAgg, &allColumnsHaveAgg);
|
||||
|
||||
if (allHave == true) {
|
||||
if (allColumnsHaveAgg == true) {
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
|
||||
// todo create this buffer during creating operator
|
||||
|
@ -236,6 +236,7 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo,
|
|||
}
|
||||
|
||||
relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols);
|
||||
// todo record the filter time cost
|
||||
doFilter(pTableScanInfo->pFilterNode, pBlock);
|
||||
if (pBlock->info.rows == 0) {
|
||||
pCost->filterOutBlocks += 1;
|
||||
|
@ -257,18 +258,15 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction
|
|||
pTableScanInfo->cond.order = TSDB_ORDER_DESC;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
|
||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||
*newgroup = false;
|
||||
|
||||
while (tsdbNextDataBlock(pTableScanInfo->dataReader)) {
|
||||
if (isTaskKilled(pOperator->pTaskInfo)) {
|
||||
longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED);
|
||||
}
|
||||
|
||||
pTableScanInfo->numOfBlocks += 1;
|
||||
tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &pBlock->info);
|
||||
|
||||
uint32_t status = 0;
|
||||
|
@ -289,7 +287,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
|
@ -298,17 +296,16 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
*newgroup = false;
|
||||
|
||||
while (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) {
|
||||
SSDataBlock* p = doTableScanImpl(pOperator, newgroup);
|
||||
// do the ascending order traverse in the first place.
|
||||
while (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) {
|
||||
SSDataBlock* p = doTableScanImpl(pOperator);
|
||||
if (p != NULL) {
|
||||
return p;
|
||||
}
|
||||
|
||||
pTableScanInfo->current += 1;
|
||||
pTableScanInfo->scanTimes += 1;
|
||||
|
||||
if (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) {
|
||||
if (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) {
|
||||
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
||||
|
||||
|
@ -323,7 +320,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
}
|
||||
|
||||
int32_t total = pTableScanInfo->scanInfo.numOfAsc + pTableScanInfo->scanInfo.numOfDesc;
|
||||
if (pTableScanInfo->current < total) {
|
||||
if (pTableScanInfo->scanTimes < total) {
|
||||
if (pTableScanInfo->cond.order == TSDB_ORDER_ASC) {
|
||||
prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, pTableScanInfo->numOfOutput);
|
||||
tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||
|
@ -333,21 +330,20 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
qDebug("%s start to descending order scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
|
||||
GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey);
|
||||
|
||||
while (pTableScanInfo->current < total) {
|
||||
SSDataBlock* p = doTableScanImpl(pOperator, newgroup);
|
||||
while (pTableScanInfo->scanTimes < total) {
|
||||
SSDataBlock* p = doTableScanImpl(pOperator);
|
||||
if (p != NULL) {
|
||||
return p;
|
||||
}
|
||||
|
||||
pTableScanInfo->current += 1;
|
||||
pTableScanInfo->scanTimes += 1;
|
||||
|
||||
if (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) {
|
||||
if (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) {
|
||||
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
||||
|
||||
qDebug("%s start to repeat descending order scan data blocks due to query func required, qrange:%" PRId64
|
||||
"-%" PRId64,
|
||||
GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey);
|
||||
"-%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey);
|
||||
|
||||
// do prepare for the next round table scan operation
|
||||
tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||
|
@ -376,58 +372,59 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCon
|
|||
pInfo->cond = *pCond;
|
||||
pInfo->scanInfo = (SScanInfo){.numOfAsc = scanInfo[0], .numOfDesc = scanInfo[1]};
|
||||
|
||||
pInfo->interval = *pInterval;
|
||||
pInfo->sampleRatio = sampleRatio;
|
||||
pInfo->interval = *pInterval;
|
||||
pInfo->sampleRatio = sampleRatio;
|
||||
pInfo->dataBlockLoadFlag = dataLoadFlag;
|
||||
pInfo->pResBlock = pResBlock;
|
||||
pInfo->pFilterNode = pCondition;
|
||||
pInfo->dataReader = pDataReader;
|
||||
pInfo->current = 0;
|
||||
pInfo->scanFlag = MAIN_SCAN;
|
||||
pInfo->pColMatchInfo = pColMatchInfo;
|
||||
pInfo->pResBlock = pResBlock;
|
||||
pInfo->pFilterNode = pCondition;
|
||||
pInfo->dataReader = pDataReader;
|
||||
pInfo->scanFlag = MAIN_SCAN;
|
||||
pInfo->pColMatchInfo = pColMatchInfo;
|
||||
|
||||
pOperator->name = "TableScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->fpSet.getNextFn = doTableScan;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->name = "TableScanOperator"; // for dubug purpose
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
static int32_t cost = 0;
|
||||
pOperator->cost.openCost = ++cost;
|
||||
|
||||
// for non-blocking operator, the open cost is always 0
|
||||
pOperator->cost.openCost = 0;
|
||||
pOperator->cost.totalCost = ++cost;
|
||||
pOperator->resultInfo.totalRows = ++cost;
|
||||
|
||||
return pOperator;
|
||||
}
|
||||
|
||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle) {
|
||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pTaskInfo) {
|
||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||
|
||||
pInfo->dataReader = pTsdbReadHandle;
|
||||
pInfo->current = 0;
|
||||
pInfo->prevGroupId = -1;
|
||||
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
pOperator->name = "TableSeqScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->fpSet.getNextFn = doTableScanImpl;
|
||||
|
||||
pInfo->dataReader = pReadHandle;
|
||||
// pInfo->prevGroupId = -1;
|
||||
|
||||
pOperator->name = "TableSeqScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
return pOperator;
|
||||
}
|
||||
|
||||
static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
*newgroup = false;
|
||||
|
||||
STableBlockDistInfo tableBlockDist = {0};
|
||||
tableBlockDist.numOfTables = 1; // TODO set the correct number of tables
|
||||
|
@ -487,7 +484,7 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo*
|
|||
|
||||
pOperator->name = "DataBlockInfoScanOperator";
|
||||
// pOperator->operatorType = OP_TableBlockInfoScan;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->fpSet._openFn = operatorDummyOpenFn;
|
||||
pOperator->fpSet.getNextFn = doBlockInfoScan;
|
||||
|
@ -514,7 +511,7 @@ static void doClearBufferedBlocks(SStreamBlockScanInfo* pInfo) {
|
|||
taosArrayClear(pInfo->pBlockLists);
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
||||
// NOTE: this operator does never check if current status is done or not
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SStreamBlockScanInfo* pInfo = pOperator->info;
|
||||
|
@ -641,20 +638,22 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
|
|||
}
|
||||
|
||||
pInfo->readerHandle = streamReadHandle;
|
||||
pInfo->pRes = pResBlock;
|
||||
pInfo->pCondition = pCondition;
|
||||
pInfo->pRes = pResBlock;
|
||||
pInfo->pCondition = pCondition;
|
||||
|
||||
pOperator->name = "StreamBlockScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pResBlock->info.numOfCols;
|
||||
pOperator->fpSet._openFn = operatorDummyOpenFn;
|
||||
pOperator->name = "StreamBlockScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pResBlock->info.numOfCols;
|
||||
pOperator->fpSet._openFn = operatorDummyOpenFn;
|
||||
pOperator->fpSet.getNextFn = doStreamBlockScan;
|
||||
pOperator->fpSet.closeFn = operatorDummyCloseFn;
|
||||
pOperator->fpSet.closeFn = operatorDummyCloseFn;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamBlockScan, NULL, NULL, operatorDummyCloseFn, NULL, NULL, NULL);
|
||||
|
||||
return pOperator;
|
||||
}
|
||||
|
||||
|
@ -676,14 +675,12 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
|
|||
switch (nType) {
|
||||
case QUERY_NODE_OPERATOR: {
|
||||
SOperatorNode* node = (SOperatorNode*)pNode;
|
||||
|
||||
if (OP_TYPE_EQUAL == node->opType) {
|
||||
*(int32_t*)pContext = 1;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
*(int32_t*)pContext = 0;
|
||||
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
case QUERY_NODE_COLUMN: {
|
||||
|
@ -714,19 +711,17 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
void getDBNameFromCondition(SNode* pCondition, char* dbName) {
|
||||
static void getDBNameFromCondition(SNode* pCondition, const char* dbName) {
|
||||
if (NULL == pCondition) {
|
||||
return;
|
||||
}
|
||||
|
||||
nodesWalkExpr(pCondition, getDBNameFromConditionWalker, dbName);
|
||||
nodesWalkExpr(pCondition, getDBNameFromConditionWalker, (char*) dbName);
|
||||
}
|
||||
|
||||
static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
static int32_t loadSysTableCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SOperatorInfo* operator=(SOperatorInfo*) param;
|
||||
SSysTableScanInfo* pScanResInfo = (SSysTableScanInfo*)operator->info;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -751,13 +746,14 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) {
|
|||
}
|
||||
|
||||
SFilterInfo* filter = NULL;
|
||||
int32_t code = filterInitFromNode(pInfo->pCondition, &filter, 0);
|
||||
|
||||
int32_t code = filterInitFromNode(pInfo->pCondition, &filter, 0);
|
||||
|
||||
SFilterColumnParam param1 = {.numOfCols = pInfo->pRes->info.numOfCols, .pDataBlock = pInfo->pRes->pDataBlock};
|
||||
code = filterSetDataFromSlotId(filter, ¶m1);
|
||||
|
||||
int8_t* rowRes = NULL;
|
||||
bool keep = filterExecute(filter, pInfo->pRes, &rowRes, NULL, param1.numOfCols);
|
||||
bool keep = filterExecute(filter, pInfo->pRes, &rowRes, NULL, param1.numOfCols);
|
||||
filterFreeInfo(filter);
|
||||
|
||||
SSDataBlock* px = createOneDataBlock(pInfo->pRes, false);
|
||||
|
@ -800,66 +796,36 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) {
|
|||
|
||||
static SSDataBlock* buildSysTableMetaBlock() {
|
||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
pBlock->info.numOfCols = 10;
|
||||
pBlock->info.hasVarCol = true;
|
||||
|
||||
size_t size = 0;
|
||||
const SSysTableMeta *pMeta = NULL;
|
||||
getInfosDbMeta(&pMeta, &size);
|
||||
|
||||
int32_t index = 0;
|
||||
for(int32_t i = 0; i < size; ++i) {
|
||||
if(strcmp(pMeta[i].name, TSDB_INS_TABLE_USER_TABLES) == 0) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pBlock->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData));
|
||||
|
||||
SColumnInfoData colInfoData = {0};
|
||||
colInfoData.info.colId = 1;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
colInfoData.info.bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
for(int32_t i = 0; i < pMeta[index].colNum; ++i) {
|
||||
SColumnInfoData colInfoData = {0};
|
||||
colInfoData.info.colId = i + 1;
|
||||
colInfoData.info.type = pMeta[index].schema[i].type;
|
||||
colInfoData.info.bytes = pMeta[index].schema[i].bytes;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
}
|
||||
|
||||
colInfoData.info.colId = 2;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
colInfoData.info.bytes = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 3;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
colInfoData.info.bytes = 8;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 4;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_INT;
|
||||
colInfoData.info.bytes = 4;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 5;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
colInfoData.info.bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 6;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_BIGINT;
|
||||
colInfoData.info.bytes = 8;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 7;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_INT;
|
||||
colInfoData.info.bytes = 4;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 8;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_INT;
|
||||
colInfoData.info.bytes = 4;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 9;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
colInfoData.info.bytes = 512 + VARSTR_HEADER_SIZE;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
|
||||
colInfoData.info.colId = 10;
|
||||
colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
colInfoData.info.bytes = 20 + VARSTR_HEADER_SIZE;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
pBlock->info.numOfCols = pMeta[index].colNum;
|
||||
pBlock->info.hasVarCol = true;
|
||||
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||
// build message and send to mnode to fetch the content of system tables.
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SSysTableScanInfo* pInfo = pOperator->info;
|
||||
|
@ -873,7 +839,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
buildSysDbTableInfo(pInfo);
|
||||
buildSysDbTableInfo(pInfo, pOperator->resultInfo.capacity);
|
||||
|
||||
doFilterResult(pInfo);
|
||||
pInfo->loadInfo.totalRows += pInfo->pRes->info.rows;
|
||||
|
@ -901,7 +867,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
varDataSetLen(dbname, strlen(varDataVal(dbname)));
|
||||
|
||||
SSDataBlock* p = buildSysTableMetaBlock();
|
||||
blockDataEnsureCapacity(p, pInfo->capacity);
|
||||
blockDataEnsureCapacity(p, pOperator->resultInfo.capacity);
|
||||
|
||||
char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
while (metaTbCursorNext(pInfo->pCur) == 0) {
|
||||
|
@ -982,7 +948,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
pColInfoData = taosArrayGet(p->pDataBlock, 9);
|
||||
colDataAppend(pColInfoData, numOfRows, str, false);
|
||||
|
||||
if (++numOfRows >= pInfo->capacity) {
|
||||
if (++numOfRows >= pOperator->resultInfo.capacity) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1027,7 +993,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
pMsgSendInfo->msgInfo.pData = buf1;
|
||||
pMsgSendInfo->msgInfo.len = contLen;
|
||||
pMsgSendInfo->msgType = TDMT_MND_SYSTABLE_RETRIEVE;
|
||||
pMsgSendInfo->fp = loadSysTableContentCb;
|
||||
pMsgSendInfo->fp = loadSysTableCallback;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
int32_t code = asyncSendMsgToServer(pInfo->pTransporter, &pInfo->epSet, &transporterId, pMsgSendInfo);
|
||||
|
@ -1065,9 +1031,9 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo) {
|
||||
int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) {
|
||||
SSDataBlock* p = buildSysTableMetaBlock();
|
||||
blockDataEnsureCapacity(p, pInfo->capacity);
|
||||
blockDataEnsureCapacity(p, capacity);
|
||||
|
||||
size_t size = 0;
|
||||
const SSysTableMeta* pSysDbTableMeta = NULL;
|
||||
|
@ -1138,18 +1104,19 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->accountId = accountId;
|
||||
pInfo->accountId = accountId;
|
||||
pInfo->showRewrite = showRewrite;
|
||||
pInfo->pRes = pResBlock;
|
||||
pInfo->capacity = 4096;
|
||||
pInfo->pCondition = pCondition;
|
||||
pInfo->scanCols = colList;
|
||||
pInfo->pRes = pResBlock;
|
||||
pInfo->pCondition = pCondition;
|
||||
pInfo->scanCols = colList;
|
||||
|
||||
initResultSizeInfo(pOperator, 4096);
|
||||
|
||||
tNameAssign(&pInfo->name, pName);
|
||||
const char* name = tNameGetTableName(&pInfo->name);
|
||||
if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) {
|
||||
pInfo->readHandle = *(SReadHandle*) readHandle;
|
||||
blockDataEnsureCapacity(pInfo->pRes, pInfo->capacity);
|
||||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
} else {
|
||||
tsem_init(&pInfo->ready, 0, 0);
|
||||
pInfo->epSet = epset;
|
||||
|
@ -1178,12 +1145,12 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe
|
|||
#endif
|
||||
}
|
||||
|
||||
pOperator->name = "SysTableScanOperator";
|
||||
pOperator->name = "SysTableScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pResBlock->info.numOfCols;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pResBlock->info.numOfCols;
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator,
|
||||
NULL, NULL, NULL);
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
@ -1191,9 +1158,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe
|
|||
return pOperator;
|
||||
}
|
||||
|
||||
static SSDataBlock* doTagScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
||||
#if 0
|
||||
SOperatorInfo* pOperator = (SOperatorInfo*) param;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1327,29 +1293,29 @@ static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
||||
}
|
||||
|
||||
SOperatorInfo* createTagScanOperatorInfo(void* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SOperatorInfo* createTagScanOperatorInfo(void* readHandle, SExprInfo* pExpr, int32_t numOfOutput, SExecTaskInfo* pTaskInfo) {
|
||||
STagScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STagScanInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->pReader = pReaderHandle;
|
||||
pInfo->curPos = 0;
|
||||
pOperator->name = "TagScanOperator";
|
||||
pInfo->pReader = readHandle;
|
||||
pInfo->curPos = 0;
|
||||
pOperator->name = "TagScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, NULL, destroyTagScanOperatorInfo, NULL, NULL, NULL);
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
taosMemoryFree(pInfo);
|
||||
taosMemoryFree(pOperator);
|
||||
|
|
|
@ -13,20 +13,21 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "function.h"
|
||||
#include "os.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
#include "taosdef.h"
|
||||
#include "tmsg.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
#include "tfill.h"
|
||||
#include "function.h"
|
||||
#include "tcommon.h"
|
||||
#include "thash.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#include "function.h"
|
||||
#include "tdatablock.h"
|
||||
#include "executorInt.h"
|
||||
#include "querynodes.h"
|
||||
#include "tfill.h"
|
||||
|
||||
#define FILL_IS_ASC_FILL(_f) ((_f)->order == TSDB_ORDER_ASC)
|
||||
#define DO_INTERPOLATION(_v1, _v2, _k1, _k2, _k) ((_v1) + ((_v2) - (_v1)) * (((double)(_k)) - ((double)(_k1))) / (((double)(_k2)) - ((double)(_k1))))
|
||||
|
||||
|
@ -37,168 +38,208 @@ static void setTagsValue(SFillInfo* pFillInfo, void** data, int32_t genRows) {
|
|||
continue;
|
||||
}
|
||||
|
||||
char* val1 = elePtrAt(data[j], pCol->col.bytes, genRows);
|
||||
SResSchema* pSchema = &pCol->pExpr->base.resSchema;
|
||||
char* val1 = elePtrAt(data[j], pSchema->bytes, genRows);
|
||||
|
||||
assert(pCol->tagIndex >= 0 && pCol->tagIndex < pFillInfo->numOfTags);
|
||||
SFillTagColInfo* pTag = &pFillInfo->pTags[pCol->tagIndex];
|
||||
|
||||
// assert (pTag->col.colId == pCol->col.colId);
|
||||
assignVal(val1, pTag->tagVal, pCol->col.bytes, pCol->col.type);
|
||||
assignVal(val1, pTag->tagVal, pSchema->bytes, pSchema->type);
|
||||
}
|
||||
}
|
||||
|
||||
static void setNullValueForRow(SFillInfo* pFillInfo, void** data, int32_t numOfCol, int32_t rowIndex) {
|
||||
static void setNullRow(SSDataBlock* pBlock, int32_t numOfCol, int32_t rowIndex) {
|
||||
// the first are always the timestamp column, so start from the second column.
|
||||
for (int32_t i = 1; i < numOfCol; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
|
||||
char* output = elePtrAt(data[i], pCol->col.bytes, rowIndex);
|
||||
setNull(output, pCol->col.type, pCol->col.bytes);
|
||||
for (int32_t i = 1; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* p = taosArrayGet(pBlock->pDataBlock, i);
|
||||
colDataAppendNULL(p, rowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
static void doFillOneRowResult(SFillInfo* pFillInfo, void** data, char** srcData, int64_t ts, bool outOfBound) {
|
||||
char* prev = pFillInfo->prevValues;
|
||||
char* next = pFillInfo->nextValues;
|
||||
#define GET_DEST_SLOT_ID(_p) ((_p)->pExpr->base.resSchema.slotId)
|
||||
#define GET_SRC_SLOT_ID(_p) ((_p)->pExpr->base.pParam[0].pCol->slotId)
|
||||
|
||||
static void doSetVal(SColumnInfoData* pDstColInfoData, int32_t rowIndex, const SGroupKeys* pKey);
|
||||
|
||||
static void doFillOneRowResult(SFillInfo* pFillInfo, SSDataBlock *pBlock, SSDataBlock* pSrcBlock, int64_t ts, bool outOfBound) {
|
||||
SPoint point1, point2, point;
|
||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pFillInfo->order);
|
||||
|
||||
// set the primary timestamp column value
|
||||
int32_t index = pFillInfo->numOfCurrent;
|
||||
char* val = elePtrAt(data[0], TSDB_KEYSIZE, index);
|
||||
SColumnInfoData *pCol0 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
char* val = colDataGetData(pCol0, index);
|
||||
|
||||
*(TSKEY*) val = pFillInfo->currentKey;
|
||||
|
||||
// set the other values
|
||||
if (pFillInfo->type == TSDB_FILL_PREV) {
|
||||
char* p = FILL_IS_ASC_FILL(pFillInfo) ? prev : next;
|
||||
SArray* p = FILL_IS_ASC_FILL(pFillInfo) ? pFillInfo->prev : pFillInfo->next;
|
||||
|
||||
if (p != NULL) {
|
||||
for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* output = elePtrAt(data[i], pCol->col.bytes, index);
|
||||
// assignVal(output, p + pCol->offset, pCol->col.bytes, pCol->col.type);
|
||||
}
|
||||
} else { // no prev value yet, set the value for NULL
|
||||
setNullValueForRow(pFillInfo, data, pFillInfo->numOfCols, index);
|
||||
}
|
||||
} else if (pFillInfo->type == TSDB_FILL_NEXT) {
|
||||
char* p = FILL_IS_ASC_FILL(pFillInfo)? next : prev;
|
||||
|
||||
if (p != NULL) {
|
||||
for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* output = elePtrAt(data[i], pCol->col.bytes, index);
|
||||
// assignVal(output, p + pCol->offset, pCol->col.bytes, pCol->col.type);
|
||||
}
|
||||
} else { // no prev value yet, set the value for NULL
|
||||
setNullValueForRow(pFillInfo, data, pFillInfo->numOfCols, index);
|
||||
}
|
||||
} else if (pFillInfo->type == TSDB_FILL_LINEAR) {
|
||||
// TODO : linear interpolation supports NULL value
|
||||
if (prev != NULL && !outOfBound) {
|
||||
for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int16_t type = pCol->col.type;
|
||||
int16_t bytes = pCol->col.bytes;
|
||||
|
||||
char *val1 = elePtrAt(data[i], pCol->col.bytes, index);
|
||||
if (type == TSDB_DATA_TYPE_BINARY|| type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BOOL) {
|
||||
setNull(val1, pCol->col.type, bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
point1 = (SPoint){.key = *(TSKEY*)(prev), .val = prev + pCol->offset};
|
||||
point2 = (SPoint){.key = ts, .val = srcData[i] + pFillInfo->index * bytes};
|
||||
point = (SPoint){.key = pFillInfo->currentKey, .val = val1};
|
||||
taosGetLinearInterpolationVal(&point, type, &point1, &point2, type);
|
||||
}
|
||||
} else {
|
||||
setNullValueForRow(pFillInfo, data, pFillInfo->numOfCols, index);
|
||||
}
|
||||
} else { // fill the default value */
|
||||
for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)/* || IS_VAR_DATA_TYPE(pCol->col.type)*/) {
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* val1 = elePtrAt(data[i], pCol->col.bytes, index);
|
||||
assignVal(val1, (char*)&pCol->val, pCol->col.bytes, pCol->col.type);
|
||||
SGroupKeys* pKey = taosArrayGet(p, i);
|
||||
SColumnInfoData* pDstColInfoData = taosArrayGet(pBlock->pDataBlock, GET_DEST_SLOT_ID(pCol));
|
||||
doSetVal(pDstColInfoData, index, pKey);
|
||||
}
|
||||
} else if (pFillInfo->type == TSDB_FILL_NEXT) {
|
||||
SArray* p = FILL_IS_ASC_FILL(pFillInfo) ? pFillInfo->next : pFillInfo->prev;
|
||||
|
||||
for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SGroupKeys* pKey = taosArrayGet(p, i);
|
||||
SColumnInfoData* pDstColInfoData = taosArrayGet(pBlock->pDataBlock, GET_DEST_SLOT_ID(pCol));
|
||||
doSetVal(pDstColInfoData, index, pKey);
|
||||
}
|
||||
} else if (pFillInfo->type == TSDB_FILL_LINEAR) {
|
||||
// TODO : linear interpolation supports NULL value
|
||||
if (outOfBound) {
|
||||
setNullRow(pBlock, pFillInfo->numOfCols, index);
|
||||
} else {
|
||||
for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t srcSlotId = GET_SRC_SLOT_ID(pCol);
|
||||
|
||||
int32_t dstSlotId = GET_DEST_SLOT_ID(pCol);
|
||||
SColumnInfoData* pDstCol = taosArrayGet(pBlock->pDataBlock, dstSlotId);
|
||||
|
||||
int16_t type = pCol->pExpr->base.resSchema.type;
|
||||
SGroupKeys* pKey = taosArrayGet(pFillInfo->prev, i);
|
||||
if (IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_BOOL || pKey->isNull) {
|
||||
colDataAppendNULL(pDstCol, index);
|
||||
continue;
|
||||
}
|
||||
|
||||
SGroupKeys* pKey1 = taosArrayGet(pFillInfo->prev, 0);
|
||||
int64_t prevTs = *(int64_t*)pKey1->pData;
|
||||
|
||||
SColumnInfoData* pSrcCol = taosArrayGet(pSrcBlock->pDataBlock, srcSlotId);
|
||||
char* data = colDataGetData(pSrcCol, pFillInfo->index);
|
||||
|
||||
point1 = (SPoint){.key = prevTs, .val = pKey->pData};
|
||||
point2 = (SPoint){.key = ts, .val = data};
|
||||
|
||||
int64_t out = 0;
|
||||
point = (SPoint){.key = pFillInfo->currentKey, .val = &out};
|
||||
taosGetLinearInterpolationVal(&point, type, &point1, &point2, type);
|
||||
|
||||
colDataAppend(pDstCol, index, (const char*)&out, false);
|
||||
}
|
||||
}
|
||||
} else if (pFillInfo->type == TSDB_FILL_NULL) { // fill with NULL
|
||||
setNullRow(pBlock, pFillInfo->numOfCols, index);
|
||||
} else { // fill with user specified value for each column
|
||||
for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)/* || IS_VAR_DATA_TYPE(pCol->schema.type)*/) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SVariant* pVar = &pFillInfo->pFillCol[i].fillVal;
|
||||
|
||||
SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (pDst->info.type == TSDB_DATA_TYPE_FLOAT) {
|
||||
float v = 0;
|
||||
GET_TYPED_DATA(v, float, pVar->nType, &pVar->i);
|
||||
colDataAppend(pDst, index, (char*)&v, false);
|
||||
} else if (pDst->info.type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double v = 0;
|
||||
GET_TYPED_DATA(v, double, pVar->nType, &pVar->i);
|
||||
colDataAppend(pDst, index, (char*)&v, false);
|
||||
} else if (IS_SIGNED_NUMERIC_TYPE(pDst->info.type)) {
|
||||
int64_t v = 0;
|
||||
GET_TYPED_DATA(v, int64_t, pVar->nType, &pVar->i);
|
||||
colDataAppend(pDst, index, (char*)&v, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTagsValue(pFillInfo, data, index);
|
||||
pFillInfo->currentKey = taosTimeAdd(pFillInfo->currentKey, pFillInfo->interval.sliding * step, pFillInfo->interval.slidingUnit,
|
||||
pFillInfo->interval.precision);
|
||||
// setTagsValue(pFillInfo, data, index);
|
||||
SInterval* pInterval = &pFillInfo->interval;
|
||||
pFillInfo->currentKey = taosTimeAdd(pFillInfo->currentKey, pInterval->sliding * step, pInterval->slidingUnit, pInterval->precision);
|
||||
pFillInfo->numOfCurrent++;
|
||||
}
|
||||
|
||||
static void initBeforeAfterDataBuf(SFillInfo* pFillInfo, char** next) {
|
||||
if (*next != NULL) {
|
||||
void doSetVal(SColumnInfoData* pDstCol, int32_t rowIndex, const SGroupKeys* pKey) {
|
||||
if (pKey->isNull) {
|
||||
colDataAppendNULL(pDstCol, rowIndex);
|
||||
} else {
|
||||
colDataAppend(pDstCol, rowIndex, pKey->pData, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void initBeforeAfterDataBuf(SFillInfo* pFillInfo) {
|
||||
if (taosArrayGetSize(pFillInfo->next) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
*next = taosMemoryCalloc(1, pFillInfo->rowSize);
|
||||
for (int i = 1; i < pFillInfo->numOfCols; i++) {
|
||||
for (int i = 0; i < pFillInfo->numOfCols; i++) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
setNull(*next + pCol->offset, pCol->col.type, pCol->col.bytes);
|
||||
|
||||
SGroupKeys key = {0};
|
||||
SResSchema* pSchema = &pCol->pExpr->base.resSchema;
|
||||
key.pData = taosMemoryMalloc(pSchema->bytes);
|
||||
key.isNull = true;
|
||||
key.bytes = pSchema->bytes;
|
||||
key.type = pSchema->type;
|
||||
|
||||
taosArrayPush(pFillInfo->next, &key);
|
||||
|
||||
key.pData = taosMemoryMalloc(pSchema->bytes);
|
||||
taosArrayPush(pFillInfo->prev, &key);
|
||||
}
|
||||
}
|
||||
|
||||
static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, char** srcData, char* buf) {
|
||||
int32_t rowIndex = pFillInfo->index;
|
||||
static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bool isNull);
|
||||
|
||||
static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SArray* pRow) {
|
||||
for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
memcpy(buf + pCol->offset, srcData[i] + rowIndex * pCol->col.bytes, pCol->col.bytes);
|
||||
int32_t srcSlotId = GET_SRC_SLOT_ID(&pFillInfo->pFillCol[i]);
|
||||
|
||||
SColumnInfoData* pSrcCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, srcSlotId);
|
||||
|
||||
bool isNull = colDataIsNull_s(pSrcCol, rowIndex);
|
||||
char* p = colDataGetData(pSrcCol, rowIndex);
|
||||
saveColData(pRow, i, p, isNull);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t fillResultImpl(SFillInfo* pFillInfo, void** data, int32_t outputRows) {
|
||||
static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t outputRows) {
|
||||
pFillInfo->numOfCurrent = 0;
|
||||
|
||||
char** srcData = pFillInfo->pData;
|
||||
char** prev = &pFillInfo->prevValues;
|
||||
char** next = &pFillInfo->nextValues;
|
||||
// todo make sure the first column is always the primary timestamp column?
|
||||
SColumnInfoData* pTsCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, 0);
|
||||
|
||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pFillInfo->order);
|
||||
bool ascFill = FILL_IS_ASC_FILL(pFillInfo);
|
||||
|
||||
if (FILL_IS_ASC_FILL(pFillInfo)) {
|
||||
assert(pFillInfo->currentKey >= pFillInfo->start);
|
||||
} else {
|
||||
assert(pFillInfo->currentKey <= pFillInfo->start);
|
||||
}
|
||||
#if 0
|
||||
ASSERT(ascFill && (pFillInfo->currentKey >= pFillInfo->start) || (!ascFill && (pFillInfo->currentKey <= pFillInfo->start)));
|
||||
#endif
|
||||
|
||||
while (pFillInfo->numOfCurrent < outputRows) {
|
||||
int64_t ts = ((int64_t*)pFillInfo->pData[0])[pFillInfo->index];
|
||||
int64_t ts = ((int64_t*)pTsCol->pData)[pFillInfo->index];
|
||||
|
||||
// set the next value for interpolation
|
||||
if ((pFillInfo->currentKey < ts && FILL_IS_ASC_FILL(pFillInfo)) ||
|
||||
(pFillInfo->currentKey > ts && !FILL_IS_ASC_FILL(pFillInfo))) {
|
||||
initBeforeAfterDataBuf(pFillInfo, next);
|
||||
copyCurrentRowIntoBuf(pFillInfo, srcData, *next);
|
||||
if ((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) {
|
||||
copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pFillInfo->next);
|
||||
}
|
||||
|
||||
if (((pFillInfo->currentKey < ts && FILL_IS_ASC_FILL(pFillInfo)) || (pFillInfo->currentKey > ts && !FILL_IS_ASC_FILL(pFillInfo))) &&
|
||||
pFillInfo->numOfCurrent < outputRows) {
|
||||
|
||||
// fill the gap between two actual input rows
|
||||
while (((pFillInfo->currentKey < ts && FILL_IS_ASC_FILL(pFillInfo)) ||
|
||||
(pFillInfo->currentKey > ts && !FILL_IS_ASC_FILL(pFillInfo))) &&
|
||||
pFillInfo->numOfCurrent < outputRows) {
|
||||
doFillOneRowResult(pFillInfo, data, srcData, ts, false);
|
||||
if (((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) && pFillInfo->numOfCurrent < outputRows) {
|
||||
// fill the gap between two input rows
|
||||
while (((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) && pFillInfo->numOfCurrent < outputRows) {
|
||||
doFillOneRowResult(pFillInfo, pBlock, pFillInfo->pSrcBlock, ts, false);
|
||||
}
|
||||
|
||||
// output buffer is full, abort
|
||||
|
@ -208,61 +249,66 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, void** data, int32_t outputR
|
|||
}
|
||||
} else {
|
||||
assert(pFillInfo->currentKey == ts);
|
||||
initBeforeAfterDataBuf(pFillInfo, prev);
|
||||
|
||||
if (pFillInfo->type == TSDB_FILL_NEXT && (pFillInfo->index + 1) < pFillInfo->numOfRows) {
|
||||
initBeforeAfterDataBuf(pFillInfo, next);
|
||||
++pFillInfo->index;
|
||||
copyCurrentRowIntoBuf(pFillInfo, srcData, *next);
|
||||
copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pFillInfo->next);
|
||||
--pFillInfo->index;
|
||||
}
|
||||
|
||||
// assign rows to dst buffer
|
||||
for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)/* || IS_VAR_DATA_TYPE(pCol->col.type)*/) {
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)/* || IS_VAR_DATA_TYPE(pCol->schema.type)*/) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* output = elePtrAt(data[i], pCol->col.bytes, pFillInfo->numOfCurrent);
|
||||
char* src = elePtrAt(srcData[i], pCol->col.bytes, pFillInfo->index);
|
||||
int32_t srcSlotId = GET_SRC_SLOT_ID(pCol);
|
||||
int32_t dstSlotId = GET_DEST_SLOT_ID(pCol);
|
||||
|
||||
if (i == 0 || (pCol->functionId != FUNCTION_COUNT && !isNull(src, pCol->col.type)) ||
|
||||
(pCol->functionId == FUNCTION_COUNT && GET_INT64_VAL(src) != 0)) {
|
||||
assignVal(output, src, pCol->col.bytes, pCol->col.type);
|
||||
memcpy(*prev + pCol->offset, src, pCol->col.bytes);
|
||||
SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, dstSlotId);
|
||||
SColumnInfoData* pSrc = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, srcSlotId);
|
||||
|
||||
char* src = colDataGetData(pSrc, pFillInfo->index);
|
||||
if (i == 0 || (/*pCol->functionId != FUNCTION_COUNT &&*/ !colDataIsNull_s(pSrc, pFillInfo->index)) /*||
|
||||
(pCol->functionId == FUNCTION_COUNT && GET_INT64_VAL(src) != 0)*/) {
|
||||
bool isNull = colDataIsNull_s(pSrc, pFillInfo->index);
|
||||
colDataAppend(pDst, pFillInfo->numOfCurrent, src, isNull);
|
||||
saveColData(pFillInfo->prev, i, src, isNull);
|
||||
} else { // i > 0 and data is null , do interpolation
|
||||
if (pFillInfo->type == TSDB_FILL_PREV) {
|
||||
assignVal(output, *prev + pCol->offset, pCol->col.bytes, pCol->col.type);
|
||||
SGroupKeys *pKey = taosArrayGet(pFillInfo->prev, i);
|
||||
doSetVal(pDst, pFillInfo->numOfCurrent, pKey);
|
||||
} else if (pFillInfo->type == TSDB_FILL_LINEAR) {
|
||||
assignVal(output, src, pCol->col.bytes, pCol->col.type);
|
||||
memcpy(*prev + pCol->offset, src, pCol->col.bytes);
|
||||
bool isNull = colDataIsNull_s(pSrc, pFillInfo->index);
|
||||
colDataAppend(pDst, pFillInfo->numOfCurrent, src, isNull);
|
||||
saveColData(pFillInfo->prev, i, src, isNull);
|
||||
} else if (pFillInfo->type == TSDB_FILL_NULL) {
|
||||
colDataAppendNULL(pDst, pFillInfo->numOfCurrent);
|
||||
} else if (pFillInfo->type == TSDB_FILL_NEXT) {
|
||||
if (*next) {
|
||||
assignVal(output, *next + pCol->offset, pCol->col.bytes, pCol->col.type);
|
||||
} else {
|
||||
setNull(output, pCol->col.type, pCol->col.bytes);
|
||||
}
|
||||
SGroupKeys *pKey = taosArrayGet(pFillInfo->next, i);
|
||||
doSetVal(pDst, pFillInfo->numOfCurrent, pKey);
|
||||
} else {
|
||||
assignVal(output, (char*)&pCol->val, pCol->col.bytes, pCol->col.type);
|
||||
SVariant* pVar = &pFillInfo->pFillCol[i].fillVal;
|
||||
colDataAppend(pDst, pFillInfo->numOfCurrent, (char*)&pVar->i, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set the tag value for final result
|
||||
setTagsValue(pFillInfo, data, pFillInfo->numOfCurrent);
|
||||
// setTagsValue(pFillInfo, data, pFillInfo->numOfCurrent);
|
||||
SInterval *pInterval = &pFillInfo->interval;
|
||||
pFillInfo->currentKey = taosTimeAdd(pFillInfo->currentKey, pInterval->sliding * step, pInterval->slidingUnit, pInterval->precision);
|
||||
|
||||
pFillInfo->currentKey = taosTimeAdd(pFillInfo->currentKey, pFillInfo->interval.sliding * step,
|
||||
pFillInfo->interval.slidingUnit, pFillInfo->interval.precision);
|
||||
pFillInfo->index += 1;
|
||||
pFillInfo->numOfCurrent += 1;
|
||||
}
|
||||
|
||||
if (pFillInfo->index >= pFillInfo->numOfRows || pFillInfo->numOfCurrent >= outputRows) {
|
||||
/* the raw data block is exhausted, next value does not exists */
|
||||
if (pFillInfo->index >= pFillInfo->numOfRows) {
|
||||
taosMemoryFreeClear(*next);
|
||||
}
|
||||
|
||||
// if (pFillInfo->index >= pFillInfo->numOfRows) {
|
||||
// taosMemoryFreeClear(*next);
|
||||
// }
|
||||
pFillInfo->numOfTotal += pFillInfo->numOfCurrent;
|
||||
return pFillInfo->numOfCurrent;
|
||||
}
|
||||
|
@ -271,14 +317,24 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, void** data, int32_t outputR
|
|||
return pFillInfo->numOfCurrent;
|
||||
}
|
||||
|
||||
static int64_t appendFilledResult(SFillInfo* pFillInfo, void** output, int64_t resultCapacity) {
|
||||
static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bool isNull) {
|
||||
SGroupKeys *pKey = taosArrayGet(rowBuf, columnIndex);
|
||||
if (isNull) {
|
||||
pKey->isNull = true;
|
||||
} else {
|
||||
memcpy(pKey->pData, src, pKey->bytes);
|
||||
pKey->isNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
static int64_t appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int64_t resultCapacity) {
|
||||
/*
|
||||
* These data are generated according to fill strategy, since the current timestamp is out of the time window of
|
||||
* real result set. Note that we need to keep the direct previous result rows, to generated the filled data.
|
||||
*/
|
||||
pFillInfo->numOfCurrent = 0;
|
||||
while (pFillInfo->numOfCurrent < resultCapacity) {
|
||||
doFillOneRowResult(pFillInfo, output, pFillInfo->pData, pFillInfo->start, true);
|
||||
doFillOneRowResult(pFillInfo, pBlock, pFillInfo->pSrcBlock, pFillInfo->start, true);
|
||||
}
|
||||
|
||||
pFillInfo->numOfTotal += pFillInfo->numOfCurrent;
|
||||
|
@ -295,15 +351,15 @@ static int32_t setTagColumnInfo(SFillInfo* pFillInfo, int32_t numOfCols, int32_t
|
|||
int32_t k = 0;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SFillColInfo* pColInfo = &pFillInfo->pFillCol[i];
|
||||
pFillInfo->pData[i] = NULL;
|
||||
SResSchema* pSchema = &pColInfo->pExpr->base.resSchema;
|
||||
|
||||
if (TSDB_COL_IS_TAG(pColInfo->flag) || pColInfo->col.type == TSDB_DATA_TYPE_BINARY) {
|
||||
if (TSDB_COL_IS_TAG(pColInfo->flag) || pSchema->type == TSDB_DATA_TYPE_BINARY) {
|
||||
numOfTags += 1;
|
||||
|
||||
bool exists = false;
|
||||
int32_t index = -1;
|
||||
for (int32_t j = 0; j < k; ++j) {
|
||||
if (pFillInfo->pTags[j].col.colId == pColInfo->col.slotId) {
|
||||
if (pFillInfo->pTags[j].col.colId == pSchema->slotId) {
|
||||
exists = true;
|
||||
index = j;
|
||||
break;
|
||||
|
@ -311,12 +367,12 @@ static int32_t setTagColumnInfo(SFillInfo* pFillInfo, int32_t numOfCols, int32_t
|
|||
}
|
||||
|
||||
if (!exists) {
|
||||
SSchema* pSchema = &pFillInfo->pTags[k].col;
|
||||
pSchema->colId = pColInfo->col.slotId;
|
||||
pSchema->type = pColInfo->col.type;
|
||||
pSchema->bytes = pColInfo->col.bytes;
|
||||
SSchema* pSchema1 = &pFillInfo->pTags[k].col;
|
||||
pSchema1->colId = pSchema->slotId;
|
||||
pSchema1->type = pSchema->type;
|
||||
pSchema1->bytes = pSchema->bytes;
|
||||
|
||||
pFillInfo->pTags[k].tagVal = taosMemoryCalloc(1, pColInfo->col.bytes);
|
||||
pFillInfo->pTags[k].tagVal = taosMemoryCalloc(1, pSchema->bytes);
|
||||
pColInfo->tagIndex = k;
|
||||
|
||||
k += 1;
|
||||
|
@ -325,7 +381,7 @@ static int32_t setTagColumnInfo(SFillInfo* pFillInfo, int32_t numOfCols, int32_t
|
|||
}
|
||||
}
|
||||
|
||||
rowsize += pColInfo->col.bytes;
|
||||
rowsize += pSchema->bytes;
|
||||
}
|
||||
|
||||
pFillInfo->numOfTags = numOfTags;
|
||||
|
@ -355,7 +411,6 @@ struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTag
|
|||
}
|
||||
|
||||
taosResetFillInfo(pFillInfo, skey);
|
||||
|
||||
pFillInfo->order = order;
|
||||
|
||||
switch(fillType) {
|
||||
|
@ -364,6 +419,7 @@ struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTag
|
|||
case FILL_MODE_NULL: pFillInfo->type = TSDB_FILL_NULL; break;
|
||||
case FILL_MODE_LINEAR: pFillInfo->type = TSDB_FILL_LINEAR;break;
|
||||
case FILL_MODE_NEXT: pFillInfo->type = TSDB_FILL_NEXT; break;
|
||||
case FILL_MODE_VALUE: pFillInfo->type = TSDB_FILL_SET_VALUE; break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
|
@ -376,7 +432,6 @@ struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTag
|
|||
pFillInfo->alloc = capacity;
|
||||
pFillInfo->id = id;
|
||||
pFillInfo->interval = *pInterval;
|
||||
pFillInfo->pData = taosMemoryMalloc(POINTER_BYTES * numOfCols);
|
||||
|
||||
// if (numOfTags > 0) {
|
||||
pFillInfo->pTags = taosMemoryCalloc(numOfCols, sizeof(SFillTagColInfo));
|
||||
|
@ -385,6 +440,11 @@ struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTag
|
|||
}
|
||||
// }
|
||||
|
||||
pFillInfo->next = taosArrayInit(numOfCols, sizeof(SGroupKeys));
|
||||
pFillInfo->prev = taosArrayInit(numOfCols, sizeof(SGroupKeys));
|
||||
|
||||
initBeforeAfterDataBuf(pFillInfo);
|
||||
|
||||
pFillInfo->rowSize = setTagColumnInfo(pFillInfo, pFillInfo->numOfCols, pFillInfo->alloc);
|
||||
assert(pFillInfo->rowSize > 0);
|
||||
return pFillInfo;
|
||||
|
@ -405,18 +465,15 @@ void* taosDestroyFillInfo(SFillInfo* pFillInfo) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pFillInfo->prevValues);
|
||||
taosMemoryFreeClear(pFillInfo->nextValues);
|
||||
taosArrayDestroy(pFillInfo->prev);
|
||||
taosArrayDestroy(pFillInfo->next);
|
||||
|
||||
for(int32_t i = 0; i < pFillInfo->numOfTags; ++i) {
|
||||
taosMemoryFreeClear(pFillInfo->pTags[i].tagVal);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pFillInfo->pTags);
|
||||
|
||||
taosMemoryFreeClear(pFillInfo->pData);
|
||||
taosMemoryFreeClear(pFillInfo->pFillCol);
|
||||
|
||||
taosMemoryFreeClear(pFillInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -436,18 +493,7 @@ void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey)
|
|||
}
|
||||
|
||||
void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const SSDataBlock* pInput) {
|
||||
for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
|
||||
SFillColInfo* pCol = &pFillInfo->pFillCol[i];
|
||||
|
||||
SColumnInfoData* pColData = taosArrayGet(pInput->pDataBlock, i);
|
||||
pFillInfo->pData[i] = pColData->pData;
|
||||
|
||||
if (TSDB_COL_IS_TAG(pCol->flag)) { // copy the tag value to tag value buffer
|
||||
SFillTagColInfo* pTag = &pFillInfo->pTags[pCol->tagIndex];
|
||||
assert (pTag->col.colId == pCol->col.slotId);
|
||||
memcpy(pTag->tagVal, pColData->pData, pCol->col.bytes); // TODO not memcpy??
|
||||
}
|
||||
}
|
||||
pFillInfo->pSrcBlock = (SSDataBlock*) pInput;
|
||||
}
|
||||
|
||||
bool taosFillHasMoreResults(SFillInfo* pFillInfo) {
|
||||
|
@ -465,8 +511,9 @@ bool taosFillHasMoreResults(SFillInfo* pFillInfo) {
|
|||
}
|
||||
|
||||
int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t maxNumOfRows) {
|
||||
int64_t* tsList = (int64_t*) pFillInfo->pData[0];
|
||||
SColumnInfoData* pCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, 0);
|
||||
|
||||
int64_t* tsList = (int64_t*) pCol->pData;
|
||||
int32_t numOfRows = taosNumOfRemainRows(pFillInfo);
|
||||
|
||||
TSKEY ekey1 = ekey;
|
||||
|
@ -513,7 +560,7 @@ int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t capacity) {
|
||||
int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity) {
|
||||
int32_t remain = taosNumOfRemainRows(pFillInfo);
|
||||
|
||||
int64_t numOfRes = getNumOfResultsAfterFillGap(pFillInfo, pFillInfo->end, capacity);
|
||||
|
@ -521,9 +568,9 @@ int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t cap
|
|||
|
||||
// no data existed for fill operation now, append result according to the fill strategy
|
||||
if (remain == 0) {
|
||||
appendFilledResult(pFillInfo, output, numOfRes);
|
||||
appendFilledResult(pFillInfo, p, numOfRes);
|
||||
} else {
|
||||
fillResultImpl(pFillInfo, output, (int32_t) numOfRes);
|
||||
fillResultImpl(pFillInfo, p, (int32_t) numOfRes);
|
||||
assert(numOfRes == pFillInfo->numOfCurrent);
|
||||
}
|
||||
|
||||
|
@ -538,28 +585,30 @@ int64_t getFillInfoStart(struct SFillInfo *pFillInfo) {
|
|||
return pFillInfo->start;
|
||||
}
|
||||
|
||||
struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, const struct SValueNode* val) {
|
||||
int32_t offset = 0;
|
||||
|
||||
struct SFillColInfo* pFillCol = taosMemoryCalloc(numOfOutput, sizeof(SFillColInfo));
|
||||
SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, const struct SNodeListNode* pValNode) {
|
||||
SFillColInfo* pFillCol = taosMemoryCalloc(numOfOutput, sizeof(SFillColInfo));
|
||||
if (pFillCol == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t len = (pValNode != NULL)? LIST_LENGTH(pValNode->pNodeList):0;
|
||||
for(int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SExprInfo* pExprInfo = &pExpr[i];
|
||||
SExprInfo* pExprInfo = &pExpr[i];
|
||||
pFillCol[i].pExpr = pExprInfo;
|
||||
pFillCol[i].tagIndex = -2;
|
||||
|
||||
pFillCol[i].col = pExprInfo->base.resSchema;
|
||||
pFillCol[i].offset = offset;
|
||||
pFillCol[i].tagIndex = -2;
|
||||
// todo refactor
|
||||
if (len > 0) {
|
||||
// if the user specified value is less than the column, alway use the last one as the fill value
|
||||
int32_t index = (i >= len)? (len - 1):i;
|
||||
|
||||
SValueNode* pv = (SValueNode*)nodesListGetNode(pValNode->pNodeList, index);
|
||||
valueNodeToVariant(pv, &pFillCol[i].fillVal);
|
||||
}
|
||||
|
||||
if (pExprInfo->base.numOfParams > 0) {
|
||||
pFillCol[i].flag = pExprInfo->base.pParam[0].pCol->flag; // always be the normal column for table query
|
||||
}
|
||||
// pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId;
|
||||
// pFillCol[i].val.d = *val;
|
||||
|
||||
offset += pExprInfo->base.resSchema.bytes;
|
||||
}
|
||||
|
||||
return pFillCol;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -55,7 +55,7 @@ typedef struct SDummyInputInfo {
|
|||
SSDataBlock* pBlock;
|
||||
} SDummyInputInfo;
|
||||
|
||||
SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
SSDataBlock* getDummyBlock(SOperatorInfo* pOperator) {
|
||||
SDummyInputInfo* pInfo = static_cast<SDummyInputInfo*>(pOperator->info);
|
||||
if (pInfo->current >= pInfo->totalPages) {
|
||||
return NULL;
|
||||
|
@ -121,7 +121,7 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
return pBlock;
|
||||
}
|
||||
|
||||
SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator) {
|
||||
SDummyInputInfo* pInfo = static_cast<SDummyInputInfo*>(pOperator->info);
|
||||
if (pInfo->current >= pInfo->totalPages) {
|
||||
return NULL;
|
||||
|
|
|
@ -78,6 +78,8 @@ typedef struct SDiffInfo {
|
|||
int64_t i64;
|
||||
double d64;
|
||||
} prev;
|
||||
|
||||
int64_t prevTs;
|
||||
} SDiffInfo;
|
||||
|
||||
typedef struct SSpreadInfo {
|
||||
|
@ -1196,9 +1198,6 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
|||
bool isFirstBlock = (pDiffInfo->hasPrev == false);
|
||||
int32_t numOfElems = 0;
|
||||
|
||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
|
||||
// int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1;
|
||||
|
||||
SColumnInfoData* pTsOutput = pCtx->pTsOutput;
|
||||
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
|
||||
|
||||
|
@ -1206,44 +1205,86 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
|||
switch (pInputCol->info.type) {
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += step) {
|
||||
int32_t pos = startOffset + (isFirstBlock ? (numOfElems - 1) : numOfElems);
|
||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||
if (pDiffInfo->includeNull) {
|
||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||
if (tsList != NULL) {
|
||||
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||
if (pCtx->order == TSDB_ORDER_ASC) {
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
|
||||
int32_t pos = startOffset + (isFirstBlock ? (numOfElems - 1) : numOfElems);
|
||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||
if (pDiffInfo->includeNull) {
|
||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||
if (tsList != NULL) {
|
||||
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t v = *(int32_t*)colDataGetData(pInputCol, i);
|
||||
if (pDiffInfo->hasPrev) {
|
||||
int32_t delta = (int32_t)(v - pDiffInfo->prev.i64); // direct previous may be null
|
||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||
} else {
|
||||
colDataAppendInt32(pOutput, pos, &delta);
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
if (pTsOutput != NULL) {
|
||||
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t v = *(int32_t*)colDataGetData(pInputCol, i);
|
||||
if (pDiffInfo->hasPrev) {
|
||||
int32_t delta = (int32_t)(v - pDiffInfo->prev.i64); // direct previous may be null
|
||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||
} else {
|
||||
pDiffInfo->prev.i64 = v;
|
||||
pDiffInfo->hasPrev = true;
|
||||
numOfElems++;
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
|
||||
int32_t v = *(int32_t*)colDataGetData(pInputCol, i);
|
||||
int32_t pos = startOffset + numOfElems;
|
||||
|
||||
// there is a row of previous data block to be handled in the first place.
|
||||
if (pDiffInfo->hasPrev) {
|
||||
int32_t delta = (int32_t)(pDiffInfo->prev.i64 - v); // direct previous may be null
|
||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||
} else {
|
||||
colDataAppendInt32(pOutput, pos, &delta);
|
||||
}
|
||||
|
||||
if (pTsOutput != NULL) {
|
||||
colDataAppendInt64(pTsOutput, pos, &pDiffInfo->prevTs);
|
||||
}
|
||||
pDiffInfo->hasPrev = false;
|
||||
}
|
||||
|
||||
// it is not the last row of current block
|
||||
if (i < pInput->numOfRows + pInput->startRowIndex - 1) {
|
||||
int32_t next = *(int32_t*)colDataGetData(pInputCol, i + 1);
|
||||
|
||||
int32_t delta = v - next; // direct previous may be null
|
||||
colDataAppendInt32(pOutput, pos, &delta);
|
||||
}
|
||||
|
||||
if (pTsOutput != NULL) {
|
||||
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||
if (pTsOutput != NULL) {
|
||||
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||
}
|
||||
} else {
|
||||
pDiffInfo->prev.i64 = v;
|
||||
if (pTsOutput != NULL) {
|
||||
pDiffInfo->prevTs = tsList[i];
|
||||
}
|
||||
pDiffInfo->hasPrev = true;
|
||||
}
|
||||
numOfElems++;
|
||||
}
|
||||
|
||||
pDiffInfo->prev.i64 = v;
|
||||
pDiffInfo->hasPrev = true;
|
||||
numOfElems++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += step) {
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
|
||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1378,7 +1419,7 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
|
||||
// initial value is not set yet
|
||||
if (!pDiffInfo->hasPrev || numOfElems <= 0) {
|
||||
if (numOfElems <= 0) {
|
||||
/*
|
||||
* 1. current block and blocks before are full of null
|
||||
* 2. current block may be null value
|
||||
|
@ -1386,15 +1427,7 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
|||
assert(pCtx->hasNull);
|
||||
return 0;
|
||||
} else {
|
||||
// for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) {
|
||||
// SqlFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t];
|
||||
// if (tagCtx->functionId == TSDB_FUNC_TAG_DUMMY) {
|
||||
// aAggs[TSDB_FUNC_TAGPRJ].xFunction(tagCtx);
|
||||
// }
|
||||
// }
|
||||
|
||||
int32_t forwardStep = (isFirstBlock) ? numOfElems - 1 : numOfElems;
|
||||
return forwardStep;
|
||||
return (isFirstBlock) ? numOfElems - 1 : numOfElems;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ struct SIndex {
|
|||
|
||||
char* path;
|
||||
|
||||
SIndexStat stat;
|
||||
SIndexStat stat;
|
||||
TdThreadMutex mtx;
|
||||
};
|
||||
|
||||
|
@ -86,6 +86,7 @@ typedef struct SIndexTerm {
|
|||
int32_t nColName;
|
||||
char* colVal;
|
||||
int32_t nColVal;
|
||||
int8_t qType; // just use for range
|
||||
} SIndexTerm;
|
||||
|
||||
typedef struct SIndexTermQuery {
|
||||
|
@ -165,7 +166,7 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf);
|
|||
} while (0)
|
||||
|
||||
#define INDEX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
|
||||
#define INDEX_TYPE_GET_TYPE(ty) (ty & 0x0F)
|
||||
#define INDEX_TYPE_GET_TYPE(ty) (ty & 0x0F)
|
||||
#define INDEX_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
|
||||
do { \
|
||||
uint8_t oldTy = ty; \
|
||||
|
|
|
@ -175,55 +175,19 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
|||
return 0;
|
||||
}
|
||||
int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result) {
|
||||
#ifdef USE_LUCENE
|
||||
EIndexOperatorType opera = multiQuerys->opera;
|
||||
|
||||
int nQuery = taosArrayGetSize(multiQuerys->query);
|
||||
char** fields = taosMemoryMalloc(sizeof(char*) * nQuery);
|
||||
char** keys = taosMemoryMalloc(sizeof(char*) * nQuery);
|
||||
int* types = taosMemoryMalloc(sizeof(int) * nQuery);
|
||||
|
||||
for (int i = 0; i < nQuery; i++) {
|
||||
SIndexTermQuery* p = taosArrayGet(multiQuerys->query, i);
|
||||
SIndexTerm* term = p->field_value;
|
||||
|
||||
fields[i] = taosMemoryCalloc(1, term->nKey + 1);
|
||||
keys[i] = taosMemoryCalloc(1, term->nVal + 1);
|
||||
|
||||
memcpy(fields[i], term->key, term->nKey);
|
||||
memcpy(keys[i], term->val, term->nVal);
|
||||
types[i] = (int)(p->type);
|
||||
}
|
||||
int* tResult = NULL;
|
||||
int tsz = 0;
|
||||
index_multi_search(index->index, (const char**)fields, (const char**)keys, types, nQuery, opera, &tResult, &tsz);
|
||||
|
||||
for (int i = 0; i < tsz; i++) {
|
||||
taosArrayPush(result, &tResult[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nQuery; i++) {
|
||||
taosMemoryFree(fields[i]);
|
||||
taosMemoryFree(keys[i]);
|
||||
}
|
||||
taosMemoryFree(fields);
|
||||
taosMemoryFree(keys);
|
||||
taosMemoryFree(types);
|
||||
#endif
|
||||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
EIndexOperatorType opera = multiQuerys->opera; // relation of querys
|
||||
|
||||
SArray* interResults = taosArrayInit(4, POINTER_BYTES);
|
||||
SArray* iRslts = taosArrayInit(4, POINTER_BYTES);
|
||||
int nQuery = taosArrayGetSize(multiQuerys->query);
|
||||
for (size_t i = 0; i < nQuery; i++) {
|
||||
SIndexTermQuery* qTerm = taosArrayGet(multiQuerys->query, i);
|
||||
SArray* tResult = NULL;
|
||||
indexTermSearch(index, qTerm, &tResult);
|
||||
taosArrayPush(interResults, (void*)&tResult);
|
||||
SIndexTermQuery* qterm = taosArrayGet(multiQuerys->query, i);
|
||||
SArray* trslt = NULL;
|
||||
indexTermSearch(index, qterm, &trslt);
|
||||
taosArrayPush(iRslts, (void*)&trslt);
|
||||
}
|
||||
indexMergeFinalResults(interResults, opera, result);
|
||||
indexInterResultsDestroy(interResults);
|
||||
indexMergeFinalResults(iRslts, opera, result);
|
||||
indexInterResultsDestroy(iRslts);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -280,8 +244,8 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde
|
|||
return 0;
|
||||
}
|
||||
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char* colName,
|
||||
int32_t nColName, const char* colVal, int32_t nColVal) {
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, int8_t queryType, uint8_t colType,
|
||||
const char* colName, int32_t nColName, const char* colVal, int32_t nColVal) {
|
||||
SIndexTerm* tm = (SIndexTerm*)taosMemoryCalloc(1, (sizeof(SIndexTerm)));
|
||||
if (tm == NULL) {
|
||||
return NULL;
|
||||
|
@ -298,6 +262,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
|
|||
tm->colVal = (char*)taosMemoryCalloc(1, nColVal + 1);
|
||||
memcpy(tm->colVal, colVal, nColVal);
|
||||
tm->nColVal = nColVal;
|
||||
tm->qType = queryType;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
|
|
@ -34,9 +34,64 @@ static char* indexCacheTermGet(const void* pData);
|
|||
|
||||
static MemTable* indexInternalCacheCreate(int8_t type);
|
||||
|
||||
static int32_t cacheSearchTerm(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchPrefix(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchSuffix(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchRegex(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchRange(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
|
||||
static int32_t (*cacheSearch[])(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) = {
|
||||
cacheSearchTerm, cacheSearchPrefix, cacheSearchSuffix, cacheSearchRegex, cacheSearchRange};
|
||||
|
||||
static void doMergeWork(SSchedMsg* msg);
|
||||
static bool indexCacheIteratorNext(Iterate* itera);
|
||||
|
||||
static int32_t cacheSearchTerm(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
if (cache == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
MemTable* mem = cache;
|
||||
char* key = indexCacheTermGet(ct);
|
||||
|
||||
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
||||
while (tSkipListIterNext(iter)) {
|
||||
SSkipListNode* node = tSkipListIterGet(iter);
|
||||
if (node == NULL) {
|
||||
break;
|
||||
}
|
||||
CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node);
|
||||
if (0 == strcmp(c->colVal, ct->colVal)) {
|
||||
if (c->operaType == ADD_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->deled, tr->added, c->uid)
|
||||
// taosArrayPush(result, &c->uid);
|
||||
*s = kTypeValue;
|
||||
} else if (c->operaType == DEL_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->added, tr->deled, c->uid)
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
tSkipListDestroyIter(iter);
|
||||
return 0;
|
||||
}
|
||||
static int32_t cacheSearchPrefix(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
// impl later
|
||||
return 0;
|
||||
}
|
||||
static int32_t cacheSearchSuffix(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
// impl later
|
||||
return 0;
|
||||
}
|
||||
static int32_t cacheSearchRegex(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
// impl later
|
||||
return 0;
|
||||
}
|
||||
static int32_t cacheSearchRange(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
// impl later
|
||||
return 0;
|
||||
}
|
||||
static IterateValue* indexCacheIteratorGetValue(Iterate* iter);
|
||||
|
||||
IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type) {
|
||||
|
@ -263,33 +318,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SI
|
|||
if (mem == NULL) {
|
||||
return 0;
|
||||
}
|
||||
char* key = indexCacheTermGet(ct);
|
||||
|
||||
SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
|
||||
while (tSkipListIterNext(iter)) {
|
||||
SSkipListNode* node = tSkipListIterGet(iter);
|
||||
if (node != NULL) {
|
||||
CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node);
|
||||
if (qtype == QUERY_TERM) {
|
||||
if (0 == strcmp(c->colVal, ct->colVal)) {
|
||||
if (c->operaType == ADD_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->deled, tr->added, c->uid)
|
||||
// taosArrayPush(result, &c->uid);
|
||||
*s = kTypeValue;
|
||||
} else if (c->operaType == DEL_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->added, tr->deled, c->uid)
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if (qtype == QUERY_PREFIX) {
|
||||
} else if (qtype == QUERY_SUFFIX) {
|
||||
} else if (qtype == QUERY_RANGE) {
|
||||
}
|
||||
}
|
||||
}
|
||||
tSkipListDestroyIter(iter);
|
||||
return 0;
|
||||
return cacheSearch[qtype](mem, ct, tr, s);
|
||||
}
|
||||
int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result, STermValueType* s) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
|
|
@ -57,6 +57,17 @@ static int tfileCompare(const void* a, const void* b);
|
|||
static int tfileParseFileName(const char* filename, uint64_t* suid, char* col, int* version);
|
||||
static void tfileGenFileName(char* filename, uint64_t suid, const char* col, int version);
|
||||
static void tfileGenFileFullName(char* fullname, const char* path, uint64_t suid, const char* col, int32_t version);
|
||||
/*
|
||||
* search from tfile
|
||||
*/
|
||||
static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
|
||||
static int32_t (*tfSearch[])(void* reader, SIndexTerm* tem, SIdxTempResult* tr) = {
|
||||
tfSearchTerm, tfSearchPrefix, tfSearchSuffix, tfSearchRegex, tfSearchRange};
|
||||
|
||||
TFileCache* tfileCacheCreate(const char* path) {
|
||||
TFileCache* tcache = taosMemoryCalloc(1, sizeof(TFileCache));
|
||||
|
@ -183,59 +194,153 @@ void tfileReaderDestroy(TFileReader* reader) {
|
|||
writerCtxDestroy(reader->ctx, reader->remove);
|
||||
taosMemoryFree(reader);
|
||||
}
|
||||
static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
uint64_t sz = tem->nColVal;
|
||||
if (hasJson) {
|
||||
p = indexPackJsonData(tem);
|
||||
sz = strlen(p);
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
uint64_t offset;
|
||||
if (fstGet(((TFileReader*)reader)->fst, &key, &offset)) {
|
||||
int64_t et = taosGetTimestampUs();
|
||||
int64_t cost = et - st;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
||||
tem->suid, tem->colName, tem->colVal, cost);
|
||||
|
||||
ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total);
|
||||
cost = taosGetTimestampUs() - et;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid,
|
||||
tem->colName, tem->colVal, cost);
|
||||
}
|
||||
if (hasJson) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
char* p = tem->colVal;
|
||||
uint64_t sz = tem->nColVal;
|
||||
if (hasJson) {
|
||||
p = indexPackJsonData(tem);
|
||||
sz = strlen(p);
|
||||
}
|
||||
|
||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||
|
||||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX);
|
||||
FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
||||
StreamWithStateResult* rt = NULL;
|
||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
||||
taosArrayPush(offsets, &(rt->out.out));
|
||||
swsResultDestroy(rt);
|
||||
}
|
||||
streamWithStateDestroy(st);
|
||||
fstStreamBuilderDestroy(sb);
|
||||
|
||||
int32_t ret = 0;
|
||||
for (int i = 0; i < taosArrayGetSize(offsets); i++) {
|
||||
uint64_t offset = *(uint64_t*)taosArrayGet(offsets, i);
|
||||
ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total);
|
||||
if (ret != 0) {
|
||||
indexError("failed to find target tablelist");
|
||||
return TSDB_CODE_TDB_FILE_CORRUPTED;
|
||||
}
|
||||
}
|
||||
if (hasJson) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
|
||||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
uint64_t sz = tem->nColVal;
|
||||
if (hasJson) {
|
||||
p = indexPackJsonData(tem);
|
||||
sz = strlen(p);
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
/*impl later*/
|
||||
if (hasJson) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
}
|
||||
static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
|
||||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
uint64_t sz = tem->nColVal;
|
||||
if (hasJson) {
|
||||
p = indexPackJsonData(tem);
|
||||
sz = strlen(p);
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
/*impl later*/
|
||||
|
||||
if (hasJson) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
}
|
||||
static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
uint64_t sz = tem->nColVal;
|
||||
if (hasJson) {
|
||||
p = indexPackJsonData(tem);
|
||||
sz = strlen(p);
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
// uint64_t offset;
|
||||
// if (fstGet(((TFileReader*)reader)->fst, &key, &offset)) {
|
||||
// int64_t et = taosGetTimestampUs();
|
||||
// int64_t cost = et - st;
|
||||
// indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
||||
// tem->suid, tem->colName, tem->colVal, cost);
|
||||
|
||||
// ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total);
|
||||
// cost = taosGetTimestampUs() - et;
|
||||
// indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid,
|
||||
// tem->colName, tem->colVal, cost);
|
||||
//}
|
||||
if (hasJson) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResult* tr) {
|
||||
SIndexTerm* term = query->term;
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON);
|
||||
EIndexQueryType qtype = query->qType;
|
||||
|
||||
// SArray* result = taosArrayInit(16, sizeof(uint64_t));
|
||||
int ret = -1;
|
||||
// refactor to callback later
|
||||
if (qtype == QUERY_TERM) {
|
||||
uint64_t offset;
|
||||
char* p = term->colVal;
|
||||
uint64_t sz = term->nColVal;
|
||||
if (hasJson) {
|
||||
p = indexPackJsonData(term);
|
||||
sz = strlen(p);
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
if (fstGet(reader->fst, &key, &offset)) {
|
||||
int64_t et = taosGetTimestampUs();
|
||||
int64_t cost = et - st;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
||||
term->suid, term->colName, term->colVal, cost);
|
||||
|
||||
ret = tfileReaderLoadTableIds(reader, offset, tr->total);
|
||||
cost = taosGetTimestampUs() - et;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", term->suid,
|
||||
term->colName, term->colVal, cost);
|
||||
} else {
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName,
|
||||
term->colVal);
|
||||
}
|
||||
fstSliceDestroy(&key);
|
||||
if (hasJson) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
} else if (qtype == QUERY_PREFIX) {
|
||||
// handle later
|
||||
//
|
||||
} else if (qtype == QUERY_SUFFIX) {
|
||||
// handle later
|
||||
} else if (qtype == QUERY_REGEX) {
|
||||
// handle later
|
||||
} else if (qtype == QUERY_RANGE) {
|
||||
// handle later
|
||||
if (qtype >= sizeof(tfSearch) / sizeof(tfSearch[0])) {
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName,
|
||||
term->colVal);
|
||||
return -1;
|
||||
} else {
|
||||
return tfSearch[qtype](reader, term, tr);
|
||||
}
|
||||
tfileReaderUnRef(reader);
|
||||
|
||||
// taosArrayAddAll(tr->total, result);
|
||||
// taosArrayDestroy(result);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const char* colName, uint8_t colType) {
|
||||
|
|
|
@ -483,9 +483,9 @@ TEST_F(IndexTFileEnv, test_tfile_write) {
|
|||
|
||||
std::string colName("voltage");
|
||||
std::string colVal("ab");
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexTermQuery query = { term, QUERY_TERM};
|
||||
SIndexTermQuery query = {term, QUERY_TERM};
|
||||
|
||||
SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t));
|
||||
fObj->Get(&query, result);
|
||||
|
@ -557,7 +557,7 @@ TEST_F(IndexCacheEnv, cache_test) {
|
|||
std::string colName("voltage");
|
||||
{
|
||||
std::string colVal("v1");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, colId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
|
@ -565,28 +565,28 @@ TEST_F(IndexCacheEnv, cache_test) {
|
|||
}
|
||||
{
|
||||
std::string colVal("v3");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, colId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
}
|
||||
{
|
||||
std::string colVal("v2");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, colId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
}
|
||||
{
|
||||
std::string colVal("v3");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, colId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
}
|
||||
{
|
||||
std::string colVal("v3");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, colId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
|
@ -595,14 +595,14 @@ TEST_F(IndexCacheEnv, cache_test) {
|
|||
std::cout << "--------first----------" << std::endl;
|
||||
{
|
||||
std::string colVal("v3");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, othColId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
}
|
||||
{
|
||||
std::string colVal("v4");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, othColId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
|
@ -613,7 +613,7 @@ TEST_F(IndexCacheEnv, cache_test) {
|
|||
std::string colVal("v4");
|
||||
for (size_t i = 0; i < 10; i++) {
|
||||
colVal[colVal.size() - 1] = 'a' + i;
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
coj->Put(term, colId, version++, suid++);
|
||||
indexTermDestroy(term);
|
||||
|
@ -623,9 +623,9 @@ TEST_F(IndexCacheEnv, cache_test) {
|
|||
// begin query
|
||||
{
|
||||
std::string colVal("v3");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexTermQuery query = { term, QUERY_TERM };
|
||||
SIndexTermQuery query = {term, QUERY_TERM};
|
||||
SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid));
|
||||
STermValueType valType;
|
||||
|
||||
|
@ -638,9 +638,9 @@ TEST_F(IndexCacheEnv, cache_test) {
|
|||
}
|
||||
{
|
||||
std::string colVal("v2");
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexTermQuery query = { term, QUERY_TERM };
|
||||
SIndexTermQuery query = {term, QUERY_TERM};
|
||||
SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid));
|
||||
STermValueType valType;
|
||||
|
||||
|
@ -670,7 +670,7 @@ class IndexObj {
|
|||
return ret;
|
||||
}
|
||||
void Del(const std::string& colName, const std::string& colVal, uint64_t uid) {
|
||||
SIndexTerm* term = indexTermCreate(0, DEL_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, DEL_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
@ -679,7 +679,7 @@ class IndexObj {
|
|||
}
|
||||
int WriteMillonData(const std::string& colName, const std::string& colVal = "Hello world",
|
||||
size_t numOfTable = 100 * 10000) {
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
@ -701,7 +701,7 @@ class IndexObj {
|
|||
// opt
|
||||
tColVal[taosRand() % colValSize] = 'a' + k % 26;
|
||||
}
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
tColVal.c_str(), tColVal.size());
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
@ -737,7 +737,7 @@ class IndexObj {
|
|||
|
||||
int SearchOne(const std::string& colName, const std::string& colVal) {
|
||||
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
indexMultiTermQueryAdd(mq, term, QUERY_TERM);
|
||||
|
||||
|
@ -759,7 +759,7 @@ class IndexObj {
|
|||
}
|
||||
int SearchOneTarget(const std::string& colName, const std::string& colVal, uint64_t val) {
|
||||
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
indexMultiTermQueryAdd(mq, term, QUERY_TERM);
|
||||
|
||||
|
@ -784,7 +784,7 @@ class IndexObj {
|
|||
|
||||
void PutOne(const std::string& colName, const std::string& colVal) {
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
indexMultiTermAdd(terms, term);
|
||||
Put(terms, 10);
|
||||
|
@ -792,7 +792,7 @@ class IndexObj {
|
|||
}
|
||||
void PutOneTarge(const std::string& colName, const std::string& colVal, uint64_t val) {
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
indexMultiTermAdd(terms, term);
|
||||
Put(terms, val);
|
||||
|
@ -832,7 +832,7 @@ TEST_F(IndexEnv2, testIndexOpen) {
|
|||
{
|
||||
std::string colName("tag1"), colVal("Hello");
|
||||
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
@ -847,7 +847,7 @@ TEST_F(IndexEnv2, testIndexOpen) {
|
|||
size_t size = 200;
|
||||
std::string colName("tag1"), colVal("hello");
|
||||
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
@ -862,7 +862,7 @@ TEST_F(IndexEnv2, testIndexOpen) {
|
|||
size_t size = 200;
|
||||
std::string colName("tag1"), colVal("Hello");
|
||||
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
@ -877,7 +877,7 @@ TEST_F(IndexEnv2, testIndexOpen) {
|
|||
{
|
||||
std::string colName("tag1"), colVal("Hello");
|
||||
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
indexMultiTermQueryAdd(mq, term, QUERY_TERM);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(JsonEnv, testWrite) {
|
|||
{
|
||||
std::string colName("test");
|
||||
std::string colVal("ab");
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
|
@ -53,7 +53,7 @@ TEST_F(JsonEnv, testWrite) {
|
|||
{
|
||||
std::string colName("voltage");
|
||||
std::string colVal("ab1");
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
|
@ -66,7 +66,7 @@ TEST_F(JsonEnv, testWrite) {
|
|||
{
|
||||
std::string colName("voltage");
|
||||
std::string colVal("123");
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
|
@ -81,7 +81,7 @@ TEST_F(JsonEnv, testWrite) {
|
|||
std::string colVal("ab");
|
||||
|
||||
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
|
||||
SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* q = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SArray* result = taosArrayInit(1, sizeof(uint64_t));
|
||||
|
@ -95,7 +95,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
{
|
||||
std::string colName("test");
|
||||
std::string colVal("ab");
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
|
@ -110,7 +110,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
std::string colVal("abxxxxxxxxxxxx");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
colVal[i % colVal.size()] = '0' + i % 128;
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
|
@ -124,7 +124,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
{
|
||||
std::string colName("voltagefdadfa");
|
||||
std::string colVal("abxxxxxxxxxxxx");
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
|
@ -139,7 +139,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
std::string colVal("ab");
|
||||
|
||||
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
|
||||
SIndexTerm* q = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
SIndexTerm* q = indexTermCreate(1, ADD_VALUE, 0, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SArray* result = taosArrayInit(1, sizeof(uint64_t));
|
||||
|
|
|
@ -1521,7 +1521,7 @@ static int32_t physiFillNodeToJson(const void* pObj, SJson* pJson) {
|
|||
static int32_t jsonToPhysiFillNode(const SJson* pJson, void* pObj) {
|
||||
SFillPhysiNode* pNode = (SFillPhysiNode*)pObj;
|
||||
|
||||
int32_t code = jsonToPhysiWindowNode(pJson, pObj);
|
||||
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkFillPhysiPlanMode, pNode->mode);
|
||||
}
|
||||
|
|
|
@ -945,7 +945,8 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType, int8_t ex
|
|||
|
||||
code = qStringToSubplan(qwMsg->msg, &plan);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
QW_TASK_ELOG("task string to subplan failed, code:%x - %s", code, tstrerror(code));
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
QW_TASK_ELOG("task physical plan to subplan failed, code:%x - %s", code, tstrerror(code));
|
||||
QW_ERR_JRET(code);
|
||||
}
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_RETRIEVE, "Invalid func retrieve
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_ALREADY_EXIST, "Transaction already exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_EXIST, "Transaction not exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_INVALID_STAGE, "Invalid stage to kill")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CANT_PARALLEL, "Invalid stage to kill")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CAN_NOT_PARALLEL, "Conflicting transaction not completed")
|
||||
|
||||
// mnode-mq
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOPIC_ALREADY_EXIST, "Topic already exists")
|
||||
|
|
Loading…
Reference in New Issue