Merge remote-tracking branch 'origin/3.0' into feature/3.0_liaohj
This commit is contained in:
commit
842b75cd9d
|
@ -7,7 +7,7 @@ project(
|
|||
)
|
||||
|
||||
if (NOT DEFINED TD_SOURCE_DIR)
|
||||
set( TD_SOURCE_DIR ${CMAKE_SOURCE_DIR} )
|
||||
set( TD_SOURCE_DIR ${PROJECT_SOURCE_DIR} )
|
||||
endif()
|
||||
|
||||
set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake")
|
||||
|
|
|
@ -60,7 +60,6 @@ int32_t init_env() {
|
|||
pRes =
|
||||
taos_query(pConn, "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags(t1 int)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
assert(0);
|
||||
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
|
@ -104,8 +103,8 @@ int32_t create_topic() {
|
|||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
/*pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");*/
|
||||
pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");
|
||||
pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");
|
||||
/*pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");*/
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
@ -163,9 +162,10 @@ tmq_t* build_consumer() {
|
|||
tmq_conf_set(conf, "group.id", "tg2");
|
||||
tmq_conf_set(conf, "td.connect.user", "root");
|
||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||
tmq_conf_set(conf, "td.connect.db", "abc1");
|
||||
/*tmq_conf_set(conf, "td.connect.db", "abc1");*/
|
||||
tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print);
|
||||
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
|
||||
assert(tmq);
|
||||
return tmq;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX)
|
||||
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
ADD_EXECUTABLE(demo apitest.c)
|
||||
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
|
||||
|
@ -13,7 +13,7 @@ IF (TD_LINUX)
|
|||
TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua)
|
||||
ENDIF ()
|
||||
IF (TD_DARWIN)
|
||||
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
ADD_EXECUTABLE(demo demo.c)
|
||||
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua)
|
||||
|
|
|
@ -234,7 +234,7 @@ DLL_EXPORT tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errst
|
|||
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
||||
|
||||
/* ------------------------TMQ CONSUMER INTERFACE------------------------ */
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, tmq_list_t *topic_list);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
|
||||
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t blocking_time);
|
||||
|
|
|
@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[];
|
|||
|
||||
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||
const char *apolloUrl, SArray *pArgs, bool tsc);
|
||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc);
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile,
|
||||
char *apolloUrl, SArray *pArgs, bool tsc);
|
||||
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc);
|
||||
void taosCleanupCfg();
|
||||
void taosCfgDynamicOptions(const char *option, const char *value);
|
||||
void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary);
|
||||
|
|
|
@ -229,6 +229,14 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t totalLen;
|
||||
int32_t len;
|
||||
// head of SSubmitBlk
|
||||
// int64_t uid; // table unique id
|
||||
// int64_t suid; // stable id
|
||||
// int32_t sversion; // data schema version
|
||||
// int32_t dataLen; // data part length, not including the SSubmitBlk head
|
||||
// int32_t schemaLen; // schema length, if length is 0, no schema exists
|
||||
// int16_t numOfRows; // total number of rows in current submit block
|
||||
// head of SSubmitBlk
|
||||
const void* pMsg;
|
||||
} SSubmitMsgIter;
|
||||
|
||||
|
@ -237,6 +245,15 @@ int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
|||
int32_t tInitSubmitBlkIter(SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
||||
|
||||
// TODO: KEEP one suite of iterator API finally.
|
||||
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
|
||||
// int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
|
||||
// int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||
// int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||
// STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter);
|
||||
|
||||
typedef struct {
|
||||
int32_t index; // index of failed block in submit blocks
|
||||
int32_t vnode; // vnode index of failed block
|
||||
|
@ -275,7 +292,6 @@ typedef struct {
|
|||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t igExists;
|
||||
float xFilesFactor;
|
||||
int32_t aggregationMethod;
|
||||
int32_t delay;
|
||||
int32_t ttl;
|
||||
int32_t numOfColumns;
|
||||
|
@ -1316,7 +1332,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int64_t consumerId;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
SArray* topicNames; // SArray<char*>
|
||||
SArray* topicNames; // SArray<char**>
|
||||
} SCMSubscribeReq;
|
||||
|
||||
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
|
||||
|
@ -1495,10 +1511,8 @@ typedef struct {
|
|||
int32_t delay;
|
||||
int32_t qmsg1Len;
|
||||
int32_t qmsg2Len;
|
||||
func_id_t* pFuncIds;
|
||||
char* qmsg1; // not null: pAst1:qmsg1:SRetention1 => trigger aggr task1
|
||||
char* qmsg2; // not null: pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||
int8_t nFuncIds;
|
||||
char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1
|
||||
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||
} SRSmaParam;
|
||||
|
||||
typedef struct SVCreateTbReq {
|
||||
|
@ -2052,80 +2066,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int64_t leftForVer;
|
||||
int32_t vgId;
|
||||
int32_t epoch;
|
||||
int64_t consumerId;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
} SMqCancelConnReq;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqCancelConnReq(void** buf, const SMqCancelConnReq* pReq) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pReq->leftForVer);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->vgId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->epoch);
|
||||
tlen += taosEncodeFixedI64(buf, pReq->consumerId);
|
||||
tlen += taosEncodeString(buf, pReq->topicName);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqCancelConnReq(void* buf, SMqCancelConnReq* pReq) {
|
||||
buf = taosDecodeFixedI64(buf, &pReq->leftForVer);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->vgId);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->epoch);
|
||||
buf = taosDecodeFixedI64(buf, &pReq->consumerId);
|
||||
buf = taosDecodeStringTo(buf, pReq->topicName);
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int8_t reserved;
|
||||
} SMqCancelConnRsp;
|
||||
|
||||
typedef struct {
|
||||
int64_t leftForVer;
|
||||
int32_t vgId;
|
||||
int64_t oldConsumerId;
|
||||
int64_t newConsumerId;
|
||||
char* topic;
|
||||
} SMqMVRebReq;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqMVRebReq(void** buf, const SMqMVRebReq* pReq) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pReq->leftForVer);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->vgId);
|
||||
tlen += taosEncodeFixedI64(buf, pReq->oldConsumerId);
|
||||
tlen += taosEncodeFixedI64(buf, pReq->newConsumerId);
|
||||
tlen += taosEncodeString(buf, pReq->topic);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqMVRebReq(void* buf, SMqMVRebReq* pReq) {
|
||||
buf = taosDecodeFixedI64(buf, &pReq->leftForVer);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->vgId);
|
||||
buf = taosDecodeFixedI64(buf, &pReq->oldConsumerId);
|
||||
buf = taosDecodeFixedI64(buf, &pReq->newConsumerId);
|
||||
buf = taosDecodeString(buf, &pReq->topic);
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SMsgHead header;
|
||||
int32_t vgId;
|
||||
int64_t consumerId;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
} SMqSetCVgRsp;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead header;
|
||||
int32_t vgId;
|
||||
int64_t consumerId;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
} SMqMVRebRsp;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int64_t offset;
|
||||
|
@ -2152,6 +2092,24 @@ typedef struct {
|
|||
SSchema* pSchema;
|
||||
} SSchemaWrapper;
|
||||
|
||||
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||
if (pSW == NULL) return pSW;
|
||||
pSW->nCols = pSchemaWrapper->nCols;
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
taosMemoryFree(pSW);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
|
||||
return pSW;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
|
||||
taosMemoryFree(pSchemaWrapper->pSchema);
|
||||
taosMemoryFree(pSchemaWrapper);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||
|
@ -2162,13 +2120,13 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema
|
|||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) {
|
||||
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->flags);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||
return buf;
|
||||
return (void*)buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) {
|
||||
|
@ -2198,7 +2156,7 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr
|
|||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
|
||||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
|
||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
|
@ -2208,7 +2166,7 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pS
|
|||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
|
||||
}
|
||||
return buf;
|
||||
return (void*)buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||
|
@ -2615,6 +2573,10 @@ static FORCE_INLINE int32_t tEncodeSMqDataBlkRsp(void** buf, const SMqDataBlkRsp
|
|||
void* data = taosArrayGetP(pRsp->blockData, i);
|
||||
tlen += taosEncodeFixedI32(buf, bLen);
|
||||
tlen += taosEncodeBinary(buf, data, bLen);
|
||||
if (pRsp->withSchema) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pRsp->blockSchema, i);
|
||||
tlen += taosEncodeSSchemaWrapper(buf, pSW);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tlen;
|
||||
|
@ -2627,6 +2589,7 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p
|
|||
buf = taosDecodeFixedI32(buf, &pRsp->blockNum);
|
||||
pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||
pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||
pRsp->blockSchema = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||
if (pRsp->blockNum != 0) {
|
||||
buf = taosDecodeFixedI8(buf, &pRsp->withTbName);
|
||||
buf = taosDecodeFixedI8(buf, &pRsp->withSchema);
|
||||
|
@ -2639,6 +2602,11 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p
|
|||
buf = taosDecodeBinary(buf, &data, bLen);
|
||||
taosArrayPush(pRsp->blockDataLen, &bLen);
|
||||
taosArrayPush(pRsp->blockData, &data);
|
||||
if (pRsp->withSchema) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||
buf = taosDecodeSSchemaWrapper(buf, pSW);
|
||||
taosArrayPush(pRsp->blockSchema, &pSW);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (void*)buf;
|
||||
|
|
|
@ -145,7 +145,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-get-sub-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-mq-ask-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mnode-mq-consumer-lost", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg)
|
||||
|
|
|
@ -322,6 +322,20 @@ struct SUdfInfo;
|
|||
void qAddUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
||||
void qRemoveUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
||||
|
||||
/**
|
||||
* create udfd proxy, called once in process that call setupUdf/callUdfxxx/teardownUdf
|
||||
* @return error code
|
||||
*/
|
||||
int32_t udfcOpen();
|
||||
|
||||
/**
|
||||
* destroy udfd proxy
|
||||
* @return error code
|
||||
*/
|
||||
int32_t udfcClose();
|
||||
|
||||
typedef void *UdfcFuncHandle;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -125,15 +125,15 @@ typedef struct SFmGetFuncInfoParam {
|
|||
struct SCatalog* pCtg;
|
||||
void *pRpc;
|
||||
const SEpSet* pMgmtEps;
|
||||
char* pErrBuf;
|
||||
int32_t errBufLen;
|
||||
} SFmGetFuncInfoParam;
|
||||
|
||||
int32_t fmFuncMgtInit();
|
||||
|
||||
void fmFuncMgtDestroy();
|
||||
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType);
|
||||
|
||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc);
|
||||
|
||||
bool fmIsAggFunc(int32_t funcId);
|
||||
bool fmIsScalarFunc(int32_t funcId);
|
||||
|
|
|
@ -25,8 +25,10 @@ extern "C" {
|
|||
#include "tvariant.h"
|
||||
|
||||
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
|
||||
#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
||||
#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||
#define TABLE_META_SIZE(pMeta) \
|
||||
(NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
||||
#define VGROUPS_INFO_SIZE(pInfo) \
|
||||
(NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||
|
||||
typedef struct SRawExprNode {
|
||||
ENodeType nodeType;
|
||||
|
@ -46,13 +48,10 @@ typedef struct SExprNode {
|
|||
ENodeType type;
|
||||
SDataType resType;
|
||||
char aliasName[TSDB_COL_NAME_LEN];
|
||||
SNodeList* pAssociationList;
|
||||
SArray* pAssociation;
|
||||
} SExprNode;
|
||||
|
||||
typedef enum EColumnType {
|
||||
COLUMN_TYPE_COLUMN = 1,
|
||||
COLUMN_TYPE_TAG
|
||||
} EColumnType;
|
||||
typedef enum EColumnType { COLUMN_TYPE_COLUMN = 1, COLUMN_TYPE_TAG } EColumnType;
|
||||
|
||||
typedef struct SColumnNode {
|
||||
SExprNode node; // QUERY_NODE_COLUMN
|
||||
|
@ -81,7 +80,6 @@ typedef struct SValueNode {
|
|||
char* literal;
|
||||
bool isDuration;
|
||||
bool translate;
|
||||
bool genByCalc;
|
||||
int16_t placeholderNo;
|
||||
union {
|
||||
bool b;
|
||||
|
@ -100,7 +98,6 @@ typedef struct SOperatorNode {
|
|||
SNode* pRight;
|
||||
} SOperatorNode;
|
||||
|
||||
|
||||
typedef struct SLogicConditionNode {
|
||||
SExprNode node; // QUERY_NODE_LOGIC_CONDITION
|
||||
ELogicConditionType condType;
|
||||
|
@ -119,6 +116,7 @@ typedef struct SFunctionNode {
|
|||
int32_t funcId;
|
||||
int32_t funcType;
|
||||
SNodeList* pParameterList;
|
||||
int32_t udfBufSize;
|
||||
} SFunctionNode;
|
||||
|
||||
typedef struct STableNode {
|
||||
|
@ -135,7 +133,7 @@ typedef struct SRealTableNode {
|
|||
STableNode table; // QUERY_NODE_REAL_TABLE
|
||||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
char useDbName[TSDB_DB_NAME_LEN];
|
||||
char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
|
||||
double ratio;
|
||||
} SRealTableNode;
|
||||
|
||||
|
@ -144,9 +142,7 @@ typedef struct STempTableNode {
|
|||
SNode* pSubquery;
|
||||
} STempTableNode;
|
||||
|
||||
typedef enum EJoinType {
|
||||
JOIN_TYPE_INNER = 1
|
||||
} EJoinType;
|
||||
typedef enum EJoinType { JOIN_TYPE_INNER = 1 } EJoinType;
|
||||
|
||||
typedef struct SJoinTableNode {
|
||||
STableNode table; // QUERY_NODE_JOIN_TABLE
|
||||
|
@ -156,9 +152,7 @@ typedef struct SJoinTableNode {
|
|||
SNode* pOnCond;
|
||||
} SJoinTableNode;
|
||||
|
||||
typedef enum EGroupingSetType {
|
||||
GP_TYPE_NORMAL = 1
|
||||
} EGroupingSetType;
|
||||
typedef enum EGroupingSetType { GP_TYPE_NORMAL = 1 } EGroupingSetType;
|
||||
|
||||
typedef struct SGroupingSetNode {
|
||||
ENodeType type; // QUERY_NODE_GROUPING_SET
|
||||
|
@ -166,16 +160,9 @@ typedef struct SGroupingSetNode {
|
|||
SNodeList* pParameterList;
|
||||
} SGroupingSetNode;
|
||||
|
||||
typedef enum EOrder {
|
||||
ORDER_ASC = 1,
|
||||
ORDER_DESC
|
||||
} EOrder;
|
||||
typedef enum EOrder { ORDER_ASC = 1, ORDER_DESC } EOrder;
|
||||
|
||||
typedef enum ENullOrder {
|
||||
NULL_ORDER_DEFAULT = 1,
|
||||
NULL_ORDER_FIRST,
|
||||
NULL_ORDER_LAST
|
||||
} ENullOrder;
|
||||
typedef enum ENullOrder { NULL_ORDER_DEFAULT = 1, NULL_ORDER_FIRST, NULL_ORDER_LAST } ENullOrder;
|
||||
|
||||
typedef struct SOrderByExprNode {
|
||||
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
||||
|
@ -242,12 +229,10 @@ typedef struct SSelectStmt {
|
|||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
bool isEmptyResult;
|
||||
bool hasAggFuncs;
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType {
|
||||
SET_OP_TYPE_UNION_ALL = 1,
|
||||
SET_OP_TYPE_UNION
|
||||
} ESetOperatorType;
|
||||
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||
|
||||
typedef struct SSetOperator {
|
||||
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
||||
|
@ -271,7 +256,6 @@ typedef enum ESqlClause {
|
|||
SQL_CLAUSE_ORDER_BY
|
||||
} ESqlClause;
|
||||
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
PAYLOAD_TYPE_RAW = 1,
|
||||
|
|
|
@ -573,7 +573,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602)
|
||||
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
|
||||
#define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||
#define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605)
|
||||
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608)
|
||||
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609)
|
||||
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
|
||||
|
@ -633,6 +632,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
|
||||
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
|
||||
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803)
|
||||
#define TSDB_CODE_FUNC_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef enum {
|
|||
CFG_STYPE_CFG_FILE,
|
||||
CFG_STYPE_ENV_FILE,
|
||||
CFG_STYPE_ENV_VAR,
|
||||
CFG_STYPE_ENV_CMD,
|
||||
CFG_STYPE_APOLLO_URL,
|
||||
CFG_STYPE_ARG_LIST,
|
||||
CFG_STYPE_TAOS_OPTIONS
|
||||
|
@ -82,7 +83,7 @@ typedef struct SConfig {
|
|||
} SConfig;
|
||||
|
||||
SConfig *cfgInit();
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr);
|
||||
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
||||
void cfgCleanup(SConfig *pCfg);
|
||||
|
||||
|
@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type);
|
|||
|
||||
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
|
||||
|
||||
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_ENV_H_
|
||||
#define _TD_ENV_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen);
|
||||
int32_t taosEnvToCfg(const char *envStr, char *cfgStr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_ENV_H_*/
|
|
@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
|
|||
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
|
||||
|
||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
|
||||
int32_t tjsonGetObjectName(const SJson* pJson, char** pName);
|
||||
int32_t tjsonGetObjectValueString(const SJson* pJson, char** pStringValue);
|
||||
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
|
||||
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
|
||||
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
|
||||
|
@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson);
|
|||
|
||||
SJson* tjsonParse(const char* pStr);
|
||||
bool tjsonValidateJson(const char* pJson);
|
||||
const char* tjsonGetError();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -41,10 +41,6 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void *param, void *han
|
|||
|
||||
void taosTmrCleanUp(void *handle);
|
||||
|
||||
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
|
||||
|
||||
void taosUninitTimer();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -231,6 +231,10 @@ static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool conver
|
|||
msg->resIter++;
|
||||
if (msg->resIter < msg->rsp.blockNum) {
|
||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(msg->rsp.blockData, msg->resIter);
|
||||
if (msg->rsp.withSchema) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(msg->rsp.blockSchema, msg->resIter);
|
||||
setResSchemaInfo(&msg->resInfo, pSW->pSchema, pSW->nCols);
|
||||
}
|
||||
setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4);
|
||||
return &msg->resInfo;
|
||||
}
|
||||
|
|
|
@ -254,12 +254,12 @@ void taos_init_imp(void) {
|
|||
|
||||
deltaToUtcInitOnce();
|
||||
|
||||
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) {
|
||||
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) {
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
*/
|
||||
|
||||
#include "catalog.h"
|
||||
#include "scheduler.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "scheduler.h"
|
||||
#include "trpc.h"
|
||||
|
||||
static SClientHbMgr clientHbMgr = {0};
|
||||
|
@ -110,7 +110,8 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
|||
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||
SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pRsp->connKey, sizeof(SClientHbKey));
|
||||
if (NULL == info) {
|
||||
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid, pRsp->connKey.connType);
|
||||
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid,
|
||||
pRsp->connKey.connType);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -641,7 +642,6 @@ void appHbMgrCleanup(void) {
|
|||
taosHashCleanup(pTarget->activeInfo);
|
||||
pTarget->activeInfo = NULL;
|
||||
|
||||
|
||||
pIter = taosHashIterate(pTarget->connInfo, NULL);
|
||||
while (pIter != NULL) {
|
||||
SHbConnInfo *info = pIter;
|
||||
|
@ -668,7 +668,7 @@ int hbMgrInit() {
|
|||
hbMgrInitHandle();
|
||||
|
||||
// init backgroud thread
|
||||
//hbCreateThread();
|
||||
/*hbCreateThread();*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -226,16 +226,14 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
|
||||
pRequest->type = pQuery->msgType;
|
||||
SPlanContext cxt = {
|
||||
.queryId = pRequest->requestId,
|
||||
SPlanContext cxt = {.queryId = pRequest->requestId,
|
||||
.acctId = pRequest->pTscObj->acctId,
|
||||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||
.pAstRoot = pQuery->pRoot,
|
||||
.showRewrite = pQuery->showRewrite,
|
||||
.pTransporter = pRequest->pTscObj->pAppInfo->pTransporter,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE
|
||||
};
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE};
|
||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
||||
|
@ -247,6 +245,7 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
|||
ASSERT(pSchema != NULL && numOfCols > 0);
|
||||
|
||||
pResInfo->numOfCols = numOfCols;
|
||||
// TODO handle memory leak
|
||||
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||
pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ const char *taos_errstr(TAOS_RES *res) {
|
|||
return (const char *)tstrerror(terrno);
|
||||
}
|
||||
|
||||
if (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) {
|
||||
if (NULL != pRequest->msgBuf && (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR)) {
|
||||
return pRequest->msgBuf;
|
||||
} else {
|
||||
return (const char *)tstrerror(pRequest->code);
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include "tmsgtype.h"
|
||||
#include "tqueue.h"
|
||||
#include "tref.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
int32_t tmqAskEp(tmq_t* tmq, bool sync);
|
||||
|
||||
typedef struct {
|
||||
int8_t tmqRspType;
|
||||
|
@ -61,29 +64,40 @@ struct tmq_conf_t {
|
|||
tmq_commit_cb* commit_cb;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int8_t inited;
|
||||
tmr_h timer;
|
||||
} SMqMgmt;
|
||||
|
||||
static SMqMgmt tmqMgmt = {0};
|
||||
|
||||
struct tmq_t {
|
||||
// conf
|
||||
char groupId[TSDB_CGROUP_LEN];
|
||||
char clientId[256];
|
||||
int8_t autoCommit;
|
||||
/*int8_t inWaiting;*/
|
||||
int64_t consumerId;
|
||||
int32_t epoch;
|
||||
int32_t resetOffsetCfg;
|
||||
int64_t status;
|
||||
STscObj* pTscObj;
|
||||
tmq_commit_cb* commit_cb;
|
||||
/*int32_t nextTopicIdx;*/
|
||||
|
||||
// status
|
||||
int8_t status;
|
||||
int8_t epStatus;
|
||||
int32_t epoch;
|
||||
int32_t epSkipCnt;
|
||||
/*int32_t waitingRequest;*/
|
||||
/*int32_t readyRequest;*/
|
||||
SArray* clientTopics; // SArray<SMqClientTopic>
|
||||
STaosQueue* mqueue; // queue of tmq_message_t
|
||||
STaosQall* qall;
|
||||
tsem_t rspSem;
|
||||
// stat
|
||||
int64_t pollCnt;
|
||||
|
||||
// connection
|
||||
STscObj* pTscObj;
|
||||
|
||||
// container
|
||||
SArray* clientTopics; // SArray<SMqClientTopic>
|
||||
STaosQueue* mqueue; // queue of rsp
|
||||
STaosQall* qall;
|
||||
STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit
|
||||
|
||||
// ctl
|
||||
tsem_t rspSem;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -93,6 +107,7 @@ enum {
|
|||
|
||||
enum {
|
||||
TMQ_CONSUMER_STATUS__INIT = 0,
|
||||
TMQ_CONSUMER_STATUS__SUBSCRIBED,
|
||||
TMQ_CONSUMER_STATUS__READY,
|
||||
};
|
||||
|
||||
|
@ -110,13 +125,11 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
// subscribe info
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
char* topicName;
|
||||
int64_t topicId;
|
||||
|
||||
SArray* vgs; // SArray<SMqClientVg>
|
||||
|
||||
int8_t isSchemaAdaptive;
|
||||
int32_t numOfFields;
|
||||
SSchemaWrapper schema;
|
||||
} SMqClientTopic;
|
||||
|
||||
|
@ -156,7 +169,6 @@ typedef struct {
|
|||
int32_t async;
|
||||
tsem_t rspSem;
|
||||
tmq_resp_err_t rspErr;
|
||||
/*SMqClientVg* pVg;*/
|
||||
} SMqCommitCbParam;
|
||||
|
||||
tmq_conf_t* tmq_conf_new() {
|
||||
|
@ -251,13 +263,7 @@ int32_t tmq_list_append(tmq_list_t* list, const char* src) {
|
|||
|
||||
void tmq_list_destroy(tmq_list_t* list) {
|
||||
SArray* container = &list->container;
|
||||
/*taosArrayDestroy(container);*/
|
||||
int32_t sz = taosArrayGetSize(container);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char* str = taosArrayGetP(container, i);
|
||||
taosMemoryFree(str);
|
||||
}
|
||||
taosArrayDestroy(container);
|
||||
taosArrayDestroyP(container, taosMemoryFree);
|
||||
}
|
||||
|
||||
int32_t tmq_list_get_size(const tmq_list_t* list) {
|
||||
|
@ -298,6 +304,8 @@ void tmqClearUnhandleMsg(tmq_t* tmq) {
|
|||
int32_t tmqSubscribeCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SMqSubscribeCbParam* pParam = (SMqSubscribeCbParam*)param;
|
||||
pParam->rspErr = code;
|
||||
tmq_t* tmq = pParam->tmq;
|
||||
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__SUBSCRIBED);
|
||||
tsem_post(&pParam->rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
@ -335,12 +343,9 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs
|
|||
return NULL;
|
||||
}
|
||||
pTmq->pTscObj = (STscObj*)conn;
|
||||
/*pTmq->inWaiting = 0;*/
|
||||
pTmq->status = 0;
|
||||
pTmq->pollCnt = 0;
|
||||
pTmq->epoch = 0;
|
||||
/*pTmq->waitingRequest = 0;*/
|
||||
/*pTmq->readyRequest = 0;*/
|
||||
pTmq->epStatus = 0;
|
||||
pTmq->epSkipCnt = 0;
|
||||
// set conf
|
||||
|
@ -367,26 +372,45 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs
|
|||
#endif
|
||||
|
||||
tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||
// init timer
|
||||
int8_t inited = atomic_val_compare_exchange_8(&tmqMgmt.inited, 0, 1);
|
||||
if (inited == 0) {
|
||||
tmqMgmt.timer = taosTmrInit(1000, 100, 360000, "TMQ");
|
||||
if (tmqMgmt.timer == NULL) {
|
||||
atomic_store_8(&tmqMgmt.inited, 0);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t));
|
||||
if (pTmq == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* user = conf->user == NULL ? TSDB_DEFAULT_USER : conf->user;
|
||||
const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass;
|
||||
|
||||
ASSERT(user);
|
||||
ASSERT(pass);
|
||||
ASSERT(conf->db);
|
||||
ASSERT(conf->groupId[0]);
|
||||
|
||||
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, conf->db, conf->port, CONN_TYPE__TMQ);
|
||||
if (pTmq->pTscObj == NULL) return NULL;
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
pTmq->delayedTask = taosOpenQueue();
|
||||
|
||||
pTmq->status = 0;
|
||||
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL) {
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
// init status
|
||||
pTmq->status = TMQ_CONSUMER_STATUS__INIT;
|
||||
pTmq->pollCnt = 0;
|
||||
pTmq->epoch = 0;
|
||||
pTmq->epStatus = 0;
|
||||
pTmq->epSkipCnt = 0;
|
||||
|
||||
// set conf
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
strcpy(pTmq->groupId, conf->groupId);
|
||||
|
@ -394,19 +418,30 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
pTmq->commit_cb = conf->commit_cb;
|
||||
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||
|
||||
// assign consumerId
|
||||
pTmq->consumerId = tGenIdPI64();
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
if (pTmq->clientTopics == NULL) {
|
||||
taosMemoryFree(pTmq);
|
||||
return NULL;
|
||||
|
||||
// init semaphore
|
||||
if (tsem_init(&pTmq->rspSem, 0, 0) != 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
|
||||
tsem_init(&pTmq->rspSem, 0, 0);
|
||||
// init connection
|
||||
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, NULL, conf->port, CONN_TYPE__TMQ);
|
||||
if (pTmq->pTscObj == NULL) {
|
||||
tsem_destroy(&pTmq->rspSem);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
return pTmq;
|
||||
|
||||
FAIL:
|
||||
if (pTmq->clientTopics) taosArrayDestroy(pTmq->clientTopics);
|
||||
if (pTmq->mqueue) taosCloseQueue(pTmq->mqueue);
|
||||
if (pTmq->delayedTask) taosCloseQueue(pTmq->delayedTask);
|
||||
if (pTmq->qall) taosFreeQall(pTmq->qall);
|
||||
taosMemoryFree(pTmq);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int32_t async) {
|
||||
|
@ -497,86 +532,64 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in
|
|||
return resp;
|
||||
}
|
||||
|
||||
tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
||||
SRequestObj* pRequest = NULL;
|
||||
SArray* container = &topic_list->container;
|
||||
tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
||||
const SArray* container = &topic_list->container;
|
||||
int32_t sz = taosArrayGetSize(container);
|
||||
// destroy ex
|
||||
taosArrayDestroy(tmq->clientTopics);
|
||||
tmq->clientTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
||||
void* buf = NULL;
|
||||
SCMSubscribeReq req = {0};
|
||||
int32_t code = -1;
|
||||
|
||||
SCMSubscribeReq req;
|
||||
req.consumerId = tmq->consumerId;
|
||||
strcpy(req.cgroup, tmq->groupId);
|
||||
tstrncpy(req.cgroup, tmq->groupId, TSDB_CGROUP_LEN);
|
||||
req.topicNames = taosArrayInit(sz, sizeof(void*));
|
||||
if (req.topicNames == NULL) goto FAIL;
|
||||
|
||||
for (int i = 0; i < sz; i++) {
|
||||
/*char* topicName = topic_list->elems[i];*/
|
||||
char* topicName = taosArrayGetP(container, i);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char* topic = taosArrayGetP(container, i);
|
||||
|
||||
SName name = {0};
|
||||
#if 0
|
||||
char* dbName = getDbOfConnection(tmq->pTscObj);
|
||||
if (dbName == NULL) {
|
||||
return TMQ_RESP_ERR__FAIL;
|
||||
}
|
||||
#endif
|
||||
tNameSetDbName(&name, tmq->pTscObj->acctId, topicName, strlen(topicName));
|
||||
#if 0
|
||||
tNameFromString(&name, topicName, T_NAME_TABLE);
|
||||
#endif
|
||||
tNameSetDbName(&name, tmq->pTscObj->acctId, topic, strlen(topic));
|
||||
|
||||
char* topicFname = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN);
|
||||
if (topicFname == NULL) {
|
||||
goto _return;
|
||||
char* topicFName = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN);
|
||||
if (topicFName == NULL) {
|
||||
goto FAIL;
|
||||
}
|
||||
tNameExtractFullName(&name, topicFname);
|
||||
tscDebug("subscribe topic: %s", topicFname);
|
||||
SMqClientTopic topic = {
|
||||
.sql = NULL,
|
||||
.sqlLen = 0,
|
||||
.topicId = 0,
|
||||
.topicName = topicFname,
|
||||
.vgs = NULL,
|
||||
};
|
||||
topic.vgs = taosArrayInit(0, sizeof(SMqClientVg));
|
||||
taosArrayPush(tmq->clientTopics, &topic);
|
||||
taosArrayPush(req.topicNames, &topicFname);
|
||||
#if 0
|
||||
taosMemoryFree(dbName);
|
||||
#endif
|
||||
tNameExtractFullName(&name, topicFName);
|
||||
|
||||
tscDebug("subscribe topic: %s", topicFName);
|
||||
|
||||
taosArrayPush(req.topicNames, &topicFName);
|
||||
}
|
||||
|
||||
int tlen = tSerializeSCMSubscribeReq(NULL, &req);
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) {
|
||||
goto _return;
|
||||
}
|
||||
int32_t tlen = tSerializeSCMSubscribeReq(NULL, &req);
|
||||
buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) goto FAIL;
|
||||
|
||||
void* abuf = buf;
|
||||
tSerializeSCMSubscribeReq(&abuf, &req);
|
||||
/*printf("formatted: %s\n", dagStr);*/
|
||||
|
||||
pRequest = createRequest(tmq->pTscObj, NULL, NULL, TDMT_MND_SUBSCRIBE);
|
||||
if (pRequest == NULL) {
|
||||
tscError("failed to malloc request");
|
||||
}
|
||||
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) goto FAIL;
|
||||
|
||||
SMqSubscribeCbParam param = {
|
||||
.rspErr = TMQ_RESP_ERR__SUCCESS,
|
||||
.tmq = tmq,
|
||||
};
|
||||
tsem_init(¶m.rspSem, 0, 0);
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){
|
||||
if (tsem_init(¶m.rspSem, 0, 0) != 0) goto FAIL;
|
||||
|
||||
sendInfo->msgInfo = (SDataBuf){
|
||||
.pData = buf,
|
||||
.len = tlen,
|
||||
.handle = NULL,
|
||||
};
|
||||
|
||||
SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest);
|
||||
sendInfo->requestId = generateRequestId();
|
||||
sendInfo->requestObjRefId = 0;
|
||||
sendInfo->param = ¶m;
|
||||
sendInfo->fp = tmqSubscribeCb;
|
||||
sendInfo->msgType = TDMT_MND_SUBSCRIBE;
|
||||
|
||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
|
@ -585,15 +598,28 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
|||
tsem_wait(¶m.rspSem);
|
||||
tsem_destroy(¶m.rspSem);
|
||||
|
||||
_return:
|
||||
/*if (sendInfo != NULL) {*/
|
||||
/*destroySendMsgInfo(sendInfo);*/
|
||||
/*}*/
|
||||
code = param.rspErr;
|
||||
if (code != 0) goto FAIL;
|
||||
|
||||
return param.rspErr;
|
||||
// TODO: add max retry cnt
|
||||
while (TSDB_CODE_MND_CONSUMER_NOT_READY == tmqAskEp(tmq, true)) {
|
||||
tscDebug("not ready, retry\n");
|
||||
taosMsleep(500);
|
||||
}
|
||||
|
||||
void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) { conf->commit_cb = cb; }
|
||||
code = 0;
|
||||
FAIL:
|
||||
if (req.topicNames != NULL) taosArrayDestroyP(req.topicNames, taosMemoryFree);
|
||||
if (code != 0) {
|
||||
taosMemoryFree(buf);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) {
|
||||
//
|
||||
conf->commit_cb = cb;
|
||||
}
|
||||
|
||||
TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) {
|
||||
STscObj* pTscObj = (STscObj*)taos;
|
||||
|
@ -627,9 +653,6 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa
|
|||
int32_t code = 0;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, false, &pQueryNode, NULL), _return);
|
||||
|
||||
// todo check for invalid sql statement and return with error code
|
||||
|
||||
CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return);
|
||||
|
||||
/*printf("%s\n", pStr);*/
|
||||
|
@ -653,7 +676,6 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa
|
|||
}
|
||||
|
||||
tSerializeSCMCreateStreamReq(buf, tlen, &req);
|
||||
/*printf("formatted: %s\n", dagStr);*/
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){
|
||||
.pData = buf,
|
||||
|
@ -684,94 +706,6 @@ _return:
|
|||
return pRequest;
|
||||
}
|
||||
|
||||
#if 0
|
||||
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
||||
STscObj* pTscObj = (STscObj*)taos;
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQuery* pQueryNode = NULL;
|
||||
char* astStr = NULL;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
if (taos == NULL || topicName == NULL || sql == NULL) {
|
||||
tscError("invalid parameters for creating topic, connObj:%p, topic name:%s, sql:%s", taos, topicName, sql);
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (strlen(topicName) >= TSDB_TOPIC_NAME_LEN) {
|
||||
tscError("topic name too long, max length:%d", TSDB_TOPIC_NAME_LEN - 1);
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (sqlLen > TSDB_MAX_ALLOWED_SQL_LEN) {
|
||||
tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
|
||||
terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
tscDebug("start to create topic: %s", topicName);
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, true, &pQueryNode), _return);
|
||||
|
||||
// todo check for invalid sql statement and return with error code
|
||||
|
||||
CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return);
|
||||
|
||||
/*printf("%s\n", pStr);*/
|
||||
|
||||
SName name = {.acctId = pTscObj->acctId, .type = TSDB_TABLE_NAME_T};
|
||||
strcpy(name.dbname, pRequest->pDb);
|
||||
strcpy(name.tname, topicName);
|
||||
|
||||
SCMCreateTopicReq req = {
|
||||
.igExists = 1,
|
||||
.ast = astStr,
|
||||
.sql = (char*)sql,
|
||||
};
|
||||
tNameExtractFullName(&name, req.name);
|
||||
|
||||
int tlen = tSerializeSCMCreateTopicReq(NULL, 0, &req);
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
tSerializeSCMCreateTopicReq(buf, tlen, &req);
|
||||
/*printf("formatted: %s\n", dagStr);*/
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){
|
||||
.pData = buf,
|
||||
.len = tlen,
|
||||
.handle = NULL,
|
||||
};
|
||||
pRequest->type = TDMT_MND_CREATE_TOPIC;
|
||||
|
||||
SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest);
|
||||
SEpSet epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
|
||||
_return:
|
||||
taosMemoryFreeClear(astStr);
|
||||
qDestroyQuery(pQueryNode);
|
||||
/*if (sendInfo != NULL) {*/
|
||||
/*destroySendMsgInfo(sendInfo);*/
|
||||
/*}*/
|
||||
|
||||
if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
|
||||
if (tmq_message == NULL) return 0;
|
||||
|
@ -954,7 +888,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
/*printf("rsp epoch %ld sz %ld\n", rsp.epoch, rsp.topics->size);*/
|
||||
/*printf("tmq epoch %ld sz %ld\n", tmq->epoch, tmq->clientTopics->size);*/
|
||||
if (tmqUpdateEp(tmq, head->epoch, &rsp)) {
|
||||
atomic_store_64(&tmq->status, TMQ_CONSUMER_STATUS__READY);
|
||||
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__READY);
|
||||
}
|
||||
tDeleteSMqCMGetSubEpRsp(&rsp);
|
||||
} else {
|
||||
|
@ -1118,7 +1052,9 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
|||
|
||||
pRspObj->resInfo.totalRows = 0;
|
||||
pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI;
|
||||
if (!pWrapper->msg.withSchema) {
|
||||
setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
|
||||
}
|
||||
|
||||
taosFreeQitem(pWrapper);
|
||||
return pRspObj;
|
||||
|
@ -1187,7 +1123,6 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
|||
|
||||
int64_t transporterId = 0;
|
||||
/*printf("send poll\n");*/
|
||||
/*atomic_add_fetch_32(&tmq->waitingRequest, 1);*/
|
||||
tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId,
|
||||
pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId);
|
||||
/*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/
|
||||
|
@ -1266,12 +1201,14 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
|||
SMqRspObj* rspObj;
|
||||
int64_t startTime = taosGetTimestampMs();
|
||||
|
||||
// TODO: put into another thread or delayed queue
|
||||
int64_t status = atomic_load_64(&tmq->status);
|
||||
while (0 != tmqAskEp(tmq, status == TMQ_CONSUMER_STATUS__INIT)) {
|
||||
// TODO: put into delayed queue
|
||||
#if 0
|
||||
int8_t status = atomic_load_8(&tmq->status);
|
||||
while (0 != tmqAskEp(tmq, status != TMQ_CONSUMER_STATUS__READY)) {
|
||||
tscDebug("not ready, retry\n");
|
||||
taosSsleep(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
rspObj = tmqHandleAllRsp(tmq, blocking_time, false);
|
||||
if (rspObj) {
|
||||
|
@ -1279,7 +1216,6 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
|||
}
|
||||
|
||||
while (1) {
|
||||
/*printf("cycle\n");*/
|
||||
tmqAskEp(tmq, false);
|
||||
tmqPollImpl(tmq, blocking_time);
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() {
|
|||
return tsCfg;
|
||||
}
|
||||
|
||||
static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) {
|
||||
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) {
|
||||
char cfgDir[PATH_MAX] = {0};
|
||||
char cfgFile[PATH_MAX + 100] = {0};
|
||||
|
||||
|
@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
|||
tstrncpy(cfgFile, cfgDir, sizeof(cfgDir));
|
||||
}
|
||||
|
||||
if (apolloUrl == NULL || apolloUrl[0] == '\0') cfgGetApollUrl(envCmd, envFile, apolloUrl);
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
||||
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
|
||||
return -1;
|
||||
|
@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) {
|
||||
uError("failed to load from cmd env variables since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
|||
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1;
|
||||
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||
if (cfgAddInt64(pCfg, "totalMemory(KB)", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "pageSizeKB", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||
if (cfgAddInt64(pCfg, "totalMemoryKB", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
|
||||
|
@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||
const char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile,
|
||||
char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
|
@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
if (taosAddServerLogCfg(pCfg) != 0) return -1;
|
||||
}
|
||||
|
||||
if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
|
||||
if (taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||
uError("failed to load cfg since %s", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
|
@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
if (tsCfg != NULL) return 0;
|
||||
tsCfg = cfgInit();
|
||||
|
||||
|
@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
|||
}
|
||||
taosAddSystemCfg(tsCfg);
|
||||
|
||||
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) {
|
||||
if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||
uError("failed to load cfg since %s", terrstr());
|
||||
cfgCleanup(tsCfg);
|
||||
tsCfg = NULL;
|
||||
|
|
|
@ -93,7 +93,87 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
|||
return row;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// TODO: KEEP one suite of iterator API finally.
|
||||
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
|
||||
|
||||
int32_t tInitSubmitMsgIterEx(const SSubmitReq *pMsg, SSubmitMsgIter *pIter) {
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pIter->totalLen = htonl(pMsg->length);
|
||||
ASSERT(pIter->totalLen > 0);
|
||||
pIter->len = 0;
|
||||
pIter->pMsg = pMsg;
|
||||
if (pIter->totalLen <= sizeof(SSubmitReq)) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tGetSubmitMsgNextEx(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) {
|
||||
ASSERT(pIter->len >= 0);
|
||||
|
||||
if (pIter->len == 0) {
|
||||
pIter->len += sizeof(SSubmitReq);
|
||||
} else {
|
||||
if (pIter->len >= pIter->totalLen) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||
pIter->len += (sizeof(SSubmitBlk) + pIter->dataLen + pIter->schemaLen);
|
||||
ASSERT(pIter->len > 0);
|
||||
}
|
||||
|
||||
if (pIter->len > pIter->totalLen) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
*pPBlock = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pIter->len == pIter->totalLen) {
|
||||
*pPBlock = NULL;
|
||||
} else {
|
||||
*pPBlock = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||
pIter->uid = htobe64((*pPBlock)->uid);
|
||||
pIter->suid = htobe64((*pPBlock)->suid);
|
||||
pIter->sversion = htonl((*pPBlock)->sversion);
|
||||
pIter->dataLen = htonl((*pPBlock)->dataLen);
|
||||
pIter->schemaLen = htonl((*pPBlock)->schemaLen);
|
||||
pIter->numOfRows = htons((*pPBlock)->numOfRows);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tInitSubmitBlkIterEx(SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
|
||||
if (pMsgIter->dataLen <= 0) return -1;
|
||||
pIter->totalLen = pMsgIter->dataLen;
|
||||
pIter->len = 0;
|
||||
pIter->row = (STSRow *)(pBlock->data + pMsgIter->schemaLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
STSRow *tGetSubmitBlkNextEx(SSubmitBlkIter *pIter) {
|
||||
STSRow *row = pIter->row;
|
||||
|
||||
if (pIter->len >= pIter->totalLen) {
|
||||
return NULL;
|
||||
} else {
|
||||
pIter->len += TD_ROW_LEN(row);
|
||||
if (pIter->len < pIter->totalLen) {
|
||||
pIter->row = POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) {
|
||||
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
|
||||
|
@ -442,10 +522,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
|
||||
}
|
||||
tlen += taosEncodeFixedI32(buf, param->qmsg1Len);
|
||||
if (param->qmsg1Len > 0) {
|
||||
tlen += taosEncodeString(buf, param->qmsg1);
|
||||
|
@ -475,10 +551,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -521,13 +593,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||
buf = taosDecodeFixedI8(buf, ¶m->nFuncIds);
|
||||
if (param->nFuncIds > 0) {
|
||||
param->pFuncIds = (func_id_t *)taosMemoryCalloc(param->nFuncIds, sizeof(func_id_t));
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
|
||||
}
|
||||
}
|
||||
buf = taosDecodeFixedI32(buf, ¶m->qmsg1Len);
|
||||
if (param->qmsg1Len > 0) {
|
||||
buf = taosDecodeString(buf, ¶m->qmsg1);
|
||||
|
@ -561,15 +626,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||
buf = taosDecodeFixedI8(buf, ¶m->nFuncIds);
|
||||
if (param->nFuncIds > 0) {
|
||||
param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t));
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
|
||||
}
|
||||
} else {
|
||||
param->pFuncIds = NULL;
|
||||
}
|
||||
} else {
|
||||
pReq->ntbCfg.pRSmaParam = NULL;
|
||||
}
|
||||
|
@ -632,7 +688,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
|||
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
||||
if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->aggregationMethod) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->delay) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1;
|
||||
|
@ -687,7 +742,6 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
||||
if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->aggregationMethod) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1;
|
||||
|
|
|
@ -24,6 +24,7 @@ static struct {
|
|||
bool printVersion;
|
||||
char envFile[PATH_MAX];
|
||||
char apolloUrl[PATH_MAX];
|
||||
const char **envCmd;
|
||||
SArray *pArgs; // SConfigPair
|
||||
SDnode *pDnode;
|
||||
EDndNodeType ntype;
|
||||
|
@ -56,6 +57,9 @@ static void dmSetSignalHandle() {
|
|||
}
|
||||
|
||||
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||
int32_t cmdEnvIndex = 0;
|
||||
global.envCmd = taosMemoryMalloc(argc-1);
|
||||
memset(global.envCmd, 0, argc-1);
|
||||
for (int32_t i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
|
@ -70,7 +74,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
}
|
||||
} else if (strcmp(argv[i], "-a") == 0) {
|
||||
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
|
||||
} else if (strcmp(argv[i], "-e") == 0) {
|
||||
} else if (strcmp(argv[i], "-E") == 0) {
|
||||
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
||||
} else if (strcmp(argv[i], "-n") == 0) {
|
||||
global.ntype = atoi(argv[++i]);
|
||||
|
@ -84,6 +88,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
global.dumpConfig = true;
|
||||
} else if (strcmp(argv[i], "-V") == 0) {
|
||||
global.printVersion = true;
|
||||
} else if (strcmp(argv[i], "-e") == 0) {
|
||||
global.envCmd[cmdEnvIndex] = argv[++i];
|
||||
cmdEnvIndex++;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +136,7 @@ static SDnodeOpt dmGetOpt() {
|
|||
static int32_t dmInitLog() {
|
||||
char logName[12] = {0};
|
||||
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
|
||||
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
|
||||
return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0);
|
||||
}
|
||||
|
||||
static void dmSetProcInfo(int32_t argc, char **argv) {
|
||||
|
@ -168,6 +175,10 @@ static int32_t dmRunDnode() {
|
|||
return code;
|
||||
}
|
||||
|
||||
static void taosCleanupArgs() {
|
||||
if (global.envCmd != NULL) taosMemoryFree(global.envCmd);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
if (!taosCheckSystemIsSmallEnd()) {
|
||||
printf("failed to start since on non-small-end machines\n");
|
||||
|
@ -176,26 +187,31 @@ int main(int argc, char const *argv[]) {
|
|||
|
||||
if (dmParseArgs(argc, argv) != 0) {
|
||||
printf("failed to start since parse args error\n");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (global.generateGrant) {
|
||||
dmGenerateGrant();
|
||||
taosCleanupArgs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (global.printVersion) {
|
||||
dmPrintVersion();
|
||||
taosCleanupArgs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dmInitLog() != 0) {
|
||||
dError("failed to start since init log error");
|
||||
printf("failed to start since init log error");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
||||
if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
||||
dError("failed to start since read config error");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -203,9 +219,11 @@ int main(int argc, char const *argv[]) {
|
|||
dmDumpCfg();
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
dmSetProcInfo(argc, (char **)argv);
|
||||
taosCleanupArgs();
|
||||
return dmRunDnode();
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
|
|||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to lock file:%s since %s", filepath, terrstr());
|
||||
dError("failed to open file:%s since %s", filepath, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,17 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
code = vnodeStart(pImpl);
|
||||
if (code != 0) {
|
||||
tFreeSCreateVnodeReq(&createReq);
|
||||
dError("vgId:%d, failed to start sync since %s", createReq.vgId, terrstr());
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(path, pMgmt->pTfs);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
code = vmWriteVnodesToFile(pMgmt);
|
||||
if (code != 0) {
|
||||
tFreeSCreateVnodeReq(&createReq);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "vmInt.h"
|
||||
#include "libs/function/function.h"
|
||||
|
||||
SVnodeObj *vmAcquireVnode(SVnodesMgmt *pMgmt, int32_t vgId) {
|
||||
SVnodeObj *pVnode = NULL;
|
||||
|
@ -73,12 +74,6 @@ int32_t vmOpenVnode(SVnodesMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// sync integration
|
||||
vnodeSyncSetQ(pImpl, NULL);
|
||||
vnodeSyncSetRpc(pImpl, NULL);
|
||||
int32_t ret = vnodeSyncStart(pImpl);
|
||||
assert(ret == 0);
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
int32_t code = taosHashPut(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnodeObj *));
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
@ -152,6 +147,7 @@ static void *vmOpenVnodeFunc(void *param) {
|
|||
pThread->failed++;
|
||||
} else {
|
||||
vmOpenVnode(pMgmt, pCfg, pImpl);
|
||||
//vnodeStart(pImpl);
|
||||
dDebug("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
}
|
||||
|
@ -275,7 +271,7 @@ static void vmCleanup(SMgmtWrapper *pWrapper) {
|
|||
pWrapper->pMgmt = NULL;
|
||||
|
||||
// syncCleanUp();
|
||||
|
||||
udfcClose();
|
||||
dInfo("vnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
|
@ -339,6 +335,10 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) {
|
|||
}
|
||||
dmReportStartup(pDnode, "vnode-vnodes", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
dError("failed to open udfc in dnode");
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
@ -359,10 +359,52 @@ static int32_t vmRequire(SMgmtWrapper *pWrapper, bool *required) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vmStart(SMgmtWrapper *pWrapper) {
|
||||
dDebug("vnode-mgmt start to run");
|
||||
SVnodesMgmt *pMgmt = pWrapper->pMgmt;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
|
||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **ppVnode = pIter;
|
||||
if (ppVnode == NULL || *ppVnode == NULL) continue;
|
||||
|
||||
SVnodeObj *pVnode = *ppVnode;
|
||||
vnodeStart(pVnode->pImpl);
|
||||
pIter = taosHashIterate(pMgmt->hash, pIter);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vmStop(SMgmtWrapper *pWrapper) {
|
||||
#if 0
|
||||
dDebug("vnode-mgmt start to stop");
|
||||
SVnodesMgmt *pMgmt = pWrapper->pMgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
|
||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **ppVnode = pIter;
|
||||
if (ppVnode == NULL || *ppVnode == NULL) continue;
|
||||
|
||||
SVnodeObj *pVnode = *ppVnode;
|
||||
vnodeStop(pVnode->pImpl);
|
||||
pIter = taosHashIterate(pMgmt->hash, pIter);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = vmInit;
|
||||
mgmtFp.closeFp = vmCleanup;
|
||||
mgmtFp.startFp = vmStart;
|
||||
mgmtFp.stopFp = vmStop;
|
||||
mgmtFp.requiredFp = vmRequire;
|
||||
|
||||
vmInitMsgHandle(pWrapper);
|
||||
|
|
|
@ -350,7 +350,6 @@ typedef struct {
|
|||
int32_t version;
|
||||
int32_t nextColId;
|
||||
float xFilesFactor;
|
||||
int32_t aggregationMethod;
|
||||
int32_t delay;
|
||||
int32_t ttl;
|
||||
int32_t numOfColumns;
|
||||
|
|
|
@ -476,7 +476,10 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
SVgObj* pVgroup = NULL;
|
||||
SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||
SQueryPlan* pPlan = NULL;
|
||||
SSubplan* plan = NULL;
|
||||
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||
if (pPlan == NULL) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
|
@ -501,7 +504,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||
return -1;
|
||||
}
|
||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
}
|
||||
|
||||
int64_t unexistKey = -1;
|
||||
SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
||||
|
@ -519,38 +523,35 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
}
|
||||
|
||||
pSub->vgNum++;
|
||||
plan->execNode.nodeId = pVgroup->vgId;
|
||||
plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp));
|
||||
pVgEp->epSet = plan->execNode.epSet;
|
||||
pVgEp->vgId = plan->execNode.nodeId;
|
||||
|
||||
#if 0
|
||||
SMqConsumerEp consumerEp = {0};
|
||||
consumerEp.status = 0;
|
||||
consumerEp.consumerId = -1;
|
||||
consumerEp.epSet = plan->execNode.epSet;
|
||||
consumerEp.vgId = plan->execNode.nodeId;
|
||||
#endif
|
||||
pVgEp->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
pVgEp->vgId = pVgroup->vgId;
|
||||
taosArrayPush(pEpInSub->vgs, &pVgEp);
|
||||
|
||||
mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId);
|
||||
|
||||
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
int32_t msgLen;
|
||||
|
||||
plan->execNode.epSet = pVgEp->epSet;
|
||||
plan->execNode.nodeId = pVgEp->vgId;
|
||||
|
||||
if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(pEpInSub->vgs, &pVgEp);
|
||||
} else {
|
||||
pVgEp->qmsg = strdup("");
|
||||
}
|
||||
|
||||
ASSERT(taosHashGetSize(pSub->consumerHash) == 1);
|
||||
|
||||
/*taosArrayPush(pSub->unassignedVg, &consumerEp);*/
|
||||
}
|
||||
|
||||
ASSERT(pEpInSub->vgs->size > 0);
|
||||
pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
||||
|
||||
ASSERT(pEpInSub->vgs->size > 0);
|
||||
|
|
|
@ -87,7 +87,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pStb->version, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->aggregationMethod, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER)
|
||||
|
@ -175,7 +174,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
int32_t xFilesFactor = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER)
|
||||
pStb->xFilesFactor = xFilesFactor / 10000.0f;
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->aggregationMethod, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER)
|
||||
|
@ -404,7 +402,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
req.name = (char *)tNameGetTableName(&name);
|
||||
req.ttl = 0;
|
||||
req.keep = 0;
|
||||
req.rollup = pStb->aggregationMethod > -1 ? 1 : 0;
|
||||
req.rollup = pStb->pAst1 > 0 ? 1 : 0;
|
||||
req.type = TD_SUPER_TABLE;
|
||||
req.stbCfg.suid = pStb->uid;
|
||||
req.stbCfg.nCols = pStb->numOfColumns;
|
||||
|
@ -433,29 +431,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
|
||||
pRSmaParam->xFilesFactor = pStb->xFilesFactor;
|
||||
pRSmaParam->delay = pStb->delay;
|
||||
pRSmaParam->nFuncIds = 1; // only 1 aggregation method supported currently
|
||||
pRSmaParam->pFuncIds = (func_id_t *)taosMemoryCalloc(pRSmaParam->nFuncIds, sizeof(func_id_t));
|
||||
if (pRSmaParam->pFuncIds == NULL) {
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
for (int32_t f = 0; f < pRSmaParam->nFuncIds; ++f) {
|
||||
*(pRSmaParam->pFuncIds + f) = pStb->aggregationMethod;
|
||||
}
|
||||
if (pStb->ast1Len > 0) {
|
||||
if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (pStb->ast2Len > 0) {
|
||||
int32_t qmsgLen2 = 0;
|
||||
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
|
@ -470,7 +454,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
||||
if (pHead == NULL) {
|
||||
if (pRSmaParam) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||
taosMemoryFreeClear(pRSmaParam);
|
||||
|
@ -488,7 +471,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
|
||||
*pContLen = contLen;
|
||||
if (pRSmaParam) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||
taosMemoryFreeClear(pRSmaParam);
|
||||
|
@ -706,7 +688,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
|
|||
stbObj.version = 1;
|
||||
stbObj.nextColId = 1;
|
||||
stbObj.xFilesFactor = pCreate->xFilesFactor;
|
||||
stbObj.aggregationMethod = pCreate->aggregationMethod;
|
||||
stbObj.delay = pCreate->delay;
|
||||
stbObj.ttl = pCreate->ttl;
|
||||
stbObj.numOfColumns = pCreate->numOfColumns;
|
||||
|
|
|
@ -282,10 +282,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
topicObj.version = 1;
|
||||
topicObj.sql = strdup(pCreate->sql);
|
||||
topicObj.sqlLen = strlen(pCreate->sql) + 1;
|
||||
topicObj.ast = strdup(pCreate->ast);
|
||||
topicObj.astLen = strlen(pCreate->ast) + 1;
|
||||
|
||||
if (pCreate->ast && pCreate->ast[0]) {
|
||||
topicObj.ast = strdup(pCreate->ast);
|
||||
topicObj.astLen = strlen(pCreate->ast) + 1;
|
||||
topicObj.subType = TOPIC_SUB_TYPE__TABLE;
|
||||
topicObj.withTbName = 0;
|
||||
topicObj.withSchema = 0;
|
||||
|
@ -314,6 +314,9 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
topicObj.ast = strdup("");
|
||||
topicObj.astLen = 1;
|
||||
topicObj.physicalPlan = strdup("");
|
||||
topicObj.subType = TOPIC_SUB_TYPE__DB;
|
||||
topicObj.withTbName = 1;
|
||||
topicObj.withSchema = 1;
|
||||
|
|
|
@ -61,6 +61,9 @@ int32_t vnodeSync(SVnode *pVnode);
|
|||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName);
|
||||
|
||||
int32_t vnodeStart(SVnode *pVnode);
|
||||
void vnodeStop(SVnode *pVnode);
|
||||
|
||||
int64_t vnodeGetSyncHandle(SVnode *pVnode);
|
||||
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot);
|
||||
|
||||
|
@ -162,11 +165,6 @@ typedef struct {
|
|||
uint64_t uid;
|
||||
} STableKeyInfo;
|
||||
|
||||
// sync integration
|
||||
void vnodeSyncSetQ(SVnode *pVnode, void *qHandle);
|
||||
void vnodeSyncSetRpc(SVnode *pVnode, void *rpcHandle);
|
||||
int32_t vnodeSyncStart(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -51,7 +51,7 @@ static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64()
|
|||
#define META_CHILD_TABLE TD_CHILD_TABLE
|
||||
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
||||
|
||||
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg);
|
||||
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
||||
int metaCommit(SMeta* pMeta);
|
||||
int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
|
||||
|
@ -74,7 +74,7 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
|
|||
// SMetaDB
|
||||
int metaOpenDB(SMeta* pMeta);
|
||||
void metaCloseDB(SMeta* pMeta);
|
||||
int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg);
|
||||
int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
||||
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
||||
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
||||
|
|
|
@ -57,7 +57,6 @@ int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid);
|
|||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
||||
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
|
||||
int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg);
|
||||
|
||||
typedef enum {
|
||||
TSDB_FILE_HEAD = 0, // .head
|
||||
TSDB_FILE_DATA, // .data
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_VNODE_TSDB_SMA_H_
|
||||
#define _TD_VNODE_TSDB_SMA_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "thash.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t (*__tb_ddl_fn_t)(void *ahandle, void **result, void *p1, void *p2);
|
||||
|
||||
struct STbDdlH {
|
||||
void *ahandle;
|
||||
void *result;
|
||||
__tb_ddl_fn_t fp;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t suid;
|
||||
SArray *tbUids;
|
||||
SHashObj *uidHash;
|
||||
} STbUidStore;
|
||||
|
||||
static FORCE_INLINE int32_t tsdbUidStoreInit(STbUidStore **pStore) {
|
||||
ASSERT(*pStore == NULL);
|
||||
*pStore = taosMemoryCalloc(1, sizeof(STbUidStore));
|
||||
if (*pStore == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid);
|
||||
void tsdbUidStoreDestory(STbUidStore *pStore);
|
||||
void *tsdbUidStoreFree(STbUidStore *pStore);
|
||||
|
||||
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq);
|
||||
int32_t tsdbFetchTbUidList(void *pTsdb, void **result, void *suid, void *uid);
|
||||
int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pUidStore);
|
||||
int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_VNODE_TSDB_SMA_H_*/
|
|
@ -103,6 +103,8 @@ struct SVnode {
|
|||
|
||||
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
||||
|
||||
typedef struct STbDdlH STbDdlH;
|
||||
|
||||
// sma
|
||||
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
||||
|
||||
|
@ -116,6 +118,8 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
|||
|
||||
#include "vnodeSync.h"
|
||||
|
||||
#include "tsdbSma.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -250,7 +250,7 @@ void metaCloseDB(SMeta *pMeta) {
|
|||
}
|
||||
}
|
||||
|
||||
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||
tb_uid_t uid;
|
||||
SMetaDB *pMetaDb;
|
||||
void *pKey;
|
||||
|
@ -349,6 +349,12 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
|||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
// child table handle for rsma
|
||||
if (pHandle && pHandle->fp) {
|
||||
if (((*pHandle->fp)(pHandle->ahandle, &pHandle->result, &ctbIdxKey.suid, &uid)) < 0) {
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||
pKey = &uid;
|
||||
kLen = sizeof(uid);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||
// Validate the tbOptions
|
||||
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) {
|
||||
// // TODO: handle error
|
||||
|
@ -24,7 +24,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
|
|||
|
||||
// TODO: add atomicity
|
||||
|
||||
if (metaSaveTableToDB(pMeta, pTbCfg) < 0) {
|
||||
if (metaSaveTableToDB(pMeta, pTbCfg, pHandle) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -411,8 +411,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
|
||||
SMqDataBlkRsp rsp = {0};
|
||||
rsp.reqOffset = pReq->currentOffset;
|
||||
rsp.withSchema = pExec->withSchema;
|
||||
rsp.blockData = taosArrayInit(0, sizeof(void*));
|
||||
rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
||||
rsp.blockSchema = taosArrayInit(0, sizeof(void*));
|
||||
|
||||
while (1) {
|
||||
consumerEpoch = atomic_load_32(&pExec->epoch);
|
||||
|
@ -512,6 +514,12 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
ASSERT(actualLen <= dataStrLen);
|
||||
taosArrayPush(rsp.blockDataLen, &actualLen);
|
||||
taosArrayPush(rsp.blockData, &buf);
|
||||
|
||||
if (pExec->withSchema) {
|
||||
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper);
|
||||
taosArrayPush(rsp.blockSchema, &pSW);
|
||||
}
|
||||
|
||||
rsp.blockNum++;
|
||||
}
|
||||
// db subscribe
|
||||
|
@ -540,6 +548,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
ASSERT(actualLen <= dataStrLen);
|
||||
taosArrayPush(rsp.blockDataLen, &actualLen);
|
||||
taosArrayPush(rsp.blockData, &buf);
|
||||
|
||||
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper);
|
||||
taosArrayPush(rsp.blockSchema, &pSW);
|
||||
|
||||
rsp.blockNum++;
|
||||
}
|
||||
} else {
|
||||
|
@ -586,6 +598,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
// TODO destroy
|
||||
taosArrayDestroy(rsp.blockData);
|
||||
taosArrayDestroy(rsp.blockDataLen);
|
||||
taosArrayDestroyP(rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -827,12 +841,16 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
pExec->pWalReader = walOpenReadHandle(pTq->pVnode->pWal);
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
pExec->pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
SReadHandle handle = {
|
||||
.reader = pExec->pExecReader[i],
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
};
|
||||
pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle);
|
||||
ASSERT(pExec->task[i]);
|
||||
} else {
|
||||
pExec->task[i] = NULL;
|
||||
}
|
||||
}
|
||||
taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec));
|
||||
return 0;
|
||||
|
|
|
@ -65,7 +65,9 @@ bool tqNextDataBlock(STqReadHandle* pHandle) {
|
|||
|
||||
/*pHandle->pBlock->uid = htobe64(pHandle->pBlock->uid);*/
|
||||
/*if (pHandle->tbUid == pHandle->pBlock->uid) {*/
|
||||
ASSERT(pHandle->tbIdHash);
|
||||
if (pHandle->tbIdHash == NULL) {
|
||||
return true;
|
||||
}
|
||||
void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->pBlock->uid, sizeof(int64_t));
|
||||
if (ret != NULL) {
|
||||
/*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/
|
||||
|
@ -107,6 +109,27 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
|||
*pNumOfRows = pHandle->pBlock->numOfRows;
|
||||
int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList);
|
||||
|
||||
if (colNumNeed == 0) {
|
||||
*ppCols = taosArrayInit(pSchemaWrapper->nCols, sizeof(SColumnInfoData));
|
||||
if (*ppCols == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t colMeta = 0;
|
||||
while (colMeta < pSchemaWrapper->nCols) {
|
||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||
SColumnInfoData colInfo = {0};
|
||||
colInfo.info.bytes = pColSchema->bytes;
|
||||
colInfo.info.colId = pColSchema->colId;
|
||||
colInfo.info.type = pColSchema->type;
|
||||
|
||||
if (colInfoDataEnsureCapacity(&colInfo, 0, *pNumOfRows) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
taosArrayPush(*ppCols, &colInfo);
|
||||
colMeta++;
|
||||
}
|
||||
} else {
|
||||
if (colNumNeed > pSchemaWrapper->nCols) {
|
||||
colNumNeed = pSchemaWrapper->nCols;
|
||||
}
|
||||
|
@ -140,6 +163,7 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
|||
colNeed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t colActual = taosArrayGetSize(*ppCols);
|
||||
*pNumOfCols = colActual;
|
||||
|
|
|
@ -81,8 +81,8 @@ static STsdb *tsdbNew(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg
|
|||
|
||||
static void tsdbFree(STsdb *pTsdb) {
|
||||
if (pTsdb) {
|
||||
// tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb));
|
||||
// tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb));
|
||||
tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb));
|
||||
tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb));
|
||||
tsdbFreeFS(pTsdb->fs);
|
||||
taosMemoryFreeClear(pTsdb->path);
|
||||
taosMemoryFree(pTsdb);
|
||||
|
|
|
@ -3618,6 +3618,8 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
|
|||
tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||
goto _error;
|
||||
} else {
|
||||
tsdbDebug("%p succeed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||
}
|
||||
|
||||
if (pTbCfg->type != META_SUPER_TABLE) {
|
||||
|
|
|
@ -33,6 +33,8 @@ static const char *TSDB_SMA_DNAME[] = {
|
|||
|
||||
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
|
||||
#define SMA_TEST_INDEX_UID 2000000001 // TODO: just for test
|
||||
|
||||
typedef struct SRSmaInfo SRSmaInfo;
|
||||
typedef enum {
|
||||
SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f200.tsma
|
||||
SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
|
||||
|
@ -46,6 +48,7 @@ typedef struct SPoolMem {
|
|||
|
||||
struct SSmaEnv {
|
||||
TdThreadRwlock lock;
|
||||
int8_t type;
|
||||
TXN txn;
|
||||
SPoolMem *pPool;
|
||||
SDiskID did;
|
||||
|
@ -55,6 +58,7 @@ struct SSmaEnv {
|
|||
};
|
||||
|
||||
#define SMA_ENV_LOCK(env) ((env)->lock)
|
||||
#define SMA_ENV_TYPE(env) ((env)->type)
|
||||
#define SMA_ENV_DID(env) ((env)->did)
|
||||
#define SMA_ENV_ENV(env) ((env)->dbEnv)
|
||||
#define SMA_ENV_PATH(env) ((env)->path)
|
||||
|
@ -91,16 +95,45 @@ typedef struct {
|
|||
* - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open,
|
||||
* without information about its previous state.
|
||||
* - TSDB_SMA_STAT_DROPPED: 1)sma dropped
|
||||
* N.B. only applicable to tsma
|
||||
*/
|
||||
int8_t state; // ETsdbSmaStat
|
||||
SHashObj *expiredWindows; // key: skey of time window, value: N/A
|
||||
STSma *pSma; // cache schema
|
||||
} SSmaStatItem;
|
||||
|
||||
#define RSMA_MAX_LEVEL 2
|
||||
#define RSMA_TASK_INFO_HASH_SLOT 8
|
||||
struct SRSmaInfo {
|
||||
void *taskInfo[RSMA_MAX_LEVEL]; // qTaskInfo_t
|
||||
};
|
||||
|
||||
struct SSmaStat {
|
||||
SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem
|
||||
union {
|
||||
SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem for tsma
|
||||
SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo;
|
||||
};
|
||||
T_REF_DECLARE()
|
||||
};
|
||||
#define SMA_STAT_ITEMS(s) ((s)->smaStatItems)
|
||||
#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash)
|
||||
|
||||
static FORCE_INLINE void tsdbFreeTaskHandle(qTaskInfo_t *taskHandle) {
|
||||
// Note: free/kill may in RC
|
||||
qTaskInfo_t otaskHandle = atomic_load_ptr(taskHandle);
|
||||
if (otaskHandle && atomic_val_compare_exchange_ptr(taskHandle, otaskHandle, NULL)) {
|
||||
qDestroyTask(otaskHandle);
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *tsdbFreeRSmaInfo(SRSmaInfo *pInfo) {
|
||||
for (int32_t i = 0; i < RSMA_MAX_LEVEL; ++i) {
|
||||
if (pInfo->taskInfo[i]) {
|
||||
tsdbFreeTaskHandle(pInfo->taskInfo[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// declaration of static functions
|
||||
|
||||
|
@ -108,11 +141,11 @@ struct SSmaStat {
|
|||
static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version);
|
||||
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
||||
int64_t version);
|
||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat);
|
||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType);
|
||||
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem);
|
||||
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
|
||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did);
|
||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv);
|
||||
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType);
|
||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did);
|
||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv);
|
||||
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey);
|
||||
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||
|
@ -139,6 +172,7 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[])
|
|||
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
||||
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
|
||||
|
||||
static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids);
|
||||
// mgmt interface
|
||||
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
|
||||
|
||||
|
@ -229,7 +263,7 @@ static void *poolMalloc(void *arg, size_t size) {
|
|||
SPoolMem *pMem;
|
||||
|
||||
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
||||
if (pMem == NULL) {
|
||||
if (!pMem) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
|
@ -317,15 +351,17 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) {
|
|||
snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TSDB_SMA_DNAME[smaType]);
|
||||
}
|
||||
|
||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) {
|
||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did) {
|
||||
SSmaEnv *pEnv = NULL;
|
||||
|
||||
pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv));
|
||||
if (pEnv == NULL) {
|
||||
if (!pEnv) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SMA_ENV_TYPE(pEnv) = smaType;
|
||||
|
||||
int code = taosThreadRwlockInit(&(pEnv->lock), NULL);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -334,15 +370,15 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
|||
}
|
||||
|
||||
ASSERT(path && (strlen(path) > 0));
|
||||
pEnv->path = strdup(path);
|
||||
if (pEnv->path == NULL) {
|
||||
SMA_ENV_PATH(pEnv) = strdup(path);
|
||||
if (!SMA_ENV_PATH(pEnv)) {
|
||||
tsdbFreeSmaEnv(pEnv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pEnv->did = did;
|
||||
SMA_ENV_DID(pEnv) = did;
|
||||
|
||||
if (tsdbInitSmaStat(&pEnv->pStat) != TSDB_CODE_SUCCESS) {
|
||||
if (tsdbInitSmaStat(&SMA_ENV_STAT(pEnv), smaType) != TSDB_CODE_SUCCESS) {
|
||||
tsdbFreeSmaEnv(pEnv);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -354,7 +390,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if ((pEnv->pPool = openPool()) == NULL) {
|
||||
if (!(pEnv->pPool = openPool())) {
|
||||
tsdbFreeSmaEnv(pEnv);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -362,14 +398,14 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
|||
return pEnv;
|
||||
}
|
||||
|
||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv) {
|
||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv) {
|
||||
if (!pEnv) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (*pEnv == NULL) {
|
||||
if ((*pEnv = tsdbNewSmaEnv(pTsdb, path, did)) == NULL) {
|
||||
if (!(*pEnv)) {
|
||||
if (!(*pEnv = tsdbNewSmaEnv(pTsdb, smaType, path, did))) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +421,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaE
|
|||
*/
|
||||
void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
|
||||
if (pSmaEnv) {
|
||||
tsdbDestroySmaState(pSmaEnv->pStat);
|
||||
tsdbDestroySmaState(pSmaEnv->pStat, SMA_ENV_TYPE(pSmaEnv));
|
||||
taosMemoryFreeClear(pSmaEnv->pStat);
|
||||
taosMemoryFreeClear(pSmaEnv->path);
|
||||
taosThreadRwlockDestroy(&(pSmaEnv->lock));
|
||||
|
@ -401,7 +437,7 @@ void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv) {
|
|||
}
|
||||
|
||||
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||
if (pStat == NULL) return 0;
|
||||
if (!pStat) return 0;
|
||||
|
||||
int ref = T_REF_INC(pStat);
|
||||
tsdbDebug("vgId:%d ref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
||||
|
@ -409,17 +445,17 @@ static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
|||
}
|
||||
|
||||
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||
if (pStat == NULL) return 0;
|
||||
if (!pStat) return 0;
|
||||
|
||||
int ref = T_REF_DEC(pStat);
|
||||
tsdbDebug("vgId:%d unref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) {
|
||||
ASSERT(pSmaStat != NULL);
|
||||
|
||||
if (*pSmaStat != NULL) { // no lock
|
||||
if (*pSmaStat) { // no lock
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -428,20 +464,32 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
|||
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
|
||||
* tsdbInitSmaStat invoked in other multithread environment later.
|
||||
*/
|
||||
if (*pSmaStat == NULL) {
|
||||
if (!(*pSmaStat)) {
|
||||
*pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat));
|
||||
if (*pSmaStat == NULL) {
|
||||
if (!(*pSmaStat)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
(*pSmaStat)->smaStatItems =
|
||||
taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||
SMA_STAT_INFO_HASH(*pSmaStat) = taosHashInit(
|
||||
RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||
|
||||
if ((*pSmaStat)->smaStatItems == NULL) {
|
||||
if (!SMA_STAT_INFO_HASH(*pSmaStat)) {
|
||||
taosMemoryFreeClear(*pSmaStat);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
} else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||
SMA_STAT_ITEMS(*pSmaStat) =
|
||||
taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
|
||||
if (!SMA_STAT_ITEMS(*pSmaStat)) {
|
||||
taosMemoryFreeClear(*pSmaStat);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -462,7 +510,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
|
|||
}
|
||||
|
||||
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
||||
if (pSmaStatItem != NULL) {
|
||||
if (pSmaStatItem) {
|
||||
tdDestroyTSma(pSmaStatItem->pSma);
|
||||
taosMemoryFreeClear(pSmaStatItem->pSma);
|
||||
taosHashCleanup(pSmaStatItem->expiredWindows);
|
||||
|
@ -477,16 +525,28 @@ static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
|||
* @param pSmaStat
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
||||
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
||||
if (pSmaStat) {
|
||||
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
|
||||
void *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
|
||||
while (item != NULL) {
|
||||
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||
void *item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), NULL);
|
||||
while (item) {
|
||||
SSmaStatItem *pItem = *(SSmaStatItem **)item;
|
||||
tsdbFreeSmaStatItem(pItem);
|
||||
item = taosHashIterate(pSmaStat->smaStatItems, item);
|
||||
item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), item);
|
||||
}
|
||||
taosHashCleanup(SMA_STAT_ITEMS(pSmaStat));
|
||||
} else if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||
void *infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), NULL);
|
||||
while (infoHash) {
|
||||
SRSmaInfo *pInfoHash = *(SRSmaInfo **)infoHash;
|
||||
tsdbFreeRSmaInfo(pInfoHash);
|
||||
infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), infoHash);
|
||||
}
|
||||
taosHashCleanup(SMA_STAT_INFO_HASH(pSmaStat));
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
taosHashCleanup(pSmaStat->smaStatItems);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -497,12 +557,12 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
|||
// return if already init
|
||||
switch (smaType) {
|
||||
case TSDB_SMA_TYPE_TIME_RANGE:
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))) != NULL) {
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb)))) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case TSDB_SMA_TYPE_ROLLUP:
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb))) != NULL) {
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb)))) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
@ -515,7 +575,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
|||
tsdbLockRepo(pTsdb);
|
||||
pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))
|
||||
: atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
||||
if (pEnv == NULL) {
|
||||
if (!pEnv) {
|
||||
char rname[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
SDiskID did = {0};
|
||||
|
@ -531,7 +591,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (tsdbInitSmaEnv(pTsdb, rname, did, &pEnv) != TSDB_CODE_SUCCESS) {
|
||||
if (tsdbInitSmaEnv(pTsdb, smaType, rname, did, &pEnv) != TSDB_CODE_SUCCESS) {
|
||||
tsdbUnlockRepo(pTsdb);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -547,10 +607,10 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
|||
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
||||
int64_t version) {
|
||||
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
||||
if (pItem == NULL) {
|
||||
if (!pItem) {
|
||||
// TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
|
||||
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_OK); // TODO use the real state
|
||||
if (pItem == NULL) {
|
||||
if (!pItem) {
|
||||
// Response to stream computing: OOM
|
||||
// For query, if the indexUid not found, the TSDB should tell query module to query raw TS data.
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -558,7 +618,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
|
|||
|
||||
// cache smaMeta
|
||||
STSma *pSma = metaGetSmaInfoByIndex(REPO_META(pTsdb), indexUid, true);
|
||||
if (pSma == NULL) {
|
||||
if (!pSma) {
|
||||
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
||||
taosHashCleanup(pItem->expiredWindows);
|
||||
taosMemoryFree(pItem);
|
||||
|
@ -574,7 +634,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
|
|||
taosMemoryFree(pItem);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
} else if ((pItem = *(SSmaStatItem **)pItem) == NULL) {
|
||||
} else if (!(pItem = *(SSmaStatItem **)pItem)) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -634,7 +694,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
|||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
||||
|
||||
TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL);
|
||||
TASSERT(pEnv && pStat && pItemsHash);
|
||||
|
||||
// basic procedure
|
||||
// TODO: optimization
|
||||
|
@ -651,7 +711,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
|||
|
||||
while (true) {
|
||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
||||
if (pBlock == NULL) break;
|
||||
if (!pBlock) break;
|
||||
|
||||
STSmaWrapper *pSW = NULL;
|
||||
STSma *pTSma = NULL;
|
||||
|
@ -664,7 +724,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
|||
|
||||
while (true) {
|
||||
STSRow *row = tGetSubmitBlkNext(&blkIter);
|
||||
if (row == NULL) {
|
||||
if (!row) {
|
||||
tdFreeTSmaWrapper(pSW);
|
||||
break;
|
||||
}
|
||||
|
@ -672,10 +732,10 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
|||
if (pSW) {
|
||||
pSW = tdFreeTSmaWrapper(pSW);
|
||||
}
|
||||
if ((pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) {
|
||||
if (!(pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid))) {
|
||||
break;
|
||||
}
|
||||
if ((pSW->number) <= 0 || (pSW->tSma == NULL)) {
|
||||
if ((pSW->number) <= 0 || !pSW->tSma) {
|
||||
pSW = tdFreeTSmaWrapper(pSW);
|
||||
break;
|
||||
}
|
||||
|
@ -721,10 +781,10 @@ static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t ind
|
|||
|
||||
tsdbRefSmaStat(pTsdb, pStat);
|
||||
|
||||
if (pStat && pStat->smaStatItems) {
|
||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||
}
|
||||
if ((pItem != NULL) && ((pItem = *(SSmaStatItem **)pItem) != NULL)) {
|
||||
if ((pItem) && ((pItem = *(SSmaStatItem **)pItem))) {
|
||||
// pItem resides in hash buffer all the time unless drop sma index
|
||||
// TODO: multithread protect
|
||||
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
||||
|
@ -934,7 +994,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
|
|||
|
||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) {
|
||||
STsdb *pTsdb = pSmaH->pTsdb;
|
||||
ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL);
|
||||
ASSERT(!pSmaH->dFile.path && !pSmaH->dFile.pDB);
|
||||
|
||||
pSmaH->dFile.fid = fid;
|
||||
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
||||
|
@ -1004,6 +1064,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||
const SArray *pDataBlocks = (const SArray *)msg;
|
||||
|
||||
// TODO: destroy SSDataBlocks(msg)
|
||||
|
||||
// For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus
|
||||
// the sma data would arrive ahead of the update-expired-window msg.
|
||||
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1011,7 +1073,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (pDataBlocks == NULL) {
|
||||
if (!pDataBlocks) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
|
@ -1029,11 +1091,11 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
|
||||
tsdbRefSmaStat(pTsdb, pStat);
|
||||
|
||||
if (pStat && pStat->smaStatItems) {
|
||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||
}
|
||||
|
||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) {
|
||||
if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) {
|
||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -1061,9 +1123,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
|
||||
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
|
||||
|
||||
// key: skey + groupId
|
||||
char smaKey[SMA_KEY_LEN] = {0};
|
||||
char dataBuf[512] = {0};
|
||||
char smaKey[SMA_KEY_LEN] = {0}; // key: skey + groupId
|
||||
char dataBuf[512] = {0}; // val: aggr data // TODO: handle 512 buffer?
|
||||
void *pDataBuf = NULL;
|
||||
int32_t sz = taosArrayGetSize(pDataBlocks);
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
|
@ -1228,7 +1289,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) {
|
|||
tsdbDebug("vgId:%d drop tSma local cache for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
||||
|
||||
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
||||
if ((pItem != NULL) || ((pItem = *(SSmaStatItem **)pItem) != NULL)) {
|
||||
if ((pItem) || ((pItem = *(SSmaStatItem **)pItem))) {
|
||||
if (tsdbSmaStatIsDropped(pItem)) {
|
||||
tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
||||
return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
|
||||
|
@ -1284,19 +1345,13 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
|
|||
SSmaEnv *pEnv = atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||
|
||||
if (pEnv == NULL) {
|
||||
if (!pEnv) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (pEnv == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (pDataBlocks == NULL) {
|
||||
if (!pDataBlocks) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
|
@ -1313,11 +1368,11 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
|
|||
|
||||
tsdbRefSmaStat(pTsdb, pStat);
|
||||
|
||||
if (pStat && pStat->smaStatItems) {
|
||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||
}
|
||||
|
||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) {
|
||||
if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) {
|
||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -1438,7 +1493,7 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
|
|||
++pReadH->smaFsIter.iter;
|
||||
}
|
||||
|
||||
if (pReadH->pDFile != NULL) {
|
||||
if (pReadH->pDFile) {
|
||||
tsdbDebug("vg%d: smaFile %s matched", REPO_ID(pReadH->pTsdb), "[pSmaFile dir]");
|
||||
return true;
|
||||
}
|
||||
|
@ -1471,7 +1526,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
|||
|
||||
tsdbRefSmaStat(pTsdb, pStat);
|
||||
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL)) {
|
||||
if (!pItem || !(pItem = *(SSmaStatItem **)pItem)) {
|
||||
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
|
||||
// it's NULL.
|
||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||
|
@ -1484,7 +1539,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
|||
int32_t nQueryWin = taosArrayGetSize(pQuerySKey);
|
||||
for (int32_t n = 0; n < nQueryWin; ++n) {
|
||||
TSKEY skey = taosArrayGet(pQuerySKey, n);
|
||||
if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY)) != NULL) {
|
||||
if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY))) {
|
||||
// TODO: mark this window as expired.
|
||||
}
|
||||
}
|
||||
|
@ -1500,7 +1555,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY)) != NULL) {
|
||||
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY))) {
|
||||
// TODO: mark this window as expired.
|
||||
tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb),
|
||||
querySKey, indexUid);
|
||||
|
@ -1534,7 +1589,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
|||
|
||||
void *result = NULL;
|
||||
int32_t valueSize = 0;
|
||||
if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) {
|
||||
if (!(result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize))) {
|
||||
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
|
||||
REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
|
||||
tsdbCloseDBF(&tReadH.dFile);
|
||||
|
@ -1578,7 +1633,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
|||
|
||||
int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
||||
SSmaCfg vCreateSmaReq = {0};
|
||||
if (tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq) == NULL) {
|
||||
if (!tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tsdbWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno));
|
||||
return -1;
|
||||
|
@ -1604,7 +1659,7 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
|||
|
||||
int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
||||
SVDropTSmaReq vDropSmaReq = {0};
|
||||
if (tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq) == NULL) {
|
||||
if (!tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -1632,6 +1687,395 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check and init qTaskInfo_t, only applicable to stable with SRSmaParam.
|
||||
*
|
||||
* @param pTsdb
|
||||
* @param pMeta
|
||||
* @param pReq
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) {
|
||||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||
|
||||
if (!param) {
|
||||
tsdbDebug("vgId:%d return directly since no rollup for stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name,
|
||||
pReq->stbCfg.suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if ((param->qmsg1Len == 0) && (param->qmsg2Len == 0)) {
|
||||
tsdbWarn("vgId:%d no qmsg1/qmsg2 for rollup stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_ROLLUP) != TSDB_CODE_SUCCESS) {
|
||||
terrno = TSDB_CODE_TDB_INIT_FAILED;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
||||
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t));
|
||||
if (pRSmaInfo) {
|
||||
tsdbWarn("vgId:%d rsma info already exists for stb: %s, %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pRSmaInfo = (SRSmaInfo *)taosMemoryCalloc(1, sizeof(SRSmaInfo));
|
||||
if (!pRSmaInfo) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
STqReadHandle *pReadHandle = tqInitSubmitMsgScanner(pMeta);
|
||||
if (!pReadHandle) {
|
||||
taosMemoryFree(pRSmaInfo);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SReadHandle handle = {
|
||||
.reader = pReadHandle,
|
||||
.meta = pMeta,
|
||||
};
|
||||
|
||||
if (param->qmsg1) {
|
||||
pRSmaInfo->taskInfo[0] = qCreateStreamExecTaskInfo(param->qmsg1, &handle);
|
||||
if (!pRSmaInfo->taskInfo[0]) {
|
||||
taosMemoryFree(pRSmaInfo);
|
||||
taosMemoryFree(pReadHandle);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (param->qmsg2) {
|
||||
pRSmaInfo->taskInfo[1] = qCreateStreamExecTaskInfo(param->qmsg2, &handle);
|
||||
if (!pRSmaInfo->taskInfo[1]) {
|
||||
taosMemoryFree(pRSmaInfo);
|
||||
taosMemoryFree(pReadHandle);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) !=
|
||||
TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_FAILED;
|
||||
} else {
|
||||
tsdbDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, REPO_ID(pTsdb), pReq->stbCfg.suid);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief store suid/[uids], prefer to use array and then hash
|
||||
*
|
||||
* @param pStore
|
||||
* @param suid
|
||||
* @param uid
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) {
|
||||
// prefer to store suid/uids in array
|
||||
if ((suid == pStore->suid) || (pStore->suid == 0)) {
|
||||
if (pStore->suid == 0) {
|
||||
pStore->suid = suid;
|
||||
}
|
||||
if (uid) {
|
||||
if (!pStore->tbUids) {
|
||||
if (!(pStore->tbUids = taosArrayInit(1, sizeof(tb_uid_t)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
if (!taosArrayPush(pStore->tbUids, &uid)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// store other suid/uids in hash when multiple stable/table included in 1 batch of request
|
||||
if (!pStore->uidHash) {
|
||||
pStore->uidHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (!pStore->uidHash) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
if (uid) {
|
||||
SArray *uidArray = taosHashGet(pStore->uidHash, &suid, sizeof(tb_uid_t));
|
||||
if (uidArray && ((uidArray = *(SArray **)uidArray))) {
|
||||
taosArrayPush(uidArray, &uid);
|
||||
} else {
|
||||
SArray *pUidArray = taosArrayInit(1, sizeof(tb_uid_t));
|
||||
if (!pUidArray) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (!taosArrayPush(pUidArray, &uid)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void tsdbUidStoreDestory(STbUidStore *pStore) {
|
||||
if (pStore) {
|
||||
if (pStore->uidHash) {
|
||||
if (pStore->tbUids) {
|
||||
void *pIter = taosHashIterate(pStore->uidHash, NULL);
|
||||
while (pIter) {
|
||||
SArray *arr = *(SArray **)pIter;
|
||||
taosArrayDestroy(arr);
|
||||
pIter = taosHashIterate(pStore->uidHash, pIter);
|
||||
}
|
||||
}
|
||||
taosHashCleanup(pStore->uidHash);
|
||||
}
|
||||
taosArrayDestroy(pStore->tbUids);
|
||||
}
|
||||
}
|
||||
|
||||
void *tsdbUidStoreFree(STbUidStore *pStore) {
|
||||
tsdbUidStoreDestory(pStore);
|
||||
taosMemoryFree(pStore);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fetch suid/uids when create child tables of rollup SMA
|
||||
*
|
||||
* @param pTsdb
|
||||
* @param ppStore
|
||||
* @param suid
|
||||
* @param uid
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbFetchTbUidList(void *pTsdb, void **ppStore, void *suid, void *uid) {
|
||||
SSmaEnv *pEnv = REPO_RSMA_ENV((STsdb *)pTsdb);
|
||||
|
||||
// only applicable to rollup SMA ctables
|
||||
if (!pEnv) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||
SHashObj *infoHash = NULL;
|
||||
if (!pStat || !(infoHash = SMA_STAT_INFO_HASH(pStat))) {
|
||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// info cached when create rsma stable and return directly for non-rsma ctables
|
||||
if (!taosHashGet(infoHash, suid, sizeof(tb_uid_t))) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (!(*ppStore)) {
|
||||
if (tsdbUidStoreInit((STbUidStore **)ppStore) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (tsdbUidStorePut(*ppStore, *(tb_uid_t *)suid, (tb_uid_t *)uid) != 0) {
|
||||
*ppStore = tsdbUidStoreFree(*ppStore);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids) {
|
||||
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
||||
if (!suid || !tbUids) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t));
|
||||
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
||||
tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64, REPO_ID(pTsdb), *suid);
|
||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (pRSmaInfo->taskInfo[0] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[0], tbUids, true) != 0)) {
|
||||
tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||
return TSDB_CODE_FAILED;
|
||||
} else {
|
||||
tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb),
|
||||
pRSmaInfo->taskInfo[0], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
|
||||
}
|
||||
|
||||
if (pRSmaInfo->taskInfo[1] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[1], tbUids, true) != 0)) {
|
||||
tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||
return TSDB_CODE_FAILED;
|
||||
} else {
|
||||
tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb),
|
||||
pRSmaInfo->taskInfo[1], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pStore) {
|
||||
if (!pStore || (taosArrayGetSize(pStore->tbUids) == 0)) {
|
||||
tsdbDebug("vgId:%d no need to update tbUids since empty uidStore", REPO_ID(pTsdb));
|
||||
tsdbUidStoreFree(pStore);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (tsdbUpdateTbUidListImpl(pTsdb, &pStore->suid, pStore->tbUids) != TSDB_CODE_SUCCESS) {
|
||||
tsdbUidStoreFree(pStore);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(pStore->uidHash, NULL);
|
||||
while (pIter) {
|
||||
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||
SArray *pTbUids = *(SArray **)pIter;
|
||||
|
||||
if (tsdbUpdateTbUidListImpl(pTsdb, pTbSuid, pTbUids) != TSDB_CODE_SUCCESS) {
|
||||
taosHashCancelIterate(pStore->uidHash, pIter);
|
||||
tsdbUidStoreFree(pStore);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pStore->uidHash, pIter);
|
||||
}
|
||||
|
||||
tsdbUidStoreFree(pStore);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
|
||||
ASSERT(pMsg != NULL);
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
STSRow *row = NULL;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
// pMsg->length = htonl(pMsg->length);
|
||||
// pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
||||
|
||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1;
|
||||
while (true) {
|
||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
||||
|
||||
if (!pBlock) break;
|
||||
tsdbUidStorePut(pStore, pBlock->suid, NULL);
|
||||
}
|
||||
|
||||
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t inputType, tb_uid_t *suid) {
|
||||
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||
if (!pEnv) {
|
||||
// only applicable when rsma env exists
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
||||
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t));
|
||||
|
||||
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
||||
tsdbDebug("vgId:%d no rsma info for suid:%" PRIu64, REPO_ID(pTsdb), *suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SArray *pResult = NULL;
|
||||
|
||||
pResult = taosArrayInit(0, sizeof(SSDataBlock));
|
||||
if (!pResult) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||
if (pRSmaInfo->taskInfo[0]) {
|
||||
qSetStreamInput(pRSmaInfo->taskInfo[0], pMsg, inputType);
|
||||
while (1) {
|
||||
SSDataBlock *output;
|
||||
uint64_t ts;
|
||||
if (qExecTask(pRSmaInfo->taskInfo[0], &output, &ts) < 0) {
|
||||
ASSERT(false);
|
||||
}
|
||||
if (!output) {
|
||||
break;
|
||||
}
|
||||
taosArrayPush(pResult, output);
|
||||
}
|
||||
blockDebugShowData(pResult);
|
||||
}
|
||||
|
||||
// if (pRSmaInfo->taskInfo[1]) {
|
||||
// qSetStreamInput(pRSmaInfo->taskInfo[1], pMsg, inputType);
|
||||
// while (1) {
|
||||
// SSDataBlock *output;
|
||||
// uint64_t ts;
|
||||
// if (qExecTask(pRSmaInfo->taskInfo[1], &output, &ts) < 0) {
|
||||
// ASSERT(false);
|
||||
// }
|
||||
// if (!output) {
|
||||
// break;
|
||||
// }
|
||||
// taosArrayPush(pResult, output);
|
||||
// }
|
||||
// blockDebugShowData(pResult);
|
||||
// }
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType) {
|
||||
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||
if (!pEnv) {
|
||||
// only applicable when rsma env exists
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||
STbUidStore uidStore = {0};
|
||||
tsdbFetchSubmitReqSuids(pMsg, &uidStore);
|
||||
|
||||
if (uidStore.suid != 0) {
|
||||
tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, &uidStore.suid);
|
||||
|
||||
void *pIter = taosHashIterate(uidStore.uidHash, NULL);
|
||||
while (pIter) {
|
||||
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||
tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, pTbSuid);
|
||||
pIter = taosHashIterate(uidStore.uidHash, pIter);
|
||||
}
|
||||
|
||||
tsdbUidStoreDestory(&uidStore);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief Get the start TS key of the last data block of one interval/sliding.
|
||||
|
@ -1674,6 +2118,7 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) {
|
|||
if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) {
|
||||
tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||
}
|
||||
// TODO: destroy SSDataBlocks(msg)
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "vnodeSync.h"
|
||||
|
||||
int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
|
||||
SVnodeInfo info = {0};
|
||||
|
@ -171,6 +172,16 @@ void vnodeClose(SVnode *pVnode) {
|
|||
}
|
||||
}
|
||||
|
||||
// start the sync timer after the queue is ready
|
||||
int32_t vnodeStart(SVnode *pVnode) {
|
||||
vnodeSyncSetQ(pVnode, NULL);
|
||||
vnodeSyncSetRpc(pVnode, NULL);
|
||||
vnodeSyncStart(pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeStop(SVnode *pVnode) {}
|
||||
|
||||
int64_t vnodeGetSyncHandle(SVnode *pVnode) { return pVnode->sync; }
|
||||
|
||||
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot) { pSnapshot->lastApplyIndex = pVnode->state.committed; }
|
|
@ -83,6 +83,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
|||
case TDMT_VND_SUBMIT:
|
||||
pRsp->msgType = TDMT_VND_SUBMIT_RSP;
|
||||
vnodeProcessSubmitReq(pVnode, ptr, pRsp);
|
||||
tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, ptr, STREAM_DATA_TYPE_SUBMIT_BLOCK);
|
||||
break;
|
||||
case TDMT_VND_MQ_VG_CHANGE:
|
||||
if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||
|
@ -101,7 +102,6 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
|||
}
|
||||
} break;
|
||||
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
||||
|
||||
if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
|
||||
// TODO
|
||||
}
|
||||
|
@ -277,24 +277,16 @@ int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
|
||||
SVCreateTbReq vCreateTbReq = {0};
|
||||
tDeserializeSVCreateTbReq(pReq, &vCreateTbReq);
|
||||
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) {
|
||||
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq), NULL) < 0) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: remove the debug log
|
||||
SRSmaParam *param = vCreateTbReq.stbCfg.pRSmaParam;
|
||||
if (param) {
|
||||
printf("qmsg1 len = %d, body = %s\n", param->qmsg1 ? (int32_t)strlen(param->qmsg1) : 0,
|
||||
param->qmsg1 ? param->qmsg1 : "");
|
||||
printf("qmsg1 len = %d, body = %s\n", param->qmsg2 ? (int32_t)strlen(param->qmsg2) : 0,
|
||||
param->qmsg2 ? param->qmsg2 : "");
|
||||
}
|
||||
tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &vCreateTbReq);
|
||||
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
|
||||
if (vCreateTbReq.stbCfg.pRSmaParam) {
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg1);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg2);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam);
|
||||
|
@ -309,6 +301,13 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
SVCreateTbBatchRsp vCreateTbBatchRsp = {0};
|
||||
tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq);
|
||||
int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray);
|
||||
|
||||
STbDdlH ddlHandle = {
|
||||
.ahandle = pVnode->pTsdb,
|
||||
.result = NULL,
|
||||
.fp = tsdbFetchTbUidList,
|
||||
};
|
||||
|
||||
for (int i = 0; i < reqNum; i++) {
|
||||
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
|
||||
|
||||
|
@ -324,7 +323,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
taosArrayPush(vCreateTbBatchRsp.rspList, &rsp);
|
||||
}
|
||||
|
||||
if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) {
|
||||
if (metaCreateTable(pVnode->pMeta, pCreateTbReq, &ddlHandle) < 0) {
|
||||
// TODO: handle error
|
||||
vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name);
|
||||
}
|
||||
|
@ -334,7 +333,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
taosMemoryFree(pCreateTbReq->stbCfg.pSchema);
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema);
|
||||
if (pCreateTbReq->stbCfg.pRSmaParam) {
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam);
|
||||
}
|
||||
} else if (pCreateTbReq->type == TD_CHILD_TABLE) {
|
||||
|
@ -342,12 +340,13 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
} else {
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pSchema);
|
||||
if (pCreateTbReq->ntbCfg.pRSmaParam) {
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tsdbUpdateTbUidList(pVnode->pTsdb, ddlHandle.result);
|
||||
|
||||
vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray));
|
||||
taosArrayDestroy(vCreateTbBatchReq.pArray);
|
||||
if (vCreateTbBatchRsp.rspList) {
|
||||
|
@ -371,7 +370,6 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) {
|
|||
taosMemoryFree(vAlterTbReq.stbCfg.pSchema);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema);
|
||||
if (vAlterTbReq.stbCfg.pRSmaParam) {
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam);
|
||||
}
|
||||
taosMemoryFree(vAlterTbReq.name);
|
||||
|
|
|
@ -407,7 +407,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
}
|
||||
}
|
||||
|
||||
EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
||||
// EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
||||
|
||||
EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg, 0), 0);
|
||||
|
||||
|
|
|
@ -1065,6 +1065,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
|
|||
|
||||
SInputColumnInfoData* pInput = &pCtx[i].input;
|
||||
pInput->uid = pBlock->info.uid;
|
||||
pInput->colDataAggIsSet = false;
|
||||
|
||||
SExprInfo* pOneExpr = &pOperator->pExpr[i];
|
||||
for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
|
||||
|
@ -3749,6 +3750,9 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
|||
}
|
||||
|
||||
memcpy(pColInfoData->pData, pStart, colLen[i]);
|
||||
//TODO setting this flag to true temporarily so aggregate function on stable will
|
||||
//examine NULL value for non-primary key column
|
||||
pColInfoData->hasNull = true;
|
||||
pStart += colLen[i];
|
||||
}
|
||||
} else { // extract data according to pColList
|
||||
|
|
|
@ -41,7 +41,9 @@ extern "C" {
|
|||
|
||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
#define FUNC_UDF_ID_START_OFFSET_VAL 5000
|
||||
#define FUNC_UDF_ID_START 5000
|
||||
#define FUNC_AGGREGATE_UDF_ID 5001
|
||||
#define FUNC_SCALAR_UDF_ID 5002
|
||||
|
||||
extern const int funcMgtUdfNum;
|
||||
|
||||
|
|
|
@ -42,19 +42,7 @@ enum {
|
|||
UDFC_CODE_INVALID_STATE = -5
|
||||
};
|
||||
|
||||
typedef void *UdfcFuncHandle;
|
||||
|
||||
/**
|
||||
* create udfd proxy, called once in process that call setupUdf/callUdfxxx/teardownUdf
|
||||
* @return error code
|
||||
*/
|
||||
int32_t udfcOpen();
|
||||
|
||||
/**
|
||||
* destroy udfd proxy
|
||||
* @return error code
|
||||
*/
|
||||
int32_t udfcClose();
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -143,9 +143,7 @@ static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in
|
|||
}
|
||||
|
||||
static int32_t translateTimezone(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type};
|
||||
//pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY};
|
||||
pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -168,7 +166,8 @@ static bool validAperventileAlgo(const SValueNode* pVal) {
|
|||
if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) {
|
||||
return false;
|
||||
}
|
||||
return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest"));
|
||||
return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") ||
|
||||
0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest"));
|
||||
}
|
||||
|
||||
static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
|
@ -185,7 +184,8 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
if (3 == paraNum) {
|
||||
SNode* pPara3 = nodesListGetNode(pFunc->pParameterList, 2);
|
||||
if (QUERY_NODE_VALUE != nodeType(pPara3) || !validAperventileAlgo((SValueNode*)pPara3)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Third parameter algorithm of apercentile must be 'default' or 't-digest'");
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"Third parameter algorithm of apercentile must be 'default' or 't-digest'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,8 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
|
||||
static int32_t translateTbnameColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
// pseudo column do not need to check parameters
|
||||
pFunc->node.resType = (SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -228,7 +229,8 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "The parameters of first/last can only be columns");
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The parameters of first/last can only be columns");
|
||||
}
|
||||
|
||||
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
||||
|
@ -245,11 +247,13 @@ static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT };
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, bool hasSep) {
|
||||
static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum,
|
||||
int32_t maxParaNum, bool hasSep) {
|
||||
int32_t paraNum = LIST_LENGTH(pFunc->pParameterList);
|
||||
if (paraNum < minParaNum || paraNum > maxParaNum) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -355,7 +359,7 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = 24, .type = TSDB_DATA_TYPE_BINARY};
|
||||
pFunc->node.resType = (SDataType){.bytes = 64, .type = TSDB_DATA_TYPE_BINARY};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -379,11 +383,13 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
|
|||
|
||||
uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type;
|
||||
if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || !IS_INTEGER_TYPE(para2Type)) {
|
||||
if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) ||
|
||||
!IS_INTEGER_TYPE(para2Type)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -425,8 +431,7 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
}
|
||||
|
||||
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||
{
|
||||
.name = "count",
|
||||
{.name = "count",
|
||||
.type = FUNCTION_TYPE_COUNT,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.translateFunc = translateCount,
|
||||
|
@ -434,10 +439,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getCountFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = countFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "sum",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "sum",
|
||||
.type = FUNCTION_TYPE_SUM,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.translateFunc = translateSum,
|
||||
|
@ -445,10 +448,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getSumFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = sumFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "min",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "min",
|
||||
.type = FUNCTION_TYPE_MIN,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.translateFunc = translateInOutNum,
|
||||
|
@ -456,10 +457,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = minFunctionSetup,
|
||||
.processFunc = minFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "max",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "max",
|
||||
.type = FUNCTION_TYPE_MAX,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.translateFunc = translateInOutNum,
|
||||
|
@ -467,48 +466,39 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "stddev",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "stddev",
|
||||
.type = FUNCTION_TYPE_STDDEV,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = getStddevFuncEnv,
|
||||
.initFunc = stddevFunctionSetup,
|
||||
.processFunc = stddevFunction,
|
||||
.finalizeFunc = stddevFinalize
|
||||
},
|
||||
{
|
||||
.name = "avg",
|
||||
.finalizeFunc = stddevFinalize},
|
||||
{.name = "avg",
|
||||
.type = FUNCTION_TYPE_AVG,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = getAvgFuncEnv,
|
||||
.initFunc = avgFunctionSetup,
|
||||
.processFunc = avgFunction,
|
||||
.finalizeFunc = avgFinalize
|
||||
},
|
||||
{
|
||||
.name = "percentile",
|
||||
.finalizeFunc = avgFinalize},
|
||||
{.name = "percentile",
|
||||
.type = FUNCTION_TYPE_PERCENTILE,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translatePercentile,
|
||||
.getEnvFunc = getPercentileFuncEnv,
|
||||
.initFunc = percentileFunctionSetup,
|
||||
.processFunc = percentileFunction,
|
||||
.finalizeFunc = percentileFinalize
|
||||
},
|
||||
{
|
||||
.name = "apercentile",
|
||||
.finalizeFunc = percentileFinalize},
|
||||
{.name = "apercentile",
|
||||
.type = FUNCTION_TYPE_APERCENTILE,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateApercentile,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
.finalizeFunc = functionFinalize},
|
||||
{
|
||||
.name = "top",
|
||||
.type = FUNCTION_TYPE_TOP,
|
||||
|
@ -519,446 +509,357 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.processFunc = topFunction,
|
||||
.finalizeFunc = topBotFinalize,
|
||||
},
|
||||
{
|
||||
.name = "bottom",
|
||||
{.name = "bottom",
|
||||
.type = FUNCTION_TYPE_BOTTOM,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateBottom,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "spread",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "spread",
|
||||
.type = FUNCTION_TYPE_SPREAD,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateSpread,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "last_row",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "last_row",
|
||||
.type = FUNCTION_TYPE_LAST_ROW,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||
.translateFunc = translateLastRow,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "first",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "first",
|
||||
.type = FUNCTION_TYPE_FIRST,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||
.translateFunc = translateFirstLast,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = firstFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "last",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "last",
|
||||
.type = FUNCTION_TYPE_LAST,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||
.translateFunc = translateFirstLast,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = lastFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "diff",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "diff",
|
||||
.type = FUNCTION_TYPE_DIFF,
|
||||
.classification = FUNC_MGT_NONSTANDARD_SQL_FUNC,
|
||||
.translateFunc = translateInOutNum,
|
||||
.getEnvFunc = getDiffFuncEnv,
|
||||
.initFunc = diffFunctionSetup,
|
||||
.processFunc = diffFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "abs",
|
||||
.finalizeFunc = functionFinalize},
|
||||
{.name = "abs",
|
||||
.type = FUNCTION_TYPE_ABS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInOutNum,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = absFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "log",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "log",
|
||||
.type = FUNCTION_TYPE_LOG,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateIn2NumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = logFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "pow",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "pow",
|
||||
.type = FUNCTION_TYPE_POW,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateIn2NumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = powFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "sqrt",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "sqrt",
|
||||
.type = FUNCTION_TYPE_SQRT,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = sqrtFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "ceil",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "ceil",
|
||||
.type = FUNCTION_TYPE_CEIL,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInOutNum,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = ceilFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "floor",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "floor",
|
||||
.type = FUNCTION_TYPE_FLOOR,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInOutNum,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = floorFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "round",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "round",
|
||||
.type = FUNCTION_TYPE_ROUND,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInOutNum,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = roundFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "sin",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "sin",
|
||||
.type = FUNCTION_TYPE_SIN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = sinFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "cos",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "cos",
|
||||
.type = FUNCTION_TYPE_COS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = cosFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "tan",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "tan",
|
||||
.type = FUNCTION_TYPE_TAN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = tanFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "asin",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "asin",
|
||||
.type = FUNCTION_TYPE_ASIN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = asinFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "acos",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "acos",
|
||||
.type = FUNCTION_TYPE_ACOS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = acosFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "atan",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "atan",
|
||||
.type = FUNCTION_TYPE_ATAN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateInNumOutDou,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = atanFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "length",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "length",
|
||||
.type = FUNCTION_TYPE_LENGTH,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateLength,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = lengthFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "char_length",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "char_length",
|
||||
.type = FUNCTION_TYPE_CHAR_LENGTH,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateLength,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = charLengthFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "concat",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "concat",
|
||||
.type = FUNCTION_TYPE_CONCAT,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateConcat,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = concatFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "concat_ws",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "concat_ws",
|
||||
.type = FUNCTION_TYPE_CONCAT_WS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateConcatWs,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = concatWsFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "lower",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "lower",
|
||||
.type = FUNCTION_TYPE_LOWER,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateInOutStr,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = lowerFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "upper",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "upper",
|
||||
.type = FUNCTION_TYPE_UPPER,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateInOutStr,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = upperFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "ltrim",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "ltrim",
|
||||
.type = FUNCTION_TYPE_LTRIM,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateInOutStr,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = ltrimFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "rtrim",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "rtrim",
|
||||
.type = FUNCTION_TYPE_RTRIM,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateInOutStr,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = rtrimFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "substr",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "substr",
|
||||
.type = FUNCTION_TYPE_SUBSTR,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.translateFunc = translateSubstr,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = substrFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "cast",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "cast",
|
||||
.type = FUNCTION_TYPE_CAST,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateCast,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = castFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "to_iso8601",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "to_iso8601",
|
||||
.type = FUNCTION_TYPE_TO_ISO8601,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateToIso8601,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = toISO8601Function,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "to_unixtimestamp",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "to_unixtimestamp",
|
||||
.type = FUNCTION_TYPE_TO_UNIXTIMESTAMP,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateToUnixtimestamp,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = toUnixtimestampFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "timetruncate",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "timetruncate",
|
||||
.type = FUNCTION_TYPE_TIMETRUNCATE,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateTimeTruncate,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = timeTruncateFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "timediff",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "timediff",
|
||||
.type = FUNCTION_TYPE_TIMEDIFF,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateTimeDiff,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = timeDiffFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "now",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "now",
|
||||
.type = FUNCTION_TYPE_NOW,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = nowFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "today",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "today",
|
||||
.type = FUNCTION_TYPE_TODAY,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = todayFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "timezone",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "timezone",
|
||||
.type = FUNCTION_TYPE_TIMEZONE,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateTimezone,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = timezoneFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_rowts",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "_rowts",
|
||||
.type = FUNCTION_TYPE_ROWTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "tbname",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "tbname",
|
||||
.type = FUNCTION_TYPE_TBNAME,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
||||
.translateFunc = translateTbnameColumn,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_qstartts",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "_qstartts",
|
||||
.type = FUNCTION_TYPE_QSTARTTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = qStartTsFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_qendts",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "_qendts",
|
||||
.type = FUNCTION_TYPE_QENDTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = qEndTsFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_wstartts",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "_wstartts",
|
||||
.type = FUNCTION_TYPE_WSTARTTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = winStartTsFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_wendts",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "_wendts",
|
||||
.type = FUNCTION_TYPE_WENDTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = winEndTsFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_wduration",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "_wduration",
|
||||
.type = FUNCTION_TYPE_WDURATION,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.translateFunc = translateWduration,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = winDurFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "to_json",
|
||||
.finalizeFunc = NULL},
|
||||
{.name = "to_json",
|
||||
.type = FUNCTION_TYPE_TO_JSON,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateToJson,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = toJsonFunction,
|
||||
.finalizeFunc = NULL
|
||||
}
|
||||
};
|
||||
.finalizeFunc = NULL}};
|
||||
|
||||
const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
typedef struct SFuncMgtService {
|
||||
SHashObj* pFuncNameHashTable;
|
||||
SArray* pUdfTable; // SUdfInfo
|
||||
} SFuncMgtService;
|
||||
|
||||
typedef struct SUdfInfo {
|
||||
|
@ -49,18 +48,12 @@ static void doInitFunctionTable() {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gFunMgtService.pUdfTable = NULL;
|
||||
}
|
||||
|
||||
static int8_t getUdfType(int32_t funcId) {
|
||||
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
|
||||
return pUdf->funcType;
|
||||
}
|
||||
|
||||
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
||||
if (fmIsUserDefinedFunc(funcId)) {
|
||||
return getUdfType(funcId);
|
||||
return FUNC_MGT_AGG_FUNC == classification ? FUNC_AGGREGATE_UDF_ID == funcId :
|
||||
(FUNC_MGT_SCALAR_FUNC == classification ? FUNC_SCALAR_UDF_ID == funcId : false);
|
||||
}
|
||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return false;
|
||||
|
@ -68,33 +61,23 @@ static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
|||
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
|
||||
}
|
||||
|
||||
static int32_t getUdfId(SFmGetFuncInfoParam* pParam, const char* pFuncName) {
|
||||
static int32_t getUdfInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
|
||||
SFuncInfo* pInfo = NULL;
|
||||
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFuncName, &pInfo);
|
||||
if (TSDB_CODE_SUCCESS != code || NULL == pInfo) {
|
||||
return -1;
|
||||
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFunc->functionName, &pInfo);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (NULL == gFunMgtService.pUdfTable) {
|
||||
gFunMgtService.pUdfTable = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SUdfInfo));
|
||||
if (NULL == pInfo) {
|
||||
snprintf(pParam->pErrBuf, pParam->errBufLen, "Invalid function name: %s", pFunc->functionName);
|
||||
return TSDB_CODE_FUNC_INVALID_FUNTION;
|
||||
}
|
||||
SUdfInfo info = { .outputDt.type = pInfo->outputType, .outputDt.bytes = pInfo->outputLen, .funcType = pInfo->funcType };
|
||||
taosArrayPush(gFunMgtService.pUdfTable, &info);
|
||||
pFunc->funcType = FUNCTION_TYPE_UDF;
|
||||
pFunc->funcId = TSDB_FUNC_TYPE_AGGREGATE == pInfo->funcType ? FUNC_AGGREGATE_UDF_ID : FUNC_SCALAR_UDF_ID;
|
||||
pFunc->node.resType.type = pInfo->outputType;
|
||||
pFunc->node.resType.bytes = pInfo->outputLen;
|
||||
pFunc->udfBufSize = pInfo->bufSize;
|
||||
tFreeSFuncInfo(pInfo);
|
||||
taosMemoryFree(pInfo);
|
||||
return taosArrayGetSize(gFunMgtService.pUdfTable) + FUNC_UDF_ID_START_OFFSET_VAL;
|
||||
}
|
||||
|
||||
static int32_t getFuncId(SFmGetFuncInfoParam* pParam, const char* pFuncName) {
|
||||
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFuncName, strlen(pFuncName));
|
||||
if (NULL == pVal) {
|
||||
return getUdfId(pParam, pFuncName);
|
||||
}
|
||||
return *(int32_t*)pVal;
|
||||
}
|
||||
|
||||
static int32_t getUdfResultType(SFunctionNode* pFunc) {
|
||||
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, pFunc->funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
|
||||
pFunc->node.resType = pUdf->outputDt;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -103,28 +86,14 @@ int32_t fmFuncMgtInit() {
|
|||
return initFunctionCode;
|
||||
}
|
||||
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) {
|
||||
*pFuncId = getFuncId(pParam, pFuncName);
|
||||
if (*pFuncId < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
|
||||
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
|
||||
if (NULL != pVal) {
|
||||
pFunc->funcId = *(int32_t*)pVal;
|
||||
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pParam->pErrBuf, pParam->errBufLen);
|
||||
}
|
||||
if (fmIsUserDefinedFunc(*pFuncId)) {
|
||||
*pFuncType = FUNCTION_TYPE_UDF;
|
||||
} else {
|
||||
*pFuncType = funcMgtBuiltins[*pFuncId].type;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (fmIsUserDefinedFunc(pFunc->funcId)) {
|
||||
return getUdfResultType(pFunc);
|
||||
}
|
||||
|
||||
if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pErrBuf, len);
|
||||
return getUdfInfo(pParam, pFunc);
|
||||
}
|
||||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||
|
@ -194,7 +163,7 @@ bool fmIsMultiResFunc(int32_t funcId) {
|
|||
}
|
||||
|
||||
bool fmIsUserDefinedFunc(int32_t funcId) {
|
||||
return funcId > FUNC_UDF_ID_START_OFFSET_VAL;
|
||||
return funcId > FUNC_UDF_ID_START;
|
||||
}
|
||||
|
||||
void fmFuncMgtDestroy() {
|
||||
|
|
|
@ -548,7 +548,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
|
|||
static int32_t udfdInitLog() {
|
||||
char logName[12] = {0};
|
||||
snprintf(logName, sizeof(logName), "%slog", "udfd");
|
||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0);
|
||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
|
||||
|
@ -656,7 +656,7 @@ int main(int argc, char *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) {
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
||||
fnError("failed to start since read config error");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@ static int32_t parseArgs(int32_t argc, char *argv[]) {
|
|||
static int32_t initLog() {
|
||||
char logName[12] = {0};
|
||||
snprintf(logName, sizeof(logName), "%slog", "udfc");
|
||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0);
|
||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
parseArgs(argc, argv);
|
||||
initLog();
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) {
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
||||
fnError("failed to start since read config error");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,32 @@ extern "C" {
|
|||
#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__)
|
||||
#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__)
|
||||
|
||||
#define NODES_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
||||
#define NODES_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||
#define NODES_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||
#define NODES_ERR_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
return _code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define NODES_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
} \
|
||||
return _code; \
|
||||
} while (0)
|
||||
|
||||
#define NODES_ERR_JRET(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
goto _return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include "cmdnodes.h"
|
||||
#include "nodesUtil.h"
|
||||
#include "plannodes.h"
|
||||
#include "querynodes.h"
|
||||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
#include "taoserror.h"
|
||||
#include "tjson.h"
|
||||
|
||||
|
@ -398,7 +398,8 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
|
|||
code = tjsonAddObject(pJson, jkTableMetaComInfo, tableComInfoToJson, &pNode->tableInfo);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema), TABLE_TOTAL_COL_NUM(pNode));
|
||||
code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema),
|
||||
TABLE_TOTAL_COL_NUM(pNode));
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -713,13 +714,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
return physiScanNodeToJson(pObj, pJson);
|
||||
}
|
||||
static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); }
|
||||
|
||||
static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) {
|
||||
return jsonToPhysiScanNode(pJson, pObj);
|
||||
}
|
||||
static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); }
|
||||
|
||||
static const char* jkTableScanPhysiPlanScanCount = "ScanCount";
|
||||
static const char* jkTableScanPhysiPlanReverseScanCount = "ReverseScanCount";
|
||||
|
@ -822,13 +819,9 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
return physiScanNodeToJson(pObj, pJson);
|
||||
}
|
||||
static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); }
|
||||
|
||||
static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) {
|
||||
return jsonToPhysiScanNode(pJson, pObj);
|
||||
}
|
||||
static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); }
|
||||
|
||||
static const char* jkEndPointFqdn = "Fqdn";
|
||||
static const char* jkEndPointPort = "Port";
|
||||
|
@ -1331,13 +1324,9 @@ static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToNodeObject(pJson, jkDataSinkInputDataBlockDesc, (SNode**)&pNode->pInputDataBlockDesc);
|
||||
}
|
||||
|
||||
static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) {
|
||||
return physicDataSinkNodeToJson(pObj, pJson);
|
||||
}
|
||||
static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return physicDataSinkNodeToJson(pObj, pJson); }
|
||||
|
||||
static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) {
|
||||
return jsonToPhysicDataSinkNode(pJson, pObj);
|
||||
}
|
||||
static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { return jsonToPhysicDataSinkNode(pJson, pObj); }
|
||||
|
||||
static const char* jkSubplanIdQueryId = "QueryId";
|
||||
static const char* jkSubplanIdGroupId = "GroupId";
|
||||
|
@ -1663,7 +1652,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkValueGenByCalc = "GenByCalc";
|
||||
static const char* jkValueLiteralSize = "LiteralSize";
|
||||
static const char* jkValueLiteral = "Literal";
|
||||
static const char* jkValueDuration = "Duration";
|
||||
static const char* jkValueTranslate = "Translate";
|
||||
|
@ -1717,9 +1706,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
|
|||
|
||||
int32_t code = exprNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkValueGenByCalc, pNode->genByCalc);
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueLiteralSize, NULL != pNode->literal ? strlen(pNode->literal) : 0);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) {
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pNode->literal) {
|
||||
code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->literal);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -1789,10 +1778,11 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
|
|||
SValueNode* pNode = (SValueNode*)pObj;
|
||||
|
||||
int32_t code = jsonToExprNode(pJson, pObj);
|
||||
int32_t literalSize = 0;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkValueGenByCalc, &pNode->genByCalc);
|
||||
code = tjsonGetIntValue(pJson, jkValueLiteralSize, &literalSize);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) {
|
||||
if (TSDB_CODE_SUCCESS == code && literalSize > 0) {
|
||||
code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->literal);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -2014,7 +2004,8 @@ static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) {
|
|||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), pNode->numOfVgroups);
|
||||
code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo),
|
||||
pNode->numOfVgroups);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -2380,6 +2371,7 @@ static const char* jkSelectStmtOrderBy = "OrderBy";
|
|||
static const char* jkSelectStmtLimit = "Limit";
|
||||
static const char* jkSelectStmtSlimit = "Slimit";
|
||||
static const char* jkSelectStmtStmtName = "StmtName";
|
||||
static const char* jkSelectStmtHasAggFuncs = "HasAggFuncs";
|
||||
|
||||
static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
||||
const SSelectStmt* pNode = (const SSelectStmt*)pObj;
|
||||
|
@ -2418,6 +2410,9 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkSelectStmtHasAggFuncs, pNode->hasAggFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2459,6 +2454,9 @@ static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkSelectStmtHasAggFuncs, &pNode->hasAggFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -17,29 +17,24 @@
|
|||
|
||||
#define COMPARE_SCALAR_FIELD(fldname) \
|
||||
do { \
|
||||
if (a->fldname != b->fldname) \
|
||||
return false; \
|
||||
if (a->fldname != b->fldname) return false; \
|
||||
} while (0)
|
||||
|
||||
#define COMPARE_STRING(a, b) \
|
||||
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
|
||||
#define COMPARE_STRING(a, b) (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
|
||||
|
||||
#define COMPARE_STRING_FIELD(fldname) \
|
||||
do { \
|
||||
if (!COMPARE_STRING(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
if (!COMPARE_STRING(a->fldname, b->fldname)) return false; \
|
||||
} while (0)
|
||||
|
||||
#define COMPARE_NODE_FIELD(fldname) \
|
||||
do { \
|
||||
if (!nodesEqualNode(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
if (!nodesEqualNode(a->fldname, b->fldname)) return false; \
|
||||
} while (0)
|
||||
|
||||
#define COMPARE_NODE_LIST_FIELD(fldname) \
|
||||
do { \
|
||||
if (!nodeNodeListEqual(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
if (!nodeNodeListEqual(a->fldname, b->fldname)) return false; \
|
||||
} while (0)
|
||||
|
||||
static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) {
|
||||
|
|
|
@ -21,9 +21,35 @@
|
|||
#include "taoserror.h"
|
||||
#include "thash.h"
|
||||
|
||||
char *gOperatorStr[] = {NULL, "+", "-", "*", "/", "%", "-", "&", "|", ">", ">=", "<", "<=", "=", "<>",
|
||||
"IN", "NOT IN", "LIKE", "NOT LIKE", "MATCH", "NMATCH", "IS NULL", "IS NOT NULL",
|
||||
"IS TRUE", "IS FALSE", "IS UNKNOWN", "IS NOT TRUE", "IS NOT FALSE", "IS NOT UNKNOWN"};
|
||||
char *gOperatorStr[] = {NULL,
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
"/",
|
||||
"%",
|
||||
"-",
|
||||
"&",
|
||||
"|",
|
||||
">",
|
||||
">=",
|
||||
"<",
|
||||
"<=",
|
||||
"=",
|
||||
"<>",
|
||||
"IN",
|
||||
"NOT IN",
|
||||
"LIKE",
|
||||
"NOT LIKE",
|
||||
"MATCH",
|
||||
"NMATCH",
|
||||
"IS NULL",
|
||||
"IS NOT NULL",
|
||||
"IS TRUE",
|
||||
"IS FALSE",
|
||||
"IS UNKNOWN",
|
||||
"IS NOT TRUE",
|
||||
"IS NOT FALSE",
|
||||
"IS NOT UNKNOWN"};
|
||||
char *gLogicConditionStr[] = {"AND", "OR", "NOT"};
|
||||
|
||||
int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "querynodes.h"
|
||||
#include "plannodes.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
typedef enum ETraversalOrder {
|
||||
TRAVERSAL_PREORDER = 1,
|
||||
|
@ -29,7 +29,8 @@ static EDealRes walkExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeWalk
|
|||
static EDealRes walkPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext);
|
||||
static EDealRes walkPhysiPlans(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext);
|
||||
|
||||
static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext, FNodeDispatcher dispatcher) {
|
||||
static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext,
|
||||
FNodeDispatcher dispatcher) {
|
||||
if (NULL == pNode) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
@ -395,7 +396,8 @@ static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNod
|
|||
return res;
|
||||
}
|
||||
|
||||
static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, void* pContext) {
|
||||
static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker,
|
||||
void* pContext) {
|
||||
EDealRes res = walkScanPhysi((SScanPhysiNode*)pScan, order, walker, pContext);
|
||||
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
||||
res = walkPhysiPlans(pScan->pDynamicScanFuncs, order, walker, pContext);
|
||||
|
|
|
@ -298,9 +298,7 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
|
|||
nodesDestroyList(pNode->pScanCols);
|
||||
}
|
||||
|
||||
static void destroyDataSinkNode(SDataSinkNode* pNode) {
|
||||
nodesDestroyNode(pNode->pInputDataBlockDesc);
|
||||
}
|
||||
static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode(pNode->pInputDataBlockDesc); }
|
||||
|
||||
void nodesDestroyNode(SNodeptr pNode) {
|
||||
if (NULL == pNode) {
|
||||
|
@ -962,7 +960,8 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
|
|||
|
||||
bool nodesIsExprNode(const SNode* pNode) {
|
||||
ENodeType type = nodeType(pNode);
|
||||
return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || QUERY_NODE_FUNCTION == type);
|
||||
return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type ||
|
||||
QUERY_NODE_FUNCTION == type);
|
||||
}
|
||||
|
||||
bool nodesIsUnaryOp(const SOperatorNode* pOp) {
|
||||
|
@ -1037,13 +1036,9 @@ bool nodesIsJsonOp(const SOperatorNode* pOp) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool nodesIsTimeorderQuery(const SNode* pQuery) {
|
||||
return false;
|
||||
}
|
||||
bool nodesIsTimeorderQuery(const SNode* pQuery) { return false; }
|
||||
|
||||
bool nodesIsTimelineQuery(const SNode* pQuery) {
|
||||
return false;
|
||||
}
|
||||
bool nodesIsTimelineQuery(const SNode* pQuery) { return false; }
|
||||
|
||||
typedef struct SCollectColumnsCxt {
|
||||
int32_t errCode;
|
||||
|
@ -1089,8 +1084,7 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
|
|||
.errCode = TSDB_CODE_SUCCESS,
|
||||
.pTableAlias = pTableAlias,
|
||||
.pCols = nodesMakeList(),
|
||||
.pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)
|
||||
};
|
||||
.pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)};
|
||||
if (NULL == cxt.pCols || NULL == cxt.pColHash) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -1129,11 +1123,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SCollectFuncsCxt cxt = {
|
||||
.errCode = TSDB_CODE_SUCCESS,
|
||||
.classifier = classifier,
|
||||
.pFuncs = nodesMakeList()
|
||||
};
|
||||
SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .classifier = classifier, .pFuncs = nodesMakeList()};
|
||||
if (NULL == cxt.pFuncs) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -1152,7 +1142,6 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
char* getFillModeString(EFillMode mode) {
|
||||
switch (mode) {
|
||||
case FILL_MODE_NONE:
|
||||
|
@ -1201,7 +1190,6 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
|
|||
return num;
|
||||
}
|
||||
|
||||
|
||||
void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
||||
pVal->nType = pNode->node.resType.type;
|
||||
pVal->nLen = pNode->node.resType.bytes;
|
||||
|
@ -1241,6 +1229,3 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "cmdnodes.h"
|
||||
#include "parser.h"
|
||||
#include "parToken.h"
|
||||
#include "parUtil.h"
|
||||
#include "parser.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
typedef struct SAstCreateContext {
|
||||
|
@ -95,7 +95,6 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
|
|||
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
|
||||
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
|
||||
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList);
|
||||
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName);
|
||||
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt);
|
||||
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList);
|
||||
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2);
|
||||
|
@ -106,7 +105,8 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok
|
|||
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder);
|
||||
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap);
|
||||
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr);
|
||||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill);
|
||||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding,
|
||||
SNode* pFill);
|
||||
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues);
|
||||
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode);
|
||||
|
||||
|
@ -131,16 +131,20 @@ SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOptio
|
|||
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment);
|
||||
SDataType createDataType(uint8_t type);
|
||||
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
|
||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions);
|
||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags);
|
||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
|
||||
SNodeList* pTags, SNode* pOptions);
|
||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
|
||||
SNodeList* pSpecificTags, SNodeList* pValsOfTags);
|
||||
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
|
||||
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType);
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
const SToken* pColName, SDataType dataType);
|
||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName);
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName);
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
const SToken* pOldColName, const SToken* pNewColName);
|
||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal);
|
||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern);
|
||||
|
@ -152,13 +156,15 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
|
|||
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue);
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions);
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName,
|
||||
SToken* pTableName, SNodeList* pCols, SNode* pOptions);
|
||||
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding);
|
||||
SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName);
|
||||
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
|
||||
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
|
||||
SNode* createTopicOptions(SAstCreateContext* pCxt);
|
||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions);
|
||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery,
|
||||
const SToken* pSubscribeDbName, SNode* pOptions);
|
||||
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
||||
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue);
|
||||
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt);
|
||||
|
@ -168,10 +174,12 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions,
|
|||
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
||||
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt);
|
||||
SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups);
|
||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize);
|
||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
|
||||
const SToken* pLibPath, SDataType dataType, int32_t bufSize);
|
||||
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName);
|
||||
SNode* createStreamOptions(SAstCreateContext* pCxt);
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery);
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable,
|
||||
SNode* pOptions, SNode* pQuery);
|
||||
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName);
|
||||
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId);
|
||||
SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
#include "catalog.h"
|
||||
#include "os.h"
|
||||
#include "ttypes.h"
|
||||
#include "tname.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
||||
|
||||
|
@ -74,7 +74,8 @@ typedef struct STableDataBlocks {
|
|||
uint32_t nAllocSize;
|
||||
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
||||
uint32_t size;
|
||||
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
|
||||
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to
|
||||
// avoid to be removed from cache
|
||||
char *pData;
|
||||
bool cloned;
|
||||
int32_t createTbReqLen;
|
||||
|
@ -89,8 +90,8 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
|
|||
(int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx,
|
||||
int32_t *toffset, col_id_t *colIdx) {
|
||||
static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset,
|
||||
col_id_t *colIdx) {
|
||||
col_id_t schemaIdx = 0;
|
||||
if (IS_DATA_COL_ORDERED(spd)) {
|
||||
schemaIdx = spd->boundColumns[idx] - PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
|
@ -115,7 +116,8 @@ static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows) {
|
||||
pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid);
|
||||
pBlocks->suid =
|
||||
(TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid);
|
||||
pBlocks->uid = dataBuf->pTableMeta->uid;
|
||||
pBlocks->sversion = dataBuf->pTableMeta->sversion;
|
||||
pBlocks->schemaLen = dataBuf->createTbReqLen;
|
||||
|
@ -136,7 +138,8 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash);
|
|||
int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo);
|
||||
int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t *numOfRows);
|
||||
int32_t getDataBlockFromList(SHashObj *pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize,
|
||||
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq);
|
||||
const STableMeta *pTableMeta, STableDataBlocks **dataBlocks, SArray *pBlockList,
|
||||
SVCreateTbReq *pCreateTbReq);
|
||||
int32_t mergeTableDataBlocks(SHashObj *pHashObj, uint8_t payloadType, SArray **pVgDataBlocks);
|
||||
int32_t buildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
||||
int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "parser.h"
|
||||
#include "parToken.h"
|
||||
#include "parUtil.h"
|
||||
#include "parser.h"
|
||||
|
||||
int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery);
|
||||
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery);
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "ttokendef.h"
|
||||
|
||||
// used to denote the minimum unite in sql parsing
|
||||
|
|
|
@ -498,6 +498,7 @@ signed_literal(A) ::= NK_BOOL(B).
|
|||
signed_literal(A) ::= TIMESTAMP NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); }
|
||||
signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); }
|
||||
signed_literal(A) ::= NULL. { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); }
|
||||
signed_literal(A) ::= literal_func(B). { A = releaseRawExprNode(pCxt, B); }
|
||||
|
||||
%type literal_list { SNodeList* }
|
||||
%destructor literal_list { nodesDestroyList($$); }
|
||||
|
@ -610,8 +611,10 @@ pseudo_column(A) ::= WDURATION(B).
|
|||
function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
function_expression(A) ::= star_func(B) NK_LP star_func_para_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
function_expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); }
|
||||
function_expression(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNodeNoArg(pCxt, &B)); }
|
||||
//function_expression(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
function_expression(A) ::= literal_func(B). { A = B; }
|
||||
|
||||
literal_func(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNode(pCxt, &B, NULL)); }
|
||||
literal_func(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
|
||||
%type noarg_func { SToken }
|
||||
%destructor noarg_func { }
|
||||
|
|
|
@ -352,12 +352,13 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
|
|||
|
||||
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
||||
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND,
|
||||
createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight));
|
||||
createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft),
|
||||
createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight));
|
||||
}
|
||||
|
||||
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
||||
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR,
|
||||
createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight));
|
||||
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft),
|
||||
createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight));
|
||||
}
|
||||
|
||||
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) {
|
||||
|
@ -368,39 +369,6 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod
|
|||
return (SNode*)func;
|
||||
}
|
||||
|
||||
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName) {
|
||||
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_OUT_OF_MEM(func);
|
||||
char buf[64] = {0};
|
||||
|
||||
int32_t dataType;
|
||||
switch (pFuncName->type) {
|
||||
case TK_NOW: {
|
||||
int64_t ts = taosGetTimestamp(TSDB_TIME_PRECISION_MILLI);
|
||||
snprintf(buf, sizeof(buf), "%"PRId64, ts);
|
||||
dataType = TSDB_DATA_TYPE_BIGINT;
|
||||
break;
|
||||
}
|
||||
case TK_TODAY: {
|
||||
int64_t ts = taosGetTimestampToday(TSDB_TIME_PRECISION_MILLI);
|
||||
snprintf(buf, sizeof(buf), "%"PRId64, ts);
|
||||
dataType = TSDB_DATA_TYPE_BIGINT;
|
||||
break;
|
||||
}
|
||||
case TK_TIMEZONE: {
|
||||
strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr));
|
||||
dataType = TSDB_DATA_TYPE_BINARY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SToken token = {.type = pFuncName->type, .n = strlen(buf), .z = buf};
|
||||
|
||||
SNodeList *pParameterList = createNodeList(pCxt, createValueNode(pCxt, dataType, &token));
|
||||
strncpy(func->functionName, pFuncName->z, pFuncName->n);
|
||||
func->pParameterList = pParameterList;
|
||||
return (SNode*)func;
|
||||
}
|
||||
|
||||
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) {
|
||||
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_OUT_OF_MEM(func);
|
||||
|
@ -444,9 +412,6 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa
|
|||
strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n);
|
||||
}
|
||||
strncpy(realTable->table.tableName, pTableName->z, pTableName->n);
|
||||
if (NULL != pCxt->pQueryCxt->db) {
|
||||
strcpy(realTable->useDbName, pCxt->pQueryCxt->db);
|
||||
}
|
||||
return (SNode*)realTable;
|
||||
}
|
||||
|
||||
|
@ -519,7 +484,8 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
|
|||
return (SNode*)state;
|
||||
}
|
||||
|
||||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill) {
|
||||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding,
|
||||
SNode* pFill) {
|
||||
SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||
CHECK_OUT_OF_MEM(interval);
|
||||
interval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
|
@ -794,8 +760,8 @@ SDataType createVarLenDataType(uint8_t type, const SToken* pLen) {
|
|||
return dt;
|
||||
}
|
||||
|
||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
||||
bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions) {
|
||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
|
||||
SNodeList* pTags, SNode* pOptions) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -811,8 +777,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt,
|
||||
bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags) {
|
||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
|
||||
SNodeList* pSpecificTags, SNodeList* pValsOfTags) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -878,7 +844,8 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode*
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType) {
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
const SToken* pColName, SDataType dataType) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -901,7 +868,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName) {
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
const SToken* pOldColName, const SToken* pNewColName) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -936,7 +904,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
|
|||
}
|
||||
|
||||
static bool needDbShowStmt(ENodeType type) {
|
||||
return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type || QUERY_NODE_SHOW_VGROUPS_STMT == type;
|
||||
return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type ||
|
||||
QUERY_NODE_SHOW_VGROUPS_STMT == type;
|
||||
}
|
||||
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) {
|
||||
|
@ -945,7 +914,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S
|
|||
pCxt->valid = false;
|
||||
return NULL;
|
||||
}
|
||||
SShowStmt* pStmt = nodesMakeNode(type);;
|
||||
SShowStmt* pStmt = nodesMakeNode(type);
|
||||
;
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->pDbName = pDbName;
|
||||
pStmt->pTbNamePattern = pTbNamePattern;
|
||||
|
@ -1040,7 +1010,8 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue) {
|
||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig,
|
||||
const SToken* pValue) {
|
||||
SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->dnodeId = strtol(pDnode->z, NULL, 10);
|
||||
|
@ -1051,7 +1022,8 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions) {
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName,
|
||||
SToken* pTableName, SNodeList* pCols, SNode* pOptions) {
|
||||
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1066,7 +1038,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding) {
|
||||
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset,
|
||||
SNode* pSliding) {
|
||||
SIndexOptions* pOptions = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->pFuncs = pFuncs;
|
||||
|
@ -1091,14 +1064,16 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken
|
|||
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
||||
SCreateComponentNodeStmt* pStmt = nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);;
|
||||
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);
|
||||
;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
||||
SDropComponentNodeStmt* pStmt = nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);;
|
||||
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);
|
||||
;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
|
@ -1111,8 +1086,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) {
|
|||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt,
|
||||
bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions) {
|
||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery,
|
||||
const SToken* pSubscribeDbName, SNode* pOptions) {
|
||||
SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
||||
|
@ -1194,8 +1169,8 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
|
|||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt,
|
||||
bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
|
||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
|
||||
const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
|
||||
if (pLibPath->n <= 2) {
|
||||
pCxt->valid = false;
|
||||
return NULL;
|
||||
|
@ -1224,7 +1199,8 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) {
|
|||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery) {
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable,
|
||||
SNode* pOptions, SNode* pQuery) {
|
||||
SCreateStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->streamName, pStreamName->z, pStreamName->n);
|
||||
|
|
|
@ -24,109 +24,37 @@ typedef struct SCalcConstContext {
|
|||
int32_t code;
|
||||
} SCalcConstContext;
|
||||
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt);
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery);
|
||||
|
||||
static int32_t calcConstSubquery(SCalcConstContext* pCxt, STempTableNode* pTempTable) {
|
||||
return calcConstQuery(pCxt, pTempTable->pSubquery, true);
|
||||
}
|
||||
|
||||
static int32_t calcConstNode(SNode** pNode) {
|
||||
if (NULL == *pNode) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static EDealRes doCalcConst(SNode** pNode, SCalcConstContext* pCxt) {
|
||||
SNode* pNew = NULL;
|
||||
pCxt->code = scalarCalculateConstants(*pNode, &pNew);
|
||||
if (TSDB_CODE_SUCCESS != pCxt->code) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
((SValueNode*)pNew)->genByCalc = true;
|
||||
((SValueNode*)pNew)->translate = true;
|
||||
int32_t code = scalarCalculateConstants(*pNode, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pNode = pNew;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool isTimestampCol(SNode* pNode) {
|
||||
if (NULL == pNode) {
|
||||
return false;
|
||||
}
|
||||
return (QUERY_NODE_COLUMN == nodeType(pNode) && TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode*)pNode)->resType.type);
|
||||
}
|
||||
|
||||
static EDealRes stringToTimestamp(SCalcConstContext* pCxt, uint8_t precision, SValueNode* pVal) {
|
||||
switch (pVal->node.resType.type) {
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY: {
|
||||
int64_t val = 0;
|
||||
if (TSDB_CODE_SUCCESS != convertStringToTimestamp(pVal->node.resType.type, pVal->datum.p, precision, &val)) {
|
||||
pCxt->code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCORRECT_TIMESTAMP_VAL, varDataVal(pVal->datum.p));
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
pVal->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
||||
taosMemoryFreeClear(pVal->datum.p);
|
||||
pVal->datum.i = val;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes calcConstOperator(SOperatorNode** pNode, void* pContext) {
|
||||
SCalcConstContext* pCxt = pContext;
|
||||
SOperatorNode* pOp = *pNode;
|
||||
if (QUERY_NODE_VALUE == nodeType(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) {
|
||||
return doCalcConst((SNode**)pNode, pCxt);
|
||||
}
|
||||
if (isTimestampCol(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) {
|
||||
return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pLeft)->node.resType.precision, (SValueNode*)pOp->pRight);
|
||||
} else if (isTimestampCol(pOp->pRight) && QUERY_NODE_VALUE == nodeType(pOp->pLeft)) {
|
||||
return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pRight)->node.resType.precision, (SValueNode*)pOp->pLeft);
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes calcConstFunction(SFunctionNode** pNode, void* pContext) {
|
||||
SFunctionNode* pFunc = *pNode;
|
||||
if (!fmIsScalarFunc(pFunc->funcId) || fmIsUserDefinedFunc(pFunc->funcId)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
SNode* pParam = NULL;
|
||||
FOREACH(pParam, pFunc->pParameterList) {
|
||||
if (QUERY_NODE_VALUE != nodeType(pParam)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
static int32_t calcConstList(SNodeList* pList) {
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
SNode* pNew = NULL;
|
||||
int32_t code = scalarCalculateConstants(pNode, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pNew);
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext);
|
||||
}
|
||||
|
||||
static EDealRes calcConstLogicCond(SLogicConditionNode** pNode, void* pContext) {
|
||||
SLogicConditionNode* pCond = *pNode;
|
||||
SNode* pParam = NULL;
|
||||
FOREACH(pParam, pCond->pParameterList) {
|
||||
// todo calc "true and c1 > 10"
|
||||
if (QUERY_NODE_VALUE != nodeType(pParam)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
}
|
||||
return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext);
|
||||
}
|
||||
|
||||
static EDealRes calcConstSubquery(STempTableNode** pNode, void* pContext) {
|
||||
SCalcConstContext* pCxt = pContext;
|
||||
pCxt->code = calcConstQuery(pCxt, (*pNode)->pSubquery);
|
||||
return (TSDB_CODE_SUCCESS == pCxt->code ? DEAL_RES_CONTINUE : DEAL_RES_ERROR);
|
||||
}
|
||||
|
||||
static EDealRes calcConst(SNode** pNode, void* pContext) {
|
||||
switch (nodeType(*pNode)) {
|
||||
case QUERY_NODE_OPERATOR:
|
||||
return calcConstOperator((SOperatorNode**)pNode, pContext);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return calcConstFunction((SFunctionNode**)pNode, pContext);
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
return calcConstLogicCond((SLogicConditionNode**)pNode, pContext);
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
return calcConstSubquery((STempTableNode**)pNode, pContext);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isCondition(const SNode* pNode) {
|
||||
|
@ -174,18 +102,41 @@ static int32_t rewriteCondition(SCalcConstContext* pCxt, SNode** pNode) {
|
|||
return pCxt->code;
|
||||
}
|
||||
|
||||
static int32_t calcConstCondition(SCalcConstContext* pCxt, SNode** pNode) {
|
||||
int32_t code = rewriteCondition(pCxt, pNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstNode(pNode);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTable) {
|
||||
if (QUERY_NODE_JOIN_TABLE == nodeType(pTable)) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pTable)) {
|
||||
case QUERY_NODE_TEMP_TABLE: {
|
||||
code = calcConstSubquery(pCxt, (STempTableNode*)pTable);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_JOIN_TABLE: {
|
||||
SJoinTableNode* pJoin = (SJoinTableNode*)pTable;
|
||||
pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pLeft);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pRight);
|
||||
code = rewriteConditionForFromTable(pCxt, pJoin->pLeft);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteConditionForFromTable(pCxt, pJoin->pRight);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code && NULL != pJoin->pOnCond) {
|
||||
pCxt->code = rewriteCondition(pCxt, &pJoin->pOnCond);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->pOnCond) {
|
||||
code = calcConstCondition(pCxt, &pJoin->pOnCond);
|
||||
}
|
||||
// todo empty table
|
||||
break;
|
||||
}
|
||||
return pCxt->code;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstFromTable(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
|
||||
return rewriteConditionForFromTable(pCxt, pSelect->pFromTable);
|
||||
}
|
||||
|
||||
static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) {
|
||||
|
@ -200,89 +151,143 @@ static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t calcConstFromTable(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
|
||||
pCxt->code = rewriteConditionForFromTable(pCxt, pSelect->pFromTable);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprPostOrder(&pSelect->pFromTable, calcConst, pCxt);
|
||||
}
|
||||
return pCxt->code;
|
||||
}
|
||||
|
||||
static int32_t calcConstCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) {
|
||||
static int32_t calcConstSelectCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) {
|
||||
if (NULL == *pCond) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pCxt->code = rewriteCondition(pCxt, pCond);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprPostOrder(pCond, calcConst, pCxt);
|
||||
int32_t code = rewriteCondition(pCxt, pCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstNode(pCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
rewriteConstCondition(pSelect, pCond);
|
||||
}
|
||||
return pCxt->code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
|
||||
nodesRewriteExprsPostOrder(pSelect->pProjectionList, calcConst, pCxt);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
pCxt->code = calcConstFromTable(pCxt, pSelect);
|
||||
static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
|
||||
SArray* pAssociation = NULL;
|
||||
if (NULL != ((SExprNode*)pProject)->pAssociation) {
|
||||
pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation);
|
||||
if (NULL == pAssociation) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
pCxt->code = calcConstCondition(pCxt, pSelect, &pSelect->pWhere);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprsPostOrder(pSelect->pPartitionByList, calcConst, pCxt);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprPostOrder(&pSelect->pWindow, calcConst, pCxt);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprsPostOrder(pSelect->pGroupByList, calcConst, pCxt);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
pCxt->code = calcConstCondition(pCxt, pSelect, &pSelect->pHaving);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprsPostOrder(pSelect->pOrderByList, calcConst, pCxt);
|
||||
}
|
||||
return pCxt->code;
|
||||
}
|
||||
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return calcConstSelect(pCxt, (SSelectStmt*)pStmt);
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return calcConstQuery(pCxt, ((SExplainStmt*)pStmt)->pQuery);
|
||||
default:
|
||||
break;
|
||||
int32_t code = scalarCalculateConstants(pProject, pNew);
|
||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE == nodeType(pNew) && NULL != pAssociation) {
|
||||
int32_t size = taosArrayGetSize(pAssociation);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SNode** pCol = taosArrayGet(pAssociation, i);
|
||||
*pCol = nodesCloneNode(pNew);
|
||||
if (NULL == *pCol) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProjections, bool subquery) {
|
||||
SNode* pProj = NULL;
|
||||
WHERE_EACH(pProj, pProjections) {
|
||||
if (subquery && NULL == ((SExprNode*)pProj)->pAssociation) {
|
||||
ERASE_NODE(pProjections);
|
||||
continue;
|
||||
}
|
||||
SNode* pNew = NULL;
|
||||
int32_t code = calcConstProject(pProj, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pNew);
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
WHERE_NEXT;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isEmptyResultQuery(SNode* pStmt) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return ((SSelectStmt*)pStmt)->isEmptyResult;
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return isEmptyResultQuery(((SExplainStmt*)pStmt)->pQuery);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
|
||||
SCalcConstContext cxt = {
|
||||
.pParseCxt = pParseCxt,
|
||||
.msgBuf.buf = pParseCxt->pMsg,
|
||||
.msgBuf.len = pParseCxt->msgLen,
|
||||
.code = TSDB_CODE_SUCCESS
|
||||
};
|
||||
int32_t code = calcConstQuery(&cxt, pQuery->pRoot);
|
||||
static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) {
|
||||
int32_t code = calcConstProjections(pCxt, pSelect->pProjectionList, subquery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pQuery->execMode = isEmptyResultQuery(pQuery->pRoot) ? QUERY_EXEC_MODE_EMPTY_RESULT : pQuery->execMode;
|
||||
code = calcConstFromTable(pCxt, pSelect);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pWhere);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstList(pSelect->pPartitionByList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstNode(&pSelect->pWindow);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstList(pSelect->pGroupByList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pHaving);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstList(pSelect->pOrderByList);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
code = calcConstSelect(pCxt, (SSelectStmt*)pStmt, subquery);
|
||||
break;
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
code = calcConstQuery(pCxt, ((SExplainStmt*)pStmt)->pQuery, subquery);
|
||||
break;
|
||||
case QUERY_NODE_SET_OPERATOR: {
|
||||
SSetOperator* pSetOp = (SSetOperator*)pStmt;
|
||||
code = calcConstQuery(pCxt, pSetOp->pLeft, subquery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstQuery(pCxt, pSetOp->pRight, subquery);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool isEmptyResultQuery(SNode* pStmt) {
|
||||
bool isEmptyResult = false;
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
isEmptyResult = ((SSelectStmt*)pStmt)->isEmptyResult;
|
||||
break;
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
isEmptyResult = isEmptyResultQuery(((SExplainStmt*)pStmt)->pQuery);
|
||||
break;
|
||||
case QUERY_NODE_SET_OPERATOR: {
|
||||
SSetOperator* pSetOp = (SSetOperator*)pStmt;
|
||||
isEmptyResult = isEmptyResultQuery(pSetOp->pLeft);
|
||||
if (isEmptyResult) {
|
||||
isEmptyResult = isEmptyResultQuery(pSetOp->pRight);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return isEmptyResult;
|
||||
}
|
||||
|
||||
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
|
||||
SCalcConstContext cxt = {.pParseCxt = pParseCxt,
|
||||
.msgBuf.buf = pParseCxt->pMsg,
|
||||
.msgBuf.len = pParseCxt->msgLen,
|
||||
.code = TSDB_CODE_SUCCESS};
|
||||
int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false);
|
||||
if (TSDB_CODE_SUCCESS == code && isEmptyResultQuery(pQuery->pRoot)) {
|
||||
pQuery->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,6 @@ typedef struct SMemParam {
|
|||
col_id_t colIdx;
|
||||
} SMemParam;
|
||||
|
||||
|
||||
#define CHECK_CODE(expr) \
|
||||
do { \
|
||||
int32_t code = expr; \
|
||||
|
@ -85,7 +84,6 @@ typedef struct SMemParam {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
static int32_t skipInsertInto(SInsertParseContext* pCxt) {
|
||||
SToken sToken;
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
|
@ -179,7 +177,6 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "name too long";
|
||||
const char* msg2 = "invalid database name";
|
||||
|
@ -739,7 +736,8 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, voi
|
|||
}
|
||||
|
||||
if (value == NULL) { // it is a null data
|
||||
// tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
|
||||
// tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset,
|
||||
// pa->colIdx);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -886,7 +884,8 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow, char* tmpTokenBuf) {
|
||||
static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow,
|
||||
char* tmpTokenBuf) {
|
||||
SParsedDataColInfo* spd = &pDataBlocks->boundColumnInfo;
|
||||
SRowBuilder* pBuilder = &pDataBlocks->rowBuilder;
|
||||
STSRow* row = (STSRow*)(pDataBlocks->pData + pDataBlocks->size); // skip the SSubmitBlk header
|
||||
|
@ -1068,7 +1067,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
}
|
||||
|
||||
if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && tbNum > 0) {
|
||||
return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt");;
|
||||
return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt");
|
||||
;
|
||||
}
|
||||
|
||||
destroyInsertParseContextForTable(pCxt);
|
||||
|
@ -1170,18 +1170,18 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) {
|
|||
.pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false),
|
||||
.totalNum = 0,
|
||||
.pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT),
|
||||
.pStmtCb = pContext->pStmtCb
|
||||
};
|
||||
.pStmtCb = pContext->pStmtCb};
|
||||
|
||||
if (pContext->pStmtCb && *pQuery) {
|
||||
(*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj, &context.pTableBlockHashObj);
|
||||
(*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj,
|
||||
&context.pTableBlockHashObj);
|
||||
} else {
|
||||
context.pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false);
|
||||
context.pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
||||
}
|
||||
|
||||
if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj ||
|
||||
NULL == context.pSubTableHashObj || NULL == context.pOutput) {
|
||||
if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pSubTableHashObj ||
|
||||
NULL == context.pOutput) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -1210,8 +1210,8 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) {
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen) {
|
||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
|
||||
int32_t msgBufLen) {
|
||||
SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
|
||||
SToken sToken;
|
||||
int32_t code = 0;
|
||||
|
@ -1237,7 +1237,6 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) {
|
||||
SVnodeModifOpStmt* modifyNode = (SVnodeModifOpStmt*)pQuery->pRoot;
|
||||
int32_t code = 0;
|
||||
|
@ -1257,7 +1256,8 @@ int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen){
|
||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, SName* pName, TAOS_BIND_v2* bind, char* msgBuf,
|
||||
int32_t msgBufLen) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
||||
|
@ -1307,7 +1307,6 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qBindStmtColsValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||
|
@ -1382,7 +1381,8 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum) {
|
||||
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
||||
int32_t rowNum) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||
int32_t extendedRowSize = getExtendedRowSize(pDataBlock);
|
||||
|
@ -1462,7 +1462,6 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD** fields) {
|
||||
if (fields) {
|
||||
*fields = taosMemoryCalloc(boundInfo->numOfBound, sizeof(TAOS_FIELD));
|
||||
|
@ -1483,7 +1482,6 @@ int32_t buildBoundFields(SParsedDataColInfo *boundInfo, SSchema *pSchema, int32_
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
||||
|
@ -1520,6 +1518,3 @@ int32_t qBuildStmtColFields(void *pBlock, int32_t *fieldNum, TAOS_FIELD** fields
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
#include "parInsertData.h"
|
||||
|
||||
#include "catalog.h"
|
||||
#include "parInt.h"
|
||||
#include "parUtil.h"
|
||||
#include "querynodes.h"
|
||||
#include "parInt.h"
|
||||
|
||||
#define IS_RAW_PAYLOAD(t) \
|
||||
(((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
|
@ -115,8 +115,8 @@ void destroyBoundColumnInfo(void* pBoundInfo) {
|
|||
taosMemoryFreeClear(pColList->colIdxInfo);
|
||||
}
|
||||
|
||||
static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset,
|
||||
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks) {
|
||||
static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, const STableMeta* pTableMeta,
|
||||
STableDataBlocks** dataBlocks) {
|
||||
STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks));
|
||||
if (dataBuf == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -177,7 +177,8 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq)
|
|||
}
|
||||
|
||||
int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize,
|
||||
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq) {
|
||||
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList,
|
||||
SVCreateTbReq* pCreateTbReq) {
|
||||
*dataBlocks = NULL;
|
||||
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id));
|
||||
if (t1 != NULL) {
|
||||
|
@ -374,7 +375,8 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
|
|||
}
|
||||
|
||||
// Erase the empty space reserved for binary data
|
||||
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, bool isRawPayload) {
|
||||
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple,
|
||||
bool isRawPayload) {
|
||||
// TODO: optimize this function, handle the case while binary is not presented
|
||||
STableMeta* pTableMeta = pTableDataBlock->pTableMeta;
|
||||
STableComInfo tinfo = getTableInfo(pTableMeta);
|
||||
|
@ -444,8 +446,9 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
|||
SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData;
|
||||
if (pBlocks->numOfRows > 0) {
|
||||
STableDataBlocks* dataBuf = NULL;
|
||||
int32_t ret = getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE,
|
||||
INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL);
|
||||
int32_t ret =
|
||||
getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0,
|
||||
pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosHashCleanup(pVnodeDataBlockHashList);
|
||||
destroyBlockArrayList(pVnodeDataBlockList);
|
||||
|
@ -490,7 +493,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
|||
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta);
|
||||
|
||||
// erase the empty space reserved for binary data
|
||||
int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload);
|
||||
int32_t finalLen =
|
||||
trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload);
|
||||
assert(finalLen <= len);
|
||||
|
||||
dataBuf->size += (finalLen + sizeof(SSubmitBlk));
|
||||
|
@ -571,7 +575,6 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
||||
STableDataBlocks* pBlock = (STableDataBlocks*)block;
|
||||
|
||||
|
@ -599,7 +602,6 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) {
|
||||
*pDst = taosMemoryMalloc(sizeof(STableDataBlocks));
|
||||
if (NULL == *pDst) {
|
||||
|
@ -630,7 +632,6 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void qFreeStmtDataBlock(void* pDataBlock) {
|
||||
if (pDataBlock == NULL) {
|
||||
return;
|
||||
|
@ -650,4 +651,3 @@ void qDestroyStmtDataBlock(void* pBlock) {
|
|||
pDataBlock->cloned = false;
|
||||
destroyDataBlock(pDataBlock);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
#include "os.h"
|
||||
#include "parToken.h"
|
||||
#include "thash.h"
|
||||
#include "taosdef.h"
|
||||
#include "thash.h"
|
||||
#include "ttokendef.h"
|
||||
|
||||
// All the keywords of the SQL language are stored in a hash table
|
||||
|
@ -557,10 +557,9 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
}
|
||||
|
||||
/* here is the 1u/1a/2s/3m/9y */
|
||||
if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' ||
|
||||
z[i] == 'y' || z[i] == 'w' ||
|
||||
z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' ||
|
||||
z[i] == 'Y' || z[i] == 'W') &&
|
||||
if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' ||
|
||||
z[i] == 'n' || z[i] == 'y' || z[i] == 'w' || z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' ||
|
||||
z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'Y' || z[i] == 'W') &&
|
||||
(isIdChar[(uint8_t)z[i + 1]] == 0)) {
|
||||
*tokenId = TK_NK_VARIABLE;
|
||||
i += 1;
|
||||
|
@ -728,9 +727,7 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
|
|||
return t0;
|
||||
}
|
||||
|
||||
bool taosIsKeyWordToken(const char* z, int32_t len) {
|
||||
return (tKeywordCode((char*)z, len) != TK_NK_ID);
|
||||
}
|
||||
bool taosIsKeyWordToken(const char* z, int32_t len) { return (tKeywordCode((char*)z, len) != TK_NK_ID); }
|
||||
|
||||
void taosCleanupKeywordsTable() {
|
||||
void* m = keywordHashTable;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "cmdnodes.h"
|
||||
#include "functionMgt.h"
|
||||
#include "parUtil.h"
|
||||
#include "scalar.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
|
||||
|
@ -305,7 +306,10 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
|
|||
|
||||
static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) {
|
||||
pCol->pProjectRef = (SNode*)pExpr;
|
||||
nodesListAppend(pExpr->pAssociationList, (SNode*)pCol);
|
||||
if (NULL == pExpr->pAssociation) {
|
||||
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
|
||||
}
|
||||
taosArrayPush(pExpr->pAssociation, &pCol);
|
||||
if (NULL != pTable) {
|
||||
strcpy(pCol->tableAlias, pTable->tableAlias);
|
||||
} else if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||
|
@ -589,15 +593,15 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
|
|||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog,
|
||||
.pRpc = pCxt->pParseCxt->pTransporter,
|
||||
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet};
|
||||
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(¶m, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName);
|
||||
}
|
||||
pCxt->errCode = fmGetFuncResultType(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
||||
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet,
|
||||
.pErrBuf = pCxt->msgBuf.buf,
|
||||
.errBufLen = pCxt->msgBuf.len};
|
||||
pCxt->errCode = fmGetFuncInfo(¶m, pFunc);
|
||||
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
if (fmIsAggFunc(pFunc->funcId) && beforeHaving(pCxt->currClause)) {
|
||||
if (fmIsAggFunc(pFunc->funcId)) {
|
||||
if (beforeHaving(pCxt->currClause)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION);
|
||||
}
|
||||
bool haveAggFunc = false;
|
||||
|
@ -605,6 +609,9 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
|||
if (haveAggFunc) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
pCxt->pCurrStmt->hasAggFuncs = true;
|
||||
}
|
||||
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -759,6 +766,19 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) {
|
||||
if (NULL == *pVgroupList) {
|
||||
*pVgroupList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVgroupInfo));
|
||||
if (NULL == *pVgroupList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
SVgroupInfo vg = {.vgId = MNODE_HANDLE};
|
||||
memcpy(&vg.epSet, pEpSet, sizeof(SEpSet));
|
||||
taosArrayPush(*pVgroupList, &vg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) {
|
||||
if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -766,12 +786,20 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea
|
|||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SArray* vgroupList = NULL;
|
||||
if ('\0' != pRealTable->useDbName[0]) {
|
||||
code = getDBVgInfo(pCxt, pRealTable->useDbName, &vgroupList);
|
||||
if ('\0' != pRealTable->qualDbName[0]) {
|
||||
// todo release after mnode can be processed
|
||||
// if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) {
|
||||
code = getDBVgInfo(pCxt, pRealTable->qualDbName, &vgroupList);
|
||||
// }
|
||||
} else {
|
||||
code = getDBVgInfoImpl(pCxt, pName, &vgroupList);
|
||||
}
|
||||
|
||||
// todo release after mnode can be processed
|
||||
// if (TSDB_CODE_SUCCESS == code) {
|
||||
// code = addMnodeToVgroupList(&pCxt->pParseCxt->mgmtEpSet, &vgroupList);
|
||||
// }
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList);
|
||||
}
|
||||
|
@ -1965,13 +1993,6 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs
|
|||
if (1 != LIST_LENGTH(pFuncs)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROLLUP_OPTION);
|
||||
}
|
||||
SFunctionNode* pFunc = nodesListGetNode(pFuncs, 0);
|
||||
SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog,
|
||||
.pRpc = pCxt->pParseCxt->pTransporter,
|
||||
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet};
|
||||
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(¶m, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -2001,13 +2022,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t getAggregationMethod(SNodeList* pFuncs) {
|
||||
if (NULL == pFuncs) {
|
||||
return -1;
|
||||
}
|
||||
return ((SFunctionNode*)nodesListGetNode(pFuncs, 0))->funcId;
|
||||
}
|
||||
|
||||
static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) {
|
||||
int8_t flags = 0;
|
||||
if (pCol->sma) {
|
||||
|
@ -2229,7 +2243,6 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
|
|||
|
||||
static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) {
|
||||
pReq->igExists = pStmt->ignoreExists;
|
||||
pReq->aggregationMethod = getAggregationMethod(pStmt->pOptions->pFuncs);
|
||||
pReq->xFilesFactor = GET_OPTION_VAL(pStmt->pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR);
|
||||
pReq->delay = GET_OPTION_VAL(pStmt->pOptions->pDelay, TSDB_DEFAULT_DB_DELAY);
|
||||
columnDefNodeToField(pStmt->pCols, &pReq->pColumns);
|
||||
|
@ -3193,7 +3206,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect)
|
|||
}
|
||||
|
||||
if (NULL != pShow->pDbName) {
|
||||
strcpy(((SRealTableNode*)pSelect->pFromTable)->useDbName, ((SValueNode*)pShow->pDbName)->literal);
|
||||
strcpy(((SRealTableNode*)pSelect->pFromTable)->qualDbName, ((SValueNode*)pShow->pDbName)->literal);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -3235,14 +3248,6 @@ static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) {
|
|||
}
|
||||
pReq->ntbCfg.pRSmaParam->delay = GET_OPTION_VAL(pOptions->pDelay, TSDB_DEFAULT_DB_DELAY);
|
||||
pReq->ntbCfg.pRSmaParam->xFilesFactor = GET_OPTION_VAL(pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR);
|
||||
pReq->ntbCfg.pRSmaParam->nFuncIds = LIST_LENGTH(pOptions->pFuncs);
|
||||
pReq->ntbCfg.pRSmaParam->pFuncIds = taosMemoryCalloc(pReq->ntbCfg.pRSmaParam->nFuncIds, sizeof(func_id_t));
|
||||
if (NULL == pReq->ntbCfg.pRSmaParam->pFuncIds) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int32_t index = 0;
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pOptions->pFuncs) { pReq->ntbCfg.pRSmaParam->pFuncIds[index++] = ((SFunctionNode*)pFunc)->funcId; }
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -3428,10 +3433,6 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
|
|||
return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId);
|
||||
}
|
||||
|
||||
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
|
||||
return pCxt->errCode;
|
||||
}
|
||||
|
||||
if (pVal->node.resType.type == TSDB_DATA_TYPE_NULL) {
|
||||
// todo
|
||||
} else {
|
||||
|
@ -3442,6 +3443,23 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createValueFromFunction(STranslateContext* pCxt, SFunctionNode* pFunc, SValueNode** pVal) {
|
||||
if (DEAL_RES_ERROR == translateFunction(pCxt, pFunc)) {
|
||||
return pCxt->errCode;
|
||||
}
|
||||
return scalarCalculateConstants((SNode*)pFunc, (SNode**)pVal);
|
||||
}
|
||||
|
||||
static int32_t translateTagVal(STranslateContext* pCxt, SNode* pNode, SValueNode** pVal) {
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
|
||||
return createValueFromFunction(pCxt, (SFunctionNode*)pNode, pVal);
|
||||
} else if (QUERY_NODE_VALUE == nodeType(pNode)) {
|
||||
return (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode) ? pCxt->errCode : TSDB_CODE_SUCCESS);
|
||||
} else {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
||||
SKVRowBuilder* pBuilder) {
|
||||
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
|
||||
|
@ -3451,8 +3469,8 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
}
|
||||
|
||||
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
|
||||
SNode * pTag, *pVal;
|
||||
FORBOTH(pTag, pStmt->pSpecificTags, pVal, pStmt->pValsOfTags) {
|
||||
SNode * pTag, *pNode;
|
||||
FORBOTH(pTag, pStmt->pSpecificTags, pNode, pStmt->pValsOfTags) {
|
||||
SColumnNode* pCol = (SColumnNode*)pTag;
|
||||
SSchema* pSchema = NULL;
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
|
@ -3464,7 +3482,18 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
if (NULL == pSchema) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName);
|
||||
}
|
||||
int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pSchema, pBuilder);
|
||||
SValueNode* pVal = NULL;
|
||||
int32_t code = translateTagVal(pCxt, pNode, &pVal);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (NULL == pVal) {
|
||||
pVal = (SValueNode*)pNode;
|
||||
} else {
|
||||
REPLACE_LIST2_NODE(pVal);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addValToKVRow(pCxt, pVal, pSchema, pBuilder);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3480,10 +3509,21 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
|||
}
|
||||
|
||||
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
|
||||
SNode* pVal;
|
||||
SNode* pNode;
|
||||
int32_t index = 0;
|
||||
FOREACH(pVal, pStmt->pValsOfTags) {
|
||||
int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pTagSchema + index++, pBuilder);
|
||||
FOREACH(pNode, pStmt->pValsOfTags) {
|
||||
SValueNode* pVal = NULL;
|
||||
int32_t code = translateTagVal(pCxt, pNode, &pVal);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (NULL == pVal) {
|
||||
pVal = (SValueNode*)pNode;
|
||||
} else {
|
||||
REPLACE_NODE(pVal);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addValToKVRow(pCxt, pVal, pTagSchema + index++, pBuilder);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
return "Column ambiguously defined: %s";
|
||||
case TSDB_CODE_PAR_WRONG_VALUE_TYPE:
|
||||
return "Invalid value type: %s";
|
||||
case TSDB_CODE_PAR_INVALID_FUNTION:
|
||||
return "Invalid function name: %s";
|
||||
case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION:
|
||||
return "There mustn't be aggregation";
|
||||
case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT:
|
||||
|
@ -202,14 +200,16 @@ SSchema *getTableColumnSchema(const STableMeta *pTableMeta) {
|
|||
}
|
||||
|
||||
static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) {
|
||||
assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta)));
|
||||
assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 &&
|
||||
colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta)));
|
||||
|
||||
SSchema* pSchema = (SSchema*)pTableMeta->schema;
|
||||
return &pSchema[colIndex];
|
||||
}
|
||||
|
||||
SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
|
||||
assert(pTableMeta != NULL && (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE));
|
||||
assert(pTableMeta != NULL &&
|
||||
(pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE));
|
||||
return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,8 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
|||
uint8_t jsonNotNULL = TSDB_DATA_TYPE_JSON;
|
||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNotNULL, CHAR_BYTES); // add json type
|
||||
}
|
||||
taosHashPut(keyHash, jsonKey, keyLen, &keyLen, CHAR_BYTES); // add key to hash to remove dumplicate, value is useless
|
||||
taosHashPut(keyHash, jsonKey, keyLen, &keyLen,
|
||||
CHAR_BYTES); // add key to hash to remove dumplicate, value is useless
|
||||
|
||||
if (item->type == cJSON_String) { // add json value format: type|data
|
||||
char* jsonValue = item->valuestring;
|
||||
|
@ -359,7 +360,8 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
|||
*valueType = TSDB_DATA_TYPE_NCHAR;
|
||||
if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)varDataVal(valueData),
|
||||
(int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) {
|
||||
qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, strerror(errno));
|
||||
qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue,
|
||||
strerror(errno));
|
||||
retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue);
|
||||
goto end;
|
||||
}
|
||||
|
@ -374,9 +376,12 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
|||
}
|
||||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||
char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
||||
*valueType = (item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE;
|
||||
if(*valueType== TSDB_DATA_TYPE_DOUBLE) *((double *)valueData) = item->valuedouble;
|
||||
else if(*valueType == TSDB_DATA_TYPE_BIGINT) *((int64_t *)valueData) = item->valueint;
|
||||
*valueType =
|
||||
(item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE;
|
||||
if (*valueType == TSDB_DATA_TYPE_DOUBLE)
|
||||
*((double*)valueData) = item->valuedouble;
|
||||
else if (*valueType == TSDB_DATA_TYPE_BIGINT)
|
||||
*((int64_t*)valueData) = item->valueint;
|
||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES);
|
||||
} else if (item->type == cJSON_True || item->type == cJSON_False) {
|
||||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||
|
@ -388,8 +393,7 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
|||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||
*valueType = TSDB_DATA_TYPE_NULL;
|
||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
retCode = buildSyntaxErrMsg(pMsgBuf, "invalidate json value", json);
|
||||
goto end;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "parser.h"
|
||||
#include "os.h"
|
||||
|
||||
#include "parInt.h"
|
||||
#include "parToken.h"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -30,103 +30,128 @@ namespace {
|
|||
|
||||
void generateInformationSchema(MockCatalogService* mcs) {
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_indexes", TSDB_SYSTEM_TABLE, 2)
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
|
||||
.addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_stables", TSDB_SYSTEM_TABLE, 2)
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
|
||||
.addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1).addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_tables", TSDB_SYSTEM_TABLE, 2)
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
|
||||
.addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||
ITableBuilder& builder =
|
||||
mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1).addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN);
|
||||
builder.done();
|
||||
}
|
||||
{
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1)
|
||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||
builder.done();
|
||||
}
|
||||
}
|
||||
|
||||
void generateTestT1(MockCatalogService* mcs) {
|
||||
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
|
||||
.setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20).addColumn("c3", TSDB_DATA_TYPE_BIGINT)
|
||||
.addColumn("c4", TSDB_DATA_TYPE_DOUBLE).addColumn("c5", TSDB_DATA_TYPE_DOUBLE);
|
||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||
.setVgid(1)
|
||||
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
||||
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||
.addColumn("c3", TSDB_DATA_TYPE_BIGINT)
|
||||
.addColumn("c4", TSDB_DATA_TYPE_DOUBLE)
|
||||
.addColumn("c5", TSDB_DATA_TYPE_DOUBLE);
|
||||
builder.done();
|
||||
}
|
||||
|
||||
void generateTestST1(MockCatalogService* mcs) {
|
||||
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
|
||||
.setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||
.addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20);
|
||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
||||
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||
.addTag("tag1", TSDB_DATA_TYPE_INT)
|
||||
.addTag("tag2", TSDB_DATA_TYPE_BINARY, 20);
|
||||
builder.done();
|
||||
mcs->createSubTable("test", "st1", "st1s1", 1);
|
||||
mcs->createSubTable("test", "st1", "st1s2", 2);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) {
|
||||
return 0;
|
||||
}
|
||||
int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; }
|
||||
|
||||
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
||||
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||
STableMeta** pTableMeta) {
|
||||
return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
||||
}
|
||||
|
||||
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo* vgInfo) {
|
||||
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps,
|
||||
const SName* pTableName, SVgroupInfo* vgInfo) {
|
||||
return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo);
|
||||
}
|
||||
|
||||
int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgList) {
|
||||
int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||
SArray** pVgList) {
|
||||
return mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList);
|
||||
}
|
||||
|
||||
int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum) {
|
||||
int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId,
|
||||
int32_t* tableNum) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SArray** vgroupList) {
|
||||
int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* dbFName,
|
||||
SArray** vgroupList) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -189,6 +214,4 @@ void generateMetaData() {
|
|||
mockCatalogService->showTables();
|
||||
}
|
||||
|
||||
void destroyMetaDataEnv() {
|
||||
mockCatalogService.reset();
|
||||
}
|
||||
void destroyMetaDataEnv() { mockCatalogService.reset(); }
|
||||
|
|
|
@ -13,12 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mockCatalogService.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include "mockCatalogService.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
#include "tdatablock.h"
|
||||
#include "tname.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
|
@ -55,15 +56,14 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
virtual void done() {
|
||||
schema()->tableInfo.rowSize = rowsize_;
|
||||
}
|
||||
virtual void done() { schema()->tableInfo.rowSize = rowsize_; }
|
||||
|
||||
private:
|
||||
friend class MockCatalogServiceImpl;
|
||||
|
||||
static std::unique_ptr<TableBuilder> createTableBuilder(int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
||||
STableMeta* meta = (STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags));
|
||||
STableMeta* meta =
|
||||
(STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags));
|
||||
if (nullptr == meta) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
@ -77,13 +77,9 @@ private:
|
|||
meta_->schema = schemaMeta;
|
||||
}
|
||||
|
||||
STableMeta* schema() {
|
||||
return meta_->schema;
|
||||
}
|
||||
STableMeta* schema() { return meta_->schema; }
|
||||
|
||||
std::shared_ptr<MockTableMeta> table() {
|
||||
return meta_;
|
||||
}
|
||||
std::shared_ptr<MockTableMeta> table() { return meta_; }
|
||||
|
||||
col_id_t colId_;
|
||||
int32_t rowsize_;
|
||||
|
@ -94,12 +90,9 @@ class MockCatalogServiceImpl {
|
|||
public:
|
||||
static const int32_t numOfDataTypes = sizeof(tDataTypes) / sizeof(tDataTypes[0]);
|
||||
|
||||
MockCatalogServiceImpl() : id_(1) {
|
||||
}
|
||||
MockCatalogServiceImpl() : id_(1) {}
|
||||
|
||||
int32_t catalogGetHandle() const {
|
||||
return 0;
|
||||
}
|
||||
int32_t catalogGetHandle() const { return 0; }
|
||||
|
||||
int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const {
|
||||
std::unique_ptr<STableMeta> table;
|
||||
|
@ -129,7 +122,8 @@ public:
|
|||
return copyTableVgroup(db, tNameGetTableName(pTableName), vgList);
|
||||
}
|
||||
|
||||
TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
||||
TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType,
|
||||
int32_t numOfColumns, int32_t numOfTags) {
|
||||
builder_ = TableBuilder::createTableBuilder(tableType, numOfColumns, numOfTags);
|
||||
meta_[db][tbname] = builder_->table();
|
||||
meta_[db][tbname]->schema->uid = id_++;
|
||||
|
@ -163,7 +157,9 @@ public:
|
|||
// number of backward fills
|
||||
#define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2)
|
||||
// center aligned
|
||||
#define CA(n, s) std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" << "|"
|
||||
#define CA(n, s) \
|
||||
std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" \
|
||||
<< "|"
|
||||
// string field length
|
||||
#define SFL 20
|
||||
// string field header
|
||||
|
@ -185,7 +181,8 @@ public:
|
|||
std::cout << SL(3, 1) << std::endl;
|
||||
for (const auto& table : db.second) {
|
||||
const auto& schema = table.second->schema;
|
||||
std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision)) << IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl;
|
||||
std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision))
|
||||
<< IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
@ -200,7 +197,8 @@ public:
|
|||
int16_t numOfFields = numOfColumns + schema->tableInfo.numOfTags;
|
||||
for (int16_t i = 0; i < numOfFields; ++i) {
|
||||
const SSchema* col = schema->schema + i;
|
||||
std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type)) << IF(col->bytes) << std::endl;
|
||||
std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type))
|
||||
<< IF(col->bytes) << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
@ -257,9 +255,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
std::string dtToString(int8_t type) const {
|
||||
return tDataTypes[type].name;
|
||||
}
|
||||
std::string dtToString(int8_t type) const { return tDataTypes[type].name; }
|
||||
|
||||
std::string ftToString(int16_t colid, int16_t numOfColumns) const {
|
||||
return (0 == colid ? "column" : (colid < numOfColumns ? "column" : "tag"));
|
||||
|
@ -270,7 +266,8 @@ private:
|
|||
return table ? table->schema : nullptr;
|
||||
}
|
||||
|
||||
int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, std::unique_ptr<STableMeta>* dst) const {
|
||||
int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname,
|
||||
std::unique_ptr<STableMeta>* dst) const {
|
||||
STableMeta* src = getTableSchemaMeta(db, tbname);
|
||||
if (nullptr == src) {
|
||||
return TSDB_CODE_TSC_INVALID_TABLE_NAME;
|
||||
|
@ -310,25 +307,24 @@ private:
|
|||
DbMetaCache meta_;
|
||||
};
|
||||
|
||||
MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {
|
||||
}
|
||||
MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {}
|
||||
|
||||
MockCatalogService::~MockCatalogService() {
|
||||
}
|
||||
MockCatalogService::~MockCatalogService() {}
|
||||
|
||||
ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
||||
ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname,
|
||||
int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
||||
return impl_->createTableBuilder(db, tbname, tableType, numOfColumns, numOfTags);
|
||||
}
|
||||
|
||||
void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid) {
|
||||
void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname,
|
||||
int16_t vgid) {
|
||||
impl_->createSubTable(db, stbname, tbname, vgid);
|
||||
}
|
||||
|
||||
void MockCatalogService::showTables() const {
|
||||
impl_->showTables();
|
||||
}
|
||||
void MockCatalogService::showTables() const { impl_->showTables(); }
|
||||
|
||||
std::shared_ptr<MockTableMeta> MockCatalogService::getTableMeta(const std::string& db, const std::string& tbname) const {
|
||||
std::shared_ptr<MockTableMeta> MockCatalogService::getTableMeta(const std::string& db,
|
||||
const std::string& tbname) const {
|
||||
return impl_->getTableMeta(db, tbname);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,17 +20,15 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define ALLOW_FORBID_FUNC
|
||||
|
||||
#include "catalog.h"
|
||||
|
||||
class ITableBuilder {
|
||||
public:
|
||||
ITableBuilder& addTag(const std::string& name, int8_t type) {
|
||||
return addColumn(name, type, tDataTypes[type].bytes);
|
||||
}
|
||||
ITableBuilder& addTag(const std::string& name, int8_t type) { return addColumn(name, type, tDataTypes[type].bytes); }
|
||||
|
||||
ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) {
|
||||
return addColumn(name, type, bytes);
|
||||
}
|
||||
ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) { return addColumn(name, type, bytes); }
|
||||
|
||||
ITableBuilder& addColumn(const std::string& name, int8_t type) {
|
||||
return addColumn(name, type, tDataTypes[type].bytes);
|
||||
|
@ -43,9 +41,7 @@ public:
|
|||
};
|
||||
|
||||
struct MockTableMeta {
|
||||
~MockTableMeta() {
|
||||
taosMemoryFree(schema);
|
||||
}
|
||||
~MockTableMeta() { taosMemoryFree(schema); }
|
||||
|
||||
STableMeta* schema;
|
||||
std::vector<SVgroupInfo> vgs;
|
||||
|
@ -56,7 +52,8 @@ class MockCatalogService {
|
|||
public:
|
||||
MockCatalogService();
|
||||
~MockCatalogService();
|
||||
ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags = 0);
|
||||
ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType,
|
||||
int32_t numOfColumns, int32_t numOfTags = 0);
|
||||
void createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid);
|
||||
void showTables() const;
|
||||
std::shared_ptr<MockTableMeta> getTableMeta(const std::string& db, const std::string& tbname) const;
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "parserTestUtil.h"
|
||||
#include "parInt.h"
|
||||
#include "parserTestUtil.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing;
|
||||
|
@ -207,7 +207,9 @@ TEST_F(ParserTest, selectConstant) {
|
|||
bind("SELECT 123, 20.4, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 10s FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1");
|
||||
bind(
|
||||
"SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", "
|
||||
"TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT 123 + 45 FROM t1 where 2 - 1");
|
||||
|
@ -353,7 +355,7 @@ TEST_F(ParserTest, selectSemanticError) {
|
|||
|
||||
// TSDB_CODE_PAR_INVALID_FUNTION
|
||||
bind("SELECT cnt(*) FROM t1");
|
||||
ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_FUNTION));
|
||||
ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_FUNC_INVALID_FUNTION));
|
||||
|
||||
// TSDB_CODE_PAR_FUNTION_PARA_NUM
|
||||
// TSDB_CODE_PAR_FUNTION_PARA_TYPE
|
||||
|
@ -449,7 +451,8 @@ TEST_F(ParserTest, createDatabase) {
|
|||
bind("create database wxy_db");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create database if not exists wxy_db "
|
||||
bind(
|
||||
"create database if not exists wxy_db "
|
||||
"BLOCKS 100 "
|
||||
"CACHE 100 "
|
||||
"CACHELAST 2 "
|
||||
|
@ -467,14 +470,13 @@ TEST_F(ParserTest, createDatabase) {
|
|||
"VGROUPS 100 "
|
||||
"SINGLE_STABLE 0 "
|
||||
"STREAM_MODE 1 "
|
||||
"RETENTIONS '15s:7d,1m:21d,15m:5y'"
|
||||
);
|
||||
"RETENTIONS '15s:7d,1m:21d,15m:5y'");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create database if not exists wxy_db "
|
||||
bind(
|
||||
"create database if not exists wxy_db "
|
||||
"DAYS 100m "
|
||||
"KEEP 200m,300h,400d "
|
||||
);
|
||||
"KEEP 200m,300h,400d ");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
|
@ -484,14 +486,14 @@ TEST_F(ParserTest, alterDatabase) {
|
|||
bind("alter database wxy_db BLOCKS 200");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("alter database wxy_db "
|
||||
bind(
|
||||
"alter database wxy_db "
|
||||
"BLOCKS 200 "
|
||||
"CACHELAST 1 "
|
||||
"FSYNC 200 "
|
||||
"KEEP 200 "
|
||||
"QUORUM 2 "
|
||||
"WAL 1 "
|
||||
);
|
||||
"WAL 1 ");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
|
@ -515,45 +517,55 @@ TEST_F(ParserTest, createTable) {
|
|||
bind("create table t1(ts timestamp, c1 int)");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create table if not exists test.t1("
|
||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
|
||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
|
||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"
|
||||
);
|
||||
bind(
|
||||
"create table if not exists test.t1("
|
||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
|
||||
"SMALLINT, "
|
||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
|
||||
"c14 JSON, c15 VARCHAR(50)) "
|
||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create table if not exists test.t1("
|
||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
|
||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
|
||||
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
|
||||
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
|
||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
|
||||
);
|
||||
bind(
|
||||
"create table if not exists test.t1("
|
||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
|
||||
"SMALLINT, "
|
||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
|
||||
"c14 JSON, c15 VARCHAR(50)) "
|
||||
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 "
|
||||
"BINARY(20), a8 SMALLINT, "
|
||||
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), "
|
||||
"a14 JSON, a15 VARCHAR(50)) "
|
||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create table if not exists t1 using st1 tags(1, 'wxy')");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create table "
|
||||
bind(
|
||||
"create table "
|
||||
"if not exists test.t1 using test.st1 (tag1, tag2) tags(1, 'abc') "
|
||||
"if not exists test.t2 using test.st1 (tag1, tag2) tags(2, 'abc') "
|
||||
"if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc') "
|
||||
"if not exists test.t4 using test.st1 (tag1, tag2) tags(3, null) "
|
||||
"if not exists test.t5 using test.st1 (tag1, tag2) tags(null, 'abc') "
|
||||
"if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)"
|
||||
);
|
||||
"if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create stable t1(ts timestamp, c1 int) TAGS(id int)");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create stable if not exists test.t1("
|
||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
|
||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
|
||||
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
|
||||
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
|
||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
|
||||
);
|
||||
bind(
|
||||
"create stable if not exists test.t1("
|
||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
|
||||
"SMALLINT, "
|
||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
|
||||
"c14 JSON, c15 VARCHAR(50)) "
|
||||
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 "
|
||||
"BINARY(20), a8 SMALLINT, "
|
||||
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), "
|
||||
"a14 JSON, a15 VARCHAR(50)) "
|
||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,8 @@ using namespace std;
|
|||
using namespace testing;
|
||||
|
||||
namespace {
|
||||
string toString(int32_t code) {
|
||||
return tstrerror(code);
|
||||
}
|
||||
}
|
||||
string toString(int32_t code) { return tstrerror(code); }
|
||||
} // namespace
|
||||
|
||||
// syntax:
|
||||
// INSERT INTO
|
||||
|
@ -49,7 +47,6 @@ protected:
|
|||
cxt_.sqlLen = strlen(sql);
|
||||
sqlBuf_[cxt_.sqlLen] = '\0';
|
||||
cxt_.pSql = sqlBuf_;
|
||||
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
|
@ -63,7 +60,8 @@ protected:
|
|||
void dumpReslut() {
|
||||
SVnodeModifOpStmt* pStmt = getVnodeModifStmt(res_);
|
||||
size_t num = taosArrayGetSize(pStmt->pDataBlocks);
|
||||
cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType << ", numOfVgs:" << num << endl;
|
||||
cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType
|
||||
<< ", numOfVgs:" << num << endl;
|
||||
for (size_t i = 0; i < num; ++i) {
|
||||
SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(pStmt->pDataBlocks, i);
|
||||
cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl;
|
||||
|
@ -73,8 +71,9 @@ protected:
|
|||
SSubmitBlk* blk = (SSubmitBlk*)(submit + 1);
|
||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||
cout << "Block:" << i << endl;
|
||||
cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding) << ", sversion:" << ntohl(blk->sversion)
|
||||
<< ", dataLen:" << ntohl(blk->dataLen) << ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl;
|
||||
cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding)
|
||||
<< ", sversion:" << ntohl(blk->sversion) << ", dataLen:" << ntohl(blk->dataLen)
|
||||
<< ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl;
|
||||
blk = (SSubmitBlk*)(blk->data + ntohl(blk->dataLen));
|
||||
}
|
||||
}
|
||||
|
@ -114,9 +113,7 @@ private:
|
|||
code_ = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) {
|
||||
return (SVnodeModifOpStmt*)pQuery->pRoot;
|
||||
}
|
||||
SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) { return (SVnodeModifOpStmt*)pQuery->pRoot; }
|
||||
|
||||
string acctId_;
|
||||
string db_;
|
||||
|
@ -141,7 +138,9 @@ TEST_F(InsertTest, singleTableSingleRowTest) {
|
|||
TEST_F(InsertTest, singleTableMultiRowTest) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, 10, 11)");
|
||||
bind(
|
||||
"insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, "
|
||||
"10, 11)");
|
||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||
dumpReslut();
|
||||
checkReslut(1, 3);
|
||||
|
@ -161,7 +160,8 @@ TEST_F(InsertTest, multiTableSingleRowTest) {
|
|||
TEST_F(InsertTest, multiTableMultiRowTest) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")"
|
||||
bind(
|
||||
"insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")"
|
||||
" st1s2 values (now, 10, \"131028\")(now+1s, 20, \"132028\")");
|
||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||
dumpReslut();
|
||||
|
@ -174,7 +174,9 @@ TEST_F(InsertTest, multiTableMultiRowTest) {
|
|||
TEST_F(InsertTest, autoCreateTableTest) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")");
|
||||
bind(
|
||||
"insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, "
|
||||
"\"guangzhou\")");
|
||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||
dumpReslut();
|
||||
checkReslut(1, 3);
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include <getopt.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
@ -23,11 +23,11 @@
|
|||
#ifdef WINDOWS
|
||||
#define TD_USE_WINSOCK
|
||||
#endif
|
||||
#include "os.h"
|
||||
#include "parserTestUtil.h"
|
||||
#include "parToken.h"
|
||||
#include "functionMgt.h"
|
||||
#include "mockCatalog.h"
|
||||
#include "os.h"
|
||||
#include "parToken.h"
|
||||
#include "parserTestUtil.h"
|
||||
|
||||
bool g_isDump = false;
|
||||
|
||||
|
@ -51,10 +51,7 @@ public:
|
|||
static void parseArg(int argc, char* argv[]) {
|
||||
int opt = 0;
|
||||
const char* optstring = "";
|
||||
static struct option long_options[] = {
|
||||
{"dump", no_argument, NULL, 'd'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}};
|
||||
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
|
|
|
@ -24,7 +24,8 @@ typedef struct SLogicPlanContext {
|
|||
typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, SSelectStmt*, SLogicNode**);
|
||||
typedef int32_t (*FCreateSetOpLogicNode)(SLogicPlanContext*, SSetOperator*, SLogicNode**);
|
||||
|
||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode);
|
||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable,
|
||||
SLogicNode** pLogicNode);
|
||||
static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode);
|
||||
|
||||
typedef struct SRewriteExprCxt {
|
||||
|
@ -115,7 +116,8 @@ static int32_t pushLogicNode(SLogicPlanContext* pCxt, SLogicNode** pOldRoot, SLo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func, SLogicNode** pRoot) {
|
||||
static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func,
|
||||
SLogicNode** pRoot) {
|
||||
SLogicNode* pNode = NULL;
|
||||
int32_t code = func(pCxt, pSelect, &pNode);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
|
||||
|
@ -191,7 +193,8 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, SLogicNode** pLogicNode) {
|
||||
static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable,
|
||||
SLogicNode** pLogicNode) {
|
||||
SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -245,18 +248,18 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, SLogicNode** pLogicNode) {
|
||||
static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable,
|
||||
SLogicNode** pLogicNode) {
|
||||
int32_t code = createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, (*pLogicNode)->pTargets) {
|
||||
strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias);
|
||||
}
|
||||
FOREACH(pNode, (*pLogicNode)->pTargets) { strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias); }
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable, SLogicNode** pLogicNode) {
|
||||
static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable,
|
||||
SLogicNode** pLogicNode) {
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_JOIN);
|
||||
if (NULL == pJoin) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -316,7 +319,8 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) {
|
||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable,
|
||||
SLogicNode** pLogicNode) {
|
||||
switch (nodeType(pTable)) {
|
||||
case QUERY_NODE_REAL_TABLE:
|
||||
return createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pTable, pLogicNode);
|
||||
|
@ -330,7 +334,8 @@ static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pS
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) {
|
||||
static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable,
|
||||
SLogicNode** pLogicNode) {
|
||||
SLogicNode* pNode = NULL;
|
||||
int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -409,12 +414,7 @@ static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pEx
|
|||
}
|
||||
|
||||
static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
SNodeList* pAggFuncs = NULL;
|
||||
int32_t code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAggFuncs);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (NULL == pAggFuncs && NULL == pSelect->pGroupByList) {
|
||||
if (!pSelect->hasAggFuncs && NULL == pSelect->pGroupByList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -423,6 +423,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
// set grouyp keys, agg funcs and having conditions
|
||||
if (NULL != pSelect->pGroupByList) {
|
||||
pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList);
|
||||
|
@ -431,17 +433,16 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
|||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pAggFuncs) {
|
||||
pAgg->pAggFuncs = nodesCloneList(pAggFuncs);
|
||||
if (NULL == pAgg->pAggFuncs) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// rewrite the expression in subsequent clauses
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) {
|
||||
code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAgg->pAggFuncs);
|
||||
}
|
||||
|
||||
// rewrite the expression in subsequent clauses
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExprForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||
}
|
||||
|
@ -470,7 +471,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) {
|
||||
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow,
|
||||
SLogicNode** pLogicNode) {
|
||||
int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs);
|
||||
|
||||
if (pCxt->pPlanCxt->streamQuery) {
|
||||
|
@ -486,6 +488,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm
|
|||
code = createColumnByRewriteExps(pCxt, pWindow->pFuncs, &pWindow->node.pTargets);
|
||||
}
|
||||
|
||||
pSelect->hasAggFuncs = false;
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pWindow;
|
||||
} else {
|
||||
|
@ -495,7 +499,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect,
|
||||
SLogicNode** pLogicNode) {
|
||||
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
||||
if (NULL == pWindow) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -513,7 +518,8 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo
|
|||
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||
}
|
||||
|
||||
static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession,
|
||||
SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
||||
if (NULL == pWindow) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -531,7 +537,8 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW
|
|||
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||
}
|
||||
|
||||
static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval,
|
||||
SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
||||
if (NULL == pWindow) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -542,7 +549,8 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva
|
|||
pWindow->intervalUnit = ((SValueNode*)pInterval->pInterval)->unit;
|
||||
pWindow->offset = (NULL != pInterval->pOffset ? ((SValueNode*)pInterval->pOffset)->datum.i : 0);
|
||||
pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval);
|
||||
pWindow->slidingUnit = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
|
||||
pWindow->slidingUnit =
|
||||
(NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
|
||||
|
||||
pWindow->pTspk = nodesCloneNode(pInterval->pCol);
|
||||
if (NULL == pWindow->pTspk) {
|
||||
|
@ -615,7 +623,8 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, SNodeList** pCols) {
|
||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs,
|
||||
SNodeList** pCols) {
|
||||
SNodeList* pList = nodesMakeList();
|
||||
if (NULL == pList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -778,7 +787,8 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, FCreateSetOpLogicNode func, SLogicNode** pRoot) {
|
||||
static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator,
|
||||
FCreateSetOpLogicNode func, SLogicNode** pRoot) {
|
||||
SLogicNode* pNode = NULL;
|
||||
int32_t code = func(pCxt, pSetOperator, &pNode);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
|
||||
|
@ -823,7 +833,8 @@ static int32_t createSetOpSortLogicNode(SLogicPlanContext* pCxt, SSetOperator* p
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) {
|
||||
static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator,
|
||||
SLogicNode** pLogicNode) {
|
||||
SProjectLogicNode* pProject = (SProjectLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PROJECT);
|
||||
if (NULL == pProject) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -927,7 +938,8 @@ static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetO
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) {
|
||||
static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator,
|
||||
SLogicNode** pLogicNode) {
|
||||
SLogicNode* pRoot = NULL;
|
||||
int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -944,7 +956,9 @@ static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator*
|
|||
}
|
||||
|
||||
static int32_t getMsgType(ENodeType sqlType) {
|
||||
return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) ? TDMT_VND_CREATE_TABLE : TDMT_VND_SUBMIT;
|
||||
return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType)
|
||||
? TDMT_VND_CREATE_TABLE
|
||||
: TDMT_VND_SUBMIT;
|
||||
}
|
||||
|
||||
static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) {
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "planInt.h"
|
||||
#include "functionMgt.h"
|
||||
#include "filter.h"
|
||||
#include "functionMgt.h"
|
||||
#include "planInt.h"
|
||||
|
||||
#define OPTIMIZE_FLAG_MASK(n) (1 << n)
|
||||
|
||||
|
@ -101,8 +101,8 @@ static bool osdMayBeOptimized(SLogicNode* pNode) {
|
|||
if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) {
|
||||
return false;
|
||||
}
|
||||
if (NULL == pNode->pParent ||
|
||||
(QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) {
|
||||
if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) &&
|
||||
QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) {
|
||||
return false;
|
||||
}
|
||||
if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent)) {
|
||||
|
@ -399,13 +399,18 @@ static EDealRes cpdIsMultiTableCondImpl(SNode* pNode, void* pContext) {
|
|||
}
|
||||
|
||||
static ECondAction cpdCondAction(EJoinType joinType, SNodeList* pLeftCols, SNodeList* pRightCols, SNode* pNode) {
|
||||
SCpdIsMultiTableCondCxt cxt = { .pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false };
|
||||
SCpdIsMultiTableCondCxt cxt = {
|
||||
.pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false};
|
||||
nodesWalkExpr(pNode, cpdIsMultiTableCondImpl, &cxt);
|
||||
return (JOIN_TYPE_INNER != joinType ? COND_ACTION_STAY :
|
||||
(cxt.havaLeftCol && cxt.haveRightCol ? COND_ACTION_PUSH_JOIN : (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD)));
|
||||
return (JOIN_TYPE_INNER != joinType
|
||||
? COND_ACTION_STAY
|
||||
: (cxt.havaLeftCol && cxt.haveRightCol
|
||||
? COND_ACTION_PUSH_JOIN
|
||||
: (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD)));
|
||||
}
|
||||
|
||||
static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) {
|
||||
static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond,
|
||||
SNode** pRightChildCond) {
|
||||
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)pJoin->node.pConditions;
|
||||
if (LOGIC_COND_TYPE_AND != pLogicCond->condType) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -473,7 +478,8 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) {
|
||||
static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond,
|
||||
SNode** pRightChildCond) {
|
||||
SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets;
|
||||
SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets;
|
||||
ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pJoin->node.pConditions);
|
||||
|
@ -490,7 +496,8 @@ static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) {
|
||||
static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond,
|
||||
SNode** pRightChildCond) {
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pJoin->node.pConditions)) {
|
||||
return cpdPartitionLogicCond(pJoin, pOnCond, pLeftChildCond, pRightChildCond);
|
||||
} else {
|
||||
|
@ -762,11 +769,9 @@ static int32_t opkOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) {
|
|||
return opkOptimizeImpl(pCxt, pSort);
|
||||
}
|
||||
|
||||
static const SOptimizeRule optimizeRuleSet[] = {
|
||||
{ .pName = "OptimizeScanData", .optimizeFunc = osdOptimize },
|
||||
static const SOptimizeRule optimizeRuleSet[] = {{.pName = "OptimizeScanData", .optimizeFunc = osdOptimize},
|
||||
{.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize},
|
||||
{ .pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize }
|
||||
};
|
||||
{.pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize}};
|
||||
|
||||
static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule));
|
||||
|
||||
|
@ -784,6 +789,4 @@ static int32_t applyOptimizeRule(SPlanContext* pCxt, SLogicNode* pLogicNode) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) {
|
||||
return applyOptimizeRule(pCxt, pLogicNode);
|
||||
}
|
||||
int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { return applyOptimizeRule(pCxt, pLogicNode); }
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
#include "planInt.h"
|
||||
|
||||
#include "catalog.h"
|
||||
#include "functionMgt.h"
|
||||
#include "tglobal.h"
|
||||
#include "catalog.h"
|
||||
|
||||
typedef struct SSlotIdInfo {
|
||||
int16_t slotId;
|
||||
|
@ -104,7 +104,8 @@ static int32_t putSlotToHash(int16_t dataBlockId, int16_t slotId, SNode* pNode,
|
|||
return putSlotToHashImpl(dataBlockId, slotId, name, len, pHash);
|
||||
}
|
||||
|
||||
static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, SHashObj** pDescHash) {
|
||||
static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId,
|
||||
SHashObj** pDescHash) {
|
||||
SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
if (NULL == pHash) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -118,7 +119,8 @@ static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, SHashObj* pHash) {
|
||||
static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc,
|
||||
SHashObj* pHash) {
|
||||
pDataBlockDesc->pSlots = nodesMakeList();
|
||||
if (NULL == pDataBlockDesc->pSlots) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -177,7 +179,8 @@ static int16_t getUnsetSlotId(const SArray* pSlotIdsInfo) {
|
|||
return ((SSlotIdInfo*)taosArrayGet(pSlotIdsInfo, 0))->slotId;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, const char* pStmtName, bool output) {
|
||||
static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc,
|
||||
const char* pStmtName, bool output) {
|
||||
if (NULL == pList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -242,7 +245,8 @@ static int32_t addDataBlockSlot(SPhysiPlanContext* pCxt, SNode** pNode, SDataBlo
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList,
|
||||
SDataBlockDescNode* pDataBlockDesc) {
|
||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, pStmtName, true);
|
||||
}
|
||||
|
||||
|
@ -277,7 +281,8 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode, SNode** pOutput) {
|
||||
static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode,
|
||||
SNode** pOutput) {
|
||||
SNode* pRes = nodesCloneNode(pNode);
|
||||
if (NULL == pRes) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -286,8 +291,7 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
SSetSlotIdCxt cxt = {
|
||||
.errCode = TSDB_CODE_SUCCESS,
|
||||
.pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
|
||||
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))
|
||||
};
|
||||
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))};
|
||||
nodesWalkExpr(pRes, doSetSlotId, &cxt);
|
||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||
nodesDestroyNode(pRes);
|
||||
|
@ -298,7 +302,8 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, const SNodeList* pList, SNodeList** pOutput) {
|
||||
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId,
|
||||
const SNodeList* pList, SNodeList** pOutput) {
|
||||
SNodeList* pRes = nodesCloneList(pList);
|
||||
if (NULL == pRes) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -307,8 +312,7 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
SSetSlotIdCxt cxt = {
|
||||
.errCode = TSDB_CODE_SUCCESS,
|
||||
.pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
|
||||
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))
|
||||
};
|
||||
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))};
|
||||
nodesWalkExprs(pRes, doSetSlotId, &cxt);
|
||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||
nodesDestroyList(pRes);
|
||||
|
@ -346,7 +350,8 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, uint8_t precision, SLo
|
|||
|
||||
static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pLogicNode, SPhysiNode* pPhysiNode) {
|
||||
if (NULL != pLogicNode->pConditions) {
|
||||
return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions, &pPhysiNode->pConditions);
|
||||
return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions,
|
||||
&pPhysiNode->pConditions);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -364,15 +369,11 @@ static int32_t sortScanCols(SNodeList* pScanCols) {
|
|||
}
|
||||
|
||||
SNode* pCol = NULL;
|
||||
FOREACH(pCol, pScanCols) {
|
||||
taosArrayPush(pArray, &pCol);
|
||||
}
|
||||
FOREACH(pCol, pScanCols) { taosArrayPush(pArray, &pCol); }
|
||||
taosArraySort(pArray, colIdCompare);
|
||||
|
||||
int32_t index = 0;
|
||||
FOREACH(pCol, pScanCols) {
|
||||
REPLACE_NODE(taosArrayGetP(pArray, index++));
|
||||
}
|
||||
FOREACH(pCol, pScanCols) { REPLACE_NODE(taosArrayGetP(pArray, index++)); }
|
||||
taosArrayDestroy(pArray);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -386,7 +387,8 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys
|
|||
return sortScanCols(pScanPhysiNode->pScanCols);
|
||||
}
|
||||
|
||||
static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) {
|
||||
static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode,
|
||||
SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) {
|
||||
int32_t code = createScanCols(pCxt, pScanPhysiNode, pScanLogicNode->pScanCols);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t
|
||||
|
@ -416,15 +418,19 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd
|
|||
}
|
||||
|
||||
static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(
|
||||
pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
if (NULL == pTagScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTagScan, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
STableScanPhysiNode* pTableScan =
|
||||
(STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode,
|
||||
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
if (NULL == pTableScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -451,8 +457,11 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
|
|||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan,
|
||||
SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSystemTableScanPhysiNode* pScan =
|
||||
(SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision,
|
||||
(SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -472,15 +481,19 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
|
|||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan =
|
||||
(SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision,
|
||||
(SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
switch (pScanLogicNode->scanType) {
|
||||
case SCAN_TYPE_TAG:
|
||||
return createTagScanPhysiNode(pCxt, pScanLogicNode, pPhyNode);
|
||||
|
@ -496,8 +509,10 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan,
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) {
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode,
|
||||
QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
if (NULL == pJoin) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -508,10 +523,12 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
|
||||
pJoin->joinType = pJoinLogicNode->joinType;
|
||||
if (NULL != pJoinLogicNode->pOnConditions) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions);
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions,
|
||||
&pJoin->pOnConditions);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets);
|
||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets,
|
||||
&pJoin->pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||
|
@ -555,7 +572,8 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode)
|
|||
if ('\0' != pRewrittenExpr->aliasName[0]) {
|
||||
strcpy(pCol->colName, pRewrittenExpr->aliasName);
|
||||
} else {
|
||||
snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, pCxt->rewriteId);
|
||||
snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId,
|
||||
pCxt->rewriteId);
|
||||
strcpy(pCol->colName, pRewrittenExpr->aliasName);
|
||||
}
|
||||
nodesDestroyNode(*pNode);
|
||||
|
@ -581,7 +599,8 @@ static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs, SNodeList** pRewrittenList) {
|
||||
static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs,
|
||||
SNodeList** pRewrittenList) {
|
||||
if (NULL == pList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -622,7 +641,8 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
|||
return cxt.errCode;
|
||||
}
|
||||
|
||||
static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs, SNode** pRewritten) {
|
||||
static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs,
|
||||
SNode** pRewritten) {
|
||||
if (NULL == pNode) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -641,8 +661,10 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) {
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode,
|
||||
QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
if (NULL == pAgg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -695,8 +717,10 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(
|
||||
pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
if (NULL == pProject) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -706,9 +730,11 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
|
|||
pProject->slimit = pProjectLogicNode->slimit;
|
||||
pProject->soffset = pProjectLogicNode->soffset;
|
||||
|
||||
int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, pProjectLogicNode->pProjections, &pProject->pProjections);
|
||||
int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId,
|
||||
-1, pProjectLogicNode->pProjections, &pProject->pProjections);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, pProject->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections,
|
||||
pProject->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject);
|
||||
|
@ -723,8 +749,10 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(
|
||||
pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
if (NULL == pExchange) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -734,8 +762,10 @@ static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogic
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(
|
||||
pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -767,7 +797,8 @@ static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExc
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
if (pCxt->pPlanCxt->streamQuery) {
|
||||
return createStreamScanPhysiNodeByExchange(pCxt, pExchangeLogicNode, pPhyNode);
|
||||
} else {
|
||||
|
@ -775,7 +806,8 @@ static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNo
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow,
|
||||
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SNodeList* pPrecalcExprs = NULL;
|
||||
SNodeList* pFuncs = NULL;
|
||||
int32_t code = rewritePrecalcExprs(pCxt, pWindowLogicNode->pFuncs, &pPrecalcExprs, &pFuncs);
|
||||
|
@ -812,8 +844,10 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(
|
||||
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
if (NULL == pInterval) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -833,8 +867,10 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
|||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(
|
||||
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
if (NULL == pSession) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -844,8 +880,10 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList*
|
|||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pSession->window, pWindowLogicNode, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW);
|
||||
static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(
|
||||
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW);
|
||||
if (NULL == pState) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -878,7 +916,8 @@ static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pC
|
|||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pState->window, pWindowLogicNode, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
switch (pWindowLogicNode->winType) {
|
||||
case WINDOW_TYPE_INTERVAL:
|
||||
return createIntervalPhysiNode(pCxt, pChildren, pWindowLogicNode, pPhyNode);
|
||||
|
@ -892,8 +931,10 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT);
|
||||
static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SORT);
|
||||
if (NULL == pSort) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -931,8 +972,10 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) {
|
||||
SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION);
|
||||
static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) {
|
||||
SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(
|
||||
pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION);
|
||||
if (NULL == pPart) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -970,7 +1013,8 @@ static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SNodeList* pChildren, SPhysiNode** pPhyNode) {
|
||||
static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan,
|
||||
SNodeList* pChildren, SPhysiNode** pPhyNode) {
|
||||
switch (nodeType(pLogicNode)) {
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return createScanPhysiNode(pCxt, pSubplan, (SScanLogicNode*)pLogicNode, pPhyNode);
|
||||
|
@ -995,7 +1039,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SPhysiNode** pPhyNode) {
|
||||
static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SNodeList* pChildren = nodesMakeList();
|
||||
if (NULL == pChildren) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1019,9 +1064,7 @@ static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode,
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
(*pPhyNode)->pChildren = pChildren;
|
||||
SNode* pChild;
|
||||
FOREACH(pChild, (*pPhyNode)->pChildren) {
|
||||
((SPhysiNode*)pChild)->pParent = (*pPhyNode);
|
||||
}
|
||||
FOREACH(pChild, (*pPhyNode)->pChildren) { ((SPhysiNode*)pChild)->pParent = (*pPhyNode); }
|
||||
} else {
|
||||
nodesDestroyList(pChildren);
|
||||
}
|
||||
|
@ -1137,7 +1180,8 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l
|
|||
return nodesListStrictAppend(pGroup->pNodeList, pSubplan);
|
||||
}
|
||||
|
||||
static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, SQueryPlan* pQueryPlan) {
|
||||
static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent,
|
||||
SQueryPlan* pQueryPlan) {
|
||||
SSubplan* pSubplan = NULL;
|
||||
int32_t code = createPhysiSubplan(pCxt, pLogicSubplan, &pSubplan);
|
||||
|
||||
|
@ -1221,13 +1265,11 @@ static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) {
|
|||
}
|
||||
|
||||
int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) {
|
||||
SPhysiPlanContext cxt = {
|
||||
.pPlanCxt = pCxt,
|
||||
SPhysiPlanContext cxt = {.pPlanCxt = pCxt,
|
||||
.errCode = TSDB_CODE_SUCCESS,
|
||||
.nextDataBlockId = 0,
|
||||
.pLocationHelper = taosArrayInit(32, POINTER_BYTES),
|
||||
.pExecNodeList = pExecNodeList
|
||||
};
|
||||
.pExecNodeList = pExecNodeList};
|
||||
if (NULL == cxt.pLocationHelper) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
|
|||
return pSubplan;
|
||||
}
|
||||
|
||||
static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan, ESubplanType subplanType) {
|
||||
static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan,
|
||||
ESubplanType subplanType) {
|
||||
SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE);
|
||||
if (NULL == pExchange) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -117,8 +118,8 @@ static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag,
|
|||
}
|
||||
|
||||
static SLogicNode* stsMatchByNode(SLogicNode* pNode) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) &&
|
||||
NULL != ((SScanLogicNode*)pNode)->pVgroupList && ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && NULL != ((SScanLogicNode*)pNode)->pVgroupList &&
|
||||
((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) {
|
||||
return pNode;
|
||||
}
|
||||
SNode* pChild;
|
||||
|
@ -145,7 +146,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
|||
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, (FSplFindSplitNode)stsFindSplitNode, &info)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS));
|
||||
int32_t code =
|
||||
nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE);
|
||||
}
|
||||
|
@ -163,7 +165,8 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) {
|
|||
SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0);
|
||||
SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pNode->pChildren, 1);
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ctjIsSingleTable(((SScanLogicNode*)pLeft)->pMeta->tableType) &&
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) {
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) &&
|
||||
ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) {
|
||||
return pRight;
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +194,8 @@ static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
|||
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, (FSplFindSplitNode)ctjFindSplitNode, &info)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ));
|
||||
int32_t code =
|
||||
nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType);
|
||||
}
|
||||
|
@ -360,12 +364,10 @@ static int32_t unSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const SSplitRule splitRuleSet[] = {
|
||||
{ .pName = "SuperTableScan", .splitFunc = stsSplit },
|
||||
static const SSplitRule splitRuleSet[] = {{.pName = "SuperTableScan", .splitFunc = stsSplit},
|
||||
{.pName = "ChildTableJoin", .splitFunc = ctjSplit},
|
||||
{.pName = "UnionAll", .splitFunc = uaSplit},
|
||||
{ .pName = "Union", .splitFunc = unSplit }
|
||||
};
|
||||
{.pName = "Union", .splitFunc = unSplit}};
|
||||
|
||||
static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule));
|
||||
|
||||
|
@ -386,14 +388,10 @@ static int32_t applySplitRule(SLogicSubplan* pSubplan) {
|
|||
static void doSetLogicNodeParent(SLogicNode* pNode, SLogicNode* pParent) {
|
||||
pNode->pParent = pParent;
|
||||
SNode* pChild;
|
||||
FOREACH(pChild, pNode->pChildren) {
|
||||
doSetLogicNodeParent((SLogicNode*)pChild, pNode);
|
||||
}
|
||||
FOREACH(pChild, pNode->pChildren) { doSetLogicNodeParent((SLogicNode*)pChild, pNode); }
|
||||
}
|
||||
|
||||
static void setLogicNodeParent(SLogicNode* pNode) {
|
||||
doSetLogicNodeParent(pNode, NULL);
|
||||
}
|
||||
static void setLogicNodeParent(SLogicNode* pNode) { doSetLogicNodeParent(pNode, NULL); }
|
||||
|
||||
int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan** pLogicSubplan) {
|
||||
SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
|
||||
|
@ -408,7 +406,8 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan
|
|||
}
|
||||
if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIF == nodeType(pLogicNode)) {
|
||||
pSubplan->subplanType = SUBPLAN_TYPE_MODIFY;
|
||||
TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks, SArray*);
|
||||
TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks,
|
||||
SArray*);
|
||||
} else {
|
||||
pSubplan->subplanType = SUBPLAN_TYPE_SCAN;
|
||||
}
|
||||
|
|
|
@ -171,9 +171,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_BIND_v2* pParam) {
|
|||
int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_BIND_v2* pParams) {
|
||||
int32_t index = 0;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pPlan->pPlaceholderValues) {
|
||||
setValueByBindParam((SValueNode*)pNode, pParams + index);
|
||||
}
|
||||
FOREACH(pNode, pPlan->pPlaceholderValues) { setValueByBindParam((SValueNode*)pNode, pParams + index); }
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -188,9 +186,7 @@ int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) {
|
|||
return nodesNodeToString((const SNode*)pSubplan, false, pStr, pLen);
|
||||
}
|
||||
|
||||
int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) {
|
||||
return nodesStringToNode(pStr, (SNode**)pSubplan);
|
||||
}
|
||||
int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) { return nodesStringToNode(pStr, (SNode**)pSubplan); }
|
||||
|
||||
char* qQueryPlanToString(const SQueryPlan* pPlan) {
|
||||
char* pStr = NULL;
|
||||
|
@ -209,6 +205,4 @@ SQueryPlan* qStringToQueryPlan(const char* pStr) {
|
|||
return pPlan;
|
||||
}
|
||||
|
||||
void qDestroyQueryPlan(SQueryPlan* pPlan) {
|
||||
nodesDestroyNode(pPlan);
|
||||
}
|
||||
void qDestroyQueryPlan(SQueryPlan* pPlan) { nodesDestroyNode(pPlan); }
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class PlanOptimizeTest : public PlannerTestBase {
|
||||
|
||||
};
|
||||
class PlanOptimizeTest : public PlannerTestBase {};
|
||||
|
||||
TEST_F(PlanOptimizeTest, orderByPrimaryKey) {
|
||||
useDb("root", "test");
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "planTestUtil.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PlanSuperTableTest : public PlannerTestBase {};
|
||||
|
||||
TEST_F(PlanSuperTableTest, unionAll) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("select tbname from st1");
|
||||
}
|
|
@ -18,9 +18,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class PlanSetOpTest : public PlannerTestBase {
|
||||
|
||||
};
|
||||
class PlanSetOpTest : public PlannerTestBase {};
|
||||
|
||||
TEST_F(PlanSetOpTest, unionAll) {
|
||||
useDb("root", "test");
|
||||
|
|
|
@ -27,9 +27,7 @@ public:
|
|||
generateMetaData();
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
destroyMetaDataEnv();
|
||||
}
|
||||
virtual void TearDown() { destroyMetaDataEnv(); }
|
||||
|
||||
PlannerEnv() {}
|
||||
virtual ~PlannerEnv() {}
|
||||
|
@ -38,10 +36,7 @@ public:
|
|||
static void parseArg(int argc, char* argv[]) {
|
||||
int opt = 0;
|
||||
const char* optstring = "";
|
||||
static struct option long_options[] = {
|
||||
{"dump", no_argument, NULL, 'd'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}};
|
||||
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include "planTestUtil.h"
|
||||
#include <array>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -29,7 +29,8 @@ using namespace testing;
|
|||
do { \
|
||||
int32_t code__ = func(__VA_ARGS__); \
|
||||
if (TSDB_CODE_SUCCESS != code__) { \
|
||||
throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + ", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \
|
||||
throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + \
|
||||
", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
|
@ -170,9 +171,7 @@ private:
|
|||
SNode* pNode;
|
||||
FOREACH(pNode, (*pPlan)->pSubplans) {
|
||||
SNode* pSubplan;
|
||||
FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) {
|
||||
res_.physiSubplans_.push_back(toString(pSubplan));
|
||||
}
|
||||
FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { res_.physiSubplans_.push_back(toString(pSubplan)); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,16 +209,10 @@ private:
|
|||
stmtRes res_;
|
||||
};
|
||||
|
||||
PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {
|
||||
}
|
||||
PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {}
|
||||
|
||||
PlannerTestBase::~PlannerTestBase() {
|
||||
}
|
||||
PlannerTestBase::~PlannerTestBase() {}
|
||||
|
||||
void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) {
|
||||
impl_->useDb(acctId, db);
|
||||
}
|
||||
void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) { impl_->useDb(acctId, db); }
|
||||
|
||||
void PlannerTestBase::run(const std::string& sql) {
|
||||
return impl_->run(sql);
|
||||
}
|
||||
void PlannerTestBase::run(const std::string& sql) { return impl_->run(sql); }
|
||||
|
|
|
@ -45,7 +45,8 @@ protected:
|
|||
int32_t code = qParseQuerySql(&cxt_, &query_);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl;
|
||||
cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code)
|
||||
<< ", msg:" << errMagBuf_ << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -90,7 +91,8 @@ protected:
|
|||
return false;
|
||||
}
|
||||
|
||||
code = createPhysiPlan(&cxt, pLogicPlan, &plan_, NULL);
|
||||
SArray* pExecNodeList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SQueryNodeAddr));
|
||||
code = createPhysiPlan(&cxt, pLogicPlan, &plan_, pExecNodeList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
cout << "sql:[" << cxt_.pSql << "] createPhysiPlan code:" << code << ", strerror:" << tstrerror(code) << endl;
|
||||
return false;
|
||||
|
@ -192,7 +194,9 @@ TEST_F(PlannerTest, selectJoin) {
|
|||
bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and t2.c2 = 'qwe'");
|
||||
bind(
|
||||
"SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and "
|
||||
"t2.c2 = 'qwe'");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
|
@ -210,12 +214,17 @@ TEST_F(PlannerTest, selectGroupBy) {
|
|||
|
||||
bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT sum(ceil(c1)) FROM t1 GROUP BY ceil(c1)");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, selectSubquery) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 group by b");
|
||||
bind(
|
||||
"SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 "
|
||||
"group by b");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
|
@ -362,7 +371,9 @@ TEST_F(PlannerTest, createTopic) {
|
|||
TEST_F(PlannerTest, createStream) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 interval(10s)");
|
||||
bind(
|
||||
"create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 "
|
||||
"interval(10s)");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
|
|
|
@ -486,7 +486,7 @@ _return:
|
|||
EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
|
||||
SFunctionNode *node = (SFunctionNode *)*pNode;
|
||||
SNode* tnode = NULL;
|
||||
if (fmIsUserDefinedFunc(node->funcId)) {
|
||||
if (!fmIsScalarFunc(node->funcId)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -511,14 +511,16 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
|
|||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
res->translate = true;
|
||||
|
||||
if (colDataIsNull_s(output.columnData, 0)) {
|
||||
res->node.resType.type = TSDB_DATA_TYPE_NULL;
|
||||
} else {
|
||||
res->node.resType = node->node.resType;
|
||||
int32_t type = output.columnData->info.type;
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
res->datum.p = output.columnData->pData;
|
||||
output.columnData->pData = NULL;
|
||||
res->datum.p = taosMemoryCalloc(res->node.resType.bytes + VARSTR_HEADER_SIZE + 1, 1);
|
||||
memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData));
|
||||
} else {
|
||||
memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes);
|
||||
}
|
||||
|
@ -553,6 +555,7 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
|
|||
}
|
||||
|
||||
res->node.resType = node->node.resType;
|
||||
res->translate = true;
|
||||
|
||||
int32_t type = output.columnData->info.type;
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
|
@ -595,6 +598,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
|
|||
}
|
||||
|
||||
res->node.resType = node->node.resType;
|
||||
res->translate = true;
|
||||
|
||||
int32_t type = output.columnData->info.type;
|
||||
if (IS_VAR_DATA_TYPE(type)) { // todo refactor
|
||||
|
@ -612,10 +616,6 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
|
|||
}
|
||||
|
||||
EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
|
||||
if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
SScalarCtx *ctx = (SScalarCtx *)pContext;
|
||||
|
||||
if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
|
||||
|
@ -630,9 +630,7 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
|
|||
return sclRewriteOperator(pNode, ctx);
|
||||
}
|
||||
|
||||
sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode));
|
||||
ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return DEAL_RES_ERROR;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) {
|
||||
|
|
|
@ -1265,8 +1265,11 @@ int32_t todayFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut
|
|||
}
|
||||
|
||||
int32_t timezoneFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
char output[TD_TIMEZONE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
memcpy(varDataVal(output), tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
varDataSetLen(output, strlen(tsTimezoneStr));
|
||||
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||
colDataAppend(pOutput->columnData, i, tsTimezoneStr, false);
|
||||
colDataAppend(pOutput->columnData, i, output, false);
|
||||
}
|
||||
pOutput->numOfRows = pInput->numOfRows;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -11,7 +11,7 @@ target_link_libraries(
|
|||
|
||||
target_include_directories(
|
||||
sync
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/libs/sync"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
|
|
|
@ -457,6 +457,20 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
|||
|
||||
void syncNodeStart(SSyncNode* pSyncNode) {
|
||||
// start raft
|
||||
if (pSyncNode->replicaNum == 1) {
|
||||
syncNodeBecomeLeader(pSyncNode);
|
||||
|
||||
syncNodeLog2("==state change become leader immediately==", pSyncNode);
|
||||
|
||||
// Raft 3.6.2 Committing entries from previous terms
|
||||
|
||||
// use this now
|
||||
syncNodeAppendNoop(pSyncNode);
|
||||
syncMaybeAdvanceCommitIndex(pSyncNode); // maybe only one replica
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
syncNodeBecomeFollower(pSyncNode);
|
||||
|
||||
// for test
|
||||
|
|
|
@ -199,197 +199,197 @@ target_sources(syncApplyMsgTest
|
|||
|
||||
target_include_directories(syncTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncEnvTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingTimerTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncIOTickQTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncIOTickPingTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncIOSendMsgTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncIOClientTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncIOServerTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRaftStoreTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncEnqTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncIndexTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncInitTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncUtilTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncVotesGrantedTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncVotesRespondTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncIndexMgrTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncLogStoreTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncEntryTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRequestVoteTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRequestVoteReplyTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncAppendEntriesTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncAppendEntriesReplyTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncClientRequestTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncTimeoutTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingReplyTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRpcMsgTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingTimerTest2
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingSelfTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncElectTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncEncodeTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncWriteTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncReplicateTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRefTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncLogStoreCheck
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRaftCfgTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRespMgrTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncSnapshotTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncApplyMsgTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
|
@ -18,6 +18,9 @@
|
|||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
#include "tenv.h"
|
||||
#include "cJSON.h"
|
||||
#include "tjson.h"
|
||||
|
||||
#define CFG_NAME_PRINT_LEN 24
|
||||
#define CFG_SRC_PRINT_LEN 12
|
||||
|
@ -25,6 +28,7 @@
|
|||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig);
|
||||
int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd);
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
|
||||
int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype);
|
||||
|
||||
|
@ -45,7 +49,7 @@ SConfig *cfgInit() {
|
|||
return pCfg;
|
||||
}
|
||||
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr) {
|
||||
switch (cfgType) {
|
||||
case CFG_STYPE_CFG_FILE:
|
||||
return cfgLoadFromCfgFile(pCfg, sourceStr);
|
||||
|
@ -55,6 +59,8 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
|
|||
return cfgLoadFromEnvVar(pCfg);
|
||||
case CFG_STYPE_APOLLO_URL:
|
||||
return cfgLoadFromApollUrl(pCfg, sourceStr);
|
||||
case CFG_STYPE_ENV_CMD:
|
||||
return cfgLoadFromEnvCmd(pCfg, (const char **)sourceStr);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
@ -463,6 +469,8 @@ const char *cfgStypeStr(ECfgSrcType type) {
|
|||
return "arg_list";
|
||||
case CFG_STYPE_TAOS_OPTIONS:
|
||||
return "taos_options";
|
||||
case CFG_STYPE_ENV_CMD:
|
||||
return "env_cmd";
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
|
@ -584,12 +592,154 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
|
|||
}
|
||||
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
||||
uDebug("load from env variables not implemented yet");
|
||||
char *line = NULL, *name, *value, *value2, *value3;
|
||||
int32_t olen, vlen, vlen2, vlen3;
|
||||
ssize_t _bytes = 0;
|
||||
TdCmdPtr pCmd = taosOpenCmd("set");
|
||||
if (pCmd == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
while (!taosEOFCmd(pCmd)) {
|
||||
name = value = value2 = value3 = NULL;
|
||||
olen = vlen = vlen2 = vlen3 = 0;
|
||||
|
||||
_bytes = taosGetLineCmd(pCmd, &line);
|
||||
if (_bytes < 0) {
|
||||
break;
|
||||
}
|
||||
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||
taosEnvToCfg(line, line);
|
||||
|
||||
paGetToken(line, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
name[olen] = 0;
|
||||
|
||||
paGetToken(name + olen + 1, &value, &vlen);
|
||||
if (vlen == 0) continue;
|
||||
value[vlen] = 0;
|
||||
|
||||
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||
if (vlen2 != 0) {
|
||||
value2[vlen2] = 0;
|
||||
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||
if (vlen3 != 0) value3[vlen3] = 0;
|
||||
}
|
||||
|
||||
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR);
|
||||
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_VAR);
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseCmd(&pCmd);
|
||||
if (line != NULL) taosMemoryFreeClear(line);
|
||||
|
||||
uInfo("load from env variables cfg success");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) {
|
||||
uDebug("load from env file not implemented yet");
|
||||
int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
|
||||
char *buf, *name, *value, *value2, *value3;
|
||||
int32_t olen, vlen, vlen2, vlen3;
|
||||
int32_t index = 0;
|
||||
if (envCmd == NULL) return 0;
|
||||
while (envCmd[index]!=NULL) {
|
||||
buf = taosMemoryMalloc(strlen(envCmd[index]));
|
||||
taosEnvToCfg(envCmd[index], buf);
|
||||
index++;
|
||||
|
||||
name = value = value2 = value3 = NULL;
|
||||
olen = vlen = vlen2 = vlen3 = 0;
|
||||
|
||||
paGetToken(buf, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
name[olen] = 0;
|
||||
|
||||
paGetToken(name + olen + 1, &value, &vlen);
|
||||
if (vlen == 0) continue;
|
||||
value[vlen] = 0;
|
||||
|
||||
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||
if (vlen2 != 0) {
|
||||
value2[vlen2] = 0;
|
||||
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||
if (vlen3 != 0) value3[vlen3] = 0;
|
||||
}
|
||||
|
||||
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD);
|
||||
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_CMD);
|
||||
}
|
||||
|
||||
taosMemoryFree(buf);
|
||||
}
|
||||
|
||||
uInfo("load from env cmd cfg success");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
|
||||
char *line = NULL, *name, *value, *value2, *value3;
|
||||
int32_t olen, vlen, vlen2, vlen3;
|
||||
ssize_t _bytes = 0;
|
||||
|
||||
const char *filepath = ".env";
|
||||
if (envFile != NULL && strlen(envFile)>0) {
|
||||
if (!taosCheckExistFile(envFile)) {
|
||||
uError("fial to load env file: %s", envFile);
|
||||
return -1;
|
||||
}
|
||||
filepath = envFile;
|
||||
}else {
|
||||
if (!taosCheckExistFile(filepath)) {
|
||||
uInfo("fial to load env file: %s", filepath);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (!taosEOFFile(pFile)) {
|
||||
name = value = value2 = value3 = NULL;
|
||||
olen = vlen = vlen2 = vlen3 = 0;
|
||||
|
||||
_bytes = taosGetLineFile(pFile, &line);
|
||||
if (_bytes <= 0) {
|
||||
break;
|
||||
}
|
||||
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||
taosEnvToCfg(line, line);
|
||||
|
||||
paGetToken(line, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
name[olen] = 0;
|
||||
|
||||
paGetToken(name + olen + 1, &value, &vlen);
|
||||
if (vlen == 0) continue;
|
||||
value[vlen] = 0;
|
||||
|
||||
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||
if (vlen2 != 0) {
|
||||
value2[vlen2] = 0;
|
||||
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||
if (vlen3 != 0) value3[vlen3] = 0;
|
||||
}
|
||||
|
||||
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE);
|
||||
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (line != NULL) taosMemoryFreeClear(line);
|
||||
|
||||
uInfo("load from env cfg file %s success", filepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -617,11 +767,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
olen = vlen = vlen2 = vlen3 = 0;
|
||||
|
||||
_bytes = taosGetLineFile(pFile, &line);
|
||||
if (_bytes < 0) {
|
||||
if (_bytes <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
line[_bytes - 1] = 0;
|
||||
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||
|
||||
paGetToken(line, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
|
@ -659,6 +809,192 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
}
|
||||
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
||||
uDebug("load from apoll url not implemented yet");
|
||||
char *cfgLineBuf = NULL, *name, *value, *value2, *value3;
|
||||
int32_t olen, vlen, vlen2, vlen3;
|
||||
if (url == NULL || strlen(url) == 0) {
|
||||
uInfo("fail to load apoll url");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *p = strchr(url, ':');
|
||||
if (p == NULL) {
|
||||
uError("fail to load apoll url: %s, unknown format", url);
|
||||
return -1;
|
||||
}
|
||||
p++;
|
||||
|
||||
if (bcmp(url, "jsonFile", 8) == 0) {
|
||||
char *filepath = p;
|
||||
if (!taosCheckExistFile(filepath)) {
|
||||
uError("fial to load json file: %s", filepath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
|
||||
char *buf = taosMemoryMalloc(fileSize);
|
||||
taosLSeekFile(pFile, 0, SEEK_SET);
|
||||
if(taosReadFile(pFile, buf, fileSize) <= 0) {
|
||||
taosCloseFile(&pFile);
|
||||
uError("load json file error: %s", filepath);
|
||||
return -1;
|
||||
}
|
||||
taosCloseFile(&pFile);
|
||||
SJson* pJson = tjsonParse(buf);
|
||||
if (NULL == pJson) {
|
||||
const char *jsonParseError = tjsonGetError();
|
||||
if (jsonParseError != NULL) {
|
||||
uError("load json file parse error: %s", jsonParseError);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
taosMemoryFreeClear(buf);
|
||||
|
||||
int32_t jsonArraySize = tjsonGetArraySize(pJson);
|
||||
for(int32_t i = 0; i < jsonArraySize; i++) {
|
||||
cJSON* item = tjsonGetArrayItem(pJson, i);
|
||||
if (item == NULL) break;
|
||||
char *itemName = NULL, *itemValueString = NULL;
|
||||
tjsonGetObjectName(item, &itemName);
|
||||
tjsonGetObjectName(item, &itemName);
|
||||
tjsonGetObjectValueString(item, &itemValueString);
|
||||
if (itemValueString != NULL && itemName != NULL) {
|
||||
size_t itemNameLen = strlen(itemName);
|
||||
size_t itemValueStringLen = strlen(itemValueString);
|
||||
cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2);
|
||||
memcpy(cfgLineBuf, itemName, itemNameLen);
|
||||
cfgLineBuf[itemNameLen] = ' ';
|
||||
memcpy(&cfgLineBuf[itemNameLen+1], itemValueString, itemValueStringLen);
|
||||
cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0';
|
||||
|
||||
paGetToken(cfgLineBuf, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
name[olen] = 0;
|
||||
|
||||
paGetToken(name + olen + 1, &value, &vlen);
|
||||
if (vlen == 0) continue;
|
||||
value[vlen] = 0;
|
||||
|
||||
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||
if (vlen2 != 0) {
|
||||
value2[vlen2] = 0;
|
||||
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||
if (vlen3 != 0) value3[vlen3] = 0;
|
||||
}
|
||||
cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL);
|
||||
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_APOLLO_URL);
|
||||
}
|
||||
}
|
||||
}
|
||||
tjsonDelete(pJson);
|
||||
|
||||
// } else if (bcmp(url, "jsonUrl", 7) == 0) {
|
||||
// } else if (bcmp(url, "etcdUrl", 7) == 0) {
|
||||
} else {
|
||||
uError("Unsupported url: %s", url);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uInfo("load from apoll url not implemented yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl) {
|
||||
int32_t index = 0;
|
||||
if (envCmd == NULL) return 0;
|
||||
while (envCmd[index]!=NULL) {
|
||||
if (bcmp(envCmd[index], "TAOS_APOLLO_URL", 14) == 0) {
|
||||
char *p = strchr(envCmd[index], '=');
|
||||
if (p != NULL) {
|
||||
p++;
|
||||
if (*p == '\'') {
|
||||
p++;
|
||||
p[strlen(p)-1] = '\0';
|
||||
}
|
||||
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
|
||||
uInfo("get apollo url from env cmd success");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
char *line = NULL;
|
||||
ssize_t _bytes = 0;
|
||||
TdCmdPtr pCmd = taosOpenCmd("set");
|
||||
if (pCmd != NULL) {
|
||||
while (!taosEOFCmd(pCmd)) {
|
||||
_bytes = taosGetLineCmd(pCmd, &line);
|
||||
if (_bytes < 0) {
|
||||
break;
|
||||
}
|
||||
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||
if (bcmp(line, "TAOS_APOLLO_URL", 14) == 0) {
|
||||
char *p = strchr(line, '=');
|
||||
if (p != NULL) {
|
||||
p++;
|
||||
if (*p == '\'') {
|
||||
p++;
|
||||
p[strlen(p)-1] = '\0';
|
||||
}
|
||||
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
|
||||
uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl);
|
||||
taosCloseCmd(&pCmd);
|
||||
if (line != NULL) taosMemoryFreeClear(line);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
taosCloseCmd(&pCmd);
|
||||
if (line != NULL) taosMemoryFreeClear(line);
|
||||
}
|
||||
|
||||
const char *filepath = ".env";
|
||||
if (envFile != NULL && strlen(envFile)>0) {
|
||||
if (!taosCheckExistFile(envFile)) {
|
||||
uError("fial to load env file: %s", envFile);
|
||||
return -1;
|
||||
}
|
||||
filepath = envFile;
|
||||
}else {
|
||||
if (!taosCheckExistFile(filepath)) {
|
||||
uInfo("fial to load env file: %s", filepath);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pFile != NULL) {
|
||||
while (!taosEOFFile(pFile)) {
|
||||
_bytes = taosGetLineFile(pFile, &line);
|
||||
if (_bytes <= 0) {
|
||||
break;
|
||||
}
|
||||
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||
if (bcmp(line, "TAOS_APOLLO_URL", 14) == 0) {
|
||||
char *p = strchr(line, '=');
|
||||
if (p != NULL) {
|
||||
p++;
|
||||
if (*p == '\'') {
|
||||
p++;
|
||||
p[strlen(p)-1] = '\0';
|
||||
}
|
||||
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
|
||||
taosCloseFile(&pFile);
|
||||
if (line != NULL) taosMemoryFreeClear(line);
|
||||
uInfo("get apollo url from env file success");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
taosCloseFile(&pFile);
|
||||
if (line != NULL) taosMemoryFreeClear(line);
|
||||
}
|
||||
|
||||
uInfo("fail get apollo url from cmd env file");
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "tenv.h"
|
||||
#include "tconfig.h"
|
||||
|
||||
static char toLowChar(char c) { return (c > 'Z' || c < 'A' ? c : (c - 'A' + 'a')); }
|
||||
|
||||
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen) {
|
||||
if (envNameStr == NULL || cfgNameStr == NULL) return -1;
|
||||
char *p = cfgNameStr;
|
||||
if (envNameStr[0] != 'T' || envNameStr[1] != 'A' || envNameStr[2] != 'O' || envNameStr[3] != 'S' ||
|
||||
envNameStr[4] != '_') {
|
||||
// if(p != envNameStr) strncpy(p, envNameStr, cfgNameMaxLen - 1);
|
||||
// p[cfgNameMaxLen - 1] = '\0';
|
||||
// return strlen(cfgNameStr);
|
||||
cfgNameStr[0] = '\0';
|
||||
return -1;
|
||||
}
|
||||
envNameStr += 5;
|
||||
if (*envNameStr != '\0') {
|
||||
*p = toLowChar(*envNameStr);
|
||||
p++;
|
||||
envNameStr++;
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < cfgNameMaxLen && *envNameStr != '\0'; i++) {
|
||||
if (*envNameStr == '_') {
|
||||
envNameStr++;
|
||||
*p = *envNameStr;
|
||||
if (*envNameStr == '\0') break;
|
||||
} else {
|
||||
*p = toLowChar(*envNameStr);
|
||||
}
|
||||
p++;
|
||||
envNameStr++;
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
return strlen(cfgNameStr);
|
||||
}
|
||||
|
||||
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
|
||||
if (envStr == NULL && cfgStr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (cfgStr != envStr) strcpy(cfgStr, envStr);
|
||||
char *p = strchr(cfgStr, '=');
|
||||
|
||||
if (p != NULL) {
|
||||
char buf[CFG_NAME_MAX_LEN];
|
||||
if (*(p+1) == '\'') {
|
||||
*(p+1)= ' ';
|
||||
char *pEnd = &cfgStr[strlen(cfgStr)-1];
|
||||
if (*pEnd == '\'') *pEnd = '\0';
|
||||
}
|
||||
*p = '\0';
|
||||
int32_t cfgNameLen = taosEnvNameToCfgName(cfgStr, buf, CFG_NAME_MAX_LEN);
|
||||
if (cfgNameLen > 0) {
|
||||
memcpy(cfgStr, buf, cfgNameLen);
|
||||
memset(&cfgStr[cfgNameLen], ' ', p - cfgStr - cfgNameLen + 1);
|
||||
}
|
||||
}
|
||||
return strlen(cfgStr);
|
||||
}
|
|
@ -403,6 +403,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CHECKSUM, "Invalid msg checksum"
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_MSGLEN, "Invalid msg length")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_MSGTYPE, "Invalid msg type")
|
||||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_LEADER, "Sync not leader")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INTERNAL_ERROR, "Sync internal error")
|
||||
|
||||
// wal
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, "Unexpected generic error in wal")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_FILE_CORRUPTED, "WAL file is corrupted")
|
||||
|
|
|
@ -144,6 +144,22 @@ char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatt
|
|||
|
||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); }
|
||||
|
||||
int32_t tjsonGetObjectName(const SJson* pJson, char** pName) {
|
||||
*pName = ((cJSON*)pJson)->string;
|
||||
if (NULL == *pName) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tjsonGetObjectValueString(const SJson* pJson, char** pValueString) {
|
||||
*pValueString = ((cJSON*)pJson)->valuestring;
|
||||
if (NULL == *pValueString) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) {
|
||||
char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName));
|
||||
if (NULL == p) {
|
||||
|
@ -310,3 +326,5 @@ bool tjsonValidateJson(const char *jIn) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* tjsonGetError() { return cJSON_GetErrorPtr(); }
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue