[td-13039] merge 3.0.
This commit is contained in:
commit
c62dfe6460
|
@ -87,7 +87,7 @@ tests/comparisonTest/opentsdb/opentsdbtest/.settings/
|
|||
tests/examples/JDBC/JDBCDemo/.classpath
|
||||
tests/examples/JDBC/JDBCDemo/.project
|
||||
tests/examples/JDBC/JDBCDemo/.settings/
|
||||
source/libs/parser/inc/new_sql.*
|
||||
source/libs/parser/inc/sql.*
|
||||
|
||||
# Emacs
|
||||
# -*- mode: gitignore; -*-
|
||||
|
|
|
@ -39,7 +39,7 @@ typedef void **TAOS_ROW;
|
|||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string, alias for varchar
|
||||
#define TSDB_DATA_TYPE_VARCHAR 8 // string, alias for varchar
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||
|
@ -47,10 +47,11 @@ typedef void **TAOS_ROW;
|
|||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_JSON 15 // json string
|
||||
#define TSDB_DATA_TYPE_VARCHAR 16 // string
|
||||
#define TSDB_DATA_TYPE_VARBINARY 17 // binary
|
||||
#define TSDB_DATA_TYPE_DECIMAL 18 // decimal
|
||||
#define TSDB_DATA_TYPE_BLOB 19 // binary
|
||||
#define TSDB_DATA_TYPE_VARBINARY 16 // binary
|
||||
#define TSDB_DATA_TYPE_DECIMAL 17 // decimal
|
||||
#define TSDB_DATA_TYPE_BLOB 18 // binary
|
||||
#define TSDB_DATA_TYPE_MEDIUMBLOB 19
|
||||
#define TSDB_DATA_TYPE_BINARY TSDB_DATA_TYPE_VARCHAR // string
|
||||
|
||||
typedef enum {
|
||||
TSDB_OPTION_LOCALE,
|
||||
|
|
|
@ -56,8 +56,9 @@ typedef struct SColumnDataAgg {
|
|||
typedef struct SDataBlockInfo {
|
||||
STimeWindow window;
|
||||
int32_t rows;
|
||||
int32_t rowSize;
|
||||
int32_t numOfCols;
|
||||
int64_t uid;
|
||||
union {int64_t uid; int64_t blockId;};
|
||||
} SDataBlockInfo;
|
||||
|
||||
typedef struct SConstantItem {
|
||||
|
@ -108,7 +109,7 @@ static FORCE_INLINE int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlo
|
|||
SColumnInfoData* pColData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);
|
||||
tlen += taosEncodeFixedI16(buf, pColData->info.colId);
|
||||
tlen += taosEncodeFixedI16(buf, pColData->info.type);
|
||||
tlen += taosEncodeFixedI16(buf, pColData->info.bytes);
|
||||
tlen += taosEncodeFixedI32(buf, pColData->info.bytes);
|
||||
int32_t colSz = rows * pColData->info.bytes;
|
||||
tlen += taosEncodeBinary(buf, pColData->pData, colSz);
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ static FORCE_INLINE void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock)
|
|||
SColumnInfoData data = {0};
|
||||
buf = taosDecodeFixedI16(buf, &data.info.colId);
|
||||
buf = taosDecodeFixedI16(buf, &data.info.type);
|
||||
buf = taosDecodeFixedI16(buf, &data.info.bytes);
|
||||
buf = taosDecodeFixedI32(buf, &data.info.bytes);
|
||||
int32_t colSz = pBlock->info.rows * data.info.bytes;
|
||||
buf = taosDecodeBinary(buf, (void**)&data.pData, colSz);
|
||||
taosArrayPush(pBlock->pDataBlock, &data);
|
||||
|
@ -212,10 +213,22 @@ static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqPollRsp* pRsp) {
|
|||
//======================================================================================================================
|
||||
// the following structure shared by parser and executor
|
||||
typedef struct SColumn {
|
||||
union {
|
||||
uint64_t uid;
|
||||
int64_t dataBlockId;
|
||||
};
|
||||
|
||||
union {
|
||||
int16_t colId;
|
||||
int16_t slotId;
|
||||
};
|
||||
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
int8_t flag; // column type: normal column, tag, or user-input column (integer/float/string)
|
||||
SColumnInfo info;
|
||||
int16_t type;
|
||||
int32_t bytes;
|
||||
uint8_t precision;
|
||||
uint8_t scale;
|
||||
} SColumn;
|
||||
|
||||
typedef struct SLimit {
|
||||
|
@ -233,20 +246,31 @@ typedef struct SGroupbyExpr {
|
|||
bool groupbyTag; // group by tag or column
|
||||
} SGroupbyExpr;
|
||||
|
||||
// the structure for sql function in select clause
|
||||
typedef struct SSqlExpr {
|
||||
char token[TSDB_COL_NAME_LEN]; // original token
|
||||
SSchema resSchema;
|
||||
typedef struct SFunctParam {
|
||||
int32_t type;
|
||||
SColumn *pCol;
|
||||
SVariant param;
|
||||
} SFunctParam;
|
||||
|
||||
int32_t numOfCols;
|
||||
SColumn* pColumns; // data columns that are required by query
|
||||
int32_t interBytes; // inter result buffer size
|
||||
// the structure for sql function in select clause
|
||||
typedef struct SResSchame {
|
||||
int8_t type;
|
||||
int32_t colId;
|
||||
int32_t bytes;
|
||||
int32_t precision;
|
||||
int32_t scale;
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
} SResSchema;
|
||||
|
||||
// TODO move away to executor.h
|
||||
typedef struct SExprBasicInfo {
|
||||
SResSchema resSchema;
|
||||
int16_t numOfParams; // argument value of each function
|
||||
SVariant param[3]; // parameters are not more than 3
|
||||
} SSqlExpr;
|
||||
SFunctParam *pParam;
|
||||
} SExprBasicInfo;
|
||||
|
||||
typedef struct SExprInfo {
|
||||
struct SSqlExpr base;
|
||||
struct SExprBasicInfo base;
|
||||
struct tExprNode *pExpr;
|
||||
} SExprInfo;
|
||||
|
||||
|
|
|
@ -94,8 +94,8 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock);
|
|||
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows);
|
||||
void colDataTrim(SColumnInfoData* pColumnInfoData);
|
||||
|
||||
size_t colDataGetNumOfCols(const SSDataBlock* pBlock);
|
||||
size_t colDataGetNumOfRows(const SSDataBlock* pBlock);
|
||||
size_t blockDataGetNumOfCols(const SSDataBlock* pBlock);
|
||||
size_t blockDataGetNumOfRows(const SSDataBlock* pBlock);
|
||||
|
||||
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc);
|
||||
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex,
|
||||
|
|
|
@ -140,6 +140,8 @@ typedef enum _mgmt_table {
|
|||
|
||||
#define TSDB_KILL_MSG_LEN 30
|
||||
|
||||
#define TSDB_TABLE_NUM_UNIT 100000
|
||||
|
||||
#define TSDB_VN_READ_ACCCESS ((char)0x1)
|
||||
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
|
||||
#define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
|
||||
|
@ -169,6 +171,7 @@ typedef struct {
|
|||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||
} SBuildUseDBInput;
|
||||
|
||||
typedef struct SField {
|
||||
|
@ -416,10 +419,15 @@ typedef struct {
|
|||
* But for data in vnode side, we need all the following information.
|
||||
*/
|
||||
typedef struct {
|
||||
union {
|
||||
int16_t colId;
|
||||
int16_t slotId;
|
||||
};
|
||||
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
SColumnFilterList flist;
|
||||
int32_t bytes;
|
||||
uint8_t precision;
|
||||
uint8_t scale;
|
||||
} SColumnInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -449,57 +457,6 @@ typedef struct {
|
|||
int64_t offset;
|
||||
} SInterval;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char version[TSDB_VERSION_LEN];
|
||||
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool interpQuery; // interp query or not
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool hasTagResults; // if there are tag values in final result or not
|
||||
bool timeWindowInterpo; // if the time window start/end required interpolation
|
||||
bool queryBlockDist; // if query data block distribution
|
||||
bool stabledev; // super table stddev query
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool simpleAgg;
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
bool needReverseScan; // need reverse scan
|
||||
bool stateWindow; // state window flag
|
||||
|
||||
STimeWindow window;
|
||||
int32_t numOfTables;
|
||||
int16_t order;
|
||||
int16_t orderColId;
|
||||
int16_t numOfCols; // the number of columns will be load from vnode
|
||||
SInterval interval;
|
||||
// SSessionWindow sw; // session window
|
||||
int16_t tagCondLen; // tag length in current query
|
||||
int16_t colCondLen; // column length in current query
|
||||
int16_t numOfGroupCols; // num of group by columns
|
||||
int16_t orderByIdx;
|
||||
int16_t orderType; // used in group by xx order by xxx
|
||||
int64_t vgroupLimit; // limit the number of rows for each table, used in order by + limit in stable projection query.
|
||||
int16_t prjOrder; // global order in super table projection query.
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int32_t queryType; // denote another query process
|
||||
int16_t numOfOutput; // final output columns numbers
|
||||
int16_t fillType; // interpolate type
|
||||
int64_t fillVal; // default value array list
|
||||
int32_t secondStageOutput;
|
||||
STsBufInfo tsBuf; // tsBuf info
|
||||
int32_t numOfTags; // number of tags columns involved
|
||||
int32_t sqlstrLen; // sql query string
|
||||
int32_t prevResultLen; // previous result length
|
||||
int32_t numOfOperator;
|
||||
int32_t tableScanOperator; // table scan operator. -1 means no scan operator
|
||||
int32_t udfNum; // number of udf function
|
||||
int32_t udfContentOffset;
|
||||
int32_t udfContentLen;
|
||||
SColumnInfo tableCols[];
|
||||
} SQueryTableReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
} SQueryTableRsp;
|
||||
|
@ -566,6 +523,7 @@ typedef struct {
|
|||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||
} SUseDbReq;
|
||||
|
||||
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
|
||||
|
@ -584,6 +542,23 @@ int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
|
|||
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
|
||||
void tFreeSUsedbRsp(SUseDbRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
int32_t rowNum;
|
||||
} SQnodeListReq;
|
||||
|
||||
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
|
||||
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
SArray *epSetList; // SArray<SEpSet>
|
||||
} SQnodeListRsp;
|
||||
|
||||
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
|
||||
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
|
||||
void tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
SArray* pArray; // Array of SUseDbRsp
|
||||
} SUseDbBatchRsp;
|
||||
|
@ -796,8 +771,10 @@ typedef struct SVgroupInfo {
|
|||
uint32_t hashBegin;
|
||||
uint32_t hashEnd;
|
||||
SEpSet epSet;
|
||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||
} SVgroupInfo;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfVgroups;
|
||||
SVgroupInfo vgroups[];
|
||||
|
@ -876,6 +853,8 @@ int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
|
|||
void tFreeSShowRsp(SShowRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
int32_t type;
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t showId;
|
||||
int8_t free;
|
||||
} SRetrieveTableReq;
|
||||
|
@ -903,6 +882,8 @@ int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq*
|
|||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
int32_t port;
|
||||
} SDropDnodeReq;
|
||||
|
||||
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
|
||||
|
@ -1026,6 +1007,7 @@ typedef struct SSubQueryMsg {
|
|||
uint64_t sId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
int64_t refId;
|
||||
int8_t taskType;
|
||||
uint32_t sqlLen; // the query sql,
|
||||
uint32_t phyLen;
|
||||
|
@ -1072,19 +1054,57 @@ typedef struct {
|
|||
typedef struct {
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
int64_t refId;
|
||||
int8_t status;
|
||||
} STaskStatus;
|
||||
|
||||
typedef struct {
|
||||
uint32_t num;
|
||||
STaskStatus status[];
|
||||
int64_t refId;
|
||||
SArray *taskStatus; //SArray<STaskStatus>
|
||||
} SSchedulerStatusRsp;
|
||||
|
||||
typedef struct {
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
int8_t action;
|
||||
} STaskAction;
|
||||
|
||||
|
||||
typedef struct SQueryNodeEpId {
|
||||
int32_t nodeId; // vgId or qnodeId
|
||||
SEp ep;
|
||||
} SQueryNodeEpId;
|
||||
|
||||
|
||||
typedef struct {
|
||||
SMsgHead header;
|
||||
uint64_t sId;
|
||||
SQueryNodeEpId epId;
|
||||
SArray *taskAction; //SArray<STaskAction>
|
||||
} SSchedulerHbReq;
|
||||
|
||||
int32_t tSerializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq);
|
||||
int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq);
|
||||
void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq);
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint64_t seqId;
|
||||
SQueryNodeEpId epId;
|
||||
SArray *taskStatus; //SArray<STaskStatus>
|
||||
} SSchedulerHbRsp;
|
||||
|
||||
int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp);
|
||||
int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp);
|
||||
void tFreeSSchedulerHbRsp(SSchedulerHbRsp *pRsp);
|
||||
|
||||
|
||||
typedef struct {
|
||||
SMsgHead header;
|
||||
uint64_t sId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
int64_t refId;
|
||||
} STaskCancelReq;
|
||||
|
||||
typedef struct {
|
||||
|
@ -1096,6 +1116,7 @@ typedef struct {
|
|||
uint64_t sId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
int64_t refId;
|
||||
} STaskDropReq;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -129,11 +129,13 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TABLE_META, "mnode-table-meta", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_QNODE_LIST, "mnode-qnode-list", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "mnode-kill-query", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "mnode-heartbeat", SClientHbBatchReq, SClientHbBatchRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SYSTABLE_RETRIEVE, "mnode-systable-retrieve", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "mnode-trans-tmr", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_KILL_TRANS, "mnode-kill-trans", NULL, NULL)
|
||||
|
@ -183,6 +185,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES, "vnode-show-tables", SVShowTablesReq, SVShowTablesRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES_FETCH, "vnode-show-tables-fetch", SVShowTablesFetchReq, SVShowTablesFetchRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_QUERY_CONTINUE, "vnode-query-continue", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_QUERY_HEARTBEAT, "vnode-query-heartbeat", NULL, NULL)
|
||||
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqCVConsumeReq, SMqCVConsumeRsp)
|
||||
|
|
|
@ -16,279 +16,159 @@
|
|||
#ifndef _TD_COMMON_TOKEN_H_
|
||||
#define _TD_COMMON_TOKEN_H_
|
||||
|
||||
#define TK_ID 1
|
||||
#define TK_BOOL 2
|
||||
#define TK_INTEGER 3
|
||||
#define TK_FLOAT 4
|
||||
#define TK_STRING 5
|
||||
#define TK_TIMESTAMP 6
|
||||
#define TK_OR 7
|
||||
#define TK_AND 8
|
||||
#define TK_NOT 9
|
||||
#define TK_EQ 10
|
||||
#define TK_NE 11
|
||||
#define TK_ISNULL 12
|
||||
#define TK_NOTNULL 13
|
||||
#define TK_IS 14
|
||||
#define TK_LIKE 15
|
||||
#define TK_MATCH 16
|
||||
#define TK_NMATCH 17
|
||||
#define TK_GLOB 18
|
||||
#define TK_BETWEEN 19
|
||||
#define TK_IN 20
|
||||
#define TK_GT 21
|
||||
#define TK_GE 22
|
||||
#define TK_LT 23
|
||||
#define TK_LE 24
|
||||
#define TK_BITAND 25
|
||||
#define TK_BITOR 26
|
||||
#define TK_LSHIFT 27
|
||||
#define TK_RSHIFT 28
|
||||
#define TK_PLUS 29
|
||||
#define TK_MINUS 30
|
||||
#define TK_DIVIDE 31
|
||||
#define TK_TIMES 32
|
||||
#define TK_STAR 33
|
||||
#define TK_SLASH 34
|
||||
#define TK_REM 35
|
||||
#define TK_CONCAT 36
|
||||
#define TK_UMINUS 37
|
||||
#define TK_UPLUS 38
|
||||
#define TK_BITNOT 39
|
||||
#define TK_SHOW 40
|
||||
#define TK_DATABASES 41
|
||||
#define TK_TOPICS 42
|
||||
#define TK_FUNCTIONS 43
|
||||
#define TK_MNODES 44
|
||||
#define TK_DNODES 45
|
||||
#define TK_ACCOUNTS 46
|
||||
#define TK_USERS 47
|
||||
#define TK_MODULES 48
|
||||
#define TK_QUERIES 49
|
||||
#define TK_CONNECTIONS 50
|
||||
#define TK_STREAMS 51
|
||||
#define TK_VARIABLES 52
|
||||
#define TK_SCORES 53
|
||||
#define TK_GRANTS 54
|
||||
#define TK_VNODES 55
|
||||
#define TK_DOT 56
|
||||
#define TK_CREATE 57
|
||||
#define TK_TABLE 58
|
||||
#define TK_OR 1
|
||||
#define TK_AND 2
|
||||
#define TK_UNION 3
|
||||
#define TK_ALL 4
|
||||
#define TK_MINUS 5
|
||||
#define TK_EXCEPT 6
|
||||
#define TK_INTERSECT 7
|
||||
#define TK_NK_BITAND 8
|
||||
#define TK_NK_BITOR 9
|
||||
#define TK_NK_LSHIFT 10
|
||||
#define TK_NK_RSHIFT 11
|
||||
#define TK_NK_PLUS 12
|
||||
#define TK_NK_MINUS 13
|
||||
#define TK_NK_STAR 14
|
||||
#define TK_NK_SLASH 15
|
||||
#define TK_NK_REM 16
|
||||
#define TK_NK_CONCAT 17
|
||||
#define TK_CREATE 18
|
||||
#define TK_USER 19
|
||||
#define TK_PASS 20
|
||||
#define TK_NK_STRING 21
|
||||
#define TK_ALTER 22
|
||||
#define TK_PRIVILEGE 23
|
||||
#define TK_DROP 24
|
||||
#define TK_SHOW 25
|
||||
#define TK_USERS 26
|
||||
#define TK_DNODE 27
|
||||
#define TK_PORT 28
|
||||
#define TK_NK_INTEGER 29
|
||||
#define TK_DNODES 30
|
||||
#define TK_NK_ID 31
|
||||
#define TK_NK_IPTOKEN 32
|
||||
#define TK_DATABASE 33
|
||||
#define TK_DATABASES 34
|
||||
#define TK_USE 35
|
||||
#define TK_IF 36
|
||||
#define TK_NOT 37
|
||||
#define TK_EXISTS 38
|
||||
#define TK_BLOCKS 39
|
||||
#define TK_CACHE 40
|
||||
#define TK_CACHELAST 41
|
||||
#define TK_COMP 42
|
||||
#define TK_DAYS 43
|
||||
#define TK_FSYNC 44
|
||||
#define TK_MAXROWS 45
|
||||
#define TK_MINROWS 46
|
||||
#define TK_KEEP 47
|
||||
#define TK_PRECISION 48
|
||||
#define TK_QUORUM 49
|
||||
#define TK_REPLICA 50
|
||||
#define TK_TTL 51
|
||||
#define TK_WAL 52
|
||||
#define TK_VGROUPS 53
|
||||
#define TK_SINGLE_STABLE 54
|
||||
#define TK_STREAM_MODE 55
|
||||
#define TK_TABLE 56
|
||||
#define TK_NK_LP 57
|
||||
#define TK_NK_RP 58
|
||||
#define TK_STABLE 59
|
||||
#define TK_DATABASE 60
|
||||
#define TK_TABLES 61
|
||||
#define TK_STABLES 62
|
||||
#define TK_VGROUPS 63
|
||||
#define TK_DROP 64
|
||||
#define TK_TOPIC 65
|
||||
#define TK_FUNCTION 66
|
||||
#define TK_DNODE 67
|
||||
#define TK_USER 68
|
||||
#define TK_ACCOUNT 69
|
||||
#define TK_USE 70
|
||||
#define TK_DESCRIBE 71
|
||||
#define TK_DESC 72
|
||||
#define TK_ALTER 73
|
||||
#define TK_PASS 74
|
||||
#define TK_PRIVILEGE 75
|
||||
#define TK_LOCAL 76
|
||||
#define TK_COMPACT 77
|
||||
#define TK_LP 78
|
||||
#define TK_RP 79
|
||||
#define TK_IF 80
|
||||
#define TK_EXISTS 81
|
||||
#define TK_PORT 82
|
||||
#define TK_IPTOKEN 83
|
||||
#define TK_AS 84
|
||||
#define TK_OUTPUTTYPE 85
|
||||
#define TK_AGGREGATE 86
|
||||
#define TK_BUFSIZE 87
|
||||
#define TK_PPS 88
|
||||
#define TK_TSERIES 89
|
||||
#define TK_DBS 90
|
||||
#define TK_STORAGE 91
|
||||
#define TK_QTIME 92
|
||||
#define TK_CONNS 93
|
||||
#define TK_STATE 94
|
||||
#define TK_COMMA 95
|
||||
#define TK_KEEP 96
|
||||
#define TK_CACHE 97
|
||||
#define TK_REPLICA 98
|
||||
#define TK_QUORUM 99
|
||||
#define TK_DAYS 100
|
||||
#define TK_MINROWS 101
|
||||
#define TK_MAXROWS 102
|
||||
#define TK_BLOCKS 103
|
||||
#define TK_CTIME 104
|
||||
#define TK_WAL 105
|
||||
#define TK_FSYNC 106
|
||||
#define TK_COMP 107
|
||||
#define TK_PRECISION 108
|
||||
#define TK_UPDATE 109
|
||||
#define TK_CACHELAST 110
|
||||
#define TK_STREAM 111
|
||||
#define TK_MODE 112
|
||||
#define TK_UNSIGNED 113
|
||||
#define TK_TAGS 114
|
||||
#define TK_USING 115
|
||||
#define TK_NULL 116
|
||||
#define TK_NOW 117
|
||||
#define TK_SELECT 118
|
||||
#define TK_UNION 119
|
||||
#define TK_ALL 120
|
||||
#define TK_DISTINCT 121
|
||||
#define TK_FROM 122
|
||||
#define TK_VARIABLE 123
|
||||
#define TK_INTERVAL 124
|
||||
#define TK_EVERY 125
|
||||
#define TK_SESSION 126
|
||||
#define TK_STATE_WINDOW 127
|
||||
#define TK_FILL 128
|
||||
#define TK_SLIDING 129
|
||||
#define TK_ORDER 130
|
||||
#define TK_BY 131
|
||||
#define TK_ASC 132
|
||||
#define TK_GROUP 133
|
||||
#define TK_HAVING 134
|
||||
#define TK_LIMIT 135
|
||||
#define TK_OFFSET 136
|
||||
#define TK_SLIMIT 137
|
||||
#define TK_SOFFSET 138
|
||||
#define TK_WHERE 139
|
||||
#define TK_RESET 140
|
||||
#define TK_QUERY 141
|
||||
#define TK_SYNCDB 142
|
||||
#define TK_ADD 143
|
||||
#define TK_COLUMN 144
|
||||
#define TK_MODIFY 145
|
||||
#define TK_TAG 146
|
||||
#define TK_CHANGE 147
|
||||
#define TK_SET 148
|
||||
#define TK_KILL 149
|
||||
#define TK_CONNECTION 150
|
||||
#define TK_COLON 151
|
||||
#define TK_ABORT 152
|
||||
#define TK_AFTER 153
|
||||
#define TK_ATTACH 154
|
||||
#define TK_BEFORE 155
|
||||
#define TK_BEGIN 156
|
||||
#define TK_CASCADE 157
|
||||
#define TK_CLUSTER 158
|
||||
#define TK_CONFLICT 159
|
||||
#define TK_COPY 160
|
||||
#define TK_DEFERRED 161
|
||||
#define TK_DELIMITERS 162
|
||||
#define TK_DETACH 163
|
||||
#define TK_EACH 164
|
||||
#define TK_END 165
|
||||
#define TK_EXPLAIN 166
|
||||
#define TK_FAIL 167
|
||||
#define TK_FOR 168
|
||||
#define TK_IGNORE 169
|
||||
#define TK_IMMEDIATE 170
|
||||
#define TK_INITIALLY 171
|
||||
#define TK_INSTEAD 172
|
||||
#define TK_KEY 173
|
||||
#define TK_OF 174
|
||||
#define TK_RAISE 175
|
||||
#define TK_REPLACE 176
|
||||
#define TK_RESTRICT 177
|
||||
#define TK_ROW 178
|
||||
#define TK_STATEMENT 179
|
||||
#define TK_TRIGGER 180
|
||||
#define TK_VIEW 181
|
||||
#define TK_SEMI 182
|
||||
#define TK_NONE 183
|
||||
#define TK_PREV 184
|
||||
#define TK_LINEAR 185
|
||||
#define TK_IMPORT 186
|
||||
#define TK_TBNAME 187
|
||||
#define TK_JOIN 188
|
||||
#define TK_INSERT 189
|
||||
#define TK_INTO 190
|
||||
#define TK_VALUES 191
|
||||
#define TK_TABLES 60
|
||||
#define TK_STABLES 61
|
||||
#define TK_USING 62
|
||||
#define TK_TAGS 63
|
||||
#define TK_NK_DOT 64
|
||||
#define TK_NK_COMMA 65
|
||||
#define TK_COMMENT 66
|
||||
#define TK_BOOL 67
|
||||
#define TK_TINYINT 68
|
||||
#define TK_SMALLINT 69
|
||||
#define TK_INT 70
|
||||
#define TK_INTEGER 71
|
||||
#define TK_BIGINT 72
|
||||
#define TK_FLOAT 73
|
||||
#define TK_DOUBLE 74
|
||||
#define TK_BINARY 75
|
||||
#define TK_TIMESTAMP 76
|
||||
#define TK_NCHAR 77
|
||||
#define TK_UNSIGNED 78
|
||||
#define TK_JSON 79
|
||||
#define TK_VARCHAR 80
|
||||
#define TK_MEDIUMBLOB 81
|
||||
#define TK_BLOB 82
|
||||
#define TK_VARBINARY 83
|
||||
#define TK_DECIMAL 84
|
||||
#define TK_SMA 85
|
||||
#define TK_MNODES 86
|
||||
#define TK_NK_FLOAT 87
|
||||
#define TK_NK_BOOL 88
|
||||
#define TK_NK_VARIABLE 89
|
||||
#define TK_BETWEEN 90
|
||||
#define TK_IS 91
|
||||
#define TK_NULL 92
|
||||
#define TK_NK_LT 93
|
||||
#define TK_NK_GT 94
|
||||
#define TK_NK_LE 95
|
||||
#define TK_NK_GE 96
|
||||
#define TK_NK_NE 97
|
||||
#define TK_NK_EQ 98
|
||||
#define TK_LIKE 99
|
||||
#define TK_MATCH 100
|
||||
#define TK_NMATCH 101
|
||||
#define TK_IN 102
|
||||
#define TK_FROM 103
|
||||
#define TK_AS 104
|
||||
#define TK_JOIN 105
|
||||
#define TK_ON 106
|
||||
#define TK_INNER 107
|
||||
#define TK_SELECT 108
|
||||
#define TK_DISTINCT 109
|
||||
#define TK_WHERE 110
|
||||
#define TK_PARTITION 111
|
||||
#define TK_BY 112
|
||||
#define TK_SESSION 113
|
||||
#define TK_STATE_WINDOW 114
|
||||
#define TK_INTERVAL 115
|
||||
#define TK_SLIDING 116
|
||||
#define TK_FILL 117
|
||||
#define TK_VALUE 118
|
||||
#define TK_NONE 119
|
||||
#define TK_PREV 120
|
||||
#define TK_LINEAR 121
|
||||
#define TK_NEXT 122
|
||||
#define TK_GROUP 123
|
||||
#define TK_HAVING 124
|
||||
#define TK_ORDER 125
|
||||
#define TK_SLIMIT 126
|
||||
#define TK_SOFFSET 127
|
||||
#define TK_LIMIT 128
|
||||
#define TK_OFFSET 129
|
||||
#define TK_ASC 130
|
||||
#define TK_DESC 131
|
||||
#define TK_NULLS 132
|
||||
#define TK_FIRST 133
|
||||
#define TK_LAST 134
|
||||
|
||||
#define NEW_TK_OR 1
|
||||
#define NEW_TK_AND 2
|
||||
#define NEW_TK_UNION 3
|
||||
#define NEW_TK_ALL 4
|
||||
#define NEW_TK_MINUS 5
|
||||
#define NEW_TK_EXCEPT 6
|
||||
#define NEW_TK_INTERSECT 7
|
||||
#define NEW_TK_NK_PLUS 8
|
||||
#define NEW_TK_NK_MINUS 9
|
||||
#define NEW_TK_NK_STAR 10
|
||||
#define NEW_TK_NK_SLASH 11
|
||||
#define NEW_TK_NK_REM 12
|
||||
#define NEW_TK_SHOW 13
|
||||
#define NEW_TK_DATABASES 14
|
||||
#define NEW_TK_NK_INTEGER 15
|
||||
#define NEW_TK_NK_FLOAT 16
|
||||
#define NEW_TK_NK_STRING 17
|
||||
#define NEW_TK_NK_BOOL 18
|
||||
#define NEW_TK_TIMESTAMP 19
|
||||
#define NEW_TK_NK_VARIABLE 20
|
||||
#define NEW_TK_NK_COMMA 21
|
||||
#define NEW_TK_NK_ID 22
|
||||
#define NEW_TK_NK_LP 23
|
||||
#define NEW_TK_NK_RP 24
|
||||
#define NEW_TK_NK_DOT 25
|
||||
#define NEW_TK_BETWEEN 26
|
||||
#define NEW_TK_NOT 27
|
||||
#define NEW_TK_IS 28
|
||||
#define NEW_TK_NULL 29
|
||||
#define NEW_TK_NK_LT 30
|
||||
#define NEW_TK_NK_GT 31
|
||||
#define NEW_TK_NK_LE 32
|
||||
#define NEW_TK_NK_GE 33
|
||||
#define NEW_TK_NK_NE 34
|
||||
#define NEW_TK_NK_EQ 35
|
||||
#define NEW_TK_LIKE 36
|
||||
#define NEW_TK_MATCH 37
|
||||
#define NEW_TK_NMATCH 38
|
||||
#define NEW_TK_IN 39
|
||||
#define NEW_TK_FROM 40
|
||||
#define NEW_TK_AS 41
|
||||
#define NEW_TK_JOIN 42
|
||||
#define NEW_TK_ON 43
|
||||
#define NEW_TK_INNER 44
|
||||
#define NEW_TK_SELECT 45
|
||||
#define NEW_TK_DISTINCT 46
|
||||
#define NEW_TK_WHERE 47
|
||||
#define NEW_TK_PARTITION 48
|
||||
#define NEW_TK_BY 49
|
||||
#define NEW_TK_SESSION 50
|
||||
#define NEW_TK_STATE_WINDOW 51
|
||||
#define NEW_TK_INTERVAL 52
|
||||
#define NEW_TK_SLIDING 53
|
||||
#define NEW_TK_FILL 54
|
||||
#define NEW_TK_VALUE 55
|
||||
#define NEW_TK_NONE 56
|
||||
#define NEW_TK_PREV 57
|
||||
#define NEW_TK_LINEAR 58
|
||||
#define NEW_TK_NEXT 59
|
||||
#define NEW_TK_GROUP 60
|
||||
#define NEW_TK_HAVING 61
|
||||
#define NEW_TK_ORDER 62
|
||||
#define NEW_TK_SLIMIT 63
|
||||
#define NEW_TK_SOFFSET 64
|
||||
#define NEW_TK_LIMIT 65
|
||||
#define NEW_TK_OFFSET 66
|
||||
#define NEW_TK_ASC 67
|
||||
#define NEW_TK_DESC 68
|
||||
#define NEW_TK_NULLS 69
|
||||
#define NEW_TK_FIRST 70
|
||||
#define NEW_TK_LAST 71
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
#define TK_NK_ILLEGAL 302
|
||||
#define TK_NK_HEX 303 // hex number 0x123
|
||||
#define TK_NK_OCT 304 // oct number
|
||||
#define TK_NK_BIN 305 // bin format data 0b111
|
||||
#define TK_NK_FILE 306
|
||||
#define TK_NK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
|
||||
|
||||
#define TK_SPACE 300
|
||||
#define TK_COMMENT 301
|
||||
#define TK_ILLEGAL 302
|
||||
#define TK_HEX 303 // hex number 0x123
|
||||
#define TK_OCT 304 // oct number
|
||||
#define TK_BIN 305 // bin format data 0b111
|
||||
#define TK_FILE 306
|
||||
#define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
|
||||
#define TK_NK_COLON 500
|
||||
#define TK_NK_BITNOT 501
|
||||
#define TK_INSERT 502
|
||||
#define TK_INTO 503
|
||||
#define TK_NOW 504
|
||||
#define TK_VALUES 507
|
||||
#define TK_IMPORT 507
|
||||
#define TK_NK_SEMI 508
|
||||
|
||||
#define TK_NIL 65535
|
||||
#define TK_NK_NIL 65535
|
||||
|
||||
#endif /*_TD_COMMON_TOKEN_H_*/
|
||||
|
|
|
@ -51,7 +51,7 @@ typedef struct SMetaData {
|
|||
SArray *pTableMeta; // STableMeta array
|
||||
SArray *pVgroupInfo; // SVgroupInfo list
|
||||
SArray *pUdfList; // udf info list
|
||||
SEpSet *pEpSet; // qnode epset list
|
||||
SArray *pEpSetList; // qnode epset list, SArray<SEpSet>
|
||||
} SMetaData;
|
||||
|
||||
typedef struct SCatalogCfg {
|
||||
|
@ -74,9 +74,9 @@ typedef struct SDbVgVersion {
|
|||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||
} SDbVgVersion;
|
||||
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
|
||||
/**
|
||||
|
@ -95,7 +95,7 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
|
|||
*/
|
||||
void catalogFreeHandle(SCatalog* pCatalog);
|
||||
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId);
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum);
|
||||
|
||||
/**
|
||||
* Get a DB's all vgroup info.
|
||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
|||
#include "os.h"
|
||||
#include "thash.h"
|
||||
#include "executor.h"
|
||||
#include "plannodes.h"
|
||||
|
||||
#define DS_BUF_LOW 1
|
||||
#define DS_BUF_FULL 2
|
||||
|
@ -58,7 +59,7 @@ typedef struct SOutputData {
|
|||
* @param pHandle output
|
||||
* @return error code
|
||||
*/
|
||||
int32_t dsCreateDataSinker(const struct SDataSink *pDataSink, DataSinkHandle* pHandle);
|
||||
int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle);
|
||||
|
||||
/**
|
||||
* Put the result set returned by the executor into datasinker.
|
||||
|
|
|
@ -20,9 +20,30 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tbuffer.h"
|
||||
#include "tcommon.h"
|
||||
#include "tvariant.h"
|
||||
#include "tbuffer.h"
|
||||
|
||||
struct SqlFunctionCtx;
|
||||
struct SResultRowEntryInfo;
|
||||
|
||||
typedef struct SFunctionNode SFunctionNode;
|
||||
|
||||
typedef struct SFuncExecEnv {
|
||||
int32_t calcMemSize;
|
||||
} SFuncExecEnv;
|
||||
|
||||
typedef bool (*FExecGetEnv)(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
||||
typedef void (*FExecProcess)(struct SqlFunctionCtx *pCtx);
|
||||
typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx);
|
||||
|
||||
typedef struct SFuncExecFuncs {
|
||||
FExecGetEnv getEnv;
|
||||
FExecInit init;
|
||||
FExecProcess process;
|
||||
FExecFinalize finalize;
|
||||
} SFuncExecFuncs;
|
||||
|
||||
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
|
||||
|
||||
|
@ -111,64 +132,65 @@ struct SqlFunctionCtx;
|
|||
struct SResultRowEntryInfo;
|
||||
|
||||
//for selectivity query, the corresponding tag value is assigned if the data is qualified
|
||||
typedef struct SExtTagsInfo {
|
||||
int16_t tagsLen; // keep the tags data for top/bottom query result
|
||||
int16_t numOfTagCols;
|
||||
struct SqlFunctionCtx **pTagCtxList;
|
||||
} SExtTagsInfo;
|
||||
typedef struct SSubsidiaryResInfo {
|
||||
int16_t bufLen; // keep the tags data for top/bottom query result
|
||||
int16_t numOfCols;
|
||||
struct SqlFunctionCtx **pCtx;
|
||||
} SSubsidiaryResInfo;
|
||||
|
||||
typedef struct SResultDataInfo {
|
||||
int16_t precision;
|
||||
int16_t scale;
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
int32_t intermediateBytes;
|
||||
int32_t interBufSize;
|
||||
} SResultDataInfo;
|
||||
|
||||
#define GET_RES_INFO(ctx) ((ctx)->resultInfo)
|
||||
|
||||
typedef struct SFunctionFpSet {
|
||||
bool (*init)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); // setup the execute environment
|
||||
void (*addInput)(struct SqlFunctionCtx *pCtx);
|
||||
|
||||
// finalizer must be called after all exec has been executed to generated final result.
|
||||
void (*finalize)(struct SqlFunctionCtx *pCtx);
|
||||
void (*combine)(struct SqlFunctionCtx *pCtx);
|
||||
} SFunctionFpSet;
|
||||
|
||||
extern SFunctionFpSet fpSet[1];
|
||||
typedef struct SInputColumnInfoData {
|
||||
int32_t totalRows; // total rows in current columnar data
|
||||
int32_t startRowIndex; // handle started row index
|
||||
int32_t numOfRows; // the number of rows needs to be handled
|
||||
int32_t numOfInputCols; // PTS is not included
|
||||
bool colDataAggIsSet;// if agg is set or not
|
||||
SColumnInfoData *pPTS; // primary timestamp column
|
||||
SColumnInfoData **pData;
|
||||
SColumnDataAgg **pColumnDataAgg;
|
||||
} SInputColumnInfoData;
|
||||
|
||||
// sql function runtime context
|
||||
typedef struct SqlFunctionCtx {
|
||||
int32_t startRow;
|
||||
int32_t size; // number of rows
|
||||
SColumnInfoData* pInput;
|
||||
|
||||
uint32_t order; // asc|desc
|
||||
int16_t inputType;
|
||||
int16_t inputBytes;
|
||||
|
||||
SInputColumnInfoData input;
|
||||
SResultDataInfo resDataInfo;
|
||||
bool hasNull; // null value exist in current block
|
||||
bool requireNull; // require null in some function
|
||||
uint32_t order; // asc|desc
|
||||
////////////////////////////////////////////////////////////////
|
||||
int32_t startRow; // start row index
|
||||
int32_t size; // handled processed row number
|
||||
SColumnInfoData* pInput;
|
||||
SColumnDataAgg agg;
|
||||
int16_t inputType; // TODO remove it
|
||||
int16_t inputBytes; // TODO remove it
|
||||
bool hasNull; // null value exist in current block, TODO remove it
|
||||
bool requireNull; // require null in some function, TODO remove it
|
||||
int32_t columnIndex; // TODO remove it
|
||||
uint8_t currentStage; // record current running step, default: 0
|
||||
bool isAggSet;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
bool stableQuery;
|
||||
int16_t functionId; // function id
|
||||
char * pOutput; // final result output buffer, point to sdata->data
|
||||
uint8_t currentStage; // record current running step, default: 0
|
||||
int64_t startTs; // timestamp range of current query when function is executed on a specific data block
|
||||
int32_t numOfParams;
|
||||
SVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param
|
||||
int64_t *ptsList; // corresponding timestamp array list
|
||||
void *ptsOutputBuf; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/
|
||||
SVariant tag;
|
||||
|
||||
bool isAggSet;
|
||||
SColumnDataAgg agg;
|
||||
struct SResultRowEntryInfo *resultInfo;
|
||||
SExtTagsInfo tagInfo;
|
||||
SSubsidiaryResInfo subsidiaryRes;
|
||||
SPoint1 start;
|
||||
SPoint1 end;
|
||||
|
||||
int32_t columnIndex;
|
||||
SFunctionFpSet* fpSet;
|
||||
SFuncExecFuncs fpSet;
|
||||
} SqlFunctionCtx;
|
||||
|
||||
enum {
|
||||
|
@ -194,9 +216,10 @@ typedef struct tExprNode {
|
|||
struct SVariant *pVal; // value node
|
||||
|
||||
struct {// function node
|
||||
char functionName[FUNCTIONS_NAME_MAX_LENGTH];
|
||||
char functionName[FUNCTIONS_NAME_MAX_LENGTH]; // todo refactor
|
||||
int32_t functionId;
|
||||
int32_t num;
|
||||
|
||||
SFunctionNode *pFunctNode;
|
||||
// Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the
|
||||
// calculation instead.
|
||||
// E.g., Cov(col1, col2), the column information, w.r.t. the col1 and col2, is kept in pChild nodes.
|
||||
|
@ -207,7 +230,6 @@ typedef struct tExprNode {
|
|||
};
|
||||
} tExprNode;
|
||||
|
||||
//TODO create?
|
||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||
|
||||
|
@ -294,7 +316,7 @@ tExprNode* exprdup(tExprNode* pTree);
|
|||
|
||||
void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num);
|
||||
void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell);
|
||||
int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num);
|
||||
int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num, SSDataBlock* pResBlock);
|
||||
bool isRowEntryCompleted(struct SResultRowEntryInfo* pEntry);
|
||||
bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry);
|
||||
|
||||
|
|
|
@ -102,22 +102,6 @@ struct SqlFunctionCtx;
|
|||
struct SResultRowEntryInfo;
|
||||
struct STimeWindow;
|
||||
|
||||
typedef struct SFuncExecEnv {
|
||||
int32_t calcMemSize;
|
||||
} SFuncExecEnv;
|
||||
|
||||
typedef bool (*FExecGetEnv)(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
||||
typedef void (*FExecProcess)(struct SqlFunctionCtx *pCtx);
|
||||
typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx);
|
||||
|
||||
typedef struct SFuncExecFuncs {
|
||||
FExecGetEnv getEnv;
|
||||
FExecInit init;
|
||||
FExecProcess process;
|
||||
FExecFinalize finalize;
|
||||
} SFuncExecFuncs;
|
||||
|
||||
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
typedef struct SScalarFuncExecFuncs {
|
||||
|
@ -127,6 +111,8 @@ typedef struct SScalarFuncExecFuncs {
|
|||
|
||||
int32_t fmFuncMgtInit();
|
||||
|
||||
void fmFuncMgtDestroy();
|
||||
|
||||
int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType);
|
||||
|
||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc);
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* 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_CMD_NODES_H_
|
||||
#define _TD_CMD_NODES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "querynodes.h"
|
||||
|
||||
typedef struct SDatabaseOptions {
|
||||
int32_t numOfBlocks;
|
||||
int32_t cacheBlockSize;
|
||||
int8_t cachelast;
|
||||
int32_t compressionLevel;
|
||||
int32_t daysPerFile;
|
||||
int32_t fsyncPeriod;
|
||||
int32_t maxRowsPerBlock;
|
||||
int32_t minRowsPerBlock;
|
||||
int32_t keep;
|
||||
int32_t precision;
|
||||
int32_t quorum;
|
||||
int32_t replica;
|
||||
int32_t ttl;
|
||||
int32_t walLevel;
|
||||
int32_t numOfVgroups;
|
||||
int8_t singleStable;
|
||||
int8_t streamMode;
|
||||
} SDatabaseOptions;
|
||||
|
||||
typedef struct SCreateDatabaseStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SDatabaseOptions options;
|
||||
} SCreateDatabaseStmt;
|
||||
|
||||
typedef struct SUseDatabaseStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SUseDatabaseStmt;
|
||||
|
||||
typedef struct SDropDatabaseStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropDatabaseStmt;
|
||||
|
||||
typedef struct STableOptions {
|
||||
int32_t keep;
|
||||
int32_t ttl;
|
||||
char comments[TSDB_STB_COMMENT_LEN];
|
||||
SNodeList* pSma;
|
||||
} STableOptions;
|
||||
|
||||
typedef struct SColumnDefNode {
|
||||
ENodeType type;
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
SDataType dataType;
|
||||
char comments[TSDB_STB_COMMENT_LEN];
|
||||
} SColumnDefNode;
|
||||
|
||||
typedef struct SCreateTableStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SNodeList* pCols;
|
||||
SNodeList* pTags;
|
||||
STableOptions options;
|
||||
} SCreateTableStmt;
|
||||
|
||||
typedef struct SCreateSubTableClause {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char useDbName[TSDB_DB_NAME_LEN];
|
||||
char useTableName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SNodeList* pSpecificTags;
|
||||
SNodeList* pValsOfTags;
|
||||
} SCreateSubTableClause;
|
||||
|
||||
typedef struct SCreateMultiTableStmt {
|
||||
ENodeType type;
|
||||
SNodeList* pSubTables;
|
||||
} SCreateMultiTableStmt;
|
||||
|
||||
typedef struct SDropTableClause {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropTableClause;
|
||||
|
||||
typedef struct SDropTableStmt {
|
||||
ENodeType type;
|
||||
SNodeList* pTables;
|
||||
} SDropTableStmt;
|
||||
|
||||
typedef struct SDropSuperTableStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropSuperTableStmt;
|
||||
|
||||
typedef struct SCreateUserStmt {
|
||||
ENodeType type;
|
||||
char useName[TSDB_USER_LEN];
|
||||
char password[TSDB_USET_PASSWORD_LEN];
|
||||
} SCreateUserStmt;
|
||||
|
||||
typedef struct SAlterUserStmt {
|
||||
ENodeType type;
|
||||
char useName[TSDB_USER_LEN];
|
||||
char password[TSDB_USET_PASSWORD_LEN];
|
||||
int8_t alterType;
|
||||
} SAlterUserStmt;
|
||||
|
||||
typedef struct SDropUserStmt {
|
||||
ENodeType type;
|
||||
char useName[TSDB_USER_LEN];
|
||||
} SDropUserStmt;
|
||||
|
||||
typedef struct SCreateDnodeStmt {
|
||||
ENodeType type;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
int32_t port;
|
||||
} SCreateDnodeStmt;
|
||||
|
||||
typedef struct SDropDnodeStmt {
|
||||
ENodeType type;
|
||||
int32_t dnodeId;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
int32_t port;
|
||||
} SDropDnodeStmt;
|
||||
|
||||
typedef struct SShowStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SShowStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_CMD_NODES_H_*/
|
|
@ -65,24 +65,60 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_TARGET,
|
||||
QUERY_NODE_DATABLOCK_DESC,
|
||||
QUERY_NODE_SLOT_DESC,
|
||||
QUERY_NODE_COLUMN_DEF,
|
||||
QUERY_NODE_DOWNSTREAM_SOURCE,
|
||||
|
||||
// Statement nodes are used in parser and planner module.
|
||||
QUERY_NODE_SET_OPERATOR,
|
||||
QUERY_NODE_SELECT_STMT,
|
||||
QUERY_NODE_SHOW_STMT,
|
||||
QUERY_NODE_VNODE_MODIF_STMT,
|
||||
QUERY_NODE_CREATE_DATABASE_STMT,
|
||||
QUERY_NODE_DROP_DATABASE_STMT,
|
||||
QUERY_NODE_SHOW_DATABASES_STMT, // temp
|
||||
QUERY_NODE_CREATE_TABLE_STMT,
|
||||
QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
|
||||
QUERY_NODE_CREATE_MULTI_TABLE_STMT,
|
||||
QUERY_NODE_DROP_TABLE_CLAUSE,
|
||||
QUERY_NODE_DROP_TABLE_STMT,
|
||||
QUERY_NODE_DROP_SUPER_TABLE_STMT,
|
||||
QUERY_NODE_SHOW_TABLES_STMT, // temp
|
||||
QUERY_NODE_SHOW_STABLES_STMT,
|
||||
QUERY_NODE_CREATE_USER_STMT,
|
||||
QUERY_NODE_ALTER_USER_STMT,
|
||||
QUERY_NODE_DROP_USER_STMT,
|
||||
QUERY_NODE_SHOW_USERS_STMT,
|
||||
QUERY_NODE_USE_DATABASE_STMT,
|
||||
QUERY_NODE_CREATE_DNODE_STMT,
|
||||
QUERY_NODE_DROP_DNODE_STMT,
|
||||
QUERY_NODE_SHOW_DNODES_STMT,
|
||||
QUERY_NODE_SHOW_VGROUPS_STMT,
|
||||
QUERY_NODE_SHOW_MNODES_STMT,
|
||||
|
||||
// logic plan node
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN,
|
||||
QUERY_NODE_LOGIC_PLAN_JOIN,
|
||||
QUERY_NODE_LOGIC_PLAN_AGG,
|
||||
QUERY_NODE_LOGIC_PLAN_PROJECT,
|
||||
QUERY_NODE_LOGIC_PLAN_VNODE_MODIF,
|
||||
QUERY_NODE_LOGIC_PLAN_EXCHANGE,
|
||||
QUERY_NODE_LOGIC_SUBPLAN,
|
||||
QUERY_NODE_LOGIC_PLAN,
|
||||
|
||||
// physical plan node
|
||||
QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_PROJECT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_JOIN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_AGG
|
||||
QUERY_NODE_PHYSICAL_PLAN_AGG,
|
||||
QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SORT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
|
||||
QUERY_NODE_PHYSICAL_PLAN_INSERT,
|
||||
QUERY_NODE_PHYSICAL_SUBPLAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN
|
||||
} ENodeType;
|
||||
|
||||
/**
|
||||
|
@ -105,15 +141,20 @@ typedef struct SNodeList {
|
|||
SListCell* pTail;
|
||||
} SNodeList;
|
||||
|
||||
SNode* nodesMakeNode(ENodeType type);
|
||||
void nodesDestroyNode(SNode* pNode);
|
||||
#define SNodeptr void*
|
||||
|
||||
SNodeptr nodesMakeNode(ENodeType type);
|
||||
void nodesDestroyNode(SNodeptr pNode);
|
||||
|
||||
SNodeList* nodesMakeList();
|
||||
int32_t nodesListAppend(SNodeList* pList, SNode* pNode);
|
||||
int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode);
|
||||
int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode);
|
||||
int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc);
|
||||
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
|
||||
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
|
||||
SNodeptr nodesListGetNode(SNodeList* pList, int32_t index);
|
||||
void nodesDestroyList(SNodeList* pList);
|
||||
// Only clear the linked list structure, without releasing the elements inside
|
||||
void nodesClearList(SNodeList* pList);
|
||||
|
||||
typedef enum EDealRes {
|
||||
DEAL_RES_CONTINUE = 1,
|
||||
|
@ -122,9 +163,9 @@ typedef enum EDealRes {
|
|||
} EDealRes;
|
||||
|
||||
typedef EDealRes (*FNodeWalker)(SNode* pNode, void* pContext);
|
||||
void nodesWalkNode(SNode* pNode, FNodeWalker walker, void* pContext);
|
||||
void nodesWalkNode(SNodeptr pNode, FNodeWalker walker, void* pContext);
|
||||
void nodesWalkList(SNodeList* pList, FNodeWalker walker, void* pContext);
|
||||
void nodesWalkNodePostOrder(SNode* pNode, FNodeWalker walker, void* pContext);
|
||||
void nodesWalkNodePostOrder(SNodeptr pNode, FNodeWalker walker, void* pContext);
|
||||
void nodesWalkListPostOrder(SNodeList* pList, FNodeWalker walker, void* pContext);
|
||||
|
||||
typedef EDealRes (*FNodeRewriter)(SNode** pNode, void* pContext);
|
||||
|
@ -133,12 +174,13 @@ void nodesRewriteList(SNodeList* pList, FNodeRewriter rewriter, void* pContext);
|
|||
void nodesRewriteNodePostOrder(SNode** pNode, FNodeRewriter rewriter, void* pContext);
|
||||
void nodesRewriteListPostOrder(SNodeList* pList, FNodeRewriter rewriter, void* pContext);
|
||||
|
||||
bool nodesEqualNode(const SNode* a, const SNode* b);
|
||||
bool nodesEqualNode(const SNodeptr a, const SNodeptr b);
|
||||
|
||||
SNode* nodesCloneNode(const SNode* pNode);
|
||||
SNodeptr nodesCloneNode(const SNodeptr pNode);
|
||||
SNodeList* nodesCloneList(const SNodeList* pList);
|
||||
|
||||
int32_t nodesNodeToString(const SNode* pNode, bool format, char** pStr, int32_t* pLen);
|
||||
const char* nodesNodeName(ENodeType type);
|
||||
int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen);
|
||||
int32_t nodesStringToNode(const char* pStr, SNode** pNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -21,7 +21,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "querynodes.h"
|
||||
#include "tmsg.h"
|
||||
#include "query.h"
|
||||
#include "tname.h"
|
||||
|
||||
typedef struct SLogicNode {
|
||||
ENodeType type;
|
||||
|
@ -43,9 +44,11 @@ typedef struct SScanLogicNode {
|
|||
SLogicNode node;
|
||||
SNodeList* pScanCols;
|
||||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
EScanType scanType;
|
||||
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||
STimeWindow scanRange;
|
||||
SName tableName;
|
||||
} SScanLogicNode;
|
||||
|
||||
typedef struct SJoinLogicNode {
|
||||
|
@ -65,6 +68,49 @@ typedef struct SProjectLogicNode {
|
|||
SNodeList* pProjections;
|
||||
} SProjectLogicNode;
|
||||
|
||||
typedef struct SVnodeModifLogicNode {
|
||||
SLogicNode node;;
|
||||
int32_t msgType;
|
||||
SArray* pDataBlocks;
|
||||
SVgDataBlocks* pVgDataBlocks;
|
||||
} SVnodeModifLogicNode;
|
||||
|
||||
typedef struct SExchangeLogicNode {
|
||||
SLogicNode node;
|
||||
int32_t srcGroupId;
|
||||
} SExchangeLogicNode;
|
||||
|
||||
typedef enum ESubplanType {
|
||||
SUBPLAN_TYPE_MERGE = 1,
|
||||
SUBPLAN_TYPE_PARTIAL,
|
||||
SUBPLAN_TYPE_SCAN,
|
||||
SUBPLAN_TYPE_MODIFY
|
||||
} ESubplanType;
|
||||
|
||||
typedef struct SSubplanId {
|
||||
uint64_t queryId;
|
||||
int32_t groupId;
|
||||
int32_t subplanId;
|
||||
} SSubplanId;
|
||||
|
||||
typedef struct SSubLogicPlan {
|
||||
ENodeType type;
|
||||
SSubplanId id;
|
||||
SNodeList* pChildren;
|
||||
SNodeList* pParents;
|
||||
SLogicNode* pNode;
|
||||
ESubplanType subplanType;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
int32_t level;
|
||||
int32_t splitFlag;
|
||||
} SSubLogicPlan;
|
||||
|
||||
typedef struct SQueryLogicPlan {
|
||||
ENodeType type;;
|
||||
int32_t totalLevel;
|
||||
SNodeList* pTopSubplans;
|
||||
} SQueryLogicPlan;
|
||||
|
||||
typedef struct SSlotDescNode {
|
||||
ENodeType type;
|
||||
int16_t slotId;
|
||||
|
@ -78,11 +124,13 @@ typedef struct SDataBlockDescNode {
|
|||
ENodeType type;
|
||||
int16_t dataBlockId;
|
||||
SNodeList* pSlots;
|
||||
int32_t resultRowSize;
|
||||
int16_t precision;
|
||||
} SDataBlockDescNode;
|
||||
|
||||
typedef struct SPhysiNode {
|
||||
ENodeType type;
|
||||
SDataBlockDescNode outputDataBlockDesc;
|
||||
SDataBlockDescNode* pOutputDataBlockDesc;
|
||||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
struct SPhysiNode* pParent;
|
||||
|
@ -96,6 +144,7 @@ typedef struct SScanPhysiNode {
|
|||
int32_t order; // scan order: TSDB_ORDER_ASC|TSDB_ORDER_DESC
|
||||
int32_t count; // repeat count
|
||||
int32_t reverse; // reverse scan count
|
||||
SName tableName;
|
||||
} SScanPhysiNode;
|
||||
|
||||
typedef SScanPhysiNode SSystemTableScanPhysiNode;
|
||||
|
@ -129,6 +178,56 @@ typedef struct SAggPhysiNode {
|
|||
SNodeList* pAggFuncs;
|
||||
} SAggPhysiNode;
|
||||
|
||||
typedef struct SDownstreamSourceNode {
|
||||
ENodeType type;
|
||||
SQueryNodeAddr addr;
|
||||
uint64_t taskId;
|
||||
uint64_t schedId;
|
||||
} SDownstreamSourceNode;
|
||||
|
||||
typedef struct SExchangePhysiNode {
|
||||
SPhysiNode node;
|
||||
int32_t srcGroupId; // group id of datasource suplans
|
||||
SNodeList* pSrcEndPoints; // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
|
||||
} SExchangePhysiNode;
|
||||
|
||||
typedef struct SDataSinkNode {
|
||||
ENodeType type;
|
||||
SDataBlockDescNode* pInputDataBlockDesc;
|
||||
} SDataSinkNode;
|
||||
|
||||
typedef struct SDataDispatcherNode {
|
||||
SDataSinkNode sink;
|
||||
} SDataDispatcherNode;
|
||||
|
||||
typedef struct SDataInserterNode {
|
||||
SDataSinkNode sink;
|
||||
int32_t numOfTables;
|
||||
uint32_t size;
|
||||
char *pData;
|
||||
} SDataInserterNode;
|
||||
|
||||
typedef struct SSubplan {
|
||||
ENodeType type;
|
||||
SSubplanId id; // unique id of the subplan
|
||||
ESubplanType subplanType;
|
||||
int32_t msgType; // message type for subplan, used to denote the send message type to vnode.
|
||||
int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner.
|
||||
SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node
|
||||
SQueryNodeStat execNodeStat; // only for scan subplan
|
||||
SNodeList* pChildren; // the datasource subplan,from which to fetch the result
|
||||
SNodeList* pParents; // the data destination subplan, get data from current subplan
|
||||
SPhysiNode* pNode; // physical plan of current subplan
|
||||
SDataSinkNode* pDataSink; // data of the subplan flow into the datasink
|
||||
} SSubplan;
|
||||
|
||||
typedef struct SQueryPlan {
|
||||
ENodeType type;;
|
||||
uint64_t queryId;
|
||||
int32_t numOfSubplans;
|
||||
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
||||
} SQueryPlan;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "nodes.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
typedef struct SRawExprNode {
|
||||
ENodeType nodeType;
|
||||
|
@ -73,6 +74,7 @@ typedef struct SValueNode {
|
|||
SExprNode node; // QUERY_NODE_VALUE
|
||||
char* literal;
|
||||
bool isDuration;
|
||||
bool translate;
|
||||
union {
|
||||
bool b;
|
||||
int64_t i;
|
||||
|
@ -122,6 +124,7 @@ struct STableMeta;
|
|||
typedef struct SRealTableNode {
|
||||
STableNode table; // QUERY_NODE_REAL_TABLE
|
||||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
} SRealTableNode;
|
||||
|
||||
typedef struct STempTableNode {
|
||||
|
@ -248,6 +251,29 @@ typedef enum ESqlClause {
|
|||
SQL_CLAUSE_ORDER_BY
|
||||
} ESqlClause;
|
||||
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
PAYLOAD_TYPE_RAW = 1,
|
||||
} EPayloadType;
|
||||
|
||||
typedef struct SVgDataBlocks {
|
||||
SVgroupInfo vg;
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
uint32_t size;
|
||||
char *pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ...
|
||||
} SVgDataBlocks;
|
||||
|
||||
typedef struct SVnodeModifOpStmt {
|
||||
ENodeType nodeType;
|
||||
ENodeType sqlNodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
int8_t schemaAttache; // denote if submit block is built with table schema or not
|
||||
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* sql; // current sql statement position
|
||||
} SVnodeModifOpStmt;
|
||||
|
||||
void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext);
|
||||
void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext);
|
||||
|
||||
|
|
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
* 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_PARSENODES_H_
|
||||
#define _TD_PARSENODES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "catalog.h"
|
||||
#include "tcommon.h"
|
||||
#include "function.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "tname.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
/**
|
||||
* The first field of a node of any type is guaranteed to be the int16_t.
|
||||
* Hence the type of any node can be gotten by casting it to SQueryNode.
|
||||
*/
|
||||
typedef struct SQueryNode {
|
||||
int16_t type;
|
||||
} SQueryNode;
|
||||
|
||||
#define queryNodeType(nodeptr) (((const SQueryNode*)(nodeptr))->type)
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutput; // number of column in result
|
||||
SField *final;
|
||||
SArray *internalField; // SArray<SInternalField>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SCond {
|
||||
uint64_t uid;
|
||||
int32_t len; // length of tag query condition data
|
||||
char * cond;
|
||||
} SCond;
|
||||
|
||||
typedef struct SJoinNode {
|
||||
uint64_t uid;
|
||||
int16_t tagColId;
|
||||
SArray* tsJoin;
|
||||
SArray* tagJoin;
|
||||
} SJoinNode;
|
||||
|
||||
typedef struct SJoinInfo {
|
||||
bool hasJoin;
|
||||
SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM];
|
||||
} SJoinInfo;
|
||||
|
||||
typedef struct STagCond {
|
||||
int16_t relType; // relation between tbname list and query condition, including : TK_AND or TK_OR
|
||||
SCond tbnameCond; // tbname query condition, only support tbname query condition on one table
|
||||
SJoinInfo joinInfo; // join condition, only support two tables join currently
|
||||
SArray *pCond; // for different table, the query condition must be seperated
|
||||
} STagCond;
|
||||
|
||||
typedef struct STableMetaInfo {
|
||||
STableMeta *pTableMeta; // table meta, cached in client side and acquired by name
|
||||
SVgroupsInfo *vgroupList;
|
||||
SName name;
|
||||
char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql
|
||||
SArray *tagColList; // SArray<SColumn*>, involved tag columns
|
||||
} STableMetaInfo;
|
||||
|
||||
typedef struct SColumnIndex {
|
||||
int16_t tableIndex;
|
||||
int16_t columnIndex;
|
||||
int16_t type; // normal column/tag/ user input constant column
|
||||
} SColumnIndex;
|
||||
|
||||
// select statement
|
||||
typedef struct SQueryStmtInfo {
|
||||
int16_t command; // the command may be different for each subclause, so keep it seperately.
|
||||
uint32_t type; // query/insert type
|
||||
STimeWindow window; // the whole query time window
|
||||
SInterval interval; // tumble time window
|
||||
SSessionWindow sessionWindow; // session time window
|
||||
SStateWindow stateWindow; // state window query
|
||||
SGroupbyExpr groupbyExpr; // groupby tags info
|
||||
SArray * colList; // SArray<SColumn*>
|
||||
SFieldInfo fieldsInfo;
|
||||
SArray** exprList; // SArray<SExprInfo*>
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
STagCond tagCond;
|
||||
SArray * colCond;
|
||||
SArray * order;
|
||||
int16_t numOfTables;
|
||||
int16_t curTableIdx;
|
||||
STableMetaInfo **pTableMetaInfo;
|
||||
struct STSBuf *tsBuf;
|
||||
|
||||
int16_t fillType; // final result fill type
|
||||
int64_t * fillVal; // default value for fill
|
||||
int32_t numOfFillVal; // fill value size
|
||||
|
||||
char * msg; // pointer to the pCmd->payload to keep error message temporarily
|
||||
int64_t clauseLimit; // limit for current sub clause
|
||||
|
||||
int64_t prjOffset; // offset value in the original sql expression, only applied at client side
|
||||
int64_t vgroupLimit; // table limit in case of super table projection query + global order + limit
|
||||
|
||||
int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
|
||||
int32_t bufLen;
|
||||
char* buf;
|
||||
SArray *pUdfInfo;
|
||||
|
||||
struct SQueryStmtInfo *sibling; // sibling
|
||||
SMultiFunctionsDesc info;
|
||||
SArray *pDownstream; // SArray<struct SQueryStmtInfo>
|
||||
int32_t havingFieldNum;
|
||||
int32_t exprListLevelIndex;
|
||||
} SQueryStmtInfo;
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
PAYLOAD_TYPE_RAW = 1,
|
||||
} EPayloadType;
|
||||
|
||||
typedef struct SVgDataBlocks {
|
||||
SVgroupInfo vg;
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
uint32_t size;
|
||||
char *pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ...
|
||||
} SVgDataBlocks;
|
||||
|
||||
typedef struct SVnodeModifOpStmtInfo {
|
||||
int16_t nodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
int8_t schemaAttache; // denote if submit block is built with table schema or not
|
||||
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* sql; // current sql statement position
|
||||
} SVnodeModifOpStmtInfo;
|
||||
|
||||
typedef struct SDclStmtInfo {
|
||||
int16_t nodeType;
|
||||
int16_t msgType;
|
||||
SEpSet epSet;
|
||||
char* pMsg;
|
||||
int32_t msgLen;
|
||||
void* pExtension; // todo remove it soon
|
||||
} SDclStmtInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_PARSENODES_H_*/
|
|
@ -20,7 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "parsenodes.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
typedef struct SParseContext {
|
||||
uint64_t requestId;
|
||||
|
@ -32,67 +32,30 @@ typedef struct SParseContext {
|
|||
size_t sqlLen; // length of the sql string
|
||||
char *pMsg; // extended error message if exists to help identifying the problem in sql statement.
|
||||
int32_t msgLen; // max length of the msg
|
||||
|
||||
struct SCatalog *pCatalog;
|
||||
} SParseContext;
|
||||
|
||||
/**
|
||||
* Parse the sql statement and then return the SQueryStmtInfo as the result of bounded AST.
|
||||
* @param pSql sql string
|
||||
* @param length length of the sql string
|
||||
* @param id operator id, generated by uuid generator
|
||||
* @param msg extended error message if exists.
|
||||
* @return error code
|
||||
*/
|
||||
int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQueryNode);
|
||||
typedef struct SCmdMsgInfo {
|
||||
int16_t msgType;
|
||||
SEpSet epSet;
|
||||
void* pMsg;
|
||||
int32_t msgLen;
|
||||
void* pExtension; // todo remove it soon
|
||||
} SCmdMsgInfo;
|
||||
|
||||
/**
|
||||
* Return true if it is a ddl/dcl sql statement
|
||||
* @param pQuery
|
||||
* @return
|
||||
*/
|
||||
bool qIsDdlQuery(const SQueryNode* pQueryNode);
|
||||
typedef struct SQuery {
|
||||
bool directRpc;
|
||||
bool haveResultSet;
|
||||
SNode* pRoot;
|
||||
int32_t numOfResCols;
|
||||
SSchema* pResSchema;
|
||||
SCmdMsgInfo* pCmdMsg;
|
||||
int32_t msgType;
|
||||
} SQuery;
|
||||
|
||||
/**
|
||||
* Destroy logic query plan
|
||||
* @param pQueryNode
|
||||
*/
|
||||
void qDestroyQuery(SQueryNode* pQueryNode);
|
||||
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
||||
|
||||
/**
|
||||
* Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
|
||||
* involved in the subscribe procedure.
|
||||
* @param pSql
|
||||
* @param length
|
||||
* @param pConvertSql
|
||||
* @return
|
||||
*/
|
||||
int32_t qParserConvertSql(const char* pStr, size_t length, char** pConvertSql);
|
||||
|
||||
void assignExprInfo(SExprInfo* dst, const SExprInfo* src);
|
||||
void columnListCopy(SArray* dst, const SArray* src, uint64_t uid);
|
||||
void columnListDestroy(SArray* pColumnList);
|
||||
|
||||
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
|
||||
void dropOneLevelExprInfo(SArray* pExprInfo);
|
||||
|
||||
typedef struct SSourceParam {
|
||||
SArray *pExprNodeList; //Array<struct tExprNode*>
|
||||
SArray *pColumnList; //Array<struct SColumn>
|
||||
int32_t num;
|
||||
} SSourceParam;
|
||||
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
|
||||
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
|
||||
int32_t copyAllExprInfo(SArray* dst, const SArray* src, bool deepcopy);
|
||||
int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo);
|
||||
|
||||
STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
|
||||
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
|
||||
|
||||
int32_t getNewResColId();
|
||||
void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn);
|
||||
SExprInfo* createBinaryExprInfo(struct tExprNode* pNode, SSchema* pResSchema);
|
||||
void qDestroyQuery(SQuery* pQueryNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,192 +20,31 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "query.h"
|
||||
#include "tmsg.h"
|
||||
#include "tarray.h"
|
||||
#include "trpc.h"
|
||||
#include "plannodes.h"
|
||||
|
||||
#define QUERY_TYPE_MERGE 1
|
||||
#define QUERY_TYPE_PARTIAL 2
|
||||
#define QUERY_TYPE_SCAN 3
|
||||
#define QUERY_TYPE_MODIFY 4
|
||||
|
||||
enum OPERATOR_TYPE_E {
|
||||
OP_Unknown,
|
||||
#define INCLUDE_AS_ENUM
|
||||
#include "plannerOp.h"
|
||||
#undef INCLUDE_AS_ENUM
|
||||
OP_TotalNum
|
||||
};
|
||||
|
||||
enum DATASINK_TYPE_E {
|
||||
DSINK_Unknown,
|
||||
DSINK_Dispatch,
|
||||
DSINK_Insert,
|
||||
DSINK_TotalNum
|
||||
};
|
||||
|
||||
struct SEpSet;
|
||||
struct SQueryStmtInfo;
|
||||
|
||||
typedef SSchema SSlotSchema;
|
||||
|
||||
typedef struct SDataBlockSchema {
|
||||
SSlotSchema *pSchema;
|
||||
int32_t numOfCols; // number of columns
|
||||
int32_t resultRowSize;
|
||||
int16_t precision;
|
||||
} SDataBlockSchema;
|
||||
|
||||
typedef struct SQueryNodeBasicInfo {
|
||||
int32_t type; // operator type
|
||||
const char *name; // operator name
|
||||
} SQueryNodeBasicInfo;
|
||||
|
||||
typedef struct SDataSink {
|
||||
SQueryNodeBasicInfo info;
|
||||
SDataBlockSchema schema;
|
||||
} SDataSink;
|
||||
|
||||
typedef struct SDataDispatcher {
|
||||
SDataSink sink;
|
||||
} SDataDispatcher;
|
||||
|
||||
typedef struct SDataInserter {
|
||||
SDataSink sink;
|
||||
int32_t numOfTables;
|
||||
uint32_t size;
|
||||
char *pData;
|
||||
} SDataInserter;
|
||||
|
||||
typedef struct SPhyNode {
|
||||
SQueryNodeBasicInfo info;
|
||||
SArray *pTargets; // target list to be computed or scanned at this node
|
||||
SArray *pConditions; // implicitly-ANDed qual conditions
|
||||
SDataBlockSchema targetSchema;
|
||||
// children plan to generated result for current node to process
|
||||
// in case of join, multiple plan nodes exist.
|
||||
SArray *pChildren;
|
||||
struct SPhyNode *pParent;
|
||||
} SPhyNode;
|
||||
|
||||
typedef struct SScanPhyNode {
|
||||
SPhyNode node;
|
||||
uint64_t uid; // unique id of the table
|
||||
int8_t tableType;
|
||||
int32_t order; // scan order: TSDB_ORDER_ASC|TSDB_ORDER_DESC
|
||||
int32_t count; // repeat count
|
||||
int32_t reverse; // reverse scan count
|
||||
} SScanPhyNode;
|
||||
|
||||
typedef SScanPhyNode SSystemTableScanPhyNode;
|
||||
typedef SScanPhyNode STagScanPhyNode;
|
||||
|
||||
typedef struct STableScanPhyNode {
|
||||
SScanPhyNode scan;
|
||||
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||
STimeWindow window;
|
||||
SArray *pTagsConditions; // implicitly-ANDed tag qual conditions
|
||||
} STableScanPhyNode;
|
||||
|
||||
typedef STableScanPhyNode STableSeqScanPhyNode;
|
||||
|
||||
typedef struct SProjectPhyNode {
|
||||
SPhyNode node;
|
||||
} SProjectPhyNode;
|
||||
|
||||
typedef struct SDownstreamSource {
|
||||
SQueryNodeAddr addr;
|
||||
uint64_t taskId;
|
||||
uint64_t schedId;
|
||||
} SDownstreamSource;
|
||||
|
||||
typedef struct SExchangePhyNode {
|
||||
SPhyNode node;
|
||||
uint64_t srcTemplateId; // template id of datasource suplans
|
||||
SArray *pSrcEndPoints; // SArray<SDownstreamSource>, scheduler fill by calling qSetSuplanExecutionNode
|
||||
} SExchangePhyNode;
|
||||
|
||||
typedef enum EAggAlgo {
|
||||
AGG_ALGO_PLAIN = 1, // simple agg across all input rows
|
||||
AGG_ALGO_SORTED, // grouped agg, input must be sorted
|
||||
AGG_ALGO_HASHED // grouped agg, use internal hashtable
|
||||
} EAggAlgo;
|
||||
|
||||
typedef enum EAggSplit {
|
||||
AGG_SPLIT_PRE = 1, // first level agg, maybe don't need calculate the final result
|
||||
AGG_SPLIT_FINAL // second level agg, must calculate the final result
|
||||
} EAggSplit;
|
||||
|
||||
typedef struct SAggPhyNode {
|
||||
SPhyNode node;
|
||||
EAggAlgo aggAlgo; // algorithm used by agg operator
|
||||
EAggSplit aggSplit; // distributed splitting mode
|
||||
SArray *pExprs; // SExprInfo list, these are expression list of group_by_clause and parameter expression of aggregate function
|
||||
SArray *pGroupByList; // SColIndex list, but these must be column node
|
||||
} SAggPhyNode;
|
||||
|
||||
typedef struct SSubplanId {
|
||||
typedef struct SPlanContext {
|
||||
uint64_t queryId;
|
||||
uint64_t templateId;
|
||||
uint64_t subplanId;
|
||||
} SSubplanId;
|
||||
int32_t acctId;
|
||||
SNode* pAstRoot;
|
||||
} SPlanContext;
|
||||
|
||||
typedef struct SSubplan {
|
||||
SSubplanId id; // unique id of the subplan
|
||||
int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN|QUERY_TYPE_MODIFY
|
||||
int32_t msgType; // message type for subplan, used to denote the send message type to vnode.
|
||||
int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner.
|
||||
SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node
|
||||
SArray *pChildren; // the datasource subplan,from which to fetch the result
|
||||
SArray *pParents; // the data destination subplan, get data from current subplan
|
||||
SPhyNode *pNode; // physical plan of current subplan
|
||||
SDataSink *pDataSink; // data of the subplan flow into the datasink
|
||||
} SSubplan;
|
||||
|
||||
typedef struct SQueryDag {
|
||||
uint64_t queryId;
|
||||
int32_t numOfSubplans;
|
||||
SArray *pSubplans; // SArray*<SArray*<SSubplan*>>. The execution level of subplan, starting from 0.
|
||||
} SQueryDag;
|
||||
|
||||
struct SQueryNode;
|
||||
|
||||
/**
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
* @param pQueryInfo
|
||||
* @param pDag
|
||||
* @param requestId
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag, SSchema** pResSchema, int32_t* numOfCols, SArray* pNodeList, uint64_t requestId);
|
||||
// Create the physical plan for the query, according to the AST.
|
||||
int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNodeList);
|
||||
|
||||
// Set datasource of this subplan, multiple calls may be made to a subplan.
|
||||
// @subplan subplan to be schedule
|
||||
// @templateId templateId of a group of datasource subplans of this @subplan
|
||||
// @ep one execution location of this group of datasource subplans
|
||||
void qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SDownstreamSource* pSource);
|
||||
// @pSubplan subplan to be schedule
|
||||
// @groupId id of a group of datasource subplans of this @pSubplan
|
||||
// @pSource one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
// Convert to subplan to string for the scheduler to send to the executor
|
||||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen);
|
||||
int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan);
|
||||
|
||||
/**
|
||||
* Convert to subplan to string for the scheduler to send to the executor
|
||||
*/
|
||||
int32_t qSubPlanToString(const SSubplan* subplan, char** str, int32_t* len);
|
||||
char* qQueryPlanToString(const SQueryPlan* pPlan);
|
||||
SQueryPlan* qStringToQueryPlan(const char* pStr);
|
||||
|
||||
int32_t qStringToSubplan(const char* str, SSubplan** subplan);
|
||||
|
||||
void qDestroySubplan(SSubplan* pSubplan);
|
||||
|
||||
/**
|
||||
* Destroy the physical plan.
|
||||
* @param pQueryPhyNode
|
||||
* @return
|
||||
*/
|
||||
void qDestroyQueryDag(SQueryDag* pDag);
|
||||
|
||||
char* qDagToString(const SQueryDag* pDag);
|
||||
SQueryDag* qStringToDag(const char* pStr);
|
||||
void qDestroyQueryPlan(SQueryPlan* pPlan);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#if defined(INCLUDE_AS_ENUM) // enum define mode
|
||||
#undef OP_ENUM_MACRO
|
||||
#define OP_ENUM_MACRO(op) OP_##op,
|
||||
#elif defined(INCLUDE_AS_NAME) // comment define mode
|
||||
#undef OP_ENUM_MACRO
|
||||
#define OP_ENUM_MACRO(op) #op,
|
||||
#else
|
||||
#error To use this include file, first define either INCLUDE_AS_ENUM or INCLUDE_AS_NAME
|
||||
#endif
|
||||
|
||||
OP_ENUM_MACRO(StreamScan)
|
||||
OP_ENUM_MACRO(TableScan)
|
||||
OP_ENUM_MACRO(TableSeqScan)
|
||||
OP_ENUM_MACRO(TagScan)
|
||||
OP_ENUM_MACRO(SystemTableScan)
|
||||
OP_ENUM_MACRO(StreamBlockScan)
|
||||
OP_ENUM_MACRO(Aggregate)
|
||||
OP_ENUM_MACRO(Project)
|
||||
// OP_ENUM_MACRO(Groupby)
|
||||
OP_ENUM_MACRO(Limit)
|
||||
OP_ENUM_MACRO(SLimit)
|
||||
OP_ENUM_MACRO(TimeWindow)
|
||||
OP_ENUM_MACRO(SessionWindow)
|
||||
OP_ENUM_MACRO(StateWindow)
|
||||
OP_ENUM_MACRO(Fill)
|
||||
OP_ENUM_MACRO(MultiTableAggregate)
|
||||
OP_ENUM_MACRO(MultiTableTimeInterval)
|
||||
OP_ENUM_MACRO(Filter)
|
||||
OP_ENUM_MACRO(Distinct)
|
||||
OP_ENUM_MACRO(Join)
|
||||
OP_ENUM_MACRO(AllTimeWindow)
|
||||
OP_ENUM_MACRO(AllMultiTableTimeInterval)
|
||||
OP_ENUM_MACRO(Order)
|
||||
OP_ENUM_MACRO(Exchange)
|
||||
OP_ENUM_MACRO(SortedMerge)
|
||||
|
||||
//OP_ENUM_MACRO(TableScan)
|
|
@ -35,7 +35,6 @@ enum {
|
|||
JOB_TASK_STATUS_CANCELLING,
|
||||
JOB_TASK_STATUS_CANCELLED,
|
||||
JOB_TASK_STATUS_DROPPING,
|
||||
JOB_TASK_STATUS_FREEING,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -85,6 +84,7 @@ typedef struct STableMeta {
|
|||
typedef struct SDBVgInfo {
|
||||
int32_t vgVersion;
|
||||
int8_t hashMethod;
|
||||
int32_t numOfTable; // DB's table num, unit is TSDB_TABLE_NUM_UNIT
|
||||
SHashObj *vgHash; //key:vgId, value:SVgroupInfo
|
||||
} SDBVgInfo;
|
||||
|
||||
|
@ -129,6 +129,11 @@ typedef struct SQueryNodeAddr {
|
|||
SEpSet epSet;
|
||||
} SQueryNodeAddr;
|
||||
|
||||
|
||||
typedef struct SQueryNodeStat {
|
||||
int32_t tableNum; // vg table number, unit is TSDB_TABLE_NUM_UNIT
|
||||
} SQueryNodeStat;
|
||||
|
||||
int32_t initTaskQueue();
|
||||
int32_t cleanupTaskQueue();
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
|||
|
||||
int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||
|
||||
int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||
|
||||
int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||
|
||||
int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
|||
|
||||
typedef struct SSchedulerCfg {
|
||||
uint32_t maxJobNum;
|
||||
int32_t maxNodeTableNum;
|
||||
} SSchedulerCfg;
|
||||
|
||||
typedef struct SQueryProfileSummary {
|
||||
|
@ -70,7 +71,7 @@ int32_t schedulerInit(SSchedulerCfg *cfg);
|
|||
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||
* @return
|
||||
*/
|
||||
int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, int64_t *pJob, const char* sql, SQueryResult *pRes);
|
||||
int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryPlan* pDag, int64_t* pJob, const char* sql, SQueryResult *pRes);
|
||||
|
||||
/**
|
||||
* Process the query job, generated according to the query physical plan.
|
||||
|
@ -78,7 +79,7 @@ int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, int
|
|||
* @param pNodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||
* @return
|
||||
*/
|
||||
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryDag* pDag, const char* sql, int64_t *pJob);
|
||||
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryPlan* pDag, const char* sql, int64_t *pJob);
|
||||
|
||||
/**
|
||||
* Fetch query result from the remote query executor
|
||||
|
@ -110,7 +111,7 @@ void schedulerDestroy(void);
|
|||
* @param pTasks SArray**<STaskInfo>
|
||||
* @return
|
||||
*/
|
||||
int32_t schedulerConvertDagToTaskList(SQueryDag* pDag, SArray **pTasks);
|
||||
int32_t schedulerConvertDagToTaskList(SQueryPlan* pDag, SArray **pTasks);
|
||||
|
||||
/**
|
||||
* make one task info's multiple copies
|
||||
|
|
|
@ -64,7 +64,6 @@ typedef struct SRpcInit {
|
|||
int8_t connType; // TAOS_CONN_UDP, TAOS_CONN_TCPC, TAOS_CONN_TCPS
|
||||
int idleTime; // milliseconds, 0 means idle timer is disabled
|
||||
|
||||
bool noPool; // create conn pool or not
|
||||
// the following is for client app ecurity only
|
||||
char *user; // user name
|
||||
char spi; // security parameter index
|
||||
|
@ -99,6 +98,9 @@ void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp)
|
|||
int rpcReportProgress(void *pConn, char *pCont, int contLen);
|
||||
void rpcCancelRequest(int64_t rid);
|
||||
|
||||
void rpcRefHandle(void *handle, int8_t type);
|
||||
void rpcUnrefHandle(void *handle, int8_t type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -460,6 +460,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_SCH_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2502)
|
||||
|
||||
//parser
|
||||
#define TSDB_CODE_PAR_SYNTAX_ERROR TAOS_DEF_ERROR_CODE(0, 0x2600)
|
||||
#define TSDB_CODE_PAR_INVALID_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2601)
|
||||
#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)
|
||||
|
@ -472,6 +473,13 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
|
||||
#define TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260B)
|
||||
#define TSDB_CODE_PAR_NOT_SINGLE_GROUP TAOS_DEF_ERROR_CODE(0, 0x260C)
|
||||
#define TSDB_CODE_PAR_TAGS_NOT_MATCHED TAOS_DEF_ERROR_CODE(0, 0x260D)
|
||||
#define TSDB_CODE_PAR_INVALID_TAG_NAME TAOS_DEF_ERROR_CODE(0, 0x260E)
|
||||
#define TSDB_CODE_PAR_INCOMPLETE_SQL TAOS_DEF_ERROR_CODE(0, 0x260F)
|
||||
#define TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x2610)
|
||||
#define TSDB_CODE_PAR_PASSWD_EMPTY TAOS_DEF_ERROR_CODE(0, 0x2611)
|
||||
#define TSDB_CODE_PAR_INVALID_PORT TAOS_DEF_ERROR_CODE(0, 0x2612)
|
||||
#define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -345,6 +345,20 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
||||
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
||||
|
||||
#define TSDB_MIN_DB_TTL_OPTION 1
|
||||
#define TSDB_DEFAULT_DB_TTL_OPTION 0
|
||||
|
||||
#define TSDB_MIN_DB_SINGLE_STABLE_OPTION 0
|
||||
#define TSDB_MAX_DB_SINGLE_STABLE_OPTION 1
|
||||
#define TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION 0
|
||||
|
||||
#define TSDB_MIN_DB_STREAM_MODE_OPTION 0
|
||||
#define TSDB_MAX_DB_STREAM_MODE_OPTION 1
|
||||
#define TSDB_DEFAULT_DB_STREAM_MODE_OPTION 0
|
||||
|
||||
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
||||
#define TSDB_MAX_UNION_CLAUSE 5
|
||||
|
||||
#define TSDB_MIN_DB_UPDATE 0
|
||||
#define TSDB_MAX_DB_UPDATE 2
|
||||
#define TSDB_DEFAULT_DB_UPDATE_OPTION 0
|
||||
|
|
|
@ -54,10 +54,12 @@ typedef int32_t (*FToJson)(const void* pObj, SJson* pJson);
|
|||
|
||||
int32_t tjsonAddObject(SJson* pJson, const char* pName, FToJson func, const void* pObj);
|
||||
int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj);
|
||||
int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void* pArray, int32_t itemSize, int32_t num);
|
||||
|
||||
typedef int32_t (*FToObject)(const SJson* pJson, void* pObj);
|
||||
|
||||
int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, void* pObj);
|
||||
int32_t tjsonToArray(const SJson* pJson, const char* pName, FToObject func, void* pArray, int32_t itemSize);
|
||||
|
||||
char* tjsonToString(const SJson* pJson);
|
||||
char* tjsonToUnformattedString(const SJson* pJson);
|
||||
|
|
|
@ -8,7 +8,7 @@ target_include_directories(
|
|||
target_link_libraries(
|
||||
taos
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport parser planner catalog scheduler function qcom
|
||||
PRIVATE os util common transport nodes parser planner catalog scheduler function qcom
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
|
|
|
@ -168,7 +168,7 @@ typedef struct SRequestSendRecvBody {
|
|||
SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed.
|
||||
SDataBuf requestMsg;
|
||||
int64_t queryJob; // query job, created according to sql query DAG.
|
||||
struct SQueryDag* pDag; // the query dag, generated according to the sql statement.
|
||||
struct SQueryPlan* pDag; // the query dag, generated according to the sql statement.
|
||||
SReqResultInfo resInfo;
|
||||
} SRequestSendRecvBody;
|
||||
|
||||
|
@ -228,7 +228,7 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
|
|||
|
||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery);
|
||||
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery);
|
||||
|
||||
// --- heartbeat
|
||||
// global, called by mgmt
|
||||
|
|
|
@ -72,8 +72,6 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
taosReleaseRef(clientConnRefPool, pTscObj->id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// todo close the transporter properly
|
||||
void closeTransporter(STscObj *pTscObj) {
|
||||
if (pTscObj == NULL || pTscObj->pAppInfo->pTransporter == NULL) {
|
||||
|
@ -184,7 +182,7 @@ static void doDestroyRequest(void *p) {
|
|||
tfree(pRequest->pInfo);
|
||||
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
qDestroyQueryDag(pRequest->body.pDag);
|
||||
qDestroyQueryPlan(pRequest->body.pDag);
|
||||
|
||||
if (pRequest->body.showInfo.pArray != NULL) {
|
||||
taosArrayDestroy(pRequest->body.showInfo.pArray);
|
||||
|
@ -241,6 +239,7 @@ void taos_init_imp(void) {
|
|||
clientConnRefPool = taosOpenRef(200, destroyTscObj);
|
||||
clientReqRefPool = taosOpenRef(40960, doDestroyRequest);
|
||||
|
||||
// transDestroyBuffer(&conn->readBuf);
|
||||
taosGetAppName(appInfo.appName, NULL);
|
||||
pthread_mutex_init(&appInfo.mutex, NULL);
|
||||
|
||||
|
|
|
@ -224,6 +224,7 @@ int32_t hbGetExpiredDBInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SCl
|
|||
SDbVgVersion *db = &dbs[i];
|
||||
db->dbId = htobe64(db->dbId);
|
||||
db->vgVersion = htonl(db->vgVersion);
|
||||
db->numOfTable = htonl(db->numOfTable);
|
||||
}
|
||||
|
||||
SKv kv = {
|
||||
|
@ -434,11 +435,11 @@ static int32_t hbCreateThread() {
|
|||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
pthread_attr_destroy(&thAttr);
|
||||
// if (pthread_create(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
// return -1;
|
||||
// }
|
||||
// pthread_attr_destroy(&thAttr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) {
|
||||
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
|
||||
SParseContext cxt = {
|
||||
|
@ -161,53 +161,44 @@ int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) {
|
|||
}
|
||||
|
||||
code = qParseQuerySql(&cxt, pQuery);
|
||||
if (TSDB_CODE_SUCCESS == code && ((*pQuery)->haveResultSet)) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, (*pQuery)->pResSchema, (*pQuery)->numOfResCols);
|
||||
}
|
||||
|
||||
tfree(cxt.db);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
||||
SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery;
|
||||
pRequest->type = pDcl->msgType;
|
||||
pRequest->body.requestMsg = (SDataBuf){.pData = pDcl->pMsg, .len = pDcl->msgLen, .handle = NULL};
|
||||
int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg;
|
||||
pRequest->type = pMsgInfo->msgType;
|
||||
pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL};
|
||||
pMsgInfo->pMsg = NULL; // pMsg transferred to SMsgSendInfo management
|
||||
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
if (pDcl->msgType == TDMT_VND_CREATE_TABLE || pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
if (pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
if (pMsgInfo->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||
if (pShowReqInfo->pArray == NULL) {
|
||||
pShowReqInfo->currentIndex = 0; // set the first vnode/ then iterate the next vnode
|
||||
pShowReqInfo->pArray = pDcl->pExtension;
|
||||
pShowReqInfo->pArray = pMsgInfo->pExtension;
|
||||
}
|
||||
}
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pDcl->epSet, &transporterId, pSendMsg);
|
||||
} else {
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pDcl->epSet, &transporterId, pSendMsg);
|
||||
}
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag, SArray* pNodeList) {
|
||||
pRequest->type = pQueryNode->type;
|
||||
|
||||
SSchema* pSchema = NULL;
|
||||
int32_t numOfCols = 0;
|
||||
int32_t code = qCreateQueryDag(pQueryNode, pDag, &pSchema, &numOfCols, pNodeList, pRequest->requestId);
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
|
||||
pRequest->type = pQuery->msgType;
|
||||
SPlanContext cxt = { .queryId = pRequest->requestId, .pAstRoot = pQuery->pRoot, .acctId = pRequest->pTscObj->acctId };
|
||||
int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pQueryNode->type == TSDB_SQL_SELECT) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, pSchema, numOfCols);
|
||||
pRequest->type = TDMT_VND_QUERY;
|
||||
}
|
||||
|
||||
tfree(pSchema);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -224,8 +215,10 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
|||
}
|
||||
}
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList) {
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -237,7 +230,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList)
|
|||
return pRequest->code;
|
||||
}
|
||||
|
||||
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) {
|
||||
if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) {
|
||||
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
||||
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
|
@ -258,24 +251,24 @@ TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) {
|
|||
}
|
||||
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQueryNode* pQueryNode = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr));
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return);
|
||||
|
||||
if (qIsDdlQuery(pQueryNode)) {
|
||||
CHECK_CODE_GOTO(execDdlQuery(pRequest, pQueryNode), _return);
|
||||
if (pQuery->directRpc) {
|
||||
CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return);
|
||||
} else {
|
||||
CHECK_CODE_GOTO(getPlan(pRequest, pQueryNode, &pRequest->body.pDag, pNodeList), _return);
|
||||
CHECK_CODE_GOTO(getPlan(pRequest, pQuery, &pRequest->body.pDag, pNodeList), _return);
|
||||
CHECK_CODE_GOTO(scheduleQuery(pRequest, pRequest->body.pDag, pNodeList), _return);
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
||||
_return:
|
||||
taosArrayDestroy(pNodeList);
|
||||
qDestroyQuery(pQueryNode);
|
||||
qDestroyQuery(pQuery);
|
||||
if (NULL != pRequest && TSDB_CODE_SUCCESS != terrno) {
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
|
|
@ -459,7 +459,7 @@ void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) { conf->
|
|||
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
||||
STscObj* pTscObj = (STscObj*)taos;
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQueryNode* pQueryNode = NULL;
|
||||
SQuery* pQueryNode = NULL;
|
||||
char* pStr = NULL;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
@ -482,7 +482,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
|||
}
|
||||
|
||||
tscDebug("start to create topic, %s", topicName);
|
||||
|
||||
#if 0
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
|
||||
|
||||
|
@ -538,7 +538,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
|||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
|
||||
#endif
|
||||
_return:
|
||||
qDestroyQuery(pQueryNode);
|
||||
/*if (sendInfo != NULL) {*/
|
||||
|
|
|
@ -53,7 +53,6 @@ TEST(testCase, driverInit_Test) {
|
|||
// taos_init();
|
||||
}
|
||||
|
||||
#if 1
|
||||
TEST(testCase, connect_Test) {
|
||||
// taos_options(TSDB_OPTION_CONFIGDIR, "/home/ubuntu/first/cfg");
|
||||
|
||||
|
@ -564,20 +563,18 @@ TEST(testCase, insert_test) {
|
|||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
TEST(testCase, projection_query_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
// TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "use abc1");
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create stable st1 (ts timestamp, k int) tags(a int)");
|
||||
|
@ -592,7 +589,7 @@ TEST(testCase, projection_query_tables) {
|
|||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
for(int32_t i = 0; i < 10000000; ++i) {
|
||||
for(int32_t i = 0; i < 10000; ++i) {
|
||||
char sql[512] = {0};
|
||||
sprintf(sql, "insert into tu values(now+%da, %d)", i, i);
|
||||
TAOS_RES* p = taos_query(pConn, sql);
|
||||
|
@ -623,7 +620,6 @@ TEST(testCase, projection_query_tables) {
|
|||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
#if 0
|
||||
|
||||
TEST(testCase, projection_query_stables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
|
@ -686,6 +682,5 @@ TEST(testCase, agg_query_tables) {
|
|||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
|
@ -239,7 +239,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co
|
|||
return numOfRow1 + numOfRow2;
|
||||
}
|
||||
|
||||
size_t colDataGetNumOfCols(const SSDataBlock* pBlock) {
|
||||
size_t blockDataGetNumOfCols(const SSDataBlock* pBlock) {
|
||||
ASSERT(pBlock);
|
||||
|
||||
size_t constantCols = (pBlock->pConstantList != NULL)? taosArrayGetSize(pBlock->pConstantList):0;
|
||||
|
@ -247,7 +247,7 @@ size_t colDataGetNumOfCols(const SSDataBlock* pBlock) {
|
|||
return pBlock->info.numOfCols;
|
||||
}
|
||||
|
||||
size_t colDataGetNumOfRows(const SSDataBlock* pBlock) {
|
||||
size_t blockDataGetNumOfRows(const SSDataBlock* pBlock) {
|
||||
return pBlock->info.rows;
|
||||
}
|
||||
|
||||
|
|
|
@ -1007,11 +1007,32 @@ int32_t tDeserializeSMCreateDropQSBNodeReq(void *buf, int32_t bufLen, SMCreateQn
|
|||
}
|
||||
|
||||
int32_t tSerializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq) {
|
||||
return tSerializeSMCreateDropQSBNodeReq(buf, bufLen, (SMCreateQnodeReq *)pReq);
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->fqdn) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->port) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tCoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq) {
|
||||
return tDeserializeSMCreateDropQSBNodeReq(buf, bufLen, (SMCreateQnodeReq *)pReq);
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->fqdn) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->port) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tCoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSMCreateDropMnodeReq(void *buf, int32_t bufLen, SMCreateMnodeReq *pReq) {
|
||||
|
@ -1423,6 +1444,7 @@ int32_t tSerializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
|
|||
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->dbId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfTable) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -1438,12 +1460,77 @@ int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
|
|||
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->dbId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfTable) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tCoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->rowNum) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tCoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSQnodeListReq(void *buf, int32_t bufLen, SQnodeListReq *pReq) {
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->rowNum) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tCoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
int32_t num = taosArrayGetSize(pRsp->epSetList);
|
||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SEpSet *epSet = taosArrayGet(pRsp->epSetList, i);
|
||||
if (tEncodeSEpSet(&encoder, epSet) < 0) return -1;
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tCoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp) {
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
int32_t num = 0;
|
||||
if (tDecodeI32(&decoder, &num) < 0) return -1;
|
||||
pRsp->epSetList = taosArrayInit(num, sizeof(SEpSet));
|
||||
if (NULL == pRsp->epSetList) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
if (tDecodeSEpSet(&decoder, TARRAY_GET_ELEM(pRsp->epSetList, i)) < 0) return -1;
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tCoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSQnodeListRsp(SQnodeListRsp *pRsp) { taosArrayDestroy(pRsp->epSetList); }
|
||||
|
||||
int32_t tSerializeSSyncDbReq(void *buf, int32_t bufLen, SSyncDbReq *pReq) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
@ -1482,6 +1569,7 @@ static int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, SUseDbRsp *pRsp) {
|
|||
if (tEncodeU32(pEncoder, pVgInfo->hashBegin) < 0) return -1;
|
||||
if (tEncodeU32(pEncoder, pVgInfo->hashEnd) < 0) return -1;
|
||||
if (tEncodeSEpSet(pEncoder, &pVgInfo->epSet) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pVgInfo->numOfTable) < 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1542,6 +1630,7 @@ int32_t tDeserializeSUseDbRspImp(SCoder *pDecoder, SUseDbRsp *pRsp) {
|
|||
if (tDecodeU32(pDecoder, &vgInfo.hashBegin) < 0) return -1;
|
||||
if (tDecodeU32(pDecoder, &vgInfo.hashEnd) < 0) return -1;
|
||||
if (tDecodeSEpSet(pDecoder, &vgInfo.epSet) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &vgInfo.numOfTable) < 0) return -1;
|
||||
taosArrayPush(pRsp->pVgroupInfos, &vgInfo);
|
||||
}
|
||||
|
||||
|
@ -2391,6 +2480,149 @@ int32_t tDecodeSMqCMCommitOffsetReq(SCoder *decoder, SMqCMCommitOffsetReq *pReq)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq) {
|
||||
int32_t headLen = sizeof(SMsgHead);
|
||||
if (buf != NULL) {
|
||||
buf = (char *)buf + headLen;
|
||||
bufLen -= headLen;
|
||||
}
|
||||
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, pReq->sId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->epId.nodeId) < 0) return -1;
|
||||
if (tEncodeU16(&encoder, pReq->epId.ep.port) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->epId.ep.fqdn) < 0) return -1;
|
||||
if (pReq->taskAction) {
|
||||
int32_t num = taosArrayGetSize(pReq->taskAction);
|
||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STaskAction *action = taosArrayGet(pReq->taskAction, i);
|
||||
if (tEncodeU64(&encoder, action->queryId) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, action->taskId) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, action->action) < 0) return -1;
|
||||
}
|
||||
} else {
|
||||
if (tEncodeI32(&encoder, 0) < 0) return -1;
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tCoderClear(&encoder);
|
||||
|
||||
if (buf != NULL) {
|
||||
SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
|
||||
pHead->vgId = htonl(pReq->header.vgId);
|
||||
pHead->contLen = htonl(tlen + headLen);
|
||||
}
|
||||
|
||||
return tlen + headLen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq) {
|
||||
int32_t headLen = sizeof(SMsgHead);
|
||||
|
||||
SMsgHead *pHead = buf;
|
||||
pHead->vgId = pReq->header.vgId;
|
||||
pHead->contLen = pReq->header.contLen;
|
||||
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, (char *)buf + headLen, bufLen - headLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pReq->sId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->epId.nodeId) < 0) return -1;
|
||||
if (tDecodeU16(&decoder, &pReq->epId.ep.port) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->epId.ep.fqdn) < 0) return -1;
|
||||
int32_t num = 0;
|
||||
if (tDecodeI32(&decoder, &num) < 0) return -1;
|
||||
if (num > 0) {
|
||||
pReq->taskAction = taosArrayInit(num, sizeof(STaskStatus));
|
||||
if (NULL == pReq->taskAction) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STaskAction action = {0};
|
||||
if (tDecodeU64(&decoder, &action.queryId) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &action.taskId) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &action.action) < 0) return -1;
|
||||
taosArrayPush(pReq->taskAction, &action);
|
||||
}
|
||||
} else {
|
||||
pReq->taskAction = NULL;
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tCoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq) { taosArrayDestroy(pReq->taskAction); }
|
||||
|
||||
|
||||
|
||||
int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, pRsp->seqId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pRsp->epId.nodeId) < 0) return -1;
|
||||
if (tEncodeU16(&encoder, pRsp->epId.ep.port) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->epId.ep.fqdn) < 0) return -1;
|
||||
if (pRsp->taskStatus) {
|
||||
int32_t num = taosArrayGetSize(pRsp->taskStatus);
|
||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STaskStatus *status = taosArrayGet(pRsp->taskStatus, i);
|
||||
if (tEncodeU64(&encoder, status->queryId) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, status->taskId) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, status->refId) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, status->status) < 0) return -1;
|
||||
}
|
||||
} else {
|
||||
if (tEncodeI32(&encoder, 0) < 0) return -1;
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tCoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp) {
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pRsp->seqId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pRsp->epId.nodeId) < 0) return -1;
|
||||
if (tDecodeU16(&decoder, &pRsp->epId.ep.port) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pRsp->epId.ep.fqdn) < 0) return -1;
|
||||
int32_t num = 0;
|
||||
if (tDecodeI32(&decoder, &num) < 0) return -1;
|
||||
if (num > 0) {
|
||||
pRsp->taskStatus = taosArrayInit(num, sizeof(STaskStatus));
|
||||
if (NULL == pRsp->taskStatus) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STaskStatus status = {0};
|
||||
if (tDecodeU64(&decoder, &status.queryId) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &status.taskId) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &status.refId) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &status.status) < 0) return -1;
|
||||
taosArrayPush(pRsp->taskStatus, &status);
|
||||
}
|
||||
} else {
|
||||
pRsp->taskStatus = NULL;
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tCoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSSchedulerHbRsp(SSchedulerHbRsp *pRsp) { taosArrayDestroy(pRsp->taskStatus); }
|
||||
|
||||
int32_t tSerializeSVCreateTSmaReq(void **buf, SVCreateTSmaReq *pReq) {
|
||||
int32_t tlen = 0;
|
||||
|
||||
|
|
|
@ -94,11 +94,11 @@ void taosVariantCreate(SVariant *pVar, const char *z, int32_t n, int32_t type) {
|
|||
bool sign = true;
|
||||
|
||||
int32_t base = 10;
|
||||
if (type == TK_HEX) {
|
||||
if (type == TK_NK_HEX) {
|
||||
base = 16;
|
||||
} else if (type == TK_OCT) {
|
||||
} else if (type == TK_NK_OCT) {
|
||||
base = 8;
|
||||
} else if (type == TK_BIN) {
|
||||
} else if (type == TK_NK_BIN) {
|
||||
base = 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -160,8 +160,8 @@ TEST(testCase, Datablock_test) {
|
|||
|
||||
printf("binary column length:%d\n", *(int32_t*) p1->pData);
|
||||
|
||||
ASSERT_EQ(colDataGetNumOfCols(b), 2);
|
||||
ASSERT_EQ(colDataGetNumOfRows(b), 40);
|
||||
ASSERT_EQ(blockDataGetNumOfCols(b), 2);
|
||||
ASSERT_EQ(blockDataGetNumOfRows(b), 40);
|
||||
|
||||
char* pData = colDataGetData(p1, 3);
|
||||
printf("the second row of binary:%s, length:%d\n", (char*)varDataVal(pData), varDataLen(pData));
|
||||
|
|
|
@ -152,6 +152,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_REB)] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_SET_CUR)] = dndProcessVnodeFetchMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CONSUME)] = dndProcessVnodeFetchMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_QUERY_HEARTBEAT)] = dndProcessVnodeFetchMsg;
|
||||
}
|
||||
|
||||
static void dndProcessResponse(void *parent, SRpcMsg *pRsp, SEpSet *pEpSet) {
|
||||
|
@ -193,7 +194,6 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
rpcInit.ckey = INTERNAL_CKEY;
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.parent = pDnode;
|
||||
rpcInit.noPool = true;
|
||||
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
|
|
|
@ -354,6 +354,23 @@ typedef struct {
|
|||
char payload[];
|
||||
} SShowObj;
|
||||
|
||||
typedef struct {
|
||||
int64_t id;
|
||||
int8_t type;
|
||||
int8_t replica;
|
||||
int16_t numOfColumns;
|
||||
int32_t rowSize;
|
||||
int32_t numOfRows;
|
||||
int32_t numOfReads;
|
||||
int32_t payloadLen;
|
||||
void* pIter;
|
||||
SMnode* pMnode;
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int16_t offset[TSDB_MAX_COLUMNS];
|
||||
int32_t bytes[TSDB_MAX_COLUMNS];
|
||||
char payload[];
|
||||
} SSysTableRetrieveObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId; // -1 for unassigned
|
||||
int32_t status;
|
||||
|
|
|
@ -885,6 +885,29 @@ DROP_DB_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
void mndGetDBTableNum(SDbObj *pDb, SMnode *pMnode, int32_t *num) {
|
||||
int32_t vindex = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
void *pIter = NULL;
|
||||
while (vindex < pDb->cfg.numOfVgroups) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (pVgroup->dbUid == pDb->uid) {
|
||||
*num += pVgroup->numOfTables / TSDB_TABLE_NUM_UNIT;
|
||||
|
||||
vindex++;
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
|
||||
static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) {
|
||||
int32_t vindex = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -900,6 +923,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) {
|
|||
vgInfo.vgId = pVgroup->vgId;
|
||||
vgInfo.hashBegin = pVgroup->hashBegin;
|
||||
vgInfo.hashEnd = pVgroup->hashEnd;
|
||||
vgInfo.numOfTable = pVgroup->numOfTables / TSDB_TABLE_NUM_UNIT;
|
||||
vgInfo.epSet.numOfEps = pVgroup->replica;
|
||||
for (int32_t gid = 0; gid < pVgroup->replica; ++gid) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[gid];
|
||||
|
@ -967,7 +991,10 @@ static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) {
|
|||
goto USE_DB_OVER;
|
||||
}
|
||||
|
||||
if (usedbReq.vgVersion < pDb->vgVersion || usedbReq.dbId != pDb->uid) {
|
||||
int32_t numOfTable = 0;
|
||||
mndGetDBTableNum(pDb, pMnode, &numOfTable);
|
||||
|
||||
if (usedbReq.vgVersion < pDb->vgVersion || usedbReq.dbId != pDb->uid || numOfTable != usedbReq.numOfTable) {
|
||||
mndBuildDBVgroupInfo(pDb, pMnode, usedbRsp.pVgroupInfos);
|
||||
}
|
||||
|
||||
|
@ -1017,6 +1044,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs,
|
|||
SDbVgVersion *pDbVgVersion = &pDbs[i];
|
||||
pDbVgVersion->dbId = htobe64(pDbVgVersion->dbId);
|
||||
pDbVgVersion->vgVersion = htonl(pDbVgVersion->vgVersion);
|
||||
pDbVgVersion->numOfTable = htonl(pDbVgVersion->numOfTable);
|
||||
|
||||
SUseDbRsp usedbRsp = {0};
|
||||
|
||||
|
@ -1027,11 +1055,18 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs,
|
|||
usedbRsp.uid = pDbVgVersion->dbId;
|
||||
usedbRsp.vgVersion = -1;
|
||||
taosArrayPush(batchUseRsp.pArray, &usedbRsp);
|
||||
} else if (pDbVgVersion->vgVersion >= pDb->vgVersion) {
|
||||
mDebug("db:%s, version not changed", pDbVgVersion->dbFName);
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t numOfTable = 0;
|
||||
mndGetDBTableNum(pDb, pMnode, &numOfTable);
|
||||
|
||||
if (pDbVgVersion->vgVersion >= pDb->vgVersion && numOfTable == pDbVgVersion->numOfTable) {
|
||||
mDebug("db:%s, version & numOfTable not changed", pDbVgVersion->dbFName);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
|
||||
usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo));
|
||||
if (usedbRsp.pVgroupInfos == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
@ -1049,7 +1084,6 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs,
|
|||
taosArrayPush(batchUseRsp.pArray, &usedbRsp);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t rspLen = tSerializeSUseDbBatchRsp(NULL, 0, &batchUseRsp);
|
||||
void *pRsp = malloc(rspLen);
|
||||
|
|
|
@ -36,6 +36,7 @@ static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pRsp);
|
|||
static int32_t mndGetQnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta);
|
||||
static int32_t mndRetrieveQnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter);
|
||||
static int32_t mndProcessQnodeListReq(SMnodeMsg *pReq);
|
||||
|
||||
int32_t mndInitQnode(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_QNODE,
|
||||
|
@ -48,6 +49,7 @@ int32_t mndInitQnode(SMnode *pMnode) {
|
|||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_QNODE, mndProcessCreateQnodeReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_QNODE, mndProcessDropQnodeReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_QNODE_LIST, mndProcessQnodeListReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_QNODE_RSP, mndProcessCreateQnodeRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_DND_DROP_QNODE_RSP, mndProcessDropQnodeRsp);
|
||||
|
||||
|
@ -430,6 +432,69 @@ DROP_QNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t mndProcessQnodeListReq(SMnodeMsg *pReq) {
|
||||
int32_t code = -1;
|
||||
SQnodeListReq qlistReq = {0};
|
||||
int32_t numOfRows = 0;
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SQnodeObj *pObj = NULL;
|
||||
SQnodeListRsp qlistRsp = {0};
|
||||
|
||||
if (tDeserializeSQnodeListReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &qlistReq) != 0) {
|
||||
mError("invalid qnode list msg");
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto QNODE_LIST_OVER;
|
||||
}
|
||||
|
||||
qlistRsp.epSetList = taosArrayInit(5, sizeof(SEpSet));
|
||||
if (NULL == qlistRsp.epSetList) {
|
||||
mError("taosArrayInit epSet failed");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto QNODE_LIST_OVER;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
void *pIter = sdbFetch(pSdb, SDB_QNODE, NULL, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
strcpy(epSet.eps[0].fqdn, pObj->pDnode->fqdn);
|
||||
epSet.eps[0].port = pObj->pDnode->port;
|
||||
epSet.numOfEps = 1;
|
||||
|
||||
taosArrayPush(qlistRsp.epSetList, &epSet);
|
||||
|
||||
numOfRows++;
|
||||
sdbRelease(pSdb, pObj);
|
||||
|
||||
if (qlistReq.rowNum > 0 && numOfRows >= qlistReq.rowNum) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
|
||||
void *pRsp = malloc(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto QNODE_LIST_OVER;
|
||||
}
|
||||
|
||||
tSerializeSQnodeListRsp(pRsp, rspLen, &qlistRsp);
|
||||
|
||||
pReq->contLen = rspLen;
|
||||
pReq->pCont = pRsp;
|
||||
code = 0;
|
||||
|
||||
QNODE_LIST_OVER:
|
||||
|
||||
tFreeSQnodeListRsp(&qlistRsp);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
|
|
|
@ -32,30 +32,30 @@
|
|||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
SVgObj* pVgroup = NULL;
|
||||
SQueryDag* pDag = qStringToDag(pTopic->physicalPlan);
|
||||
if (pDag == NULL) {
|
||||
SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||
if (pPlan == NULL) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ASSERT(pSub->vgNum == 0);
|
||||
|
||||
int32_t levelNum = taosArrayGetSize(pDag->pSubplans);
|
||||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||
if (levelNum != 1) {
|
||||
qDestroyQueryDag(pDag);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SArray* plans = taosArrayGetP(pDag->pSubplans, 0);
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0);
|
||||
|
||||
int32_t opNum = taosArrayGetSize(plans);
|
||||
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||
if (opNum != 1) {
|
||||
qDestroyQueryDag(pDag);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||
return -1;
|
||||
}
|
||||
SSubplan* plan = taosArrayGetP(plans, 0);
|
||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
|
@ -78,14 +78,14 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
int32_t msgLen;
|
||||
if (qSubPlanToString(plan, &consumerEp.qmsg, &msgLen) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryDag(pDag);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(pSub->unassignedVg, &consumerEp);
|
||||
}
|
||||
|
||||
qDestroyQueryDag(pDag);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove);
|
|||
static int32_t mndProcessShowReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq);
|
||||
static bool mndCheckRetrieveFinished(SShowObj *pShow);
|
||||
static int32_t mndProcessRetrieveSysTableReq(SMnodeMsg *pReq);
|
||||
|
||||
int32_t mndInitShow(SMnode *pMnode) {
|
||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||
|
@ -38,6 +39,7 @@ int32_t mndInitShow(SMnode *pMnode) {
|
|||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveSysTableReq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -261,6 +263,106 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessRetrieveSysTableReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||
int32_t rowsToRead = 0;
|
||||
int32_t size = 0;
|
||||
int32_t rowsRead = 0;
|
||||
|
||||
SRetrieveTableReq retrieveReq = {0};
|
||||
if (tDeserializeSRetrieveTableReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &retrieveReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SShowObj* pShow = NULL;
|
||||
|
||||
if (retrieveReq.showId == 0) {
|
||||
SShowReq req = {0};
|
||||
req.type = retrieveReq.type;
|
||||
strncpy(req.db, retrieveReq.db, tListLen(req.db));
|
||||
|
||||
pShow = mndCreateShowObj(pMnode, &req);
|
||||
if (pShow == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to process show-meta req since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
|
||||
if (pShow == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_SHOWOBJ;
|
||||
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
|
||||
if (retrieveFp == NULL) {
|
||||
mndReleaseShowObj((SShowObj*) pShow, false);
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mDebug("show:0x%" PRIx64 ", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads,
|
||||
pShow->numOfRows, mndShowStr(pShow->type));
|
||||
|
||||
if (mndCheckRetrieveFinished((SShowObj*) pShow)) {
|
||||
mDebug("show:0x%" PRIx64 ", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads,
|
||||
pShow->numOfRows);
|
||||
pShow->numOfReads = pShow->numOfRows;
|
||||
}
|
||||
|
||||
if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
|
||||
rowsToRead = pShow->numOfRows - pShow->numOfReads;
|
||||
}
|
||||
|
||||
/* return no more than 100 tables in one round trip */
|
||||
if (rowsToRead > SHOW_STEP_SIZE) rowsToRead = SHOW_STEP_SIZE;
|
||||
|
||||
/*
|
||||
* the actual number of table may be larger than the value of pShow->numOfRows, if a query is
|
||||
* issued during a continuous create table operation. Therefore, rowToRead may be less than 0.
|
||||
*/
|
||||
if (rowsToRead < 0) rowsToRead = 0;
|
||||
size = pShow->rowSize * rowsToRead;
|
||||
|
||||
size += SHOW_STEP_SIZE;
|
||||
SRetrieveTableRsp *pRsp = rpcMallocCont(size);
|
||||
if (pRsp == NULL) {
|
||||
mndReleaseShowObj((SShowObj*) pShow, false);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// if free flag is set, client wants to clean the resources
|
||||
if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
|
||||
rowsRead = (*retrieveFp)(pReq, (SShowObj*) pShow, pRsp->data, rowsToRead);
|
||||
}
|
||||
|
||||
mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead);
|
||||
|
||||
pRsp->numOfRows = htonl(rowsRead);
|
||||
pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision
|
||||
|
||||
pReq->pCont = pRsp;
|
||||
pReq->contLen = size;
|
||||
|
||||
if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) {
|
||||
pRsp->completed = 1;
|
||||
mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
|
||||
mndReleaseShowObj((SShowObj*) pShow, true);
|
||||
} else {
|
||||
mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
|
||||
mndReleaseShowObj((SShowObj*) pShow, false);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char *mndShowStr(int32_t showType) {
|
||||
switch (showType) {
|
||||
case TSDB_MGMT_TABLE_ACCT:
|
||||
|
|
|
@ -773,10 +773,10 @@ static int32_t mndProcessDoRebalanceMsg(SMnodeMsg *pMsg) {
|
|||
static int32_t mndInitUnassignedVg(SMnode *pMnode, const SMqTopicObj *pTopic, SMqSubscribeObj *pSub) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
SQueryDag *pDag = qStringToDag(pTopic->physicalPlan);
|
||||
SQueryPlan *pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||
SArray *pArray = NULL;
|
||||
SArray *inner = taosArrayGet(pDag->pSubplans, 0);
|
||||
SSubplan *plan = taosArrayGetP(inner, 0);
|
||||
SNodeListNode *inner = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
||||
SSubplan *plan = (SSubplan*)nodesListGetNode(inner->pNodeList, 0);
|
||||
SArray *unassignedVg = pSub->unassignedVg;
|
||||
|
||||
void *pIter = NULL;
|
||||
|
@ -792,7 +792,7 @@ static int32_t mndInitUnassignedVg(SMnode *pMnode, const SMqTopicObj *pTopic, SM
|
|||
plan->execNode.nodeId = pVgroup->vgId;
|
||||
plan->execNode.epset = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
if (schedulerConvertDagToTaskList(pDag, &pArray) < 0) {
|
||||
if (schedulerConvertDagToTaskList(pPlan, &pArray) < 0) {
|
||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||
mError("unsupport topic: %s, sql: %s", pTopic->name, pTopic->sql);
|
||||
return -1;
|
||||
|
|
|
@ -11,4 +11,7 @@ target_link_libraries(
|
|||
PRIVATE os
|
||||
PRIVATE common
|
||||
PRIVATE util
|
||||
PRIVATE qworker
|
||||
PRIVATE qcom
|
||||
PRIVATE executor
|
||||
)
|
|
@ -28,8 +28,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SQWorkerMgmt SQHandle;
|
||||
|
||||
typedef struct SQnode {
|
||||
int32_t qndId;
|
||||
SQnodeOpt opt;
|
||||
SQHandle* pQuery;
|
||||
} SQnode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -14,13 +14,35 @@
|
|||
*/
|
||||
|
||||
#include "qndInt.h"
|
||||
#include "query.h"
|
||||
#include "qworker.h"
|
||||
#include "executor.h"
|
||||
|
||||
int32_t qnodePutReqToVQueryQ(SQnode* pQnode, struct SRpcMsg* pReq) {}
|
||||
void qnodeSendReqToDnode(SQnode* pQnode, struct SEpSet* epSet, struct SRpcMsg* pReq) {}
|
||||
|
||||
|
||||
SQnode *qndOpen(const SQnodeOpt *pOption) {
|
||||
SQnode *pQnode = calloc(1, sizeof(SQnode));
|
||||
if (NULL == pQnode) {
|
||||
qError("calloc SQnode failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, NULL, (void **)&pQnode->pQuery, pQnode,
|
||||
(putReqToQueryQFp)qnodePutReqToVQueryQ, (sendReqToDnodeFp)qnodeSendReqToDnode)) {
|
||||
tfree(pQnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pQnode;
|
||||
}
|
||||
|
||||
void qndClose(SQnode *pQnode) { free(pQnode); }
|
||||
void qndClose(SQnode *pQnode) {
|
||||
qWorkerDestroy((void **)&pQnode->pQuery);
|
||||
|
||||
free(pQnode);
|
||||
}
|
||||
|
||||
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
||||
|
||||
|
@ -29,3 +51,51 @@ int32_t qndProcessMsg(SQnode *pQnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int qnodeProcessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
||||
qTrace("message in query queue is processing");
|
||||
SReadHandle handle = {0};
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_VND_QUERY:{
|
||||
return qWorkerProcessQueryMsg(&handle, pQnode->pQuery, pMsg);
|
||||
}
|
||||
case TDMT_VND_QUERY_CONTINUE:
|
||||
return qWorkerProcessCQueryMsg(&handle, pQnode->pQuery, pMsg);
|
||||
default:
|
||||
qError("unknown msg type:%d in query queue", pMsg->msgType);
|
||||
return TSDB_CODE_VND_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
int qnodeProcessFetchMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
||||
qTrace("message in fetch queue is processing");
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_VND_FETCH:
|
||||
return qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg);
|
||||
case TDMT_VND_FETCH_RSP:
|
||||
return qWorkerProcessFetchRsp(pQnode, pQnode->pQuery, pMsg);
|
||||
case TDMT_VND_RES_READY:
|
||||
return qWorkerProcessReadyMsg(pQnode, pQnode->pQuery, pMsg);
|
||||
case TDMT_VND_TASKS_STATUS:
|
||||
return qWorkerProcessStatusMsg(pQnode, pQnode->pQuery, pMsg);
|
||||
case TDMT_VND_CANCEL_TASK:
|
||||
return qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg);
|
||||
case TDMT_VND_DROP_TASK:
|
||||
return qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg);
|
||||
case TDMT_VND_SHOW_TABLES:
|
||||
return qWorkerProcessShowMsg(pQnode, pQnode->pQuery, pMsg);
|
||||
case TDMT_VND_SHOW_TABLES_FETCH:
|
||||
//return vnodeGetTableList(pQnode, pMsg);
|
||||
case TDMT_VND_TABLE_META:
|
||||
//return vnodeGetTableMeta(pQnode, pMsg);
|
||||
case TDMT_VND_CONSUME:
|
||||
//return tqProcessConsumeReq(pQnode->pTq, pMsg);
|
||||
default:
|
||||
qError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
||||
return TSDB_CODE_VND_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
|||
typedef struct SQWorkerMgmt SQHandle;
|
||||
|
||||
int vnodeQueryOpen(SVnode *pVnode);
|
||||
void vnodeQueryClose(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -13,18 +13,19 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <tdatablock.h>
|
||||
#include "os.h"
|
||||
#include "talgo.h"
|
||||
#include "tcompare.h"
|
||||
#include "tdataformat.h"
|
||||
#include "texception.h"
|
||||
#include "tsdb.h"
|
||||
#include "tsdbDef.h"
|
||||
#include "tsdbFS.h"
|
||||
#include "tsdbLog.h"
|
||||
#include "tsdbReadImpl.h"
|
||||
#include "ttime.h"
|
||||
#include "texception.h"
|
||||
#include "os.h"
|
||||
#include "talgo.h"
|
||||
#include "tcompare.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tskiplist.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#include "taosdef.h"
|
||||
#include "tlosertree.h"
|
||||
|
@ -1472,6 +1473,8 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
|||
return numOfRows + num;
|
||||
}
|
||||
|
||||
// TODO fix bug for reverse copy data
|
||||
// TODO handle the null data
|
||||
// Note: row1 always has high priority
|
||||
static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, STSRow* row1,
|
||||
STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2,
|
||||
|
@ -1515,7 +1518,6 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t i = 0, j = 0, k = 0;
|
||||
while(i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) {
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i);
|
||||
|
@ -1586,7 +1588,6 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
tdSKvRowGetVal(row, colId, offset, chosen_itr, &sVal);
|
||||
}
|
||||
|
||||
|
||||
if (colId == pColInfo->info.colId) {
|
||||
if (tdValTypeIsNorm(sVal.valType)) {
|
||||
switch (pColInfo->info.type) {
|
||||
|
@ -1594,7 +1595,6 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
case TSDB_DATA_TYPE_NCHAR:
|
||||
memcpy(pData, sVal.val, varDataTLen(sVal.val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
|
@ -1625,11 +1625,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
memcpy(pData, sVal.val, pColInfo->info.bytes);
|
||||
}
|
||||
} else if (forceSetNull) {
|
||||
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
|
||||
setVardataNull(pData, pColInfo->info.type);
|
||||
} else {
|
||||
setNull(pData, pColInfo->info.type, pColInfo->info.bytes);
|
||||
}
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
}
|
||||
i++;
|
||||
|
||||
|
@ -1640,11 +1636,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
}
|
||||
} else {
|
||||
if(forceSetNull) {
|
||||
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
|
||||
setVardataNull(pData, pColInfo->info.type);
|
||||
} else {
|
||||
setNull(pData, pColInfo->info.type, pColInfo->info.bytes);
|
||||
}
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -1653,18 +1645,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
if(forceSetNull) {
|
||||
while (i < numOfCols) { // the remain columns are all null data
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i);
|
||||
if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) {
|
||||
pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;
|
||||
} else {
|
||||
pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes;
|
||||
}
|
||||
|
||||
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
|
||||
setVardataNull(pData, pColInfo->info.type);
|
||||
} else {
|
||||
setNull(pData, pColInfo->info.type, pColInfo->info.bytes);
|
||||
}
|
||||
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,5 +154,6 @@ static void vnodeCloseImpl(SVnode *pVnode) {
|
|||
tsdbClose(pVnode->pTsdb);
|
||||
tqClose(pVnode->pTq);
|
||||
walClose(pVnode->pWal);
|
||||
vnodeQueryClose(pVnode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,10 @@ int vnodeQueryOpen(SVnode *pVnode) {
|
|||
(putReqToQueryQFp)vnodePutReqToVQueryQ, (sendReqToDnodeFp)vnodeSendReqToDnode);
|
||||
}
|
||||
|
||||
void vnodeQueryClose(SVnode *pVnode) {
|
||||
qWorkerDestroy((void **)&pVnode->pQuery);
|
||||
}
|
||||
|
||||
int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
vTrace("message in query queue is processing");
|
||||
SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta};
|
||||
|
@ -64,6 +68,8 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
return vnodeGetTableMeta(pVnode, pMsg);
|
||||
case TDMT_VND_CONSUME:
|
||||
return tqProcessPollReq(pVnode->pTq, pMsg);
|
||||
case TDMT_VND_QUERY_HEARTBEAT:
|
||||
return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg);
|
||||
default:
|
||||
vError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
||||
return TSDB_CODE_VND_APP_ERROR;
|
||||
|
|
|
@ -558,6 +558,42 @@ int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCac
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, SArray **out) {
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
|
||||
ctgDebug("try to get qnode list from mnode, mgmtEpInUse:%d", pMgmtEps->inUse);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)](NULL, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build qnode list msg failed, error:%s", tstrerror(code));
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = TDMT_MND_QNODE_LIST,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
if (TSDB_CODE_SUCCESS != rpcRsp.code) {
|
||||
ctgError("error rsp for qnode list, error:%s", tstrerror(rpcRsp.code));
|
||||
CTG_ERR_RET(rpcRsp.code);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)](out, rpcRsp.pCont, rpcRsp.contLen);
|
||||
if (code) {
|
||||
ctgError("Process qnode list rsp failed, error:%s", tstrerror(rpcRsp.code));
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
ctgDebug("Got qnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(*out));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, SBuildUseDBInput *input, SUseDbOutput *out) {
|
||||
|
@ -965,7 +1001,7 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgStbVersionCompare(const void* key1, const void* key2) {
|
||||
int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2) {
|
||||
if (*(uint64_t *)key1 < ((SSTableMetaVersion*)key2)->suid) {
|
||||
return -1;
|
||||
} else if (*(uint64_t *)key1 > ((SSTableMetaVersion*)key2)->suid) {
|
||||
|
@ -975,7 +1011,7 @@ int32_t ctgStbVersionCompare(const void* key1, const void* key2) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ctgDbVgVersionCompare(const void* key1, const void* key2) {
|
||||
int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2) {
|
||||
if (*(int64_t *)key1 < ((SDbVgVersion*)key2)->dbId) {
|
||||
return -1;
|
||||
} else if (*(int64_t *)key1 > ((SDbVgVersion*)key2)->dbId) {
|
||||
|
@ -985,6 +1021,27 @@ int32_t ctgDbVgVersionCompare(const void* key1, const void* key2) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2) {
|
||||
if (((SSTableMetaVersion*)key1)->suid < ((SSTableMetaVersion*)key2)->suid) {
|
||||
return -1;
|
||||
} else if (((SSTableMetaVersion*)key1)->suid > ((SSTableMetaVersion*)key2)->suid) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ctgDbVgVersionSortCompare(const void* key1, const void* key2) {
|
||||
if (((SDbVgVersion*)key1)->dbId < ((SDbVgVersion*)key2)->dbId) {
|
||||
return -1;
|
||||
} else if (((SDbVgVersion*)key1)->dbId > ((SDbVgVersion*)key2)->dbId) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type) {
|
||||
mgmt->slotRIdx = 0;
|
||||
mgmt->slotNum = rentSec / CTG_RENT_SLOT_SECOND;
|
||||
|
@ -1034,7 +1091,7 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size, __compar_fn_t compare) {
|
||||
int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
||||
int16_t widx = abs(id % mgmt->slotNum);
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
|
@ -1048,12 +1105,12 @@ int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t si
|
|||
|
||||
if (slot->needSort) {
|
||||
qDebug("meta slot before sorte, slot idx:%d, type:%d, size:%d", widx, mgmt->type, (int32_t)taosArrayGetSize(slot->meta));
|
||||
taosArraySort(slot->meta, compare);
|
||||
taosArraySort(slot->meta, sortCompare);
|
||||
slot->needSort = false;
|
||||
qDebug("meta slot sorted, slot idx:%d, type:%d, size:%d", widx, mgmt->type, (int32_t)taosArrayGetSize(slot->meta));
|
||||
}
|
||||
|
||||
void *orig = taosArraySearch(slot->meta, &id, compare, TD_EQ);
|
||||
void *orig = taosArraySearch(slot->meta, &id, searchCompare, TD_EQ);
|
||||
if (NULL == orig) {
|
||||
qError("meta not found in slot, id:%"PRIx64", slot idx:%d, type:%d, size:%d", id, widx, mgmt->type, (int32_t)taosArrayGetSize(slot->meta));
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
|
@ -1075,8 +1132,8 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t compare) {
|
||||
int16_t widx = labs(id % mgmt->slotNum);
|
||||
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
||||
int16_t widx = abs(id % mgmt->slotNum);
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
int32_t code = 0;
|
||||
|
@ -1088,12 +1145,12 @@ int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t compare)
|
|||
}
|
||||
|
||||
if (slot->needSort) {
|
||||
taosArraySort(slot->meta, compare);
|
||||
taosArraySort(slot->meta, sortCompare);
|
||||
slot->needSort = false;
|
||||
qDebug("meta slot sorted, slot idx:%d, type:%d", widx, mgmt->type);
|
||||
}
|
||||
|
||||
int32_t idx = taosArraySearchIdx(slot->meta, &id, compare, TD_EQ);
|
||||
int32_t idx = taosArraySearchIdx(slot->meta, &id, searchCompare, TD_EQ);
|
||||
if (idx < 0) {
|
||||
qError("meta not found in slot, id:%"PRIx64", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
|
@ -1240,7 +1297,7 @@ void ctgRemoveStbRent(SCatalog* pCtg, SCtgTbMetaCache *cache) {
|
|||
uint64_t *suid = NULL;
|
||||
suid = taosHashGetKey(pIter, NULL);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == ctgMetaRentRemove(&pCtg->stbRent, *suid, ctgStbVersionCompare)) {
|
||||
if (TSDB_CODE_SUCCESS == ctgMetaRentRemove(&pCtg->stbRent, *suid, ctgStbVersionSortCompare, ctgStbVersionSearchCompare)) {
|
||||
ctgDebug("stb removed from rent, suid:%"PRIx64, *suid);
|
||||
}
|
||||
|
||||
|
@ -1264,7 +1321,7 @@ int32_t ctgRemoveDB(SCatalog* pCtg, SCtgDBCache *dbCache, const char* dbFName) {
|
|||
|
||||
ctgInfo("db removed from cache, dbFName:%s, dbId:%"PRIx64, dbFName, dbCache->dbId);
|
||||
|
||||
CTG_ERR_RET(ctgMetaRentRemove(&pCtg->dbRent, dbCache->dbId, ctgDbVgVersionCompare));
|
||||
CTG_ERR_RET(ctgMetaRentRemove(&pCtg->dbRent, dbCache->dbId, ctgDbVgVersionSortCompare, ctgDbVgVersionSearchCompare));
|
||||
|
||||
ctgDebug("db removed from rent, dbFName:%s, dbId:%"PRIx64, dbFName, dbCache->dbId);
|
||||
|
||||
|
@ -1331,7 +1388,7 @@ int32_t ctgUpdateDBVgInfo(SCatalog* pCtg, const char* dbFName, uint64_t dbId, SD
|
|||
}
|
||||
|
||||
bool newAdded = false;
|
||||
SDbVgVersion vgVersion = {.dbId = dbId, .vgVersion = dbInfo->vgVersion};
|
||||
SDbVgVersion vgVersion = {.dbId = dbId, .vgVersion = dbInfo->vgVersion, .numOfTable = dbInfo->numOfTable};
|
||||
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
CTG_ERR_RET(ctgGetAddDBCache(pCtg, dbFName, dbId, &dbCache));
|
||||
|
@ -1344,8 +1401,15 @@ int32_t ctgUpdateDBVgInfo(SCatalog* pCtg, const char* dbFName, uint64_t dbId, SD
|
|||
CTG_ERR_RET(ctgWAcquireVgInfo(pCtg, dbCache));
|
||||
|
||||
if (dbCache->vgInfo) {
|
||||
if (dbInfo->vgVersion <= dbCache->vgInfo->vgVersion) {
|
||||
ctgInfo("db vgVersion is old, dbFName:%s, vgVersion:%d, currentVersion:%d", dbFName, dbInfo->vgVersion, dbCache->vgInfo->vgVersion);
|
||||
if (dbInfo->vgVersion < dbCache->vgInfo->vgVersion) {
|
||||
ctgDebug("db vgVersion is old, dbFName:%s, vgVersion:%d, currentVersion:%d", dbFName, dbInfo->vgVersion, dbCache->vgInfo->vgVersion);
|
||||
ctgWReleaseVgInfo(dbCache);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (dbInfo->vgVersion == dbCache->vgInfo->vgVersion && dbInfo->numOfTable == dbCache->vgInfo->numOfTable) {
|
||||
ctgDebug("no new db vgVersion or numOfTable, dbFName:%s, vgVersion:%d, numOfTable:%d", dbFName, dbInfo->vgVersion, dbInfo->numOfTable);
|
||||
ctgWReleaseVgInfo(dbCache);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1365,7 +1429,7 @@ int32_t ctgUpdateDBVgInfo(SCatalog* pCtg, const char* dbFName, uint64_t dbId, SD
|
|||
dbCache = NULL;
|
||||
|
||||
strncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
|
||||
CTG_ERR_RET(ctgMetaRentUpdate(&pCtg->dbRent, &vgVersion, vgVersion.dbId, sizeof(SDbVgVersion), ctgDbVgVersionCompare));
|
||||
CTG_ERR_RET(ctgMetaRentUpdate(&pCtg->dbRent, &vgVersion, vgVersion.dbId, sizeof(SDbVgVersion), ctgDbVgVersionSortCompare, ctgDbVgVersionSearchCompare));
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
@ -1398,7 +1462,7 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui
|
|||
|
||||
ctgDebug("stb removed from stbCache, dbFName:%s, stb:%s, suid:%"PRIx64, dbFName, tbName, orig->suid);
|
||||
|
||||
ctgMetaRentRemove(&pCtg->stbRent, orig->suid, ctgStbVersionCompare);
|
||||
ctgMetaRentRemove(&pCtg->stbRent, orig->suid, ctgStbVersionSortCompare, ctgStbVersionSearchCompare);
|
||||
}
|
||||
|
||||
origSuid = orig->suid;
|
||||
|
@ -1511,6 +1575,7 @@ int32_t ctgGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const
|
|||
if (inCache) {
|
||||
input.dbId = (*dbCache)->dbId;
|
||||
input.vgVersion = (*dbCache)->vgInfo->vgVersion;
|
||||
input.numOfTable = (*dbCache)->vgInfo->numOfTable;
|
||||
} else {
|
||||
input.vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||
}
|
||||
|
@ -1924,7 +1989,7 @@ int32_t ctgActRemoveStb(SCtgMetaAction *action) {
|
|||
|
||||
ctgInfo("stb removed from cache, dbFName:%s, stbName:%s, suid:%"PRIx64, msg->dbFName, msg->stbName, msg->suid);
|
||||
|
||||
CTG_ERR_JRET(ctgMetaRentRemove(&msg->pCtg->stbRent, msg->suid, ctgStbVersionCompare));
|
||||
CTG_ERR_JRET(ctgMetaRentRemove(&msg->pCtg->stbRent, msg->suid, ctgStbVersionSortCompare, ctgStbVersionSearchCompare));
|
||||
|
||||
ctgDebug("stb removed from rent, dbFName:%s, stbName:%s, suid:%"PRIx64, msg->dbFName, msg->stbName, msg->suid);
|
||||
|
||||
|
@ -2163,7 +2228,7 @@ void catalogFreeHandle(SCatalog* pCtg) {
|
|||
ctgInfo("handle freed, culsterId:%"PRIx64, clusterId);
|
||||
}
|
||||
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId) {
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == pCtg || NULL == dbFName || NULL == version || NULL == dbId) {
|
||||
|
@ -2194,6 +2259,7 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers
|
|||
|
||||
*version = dbCache->vgInfo->vgVersion;
|
||||
*dbId = dbCache->dbId;
|
||||
*tableNum = dbCache->vgInfo->numOfTable;
|
||||
|
||||
ctgReleaseVgInfo(dbCache);
|
||||
ctgReleaseDBCache(pCtg, dbCache);
|
||||
|
@ -2572,6 +2638,10 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps,
|
|||
}
|
||||
}
|
||||
|
||||
if (pReq->qNodeRequired) {
|
||||
CTG_ERR_JRET(ctgGetQnodeListFromMnode(pCtg, pTrans, pMgmtEps, &pRsp->pEpSetList));
|
||||
}
|
||||
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
|
||||
_return:
|
||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
|||
|
||||
#include "tcommon.h"
|
||||
#include "dataSinkMgt.h"
|
||||
#include "plannodes.h"
|
||||
|
||||
struct SDataSink;
|
||||
struct SDataSinkHandle;
|
||||
|
@ -45,7 +46,7 @@ typedef struct SDataSinkHandle {
|
|||
FDestroyDataSinker fDestroy;
|
||||
} SDataSinkHandle;
|
||||
|
||||
int32_t createDataDispatcher(SDataSinkManager* pManager, const struct SDataSink* pDataSink, DataSinkHandle* pHandle);
|
||||
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -92,10 +92,11 @@ typedef struct SResultRowPool {
|
|||
struct STaskAttr;
|
||||
struct STaskRuntimeEnv;
|
||||
struct SUdfInfo;
|
||||
struct SqlFunctionCtx;
|
||||
|
||||
int32_t getOutputInterResultBufSize(struct STaskAttr* pQueryAttr);
|
||||
|
||||
size_t getResultRowSize(SArray* pExprInfo);
|
||||
size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
int32_t initResultRowInfo(SResultRowInfo* pResultRowInfo, int32_t size);
|
||||
void cleanupResultRowInfo(SResultRowInfo* pResultRowInfo);
|
||||
|
||||
|
@ -111,7 +112,6 @@ void clearResultRow(struct STaskRuntimeEnv* pRuntimeEnv, SResultRow* pResultR
|
|||
struct SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t* offset);
|
||||
|
||||
void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr);
|
||||
void* freeColumnInfo(SColumnInfo* pColumnInfo, int32_t numOfCols);
|
||||
int32_t getRowNumForMultioutput(struct STaskAttr* pQueryAttr, bool topBottomQuery, bool stable);
|
||||
|
||||
static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {
|
||||
|
|
|
@ -371,8 +371,8 @@ typedef struct STaskParam {
|
|||
char* tbnameCond;
|
||||
char* prevResult;
|
||||
SArray* pTableIdList;
|
||||
SSqlExpr** pExpr;
|
||||
SSqlExpr** pSecExpr;
|
||||
SExprBasicInfo** pExpr;
|
||||
SExprBasicInfo** pSecExpr;
|
||||
SExprInfo* pExprs;
|
||||
SExprInfo* pSecExprs;
|
||||
|
||||
|
@ -419,12 +419,10 @@ typedef struct STableScanInfo {
|
|||
int32_t numOfSkipped;
|
||||
int32_t numOfBlockStatis;
|
||||
int64_t numOfRows;
|
||||
|
||||
int32_t order; // scan order
|
||||
int32_t times; // repeat counts
|
||||
int32_t current;
|
||||
int32_t reverseTimes; // 0 by default
|
||||
|
||||
SqlFunctionCtx* pCtx; // next operator query context
|
||||
SResultRowInfo* pResultRowInfo;
|
||||
int32_t* rowCellInfoOffset;
|
||||
|
@ -433,7 +431,6 @@ typedef struct STableScanInfo {
|
|||
int32_t numOfOutput;
|
||||
int64_t elapsedTime;
|
||||
int32_t prevGroupId; // previous table group id
|
||||
|
||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||
} STableScanInfo;
|
||||
|
||||
|
@ -452,21 +449,43 @@ typedef struct SStreamBlockScanInfo {
|
|||
void* readerHandle; // stream block reader handle
|
||||
} SStreamBlockScanInfo;
|
||||
|
||||
typedef struct SSysTableScanInfo {
|
||||
union {
|
||||
void* pTransporter;
|
||||
void* readHandle;
|
||||
};
|
||||
|
||||
void *pCur; // cursor
|
||||
SRetrieveTableReq* pReq;
|
||||
SEpSet epSet;
|
||||
int32_t type; // show type
|
||||
tsem_t ready;
|
||||
SSchema* pSchema;
|
||||
SSDataBlock* pRes;
|
||||
|
||||
int32_t capacity;
|
||||
int64_t numOfBlocks; // extract basic running information.
|
||||
int64_t totalRows;
|
||||
int64_t elapsedTime;
|
||||
int64_t totalBytes;
|
||||
} SSysTableScanInfo;
|
||||
|
||||
typedef struct SOptrBasicInfo {
|
||||
SResultRowInfo resultRowInfo;
|
||||
int32_t* rowCellInfoOffset; // offset value for each row result cell info
|
||||
SqlFunctionCtx* pCtx;
|
||||
SSDataBlock* pRes;
|
||||
uint32_t resRowSize;
|
||||
int32_t capacity;
|
||||
} SOptrBasicInfo;
|
||||
|
||||
//TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
|
||||
typedef struct SAggSupporter {
|
||||
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
||||
SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
|
||||
SArray* pResultRowArrayList; // The array list that contains the Result rows
|
||||
char* keyBuf; // window key buffer
|
||||
SResultRowPool *pool; // The window result objects pool, all the resultRow Objects are allocated and managed by this object.
|
||||
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
||||
} SAggSupporter;
|
||||
|
||||
typedef struct STableIntervalOperatorInfo {
|
||||
|
@ -622,15 +641,19 @@ typedef struct SOrderOperatorInfo {
|
|||
uint64_t totalElapsed; // total elapsed time
|
||||
} SOrderOperatorInfo;
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SArray* pSources, const SArray* pSchema, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput,
|
||||
int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
|
||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createOrderOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SArray* pOrderVal, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SArray* pExprInfo, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, const SArray* pExprInfo, const SSchema* pSchema,
|
||||
int32_t tableType, SEpSet epset, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
|
||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SInterval* pInterval, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
|
||||
|
@ -661,8 +684,6 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper
|
|||
int32_t numOfOutput);
|
||||
SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr,
|
||||
int32_t numOfOutput, void* merger, bool multigroupResult);
|
||||
SOperatorInfo* createFilterOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr,
|
||||
int32_t numOfOutput, SColumnInfo* pCols, int32_t numOfFilter);
|
||||
|
||||
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema,
|
||||
int32_t numOfOutput);
|
||||
|
@ -682,13 +703,8 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SResult
|
|||
void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity);
|
||||
void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
|
||||
int32_t createIndirectQueryFuncExprFromMsg(SQueryTableReq* pQueryMsg, int32_t numOfOutput, SExprInfo** pExprInfo,
|
||||
SSqlExpr** pExpr, SExprInfo* prevExpr, struct SUdfInfo* pUdfInfo);
|
||||
|
||||
int32_t createQueryFilter(char* data, uint16_t len, SFilterInfo** pFilters);
|
||||
|
||||
SGroupbyExpr* createGroupbyExprFromMsg(SQueryTableReq* pQueryMsg, SColIndex* pColIndex, int32_t* code);
|
||||
|
||||
int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* pQInfo, STaskParam* param, char* start,
|
||||
int32_t prevResultLen, void* merger);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ typedef struct SDataCacheEntry {
|
|||
typedef struct SDataDispatchHandle {
|
||||
SDataSinkHandle sink;
|
||||
SDataSinkManager* pManager;
|
||||
SDataBlockSchema schema;
|
||||
SDataBlockDescNode* pSchema;
|
||||
STaosQueue* pDataBlocks;
|
||||
SDataDispatchBuf nextOutput;
|
||||
int32_t status;
|
||||
|
@ -46,12 +46,13 @@ typedef struct SDataDispatchHandle {
|
|||
pthread_mutex_t mutex;
|
||||
} SDataDispatchHandle;
|
||||
|
||||
static bool needCompress(const SSDataBlock* pData, const SDataBlockSchema* pSchema) {
|
||||
static bool needCompress(const SSDataBlock* pData, const SDataBlockDescNode* pSchema) {
|
||||
if (tsCompressColData < 0 || 0 == pData->info.rows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int32_t col = 0; col < pSchema->numOfCols; ++col) {
|
||||
int32_t numOfCols = LIST_LENGTH(pSchema->pSlots);
|
||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||
SColumnInfoData* pColRes = taosArrayGet(pData->pDataBlock, col);
|
||||
int32_t colSize = pColRes->info.bytes * pData->info.rows;
|
||||
if (NEEDTO_COMPRESS_QUERY(colSize)) {
|
||||
|
@ -68,13 +69,14 @@ static int32_t compressColData(SColumnInfoData *pColRes, int32_t numOfRows, char
|
|||
pColRes->pData, colSize, numOfRows, data, colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0);
|
||||
}
|
||||
|
||||
static void copyData(const SInputData* pInput, const SDataBlockSchema* pSchema, char* data, int8_t compressed, int32_t *compLen) {
|
||||
static void copyData(const SInputData* pInput, const SDataBlockDescNode* pSchema, char* data, int8_t compressed, int32_t *compLen) {
|
||||
int32_t numOfCols = LIST_LENGTH(pSchema->pSlots);
|
||||
int32_t *compSizes = (int32_t*)data;
|
||||
if (compressed) {
|
||||
data += pSchema->numOfCols * sizeof(int32_t);
|
||||
data += numOfCols * sizeof(int32_t);
|
||||
}
|
||||
|
||||
for (int32_t col = 0; col < pSchema->numOfCols; ++col) {
|
||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||
SColumnInfoData* pColRes = taosArrayGet(pInput->pData->pDataBlock, col);
|
||||
if (compressed) {
|
||||
compSizes[col] = compressColData(pColRes, pInput->pData->info.rows, data, compressed);
|
||||
|
@ -92,14 +94,14 @@ static void copyData(const SInputData* pInput, const SDataBlockSchema* pSchema,
|
|||
// data format: SDataCacheEntry | col1_data col2_data ... | numOfTables | STableIdInfo STableIdInfo ...
|
||||
static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) {
|
||||
SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData;
|
||||
pEntry->compressed = (int8_t)needCompress(pInput->pData, &(pHandle->schema));
|
||||
pEntry->compressed = (int8_t)needCompress(pInput->pData, pHandle->pSchema);
|
||||
pEntry->numOfRows = pInput->pData->info.rows;
|
||||
pEntry->dataLen = 0;
|
||||
|
||||
pBuf->useSize = sizeof(SRetrieveTableRsp);
|
||||
copyData(pInput, &pHandle->schema, pEntry->data, pEntry->compressed, &pEntry->dataLen);
|
||||
copyData(pInput, pHandle->pSchema, pEntry->data, pEntry->compressed, &pEntry->dataLen);
|
||||
if (0 == pEntry->compressed) {
|
||||
pEntry->dataLen = pHandle->schema.resultRowSize * pInput->pData->info.rows;
|
||||
pEntry->dataLen = pHandle->pSchema->resultRowSize * pInput->pData->info.rows;
|
||||
}
|
||||
pBuf->useSize += pEntry->dataLen;
|
||||
// todo completed
|
||||
|
@ -113,7 +115,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
|
|||
return false;
|
||||
}
|
||||
|
||||
pBuf->allocSize = sizeof(SRetrieveTableRsp) + pDispatcher->schema.resultRowSize * pInput->pData->info.rows;
|
||||
pBuf->allocSize = sizeof(SRetrieveTableRsp) + pDispatcher->pSchema->resultRowSize * pInput->pData->info.rows;
|
||||
pBuf->pData = malloc(pBuf->allocSize);
|
||||
if (pBuf->pData == NULL) {
|
||||
qError("SinkNode failed to malloc memory, size:%d, code:%d", pBuf->allocSize, TAOS_SYSTEM_ERROR(errno));
|
||||
|
@ -179,7 +181,7 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
|
|||
if (NULL == pDispatcher->nextOutput.pData) {
|
||||
assert(pDispatcher->queryEnd);
|
||||
pOutput->useconds = pDispatcher->useconds;
|
||||
pOutput->precision = pDispatcher->schema.precision;
|
||||
pOutput->precision = pDispatcher->pSchema->precision;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDispatcher->nextOutput.pData);
|
||||
|
@ -191,7 +193,7 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
|
|||
pthread_mutex_lock(&pDispatcher->mutex);
|
||||
pOutput->queryEnd = pDispatcher->queryEnd;
|
||||
pOutput->useconds = pDispatcher->useconds;
|
||||
pOutput->precision = pDispatcher->schema.precision;
|
||||
pOutput->precision = pDispatcher->pSchema->precision;
|
||||
pthread_mutex_unlock(&pDispatcher->mutex);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -209,7 +211,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
|
|||
pthread_mutex_destroy(&pDispatcher->mutex);
|
||||
}
|
||||
|
||||
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSink* pDataSink, DataSinkHandle* pHandle) {
|
||||
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle) {
|
||||
SDataDispatchHandle* dispatcher = calloc(1, sizeof(SDataDispatchHandle));
|
||||
if (NULL == dispatcher) {
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
|
@ -221,7 +223,7 @@ int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSink* pDataS
|
|||
dispatcher->sink.fGetData = getDataBlock;
|
||||
dispatcher->sink.fDestroy = destroyDataSinker;
|
||||
dispatcher->pManager = pManager;
|
||||
dispatcher->schema = pDataSink->schema;
|
||||
dispatcher->pSchema = pDataSink->pInputDataBlockDesc;
|
||||
dispatcher->status = DS_BUF_EMPTY;
|
||||
dispatcher->queryEnd = false;
|
||||
dispatcher->pDataBlocks = taosOpenQueue();
|
||||
|
|
|
@ -25,8 +25,8 @@ int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg) {
|
|||
pthread_mutex_init(&gDataSinkManager.mutex, NULL);
|
||||
}
|
||||
|
||||
int32_t dsCreateDataSinker(const struct SDataSink *pDataSink, DataSinkHandle* pHandle) {
|
||||
if (DSINK_Dispatch == pDataSink->info.type) {
|
||||
int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle) {
|
||||
if (QUERY_NODE_PHYSICAL_PLAN_DISPATCH == nodeType(pDataSink)) {
|
||||
return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle);
|
||||
}
|
||||
return TSDB_CODE_FAILED;
|
||||
|
|
|
@ -46,7 +46,7 @@ int32_t getOutputInterResultBufSize(STaskAttr* pQueryAttr) {
|
|||
int32_t size = 0;
|
||||
|
||||
for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
|
||||
size += pQueryAttr->pExpr1[i].base.interBytes;
|
||||
// size += pQueryAttr->pExpr1[i].base.interBytes;
|
||||
}
|
||||
|
||||
assert(size >= 0);
|
||||
|
@ -172,9 +172,14 @@ SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_
|
|||
return (SResultRowEntryInfo*)((char*) pRow->pEntryInfo + offset[index]);
|
||||
}
|
||||
|
||||
size_t getResultRowSize(SArray* pExprInfo) {
|
||||
size_t numOfOutput = taosArrayGetSize(pExprInfo);
|
||||
return (numOfOutput * sizeof(SResultRowEntryInfo)) + /*pQueryAttr->interBufSize +*/ sizeof(SResultRow);
|
||||
size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||
int32_t rowSize = (numOfOutput * sizeof(SResultRowEntryInfo)) + sizeof(SResultRow);
|
||||
|
||||
for(int32_t i = 0; i < numOfOutput; ++i) {
|
||||
rowSize += pCtx[i].resDataInfo.interBufSize;
|
||||
}
|
||||
|
||||
return rowSize;
|
||||
}
|
||||
|
||||
SResultRowPool* initResultRowPool(size_t size) {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, char* id) {
|
||||
ASSERT(pOperator != NULL);
|
||||
if (pOperator->operatorType != OP_StreamScan) {
|
||||
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
if (pOperator->numOfDownstream == 0) {
|
||||
qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
|
@ -99,7 +99,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isA
|
|||
|
||||
// traverse to the streamscan node to add this table id
|
||||
SOperatorInfo* pInfo = pTaskInfo->pRoot;
|
||||
while (pInfo->operatorType != OP_StreamScan) {
|
||||
while(pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
pInfo = pInfo->pDownstream[0];
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -224,17 +224,40 @@ int main(int argc, char** argv) {
|
|||
|
||||
TEST(testCase, build_executor_tree_Test) {
|
||||
const char* msg = "{\n"
|
||||
" \"Type\": \"33\",\n"
|
||||
" \"NodeType\": \"48\",\n"
|
||||
" \"Name\": \"PhysiSubplan\",\n"
|
||||
" \"PhysiSubplan\": {\n"
|
||||
" \"Id\": {\n"
|
||||
" \"QueryId\": \"0\",\n"
|
||||
" \"TemplateId\": \"0\",\n"
|
||||
" \"SubplanId\": \"0\"\n"
|
||||
" },\n"
|
||||
" \"SubplanType\": \"0\",\n"
|
||||
" \"MsgType\": \"515\",\n"
|
||||
" \"Level\": \"0\",\n"
|
||||
" \"NodeAddr\": {\n"
|
||||
" \"Id\": \"1\",\n"
|
||||
" \"InUse\": \"0\",\n"
|
||||
" \"NumOfEps\": \"1\",\n"
|
||||
" \"Eps\": [\n"
|
||||
" {\n"
|
||||
" \"Fqdn\": \"node1\",\n"
|
||||
" \"Port\": \"6030\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" },\n"
|
||||
" \"RootNode\": {\n"
|
||||
" \"NodeType\": \"41\",\n"
|
||||
" \"Name\": \"PhysiProject\",\n"
|
||||
" \"PhysiProject\": {\n"
|
||||
" \"OutputDataBlockDesc\": {\n"
|
||||
" \"Type\": \"19\",\n"
|
||||
" \"NodeType\": \"19\",\n"
|
||||
" \"Name\": \"TupleDesc\",\n"
|
||||
" \"TupleDesc\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"Slots\": [\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"0\",\n"
|
||||
|
@ -249,7 +272,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"1\",\n"
|
||||
|
@ -264,7 +287,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"2\",\n"
|
||||
|
@ -279,7 +302,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"3\",\n"
|
||||
|
@ -294,7 +317,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"4\",\n"
|
||||
|
@ -309,7 +332,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"5\",\n"
|
||||
|
@ -328,17 +351,17 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" },\n"
|
||||
" \"Children\": [\n"
|
||||
" {\n"
|
||||
" \"Type\": \"30\",\n"
|
||||
" \"NodeType\": \"38\",\n"
|
||||
" \"Name\": \"PhysiTableScan\",\n"
|
||||
" \"PhysiTableScan\": {\n"
|
||||
" \"OutputDataBlockDesc\": {\n"
|
||||
" \"Type\": \"19\",\n"
|
||||
" \"NodeType\": \"19\",\n"
|
||||
" \"Name\": \"TupleDesc\",\n"
|
||||
" \"TupleDesc\": {\n"
|
||||
" \"DataBlockId\": \"0\",\n"
|
||||
" \"Slots\": [\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"0\",\n"
|
||||
|
@ -353,7 +376,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"1\",\n"
|
||||
|
@ -368,7 +391,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"2\",\n"
|
||||
|
@ -383,7 +406,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"3\",\n"
|
||||
|
@ -398,7 +421,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"4\",\n"
|
||||
|
@ -413,7 +436,7 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"20\",\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"5\",\n"
|
||||
|
@ -432,13 +455,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" },\n"
|
||||
" \"ScanCols\": [\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"0\",\n"
|
||||
" \"SlotId\": \"0\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -462,13 +485,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"0\",\n"
|
||||
" \"SlotId\": \"1\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -492,13 +515,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"0\",\n"
|
||||
" \"SlotId\": \"2\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -522,13 +545,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"0\",\n"
|
||||
" \"SlotId\": \"3\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -552,13 +575,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"0\",\n"
|
||||
" \"SlotId\": \"4\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -582,13 +605,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"0\",\n"
|
||||
" \"SlotId\": \"5\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -625,13 +648,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" ],\n"
|
||||
" \"Projections\": [\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"SlotId\": \"0\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -655,13 +678,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"SlotId\": \"1\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -685,13 +708,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"SlotId\": \"2\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -715,13 +738,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"SlotId\": \"3\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -745,13 +768,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"SlotId\": \"4\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -775,13 +798,13 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Type\": \"18\",\n"
|
||||
" \"NodeType\": \"18\",\n"
|
||||
" \"Name\": \"Target\",\n"
|
||||
" \"Target\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"SlotId\": \"5\",\n"
|
||||
" \"Expr\": {\n"
|
||||
" \"Type\": \"1\",\n"
|
||||
" \"NodeType\": \"1\",\n"
|
||||
" \"Name\": \"Column\",\n"
|
||||
" \"Column\": {\n"
|
||||
" \"DataType\": {\n"
|
||||
|
@ -806,18 +829,129 @@ TEST(testCase, build_executor_tree_Test) {
|
|||
" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" \"DataSink\": {\n"
|
||||
" \"NodeType\": \"46\",\n"
|
||||
" \"Name\": \"PhysiDispatch\",\n"
|
||||
" \"PhysiDispatch\": {\n"
|
||||
" \"InputDataBlockDesc\": {\n"
|
||||
" \"NodeType\": \"19\",\n"
|
||||
" \"Name\": \"TupleDesc\",\n"
|
||||
" \"TupleDesc\": {\n"
|
||||
" \"DataBlockId\": \"1\",\n"
|
||||
" \"Slots\": [\n"
|
||||
" {\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"0\",\n"
|
||||
" \"DataType\": {\n"
|
||||
" \"Type\": \"9\",\n"
|
||||
" \"Precision\": \"0\",\n"
|
||||
" \"Scale\": \"0\",\n"
|
||||
" \"Bytes\": \"8\"\n"
|
||||
" },\n"
|
||||
" \"Reserve\": false,\n"
|
||||
" \"Output\": false\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"1\",\n"
|
||||
" \"DataType\": {\n"
|
||||
" \"Type\": \"4\",\n"
|
||||
" \"Precision\": \"0\",\n"
|
||||
" \"Scale\": \"0\",\n"
|
||||
" \"Bytes\": \"4\"\n"
|
||||
" },\n"
|
||||
" \"Reserve\": false,\n"
|
||||
" \"Output\": false\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"2\",\n"
|
||||
" \"DataType\": {\n"
|
||||
" \"Type\": \"8\",\n"
|
||||
" \"Precision\": \"0\",\n"
|
||||
" \"Scale\": \"0\",\n"
|
||||
" \"Bytes\": \"20\"\n"
|
||||
" },\n"
|
||||
" \"Reserve\": false,\n"
|
||||
" \"Output\": false\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"3\",\n"
|
||||
" \"DataType\": {\n"
|
||||
" \"Type\": \"5\",\n"
|
||||
" \"Precision\": \"0\",\n"
|
||||
" \"Scale\": \"0\",\n"
|
||||
" \"Bytes\": \"8\"\n"
|
||||
" },\n"
|
||||
" \"Reserve\": false,\n"
|
||||
" \"Output\": false\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"4\",\n"
|
||||
" \"DataType\": {\n"
|
||||
" \"Type\": \"7\",\n"
|
||||
" \"Precision\": \"0\",\n"
|
||||
" \"Scale\": \"0\",\n"
|
||||
" \"Bytes\": \"8\"\n"
|
||||
" },\n"
|
||||
" \"Reserve\": false,\n"
|
||||
" \"Output\": false\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"NodeType\": \"20\",\n"
|
||||
" \"Name\": \"SlotDesc\",\n"
|
||||
" \"SlotDesc\": {\n"
|
||||
" \"SlotId\": \"5\",\n"
|
||||
" \"DataType\": {\n"
|
||||
" \"Type\": \"7\",\n"
|
||||
" \"Precision\": \"0\",\n"
|
||||
" \"Scale\": \"0\",\n"
|
||||
" \"Bytes\": \"8\"\n"
|
||||
" },\n"
|
||||
" \"Reserve\": false,\n"
|
||||
" \"Output\": false\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}";
|
||||
|
||||
SExecTaskInfo* pTaskInfo = nullptr;
|
||||
DataSinkHandle sinkHandle = nullptr;
|
||||
SReadHandle handle = {.reader = reinterpret_cast<void*>(0x1), .meta = reinterpret_cast<void*>(0x1)};
|
||||
|
||||
SSubplan* plan = NULL;
|
||||
qStringToSubplan(msg, &plan);
|
||||
struct SSubplan *plan = NULL;
|
||||
int32_t code = qStringToSubplan(msg, &plan);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
int32_t code = qCreateExecTask(&handle, 2, 1, NULL, (void**) &pTaskInfo, &sinkHandle);
|
||||
code = qCreateExecTask(&handle, 2, 1, plan, (void**) &pTaskInfo, &sinkHandle);
|
||||
ASSERT_EQ(code, 0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
TEST(testCase, inMem_sort_Test) {
|
||||
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
|
||||
SOrder o = {.order = TSDB_ORDER_ASC};
|
||||
|
@ -847,6 +981,8 @@ TEST(testCase, inMem_sort_Test) {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct su {
|
||||
int32_t v;
|
||||
char *c;
|
||||
|
@ -865,6 +1001,7 @@ int32_t cmp(const void* p1, const void* p2) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST(testCase, external_sort_Test) {
|
||||
#if 0
|
||||
su* v = static_cast<su*>(calloc(1000000, sizeof(su)));
|
||||
|
@ -1091,5 +1228,6 @@ TEST(testCase, time_interval_Operator_Test) {
|
|||
taosArrayDestroy(pExprInfo);
|
||||
taosArrayDestroy(pOrderVal);
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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 TDENGINE_BUILTINSIMPL_H
|
||||
#define TDENGINE_BUILTINSIMPL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "function.h"
|
||||
|
||||
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
void functionFinalizer(SqlFunctionCtx *pCtx);
|
||||
|
||||
bool getCountFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
void countFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
void sumFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
bool getMinmaxFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
void minFunction(SqlFunctionCtx* pCtx);
|
||||
void maxFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // TDENGINE_BUILTINSIMPL_H
|
|
@ -83,9 +83,7 @@ static FORCE_INLINE void initResultRowEntry(SResultRowEntryInfo *pResInfo, int32
|
|||
pResInfo->initialized = true; // the this struct has been initialized flag
|
||||
|
||||
pResInfo->complete = false;
|
||||
pResInfo->hasResult = false;
|
||||
pResInfo->numOfRes = 0;
|
||||
|
||||
memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
*/
|
||||
|
||||
#include "builtins.h"
|
||||
#include "builtinsimpl.h"
|
||||
#include "taoserror.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
int32_t stubCheckAndGetResultType(SFunctionNode* pFunc);
|
||||
|
||||
|
@ -24,20 +26,40 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.type = FUNCTION_TYPE_COUNT,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.processFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
.getEnvFunc = getCountFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = countFunction,
|
||||
.finalizeFunc = functionFinalizer
|
||||
},
|
||||
{
|
||||
.name = "sum",
|
||||
.type = FUNCTION_TYPE_SUM,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.processFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
.getEnvFunc = getSumFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = sumFunction,
|
||||
.finalizeFunc = functionFinalizer
|
||||
},
|
||||
{
|
||||
.name = "min",
|
||||
.type = FUNCTION_TYPE_MIN,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = minFunctionSetup,
|
||||
.processFunc = minFunction,
|
||||
.finalizeFunc = functionFinalizer
|
||||
},
|
||||
{
|
||||
.name = "max",
|
||||
.type = FUNCTION_TYPE_MAX,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalizer
|
||||
},
|
||||
{
|
||||
.name = "concat",
|
||||
|
@ -51,8 +73,44 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
}
|
||||
};
|
||||
|
||||
const int funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
|
||||
const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
|
||||
|
||||
int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
|
||||
switch(pFunc->funcType) {
|
||||
case FUNCTION_TYPE_COUNT:
|
||||
pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT};
|
||||
break;
|
||||
case FUNCTION_TYPE_SUM: {
|
||||
SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
int32_t paraType = pParam->node.resType.type;
|
||||
|
||||
int32_t resType = 0;
|
||||
if (IS_SIGNED_NUMERIC_TYPE(paraType)) {
|
||||
resType = TSDB_DATA_TYPE_BIGINT;
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) {
|
||||
resType = TSDB_DATA_TYPE_UBIGINT;
|
||||
} else if (IS_FLOAT_TYPE(paraType)) {
|
||||
resType = TSDB_DATA_TYPE_DOUBLE;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType };
|
||||
break;
|
||||
}
|
||||
case FUNCTION_TYPE_MIN:
|
||||
case FUNCTION_TYPE_MAX: {
|
||||
SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
int32_t paraType = pParam->node.resType.type;
|
||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType };
|
||||
break;
|
||||
}
|
||||
case FUNCTION_TYPE_CONCAT:
|
||||
// todo
|
||||
break;
|
||||
default:
|
||||
ASSERT(0); // to found the fault ASAP.
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,448 @@
|
|||
/*
|
||||
* 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 "builtinsimpl.h"
|
||||
#include "querynodes.h"
|
||||
#include "taggfunction.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
#define SET_VAL(_info, numOfElem, res) \
|
||||
do { \
|
||||
if ((numOfElem) <= 0) { \
|
||||
break; \
|
||||
} \
|
||||
(_info)->numOfRes = (res); \
|
||||
(_info)->hasResult = DATA_SET_FLAG; \
|
||||
} while (0)
|
||||
|
||||
typedef struct SSumRes {
|
||||
union {
|
||||
int64_t isum;
|
||||
uint64_t usum;
|
||||
double dsum;
|
||||
};
|
||||
} SSumRes;
|
||||
|
||||
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (pResultInfo->initialized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pCtx->pOutput != NULL) {
|
||||
memset(pCtx->pOutput, 0, (size_t)pCtx->resDataInfo.bytes);
|
||||
}
|
||||
|
||||
initResultRowEntry(pResultInfo, pCtx->resDataInfo.interBufSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void doFinalizer(SResultRowEntryInfo* pResInfo) { cleanupResultRowEntry(pResInfo); }
|
||||
|
||||
void functionFinalizer(SqlFunctionCtx *pCtx) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
if (pResInfo->hasResult != DATA_SET_FLAG) {
|
||||
// setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes);
|
||||
}
|
||||
|
||||
doFinalizer(pResInfo);
|
||||
}
|
||||
|
||||
bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(int64_t);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* count function does need the finalize, if data is missing, the default value, which is 0, is used
|
||||
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
|
||||
*/
|
||||
void countFunction(SqlFunctionCtx *pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
/*
|
||||
* 1. column data missing (schema modified) causes pCtx->hasNull == true. pCtx->isAggSet == true;
|
||||
* 2. for general non-primary key columns, pCtx->hasNull may be true or false, pCtx->isAggSet == true;
|
||||
* 3. for primary key column, pCtx->hasNull always be false, pCtx->isAggSet == false;
|
||||
*/
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
|
||||
if (pInput->colDataAggIsSet && pInput->totalRows == pInput->numOfRows) {
|
||||
numOfElem = pInput->numOfRows - pInput->pColumnDataAgg[0]->numOfNull;
|
||||
ASSERT(numOfElem >= 0);
|
||||
} else {
|
||||
if (pInputCol->hasNull) {
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
if (colDataIsNull(pInputCol, pInput->totalRows, i, NULL)) {
|
||||
continue;
|
||||
}
|
||||
numOfElem += 1;
|
||||
}
|
||||
} else {
|
||||
//when counting on the primary time stamp column and no statistics data is presented, use the size value directly.
|
||||
numOfElem = pInput->numOfRows;
|
||||
}
|
||||
}
|
||||
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
*((int64_t *)buf) += numOfElem;
|
||||
|
||||
SET_VAL(pResInfo, numOfElem, 1);
|
||||
}
|
||||
|
||||
#define LIST_ADD_N(_res, _col, _start, _rows, _t, numOfElem) \
|
||||
do { \
|
||||
_t *d = (_t *)(_col->pData); \
|
||||
for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \
|
||||
if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \
|
||||
continue; \
|
||||
}; \
|
||||
(_res) += (d)[i]; \
|
||||
(numOfElem)++; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void sumFunction(SqlFunctionCtx *pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
// Only the pre-computing information loaded and actual data does not loaded
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0];
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
SSumRes* pSumRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
||||
if (pInput->colDataAggIsSet) {
|
||||
numOfElem = pInput->numOfRows - pAgg->numOfNull;
|
||||
ASSERT(numOfElem >= 0);
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
pSumRes->isum += pAgg->sum;
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
pSumRes->usum += pAgg->sum;
|
||||
} else if (IS_FLOAT_TYPE(type)) {
|
||||
pSumRes->dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
|
||||
}
|
||||
} else { // computing based on the true data block
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
if (type == TSDB_DATA_TYPE_TINYINT) {
|
||||
LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int8_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_SMALLINT) {
|
||||
LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int16_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_INT) {
|
||||
LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int32_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_BIGINT) {
|
||||
LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int64_t, numOfElem);
|
||||
}
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
if (type == TSDB_DATA_TYPE_UTINYINT) {
|
||||
LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint8_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_USMALLINT) {
|
||||
LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint16_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_UINT) {
|
||||
LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint32_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_UBIGINT) {
|
||||
LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint64_t, numOfElem);
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
LIST_ADD_N(pSumRes->dsum, pCol, start, numOfRows, double, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
LIST_ADD_N(pSumRes->dsum, pCol, start, numOfRows, float, numOfElem);
|
||||
}
|
||||
}
|
||||
|
||||
// data in the check operation are all null, not output
|
||||
SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1);
|
||||
}
|
||||
|
||||
bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SSumRes);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (!functionSetup(pCtx, pResultInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResultInfo);
|
||||
switch (pCtx->resDataInfo.type) {
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
*((int32_t *)buf) = INT32_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
*((uint32_t *)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
*((float *)buf) = -FLT_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
SET_DOUBLE_VAL(((double *)buf), -DBL_MAX);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
*((int64_t *)buf) = INT64_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
*((uint64_t *)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
*((int16_t *)buf) = INT16_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
*((uint16_t *)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
*((int8_t *)buf) = INT8_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
*((uint8_t *)buf) = 0;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (!functionSetup(pCtx, pResultInfo)) {
|
||||
return false; // not initialized since it has been initialized
|
||||
}
|
||||
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResultInfo);
|
||||
switch (pCtx->resDataInfo.type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
*((int8_t *)buf) = INT8_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
*(uint8_t *) buf = UINT8_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
*((int16_t *)buf) = INT16_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
*((uint16_t *)buf) = UINT16_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
*((int32_t *)buf) = INT32_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
*((uint32_t *)buf) = UINT32_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
*((int64_t *)buf) = INT64_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
*((uint64_t *)buf) = UINT64_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
*((float *)buf) = FLT_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
SET_DOUBLE_VAL(((double *)buf), DBL_MAX);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getMinmaxFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
SNode* pNode = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
pEnv->calcMemSize = sizeof(int64_t);
|
||||
return true;
|
||||
}
|
||||
|
||||
#define GET_TS_LIST(x) ((TSKEY*)((x)->ptsList))
|
||||
#define GET_TS_DATA(x, y) (GET_TS_LIST(x)[(y)])
|
||||
|
||||
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
|
||||
do { \
|
||||
for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \
|
||||
SqlFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[_i]; \
|
||||
__ctx->fpSet.process(__ctx); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define DO_UPDATE_SUBSID_RES(ctx, ts) \
|
||||
do { \
|
||||
for (int32_t _i = 0; _i < (ctx)->subsidiaryRes.numOfCols; ++_i) { \
|
||||
SqlFunctionCtx *__ctx = (ctx)->subsidiaryRes.pCtx[_i]; \
|
||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { \
|
||||
__ctx->tag.i = (ts); \
|
||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
|
||||
} \
|
||||
__ctx->fpSet.process(__ctx); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define UPDATE_DATA(ctx, left, right, num, sign, _ts) \
|
||||
do { \
|
||||
if (((left) < (right)) ^ (sign)) { \
|
||||
(left) = (right); \
|
||||
DO_UPDATE_SUBSID_RES(ctx, _ts); \
|
||||
(num) += 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOOPCHECK_N(val, _col, ctx, _t, _nrow, _start, sign, num) \
|
||||
do { \
|
||||
_t* d = (_t*)((_col)->pData); \
|
||||
for (int32_t i = (_start); i < (_nrow) + (_start); ++i) { \
|
||||
if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \
|
||||
continue; \
|
||||
} \
|
||||
TSKEY ts = (ctx)->ptsList != NULL ? GET_TS_DATA(ctx, i) : 0; \
|
||||
UPDATE_DATA(ctx, val, d[i], num, sign, ts); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
||||
int32_t numOfElems = 0;
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0];
|
||||
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
int32_t type = pCol->info.type;
|
||||
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
// data in current data block are qualified to the query
|
||||
if (pInput->colDataAggIsSet) {
|
||||
numOfElems = pInput->numOfRows - pAgg->numOfNull;
|
||||
ASSERT(pInput->numOfRows == pInput->totalRows && numOfElems >= 0);
|
||||
|
||||
if (numOfElems == 0) {
|
||||
return numOfElems;
|
||||
}
|
||||
|
||||
void* tval = NULL;
|
||||
int16_t index = 0;
|
||||
|
||||
if (isMinFunc) {
|
||||
tval = &pInput->pColumnDataAgg[0]->min;
|
||||
index = pInput->pColumnDataAgg[0]->minIndex;
|
||||
} else {
|
||||
tval = &pInput->pColumnDataAgg[0]->max;
|
||||
index = pInput->pColumnDataAgg[0]->maxIndex;
|
||||
}
|
||||
|
||||
TSKEY key = TSKEY_INITIAL_VAL;
|
||||
if (pCtx->ptsList != NULL) {
|
||||
// the index is the original position, not the relative position
|
||||
key = pCtx->ptsList[index];
|
||||
}
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
int64_t val = GET_INT64_VAL(tval);
|
||||
|
||||
#if defined(_DEBUG_VIEW)
|
||||
qDebug("max value updated according to pre-cal:%d", *data);
|
||||
#endif
|
||||
|
||||
if ((*(int64_t*)buf < val) ^ isMinFunc) {
|
||||
*(int64_t*) buf = val;
|
||||
for (int32_t i = 0; i < (pCtx)->subsidiaryRes.numOfCols; ++i) {
|
||||
SqlFunctionCtx* __ctx = pCtx->subsidiaryRes.pCtx[i];
|
||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||
__ctx->tag.i = key;
|
||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||
}
|
||||
|
||||
__ctx->fpSet.process(__ctx);
|
||||
}
|
||||
}
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
uint64_t val = GET_UINT64_VAL(tval);
|
||||
UPDATE_DATA(pCtx, *(uint64_t*)buf, val, numOfElems, isMinFunc, key);
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double val = GET_DOUBLE_VAL(tval);
|
||||
UPDATE_DATA(pCtx, *(double*)buf, val, numOfElems, isMinFunc, key);
|
||||
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
double val = GET_DOUBLE_VAL(tval);
|
||||
UPDATE_DATA(pCtx, *(float*)buf, (float)val, numOfElems, isMinFunc, key);
|
||||
}
|
||||
|
||||
return numOfElems;
|
||||
}
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
if (type == TSDB_DATA_TYPE_TINYINT) {
|
||||
LOOPCHECK_N(*(int8_t*)buf, pCol, pCtx, int8_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_SMALLINT) {
|
||||
LOOPCHECK_N(*(int16_t*) buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_INT) {
|
||||
int32_t *pData = (int32_t*)pCol->pData;
|
||||
int32_t *val = (int32_t*) buf;
|
||||
|
||||
for (int32_t i = 0; i < pCtx->size; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
TSKEY ts = (pCtx->ptsList != NULL)? GET_TS_DATA(pCtx, i) : 0;
|
||||
DO_UPDATE_SUBSID_RES(pCtx, ts);
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
|
||||
#if defined(_DEBUG_VIEW)
|
||||
qDebug("max value updated:%d", *retVal);
|
||||
#endif
|
||||
} else if (type == TSDB_DATA_TYPE_BIGINT) {
|
||||
LOOPCHECK_N(*(int64_t*) buf, pCol, pCtx, int64_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
}
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
if (type == TSDB_DATA_TYPE_UTINYINT) {
|
||||
LOOPCHECK_N(*(uint8_t*) buf, pCol, pCtx, uint8_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_USMALLINT) {
|
||||
LOOPCHECK_N(*(uint16_t*) buf, pCol, pCtx, uint16_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_UINT) {
|
||||
LOOPCHECK_N(*(uint32_t*) buf, pCol, pCtx, uint32_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_UBIGINT) {
|
||||
LOOPCHECK_N(*(uint64_t*) buf, pCol, pCtx, uint64_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
LOOPCHECK_N(*(double*) buf, pCol, pCtx, double, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
LOOPCHECK_N(*(float*) buf, pCol, pCtx, float, numOfRows, start, isMinFunc, numOfElems);
|
||||
}
|
||||
|
||||
return numOfElems;
|
||||
}
|
||||
|
||||
void minFunction(SqlFunctionCtx *pCtx) {
|
||||
int32_t numOfElems = doMinMaxHelper(pCtx, 1);
|
||||
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
|
||||
}
|
||||
|
||||
void maxFunction(SqlFunctionCtx *pCtx) {
|
||||
int32_t numOfElems = doMinMaxHelper(pCtx, 0);
|
||||
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
|
||||
}
|
|
@ -26,18 +26,27 @@ typedef struct SFuncMgtService {
|
|||
} SFuncMgtService;
|
||||
|
||||
static SFuncMgtService gFunMgtService;
|
||||
static pthread_once_t functionHashTableInit = PTHREAD_ONCE_INIT;
|
||||
static int32_t initFunctionCode = 0;
|
||||
|
||||
int32_t fmFuncMgtInit() {
|
||||
static void doInitFunctionHashTable() {
|
||||
gFunMgtService.pFuncNameHashTable = taosHashInit(funcMgtBuiltinsNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
if (NULL == gFunMgtService.pFuncNameHashTable) {
|
||||
return TSDB_CODE_FAILED;
|
||||
initFunctionCode = TSDB_CODE_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
|
||||
if (TSDB_CODE_SUCCESS != taosHashPut(gFunMgtService.pFuncNameHashTable, funcMgtBuiltins[i].name, strlen(funcMgtBuiltins[i].name), &i, sizeof(int32_t))) {
|
||||
return TSDB_CODE_FAILED;
|
||||
initFunctionCode = TSDB_CODE_FAILED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t fmFuncMgtInit() {
|
||||
pthread_once(&functionHashTableInit, doInitFunctionHashTable);
|
||||
return initFunctionCode;
|
||||
}
|
||||
|
||||
int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) {
|
||||
|
@ -85,3 +94,10 @@ bool fmIsAggFunc(int32_t funcId) {
|
|||
}
|
||||
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, FUNC_MGT_AGG_FUNC);
|
||||
}
|
||||
|
||||
void fmFuncMgtDestroy() {
|
||||
void* m = gFunMgtService.pFuncNameHashTable;
|
||||
if (m != NULL && atomic_val_compare_exchange_ptr(&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
||||
taosHashCleanup(m);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -543,7 +543,7 @@ struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, co
|
|||
pFillCol[i].col.offset = offset;
|
||||
pFillCol[i].col.colId = pExprInfo->base.resSchema.colId;
|
||||
pFillCol[i].tagIndex = -2;
|
||||
pFillCol[i].flag = pExprInfo->base.pColumns->flag; // always be the normal column for table query
|
||||
pFillCol[i].flag = pExprInfo->base.pParam[0].pCol->flag; // always be the normal column for table query
|
||||
// pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId;
|
||||
pFillCol[i].fillVal.i = fillVal[i];
|
||||
|
||||
|
|
|
@ -341,6 +341,8 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
|
|||
// TODO: iterator mem and tidex
|
||||
STermValueType s = kTypeValue;
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
SIdxTempResult* tr = sIdxTempResultCreate();
|
||||
if (0 == indexCacheSearch(cache, query, tr, &s)) {
|
||||
if (s == kTypeDeletion) {
|
||||
|
@ -348,17 +350,23 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
|
|||
// coloum already drop by other oper, no need to query tindex
|
||||
return 0;
|
||||
} else {
|
||||
st = taosGetTimestampUs();
|
||||
if (0 != indexTFileSearch(sIdx->tindex, query, tr)) {
|
||||
indexError("corrupt at index(TFile) col:%s val: %s", term->colName, term->colVal);
|
||||
goto END;
|
||||
}
|
||||
int64_t tfCost = taosGetTimestampUs() - st;
|
||||
indexInfo("tfile search cost: %" PRIu64 "us", tfCost);
|
||||
}
|
||||
} else {
|
||||
indexError("corrupt at index(cache) col:%s val: %s", term->colName, term->colVal);
|
||||
goto END;
|
||||
}
|
||||
int64_t cost = taosGetTimestampUs() - st;
|
||||
indexInfo("search cost: %" PRIu64 "us", cost);
|
||||
|
||||
sIdxTempResultMergeTo(*result, tr);
|
||||
|
||||
sIdxTempResultDestroy(tr);
|
||||
return 0;
|
||||
END:
|
||||
|
|
|
@ -276,7 +276,12 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SI
|
|||
} else if (c->operaType == DEL_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->added, tr->deled, c->uid)
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if (qtype == QUERY_PREFIX) {
|
||||
} else if (qtype == QUERY_SUFFIX) {
|
||||
} else if (qtype == QUERY_RANGE) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -284,6 +289,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SI
|
|||
return 0;
|
||||
}
|
||||
int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result, STermValueType* s) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
if (cache == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -312,12 +318,14 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result
|
|||
// continue search in imm
|
||||
ret = indexQueryMem(imm, &ct, qtype, result, s);
|
||||
}
|
||||
|
||||
if (hasJson) {
|
||||
tfree(p);
|
||||
}
|
||||
|
||||
indexMemUnRef(mem);
|
||||
indexMemUnRef(imm);
|
||||
indexInfo("cache search, time cost %" PRIu64 "us", taosGetTimestampUs() - st);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul
|
|||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON);
|
||||
EIndexQueryType qtype = query->qType;
|
||||
|
||||
SArray* result = taosArrayInit(16, sizeof(uint64_t));
|
||||
// SArray* result = taosArrayInit(16, sizeof(uint64_t));
|
||||
int ret = -1;
|
||||
// refactor to callback later
|
||||
if (qtype == QUERY_TERM) {
|
||||
|
@ -200,11 +200,18 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul
|
|||
p = indexPackJsonData(term);
|
||||
sz = strlen(p);
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
if (fstGet(reader->fst, &key, &offset)) {
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex", term->suid, term->colName,
|
||||
term->colVal);
|
||||
ret = tfileReaderLoadTableIds(reader, offset, result);
|
||||
int64_t et = taosGetTimestampUs();
|
||||
int64_t cost = et - st;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
||||
term->suid, term->colName, term->colVal, cost);
|
||||
|
||||
ret = tfileReaderLoadTableIds(reader, offset, tr->total);
|
||||
cost = taosGetTimestampUs() - et;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", term->suid,
|
||||
term->colName, term->colVal, cost);
|
||||
} else {
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName,
|
||||
term->colVal);
|
||||
|
@ -225,8 +232,8 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul
|
|||
}
|
||||
tfileReaderUnRef(reader);
|
||||
|
||||
taosArrayAddAll(tr->total, result);
|
||||
taosArrayDestroy(result);
|
||||
// taosArrayAddAll(tr->total, result);
|
||||
// taosArrayDestroy(result);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -391,6 +398,7 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTempResult* result
|
|||
return ret;
|
||||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
IndexTFile* pTfile = tfile;
|
||||
|
||||
SIndexTerm* term = query->term;
|
||||
|
@ -399,6 +407,8 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTempResult* result
|
|||
if (reader == NULL) {
|
||||
return 0;
|
||||
}
|
||||
int64_t cost = taosGetTimestampUs() - st;
|
||||
indexInfo("index tfile stage 1 cost: %" PRId64 "", cost);
|
||||
|
||||
return tfileReaderSearch(reader, query, result);
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ void checkFstCheckIterator() {
|
|||
// prefix search
|
||||
std::vector<uint64_t> result;
|
||||
|
||||
AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
|
||||
AutomationCtx* ctx = automCtxCreate((void*)"H", AUTOMATION_PREFIX);
|
||||
m->Search(ctx, result);
|
||||
std::cout << "size: " << result.size() << std::endl;
|
||||
// assert(result.size() == count);
|
||||
|
@ -328,11 +328,11 @@ void iterTFileReader(char* path, char* uid, char* colName, char* ver) {
|
|||
int main(int argc, char* argv[]) {
|
||||
// tool to check all kind of fst test
|
||||
// if (argc > 1) { validateTFile(argv[1]); }
|
||||
if (argc > 4) {
|
||||
// if (argc > 4) {
|
||||
// path suid colName ver
|
||||
iterTFileReader(argv[1], argv[2], argv[3], argv[4]);
|
||||
}
|
||||
// checkFstCheckIterator();
|
||||
// iterTFileReader(argv[1], argv[2], argv[3], argv[4]);
|
||||
//}
|
||||
checkFstCheckIterator();
|
||||
// checkFstLongTerm();
|
||||
// checkFstPrefixSearch();
|
||||
|
||||
|
|
|
@ -768,7 +768,7 @@ class IndexObj {
|
|||
int64_t s = taosGetTimestampUs();
|
||||
if (Search(mq, result) == 0) {
|
||||
int64_t e = taosGetTimestampUs();
|
||||
std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName
|
||||
std::cout << "search one successfully and time cost:" << e - s << "us\tquery col:" << colName
|
||||
<< "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl;
|
||||
} else {
|
||||
}
|
||||
|
@ -1106,6 +1106,7 @@ TEST_F(IndexEnv2, testIndex_del) {
|
|||
}
|
||||
index->Del("tag10", "Hello", 12);
|
||||
index->Del("tag10", "Hello", 11);
|
||||
EXPECT_EQ(98, index->SearchOne("tag10", "Hello"));
|
||||
|
||||
index->WriteMultiMillonData("tag10", "xxxxxxxxxxxxxx", 100 * 10000);
|
||||
index->Del("tag10", "Hello", 17);
|
||||
|
|
|
@ -13,26 +13,22 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_NODES_SHOW_STMTS_H_
|
||||
#define _TD_NODES_SHOW_STMTS_H_
|
||||
#ifndef _TD_NODES_INT_H_
|
||||
#define _TD_NODES_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
typedef enum EShowStmtType {
|
||||
SHOW_TYPE_DATABASE = 1
|
||||
} EShowStmtType;
|
||||
|
||||
typedef struct SShowStmt {
|
||||
ENodeType type; // QUERY_NODE_SHOW_STMT
|
||||
EShowStmtType showType;
|
||||
} SShowStmt;
|
||||
#define nodesFatal(param, ...) qFatal("NODES: " param, __VA_ARGS__)
|
||||
#define nodesError(param, ...) qError("NODES: " param, __VA_ARGS__)
|
||||
#define nodesWarn(param, ...) qWarn("NODES: " param, __VA_ARGS__)
|
||||
#define nodesInfo(param, ...) qInfo("NODES: " param, __VA_ARGS__)
|
||||
#define nodesDebug(param, ...) qDebug("NODES: " param, __VA_ARGS__)
|
||||
#define nodesTrace(param, ...) qTrace("NODES: " param, __VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_NODES_SHOW_STMTS_H_*/
|
||||
#endif /*_TD_NODES_INT_H_*/
|
|
@ -13,6 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nodesUtil.h"
|
||||
#include "plannodes.h"
|
||||
#include "querynodes.h"
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
|
@ -32,8 +34,11 @@
|
|||
(pDst)->fldname = strdup((pSrc)->fldname); \
|
||||
} while (0)
|
||||
|
||||
#define COPY_NODE_FIELD(fldname) \
|
||||
#define CLONE_NODE_FIELD(fldname) \
|
||||
do { \
|
||||
if (NULL == (pSrc)->fldname) { \
|
||||
break; \
|
||||
} \
|
||||
(pDst)->fldname = nodesCloneNode((pSrc)->fldname); \
|
||||
if (NULL == (pDst)->fldname) { \
|
||||
nodesDestroyNode((SNode*)(pDst)); \
|
||||
|
@ -41,8 +46,11 @@
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define COPY_NODE_LIST_FIELD(fldname) \
|
||||
#define CLONE_NODE_LIST_FIELD(fldname) \
|
||||
do { \
|
||||
if (NULL == (pSrc)->fldname) { \
|
||||
break; \
|
||||
} \
|
||||
(pDst)->fldname = nodesCloneList((pSrc)->fldname); \
|
||||
if (NULL == (pDst)->fldname) { \
|
||||
nodesDestroyNode((SNode*)(pDst)); \
|
||||
|
@ -50,6 +58,25 @@
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \
|
||||
do { \
|
||||
if (NULL == (pSrc)->fldname) { \
|
||||
break; \
|
||||
} \
|
||||
(pDst)->fldname = cloneFunc((pSrc)->fldname); \
|
||||
if (NULL == (pDst)->fldname) { \
|
||||
nodesDestroyNode((SNode*)(pDst)); \
|
||||
return NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \
|
||||
do { \
|
||||
if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \
|
||||
return NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) {
|
||||
COPY_SCALAR_FIELD(type);
|
||||
COPY_SCALAR_FIELD(precision);
|
||||
|
@ -60,7 +87,7 @@ static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) {
|
|||
static void exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) {
|
||||
dataTypeCopy(&pSrc->resType, &pDst->resType);
|
||||
COPY_CHAR_ARRAY_FIELD(aliasName);
|
||||
// COPY_NODE_LIST_FIELD(pAssociationList);
|
||||
// CLONE_NODE_LIST_FIELD(pAssociationList);
|
||||
}
|
||||
|
||||
static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
|
||||
|
@ -71,7 +98,7 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
|
|||
COPY_CHAR_ARRAY_FIELD(tableName);
|
||||
COPY_CHAR_ARRAY_FIELD(tableAlias);
|
||||
COPY_CHAR_ARRAY_FIELD(colName);
|
||||
// COPY_NODE_FIELD(pProjectRef);
|
||||
// CLONE_NODE_FIELD(pProjectRef);
|
||||
COPY_SCALAR_FIELD(dataBlockId);
|
||||
COPY_SCALAR_FIELD(slotId);
|
||||
return (SNode*)pDst;
|
||||
|
@ -104,7 +131,6 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
COPY_SCALAR_FIELD(datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
|
@ -123,15 +149,15 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
|
|||
static SNode* operatorNodeCopy(const SOperatorNode* pSrc, SOperatorNode* pDst) {
|
||||
exprNodeCopy((const SExprNode*)pSrc, (SExprNode*)pDst);
|
||||
COPY_SCALAR_FIELD(opType);
|
||||
COPY_NODE_FIELD(pLeft);
|
||||
COPY_NODE_FIELD(pRight);
|
||||
CLONE_NODE_FIELD(pLeft);
|
||||
CLONE_NODE_FIELD(pRight);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicConditionNodeCopy(const SLogicConditionNode* pSrc, SLogicConditionNode* pDst) {
|
||||
exprNodeCopy((const SExprNode*)pSrc, (SExprNode*)pDst);
|
||||
COPY_SCALAR_FIELD(condType);
|
||||
COPY_NODE_LIST_FIELD(pParameterList);
|
||||
CLONE_NODE_LIST_FIELD(pParameterList);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -140,24 +166,119 @@ static SNode* functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) {
|
|||
COPY_CHAR_ARRAY_FIELD(functionName);
|
||||
COPY_SCALAR_FIELD(funcId);
|
||||
COPY_SCALAR_FIELD(funcType);
|
||||
COPY_NODE_LIST_FIELD(pParameterList);
|
||||
CLONE_NODE_LIST_FIELD(pParameterList);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) {
|
||||
COPY_SCALAR_FIELD(dataBlockId);
|
||||
COPY_SCALAR_FIELD(slotId);
|
||||
COPY_NODE_FIELD(pExpr);
|
||||
CLONE_NODE_FIELD(pExpr);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode* pDst) {
|
||||
COPY_SCALAR_FIELD(groupingSetType);
|
||||
COPY_NODE_LIST_FIELD(pParameterList);
|
||||
CLONE_NODE_LIST_FIELD(pParameterList);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
SNode* nodesCloneNode(const SNode* pNode) {
|
||||
static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
|
||||
COPY_SCALAR_FIELD(id);
|
||||
CLONE_NODE_LIST_FIELD(pTargets);
|
||||
CLONE_NODE_FIELD(pConditions);
|
||||
CLONE_NODE_LIST_FIELD(pChildren);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static STableMeta* tableMetaClone(const STableMeta* pSrc) {
|
||||
int32_t len = sizeof(STableMeta) + (pSrc->tableInfo.numOfTags + pSrc->tableInfo.numOfColumns) * sizeof(SSchema);
|
||||
STableMeta* pDst = malloc(len);
|
||||
if (NULL == pDst) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(pDst, pSrc, len);
|
||||
return pDst;
|
||||
}
|
||||
|
||||
static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) {
|
||||
int32_t len = sizeof(SVgroupsInfo) + pSrc->numOfVgroups * sizeof(SVgroupInfo);
|
||||
SVgroupsInfo* pDst = malloc(len);
|
||||
if (NULL == pDst) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(pDst, pSrc, len);
|
||||
return pDst;
|
||||
}
|
||||
|
||||
static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pScanCols);
|
||||
CLONE_OBJECT_FIELD(pMeta, tableMetaClone);
|
||||
CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone);
|
||||
COPY_SCALAR_FIELD(scanType);
|
||||
COPY_SCALAR_FIELD(scanFlag);
|
||||
COPY_SCALAR_FIELD(scanRange);
|
||||
COPY_SCALAR_FIELD(tableName);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pGroupKeys);
|
||||
CLONE_NODE_LIST_FIELD(pAggFuncs);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pProjections);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicVnodeModifCopy(const SVnodeModifLogicNode* pSrc, SVnodeModifLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
COPY_SCALAR_FIELD(msgType);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
COPY_SCALAR_FIELD(srcGroupId);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicSubplanCopy(const SSubLogicPlan* pSrc, SSubLogicPlan* pDst) {
|
||||
CLONE_NODE_FIELD(pNode);
|
||||
COPY_SCALAR_FIELD(subplanType);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) {
|
||||
COPY_SCALAR_FIELD(dataBlockId);
|
||||
CLONE_NODE_LIST_FIELD(pSlots);
|
||||
COPY_SCALAR_FIELD(resultRowSize);
|
||||
COPY_SCALAR_FIELD(precision);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) {
|
||||
COPY_SCALAR_FIELD(slotId);
|
||||
dataTypeCopy(&pSrc->dataType, &pDst->dataType);
|
||||
COPY_SCALAR_FIELD(reserve);
|
||||
COPY_SCALAR_FIELD(output);
|
||||
COPY_SCALAR_FIELD(tag);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* downstreamSourceCopy(const SDownstreamSourceNode* pSrc, SDownstreamSourceNode* pDst) {
|
||||
COPY_SCALAR_FIELD(addr);
|
||||
COPY_SCALAR_FIELD(taskId);
|
||||
COPY_SCALAR_FIELD(schedId);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
SNodeptr nodesCloneNode(const SNodeptr pNode) {
|
||||
if (NULL == pNode) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -187,10 +308,31 @@ SNode* nodesCloneNode(const SNode* pNode) {
|
|||
return groupingSetNodeCopy((const SGroupingSetNode*)pNode, (SGroupingSetNode*)pDst);
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
case QUERY_NODE_LIMIT:
|
||||
break;
|
||||
case QUERY_NODE_DATABLOCK_DESC:
|
||||
return dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst);
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst);
|
||||
case QUERY_NODE_DOWNSTREAM_SOURCE:
|
||||
return downstreamSourceCopy((const SDownstreamSourceNode*)pNode, (SDownstreamSourceNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_AGG:
|
||||
return logicAggCopy((const SAggLogicNode*)pNode, (SAggLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_PROJECT:
|
||||
return logicProjectCopy((const SProjectLogicNode*)pNode, (SProjectLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
|
||||
return logicVnodeModifCopy((const SVnodeModifLogicNode*)pNode, (SVnodeModifLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
|
||||
return logicExchangeCopy((const SExchangeLogicNode*)pNode, (SExchangeLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return logicSubplanCopy((const SSubLogicPlan*)pNode, (SSubLogicPlan*)pDst);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return pDst;
|
||||
nodesDestroyNode(pDst);
|
||||
nodesError("nodesCloneNode unknown node = %s", nodesNodeName(nodeType(pNode)));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SNodeList* nodesCloneList(const SNodeList* pList) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nodesUtil.h"
|
||||
#include "plannodes.h"
|
||||
#include "querynodes.h"
|
||||
#include "query.h"
|
||||
|
@ -24,7 +25,7 @@ static int32_t jsonToNode(const SJson* pJson, void* pObj);
|
|||
static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** pNode);
|
||||
static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode);
|
||||
|
||||
static char* nodeName(ENodeType type) {
|
||||
const char* nodesNodeName(ENodeType type) {
|
||||
switch (type) {
|
||||
case QUERY_NODE_COLUMN:
|
||||
return "Column";
|
||||
|
@ -58,20 +59,32 @@ static char* nodeName(ENodeType type) {
|
|||
return "NodeList";
|
||||
case QUERY_NODE_FILL:
|
||||
return "Fill";
|
||||
case QUERY_NODE_TARGET:
|
||||
return "Target";
|
||||
case QUERY_NODE_RAW_EXPR:
|
||||
return "RawExpr";
|
||||
case QUERY_NODE_TARGET:
|
||||
return "Target";
|
||||
case QUERY_NODE_DATABLOCK_DESC:
|
||||
return "TupleDesc";
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return "SlotDesc";
|
||||
case QUERY_NODE_COLUMN_DEF:
|
||||
return "ColumnDef";
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
return "SetOperator";
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return "SelectStmt";
|
||||
case QUERY_NODE_SHOW_STMT:
|
||||
return "ShowStmt";
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
return "VnodeModifStmt";
|
||||
case QUERY_NODE_CREATE_DATABASE_STMT:
|
||||
return "CreateDatabaseStmt";
|
||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||
return "CreateTableStmt";
|
||||
case QUERY_NODE_USE_DATABASE_STMT:
|
||||
return "UseDatabaseStmt";
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
return "ShowDatabaseStmt";
|
||||
case QUERY_NODE_SHOW_TABLES_STMT:
|
||||
return "ShowTablesStmt";
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return "LogicScan";
|
||||
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
|
@ -80,22 +93,43 @@ static char* nodeName(ENodeType type) {
|
|||
return "LogicAgg";
|
||||
case QUERY_NODE_LOGIC_PLAN_PROJECT:
|
||||
return "LogicProject";
|
||||
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
|
||||
return "LogicVnodeModif";
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return "LogicSubplan";
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
return "LogicPlan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
||||
return "PhysiTagScan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
||||
return "PhysiTableScan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
||||
return "PhysiTableSeqScan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
||||
return "PhysiSreamScan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return "PhysiProject";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_JOIN:
|
||||
return "PhysiJoin";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_AGG:
|
||||
return "PhysiAgg";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return "PhysiExchange";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return "PhysiSort";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return "PhysiDispatch";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||
return "PhysiInsert";
|
||||
case QUERY_NODE_PHYSICAL_SUBPLAN:
|
||||
return "PhysiSubplan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN:
|
||||
return "PhysiPlan";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
static char tmp[20];
|
||||
snprintf(tmp, sizeof(tmp), "Unknown %d", type);
|
||||
return tmp;
|
||||
nodesWarn("nodesNodeName unknown node = %d", type);
|
||||
return "UnknownNode";
|
||||
}
|
||||
|
||||
static int32_t nodeListToJson(SJson* pJson, const char* pName, const SNodeList* pList) {
|
||||
|
@ -230,7 +264,7 @@ static const char* jkPhysiPlanChildren = "Children";
|
|||
static int32_t physicPlanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SPhysiNode* pNode = (const SPhysiNode*)pObj;
|
||||
|
||||
int32_t code = tjsonAddObject(pJson, jkPhysiPlanOutputDataBlockDesc, nodeToJson, &pNode->outputDataBlockDesc);
|
||||
int32_t code = tjsonAddObject(pJson, jkPhysiPlanOutputDataBlockDesc, nodeToJson, pNode->pOutputDataBlockDesc);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkPhysiPlanConditions, nodeToJson, pNode->pConditions);
|
||||
}
|
||||
|
@ -244,7 +278,7 @@ static int32_t physicPlanNodeToJson(const void* pObj, SJson* pJson) {
|
|||
static int32_t jsonToPhysicPlanNode(const SJson* pJson, void* pObj) {
|
||||
SPhysiNode* pNode = (SPhysiNode*)pObj;
|
||||
|
||||
int32_t code = tjsonToObject(pJson, jkPhysiPlanOutputDataBlockDesc, jsonToNode, &pNode->outputDataBlockDesc);
|
||||
int32_t code = jsonToNodeObject(pJson, jkPhysiPlanOutputDataBlockDesc, (SNode**)&pNode->pOutputDataBlockDesc);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkPhysiPlanConditions, &pNode->pConditions);
|
||||
}
|
||||
|
@ -255,12 +289,52 @@ static int32_t jsonToPhysicPlanNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkNameType = "NameType";
|
||||
static const char* jkNameAcctId = "AcctId";
|
||||
static const char* jkNameDbName = "DbName";
|
||||
static const char* jkNameTableName = "TableName";
|
||||
|
||||
static int32_t nameToJson(const void* pObj, SJson* pJson) {
|
||||
const SName* pNode = (const SName*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkNameType, pNode->type);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkNameAcctId, pNode->acctId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkNameDbName, pNode->dbname);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkNameTableName, pNode->tname);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToName(const SJson* pJson, void* pObj) {
|
||||
SName* pNode = (SName*)pObj;
|
||||
|
||||
int32_t code = tjsonGetUTinyIntValue(pJson, jkNameType, &pNode->type);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkNameAcctId, &pNode->acctId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkNameDbName, pNode->dbname);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkNameTableName, pNode->tname);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkScanPhysiPlanScanCols = "ScanCols";
|
||||
static const char* jkScanPhysiPlanTableId = "TableId";
|
||||
static const char* jkScanPhysiPlanTableType = "TableType";
|
||||
static const char* jkScanPhysiPlanScanOrder = "ScanOrder";
|
||||
static const char* jkScanPhysiPlanScanCount = "ScanCount";
|
||||
static const char* jkScanPhysiPlanReverseScanCount = "ReverseScanCount";
|
||||
static const char* jkScanPhysiPlanTableName = "TableName";
|
||||
|
||||
static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const STagScanPhysiNode* pNode = (const STagScanPhysiNode*)pObj;
|
||||
|
@ -284,6 +358,9 @@ static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanReverseScanCount, pNode->reverse);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkScanPhysiPlanTableName, nameToJson, &pNode->tableName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -310,6 +387,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkScanPhysiPlanReverseScanCount, &pNode->reverse);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, jkScanPhysiPlanTableName, jsonToName, &pNode->tableName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -462,6 +542,247 @@ static int32_t jsonToPhysiAggNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkExchangePhysiPlanSrcGroupId = "SrcGroupId";
|
||||
static const char* jkExchangePhysiPlanSrcEndPoints = "SrcEndPoints";
|
||||
|
||||
static int32_t physiExchangeNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SExchangePhysiNode* pNode = (const SExchangePhysiNode*)pObj;
|
||||
|
||||
int32_t code = physicPlanNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkExchangePhysiPlanSrcGroupId, pNode->srcGroupId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkExchangePhysiPlanSrcEndPoints, pNode->pSrcEndPoints);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) {
|
||||
SExchangePhysiNode* pNode = (SExchangePhysiNode*)pObj;
|
||||
|
||||
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkExchangePhysiPlanSrcGroupId, &pNode->srcGroupId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkExchangePhysiPlanSrcEndPoints, &pNode->pSrcEndPoints);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkDataSinkInputDataBlockDesc = "InputDataBlockDesc";
|
||||
|
||||
static int32_t physicDataSinkNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SDataSinkNode* pNode = (const SDataSinkNode*)pObj;
|
||||
return tjsonAddObject(pJson, jkDataSinkInputDataBlockDesc, nodeToJson, pNode->pInputDataBlockDesc);
|
||||
}
|
||||
|
||||
static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) {
|
||||
SDataSinkNode* pNode = (SDataSinkNode*)pObj;
|
||||
return jsonToNodeObject(pJson, jkDataSinkInputDataBlockDesc, (SNode**)&pNode->pInputDataBlockDesc);
|
||||
}
|
||||
|
||||
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 const char* jkSubplanIdQueryId = "QueryId";
|
||||
static const char* jkSubplanIdGroupId = "GroupId";
|
||||
static const char* jkSubplanIdSubplanId = "SubplanId";
|
||||
|
||||
static int32_t subplanIdToJson(const void* pObj, SJson* pJson) {
|
||||
const SSubplanId* pNode = (const SSubplanId*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkSubplanIdQueryId, pNode->queryId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkSubplanIdGroupId, pNode->groupId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkSubplanIdSubplanId, pNode->subplanId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToSubplanId(const SJson* pJson, void* pObj) {
|
||||
SSubplanId* pNode = (SSubplanId*)pObj;
|
||||
|
||||
int32_t code = tjsonGetUBigIntValue(pJson, jkSubplanIdQueryId, &pNode->queryId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkSubplanIdGroupId, &pNode->groupId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkSubplanIdSubplanId, &pNode->subplanId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkEndPointFqdn = "Fqdn";
|
||||
static const char* jkEndPointPort = "Port";
|
||||
|
||||
static int32_t epToJson(const void* pObj, SJson* pJson) {
|
||||
const SEp* pNode = (const SEp*)pObj;
|
||||
|
||||
int32_t code = tjsonAddStringToObject(pJson, jkEndPointFqdn, pNode->fqdn);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkEndPointPort, pNode->port);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToEp(const SJson* pJson, void* pObj) {
|
||||
SEp* pNode = (SEp*)pObj;
|
||||
|
||||
int32_t code = tjsonGetStringValue(pJson, jkEndPointFqdn, pNode->fqdn);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetSmallIntValue(pJson, jkEndPointPort, &pNode->port);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkQueryNodeAddrId = "Id";
|
||||
static const char* jkQueryNodeAddrInUse = "InUse";
|
||||
static const char* jkQueryNodeAddrNumOfEps = "NumOfEps";
|
||||
static const char* jkQueryNodeAddrEps = "Eps";
|
||||
|
||||
static int32_t queryNodeAddrToJson(const void* pObj, SJson* pJson) {
|
||||
const SQueryNodeAddr* pNode = (const SQueryNodeAddr*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrId, pNode->nodeId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrInUse, pNode->epSet.inUse);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrNumOfEps, pNode->epSet.numOfEps);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddArray(pJson, jkQueryNodeAddrEps, epToJson, pNode->epSet.eps, sizeof(SEp), pNode->epSet.numOfEps);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToQueryNodeAddr(const SJson* pJson, void* pObj) {
|
||||
SQueryNodeAddr* pNode = (SQueryNodeAddr*)pObj;
|
||||
|
||||
int32_t code = tjsonGetIntValue(pJson, jkQueryNodeAddrId, &pNode->nodeId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrInUse, &pNode->epSet.inUse);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrNumOfEps, &pNode->epSet.numOfEps);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToArray(pJson, jkQueryNodeAddrEps, jsonToEp, pNode->epSet.eps, sizeof(SEp));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkSubplanId = "Id";
|
||||
static const char* jkSubplanType = "SubplanType";
|
||||
static const char* jkSubplanMsgType = "MsgType";
|
||||
static const char* jkSubplanLevel = "Level";
|
||||
static const char* jkSubplanNodeAddr = "NodeAddr";
|
||||
static const char* jkSubplanRootNode = "RootNode";
|
||||
static const char* jkSubplanDataSink = "DataSink";
|
||||
|
||||
static int32_t subplanToJson(const void* pObj, SJson* pJson) {
|
||||
const SSubplan* pNode = (const SSubplan*)pObj;
|
||||
|
||||
int32_t code = tjsonAddObject(pJson, jkSubplanId, subplanIdToJson, &pNode->id);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkSubplanType, pNode->subplanType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkSubplanMsgType, pNode->msgType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkSubplanLevel, pNode->level);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkSubplanNodeAddr, queryNodeAddrToJson, &pNode->execNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkSubplanRootNode, nodeToJson, pNode->pNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkSubplanDataSink, nodeToJson, pNode->pDataSink);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToSubplan(const SJson* pJson, void* pObj) {
|
||||
SSubplan* pNode = (SSubplan*)pObj;
|
||||
|
||||
int32_t code = tjsonToObject(pJson, jkSubplanId, jsonToSubplanId, &pNode->id);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkSubplanType, &val);
|
||||
pNode->subplanType = val;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkSubplanMsgType, &pNode->msgType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkSubplanLevel, &pNode->level);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, jkSubplanNodeAddr, jsonToQueryNodeAddr, &pNode->execNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSubplanRootNode, (SNode**)&pNode->pNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSubplanDataSink, (SNode**)&pNode->pDataSink);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkPlanQueryId = "QueryId";
|
||||
static const char* jkPlanNumOfSubplans = "NumOfSubplans";
|
||||
static const char* jkPlanSubplans = "Subplans";
|
||||
|
||||
static int32_t planToJson(const void* pObj, SJson* pJson) {
|
||||
const SQueryPlan* pNode = (const SQueryPlan*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkPlanQueryId, pNode->queryId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkPlanNumOfSubplans, pNode->numOfSubplans);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkPlanSubplans, pNode->pSubplans);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToPlan(const SJson* pJson, void* pObj) {
|
||||
SQueryPlan* pNode = (SQueryPlan*)pObj;
|
||||
|
||||
int32_t code = tjsonGetUBigIntValue(pJson, jkPlanQueryId, &pNode->queryId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkPlanNumOfSubplans, &pNode->numOfSubplans);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkPlanSubplans, &pNode->pSubplans);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkAggLogicPlanGroupKeys = "GroupKeys";
|
||||
static const char* jkAggLogicPlanAggFuncs = "AggFuncs";
|
||||
|
||||
|
@ -627,8 +948,52 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
static const char* jkValueLiteral = "Literal";
|
||||
static const char* jkValueDuration = "Duration";
|
||||
static const char* jkValueTranslate = "Translate";
|
||||
static const char* jkValueDatum = "Datum";
|
||||
|
||||
static int32_t datumToJson(const void* pObj, SJson* pJson) {
|
||||
const SValueNode* pNode = (const SValueNode*)pObj;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (pNode->node.resType.type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.b);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.u);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
code = tjsonAddDoubleToObject(pJson, jkValueDatum, pNode->datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
code = tjsonAddStringToObject(pJson, jkValueDatum, pNode->datum.p);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
// todo
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return code ;
|
||||
}
|
||||
|
||||
static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SValueNode* pNode = (const SValueNode*)pObj;
|
||||
|
||||
|
@ -639,34 +1004,47 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkValueDuration, pNode->isDuration);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkValueTranslate, pNode->translate);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && pNode->translate) {
|
||||
code = datumToJson(pNode, pJson);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToDatum(const SJson* pJson, void* pObj) {
|
||||
SValueNode* pNode = (SValueNode*)pObj;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (pNode->node.resType.type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueDuration, pNode->datum.b);
|
||||
code = tjsonGetBoolValue(pJson, jkValueDatum, &pNode->datum.b);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueDuration, pNode->datum.i);
|
||||
code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueDuration, pNode->datum.u);
|
||||
code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
code = tjsonAddDoubleToObject(pJson, jkValueDuration, pNode->datum.d);
|
||||
code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->datum.p);
|
||||
code = tjsonDupStringValue(pJson, jkValueDatum, &pNode->datum.p);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
|
@ -689,41 +1067,11 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkValueDuration, &pNode->isDuration);
|
||||
}
|
||||
switch (pNode->node.resType.type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
code = tjsonGetBoolValue(pJson, jkValueDuration, &pNode->datum.b);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
code = tjsonGetBigIntValue(pJson, jkValueDuration, &pNode->datum.i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
code = tjsonGetUBigIntValue(pJson, jkValueDuration, &pNode->datum.u);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
code = tjsonGetDoubleValue(pJson, jkValueDuration, &pNode->datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->datum.p);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
// todo
|
||||
default:
|
||||
break;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkValueTranslate, &pNode->translate);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && pNode->translate) {
|
||||
code = jsonToDatum(pJson, pNode);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -861,6 +1209,31 @@ static int32_t groupingSetNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkNodeListDataType = "DataType";
|
||||
static const char* jkNodeListNodeList = "NodeList";
|
||||
|
||||
static int32_t nodeListNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SNodeListNode* pNode = (const SNodeListNode*)pObj;
|
||||
|
||||
int32_t code = tjsonAddObject(pJson, jkNodeListDataType, dataTypeToJson, &pNode->dataType);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkNodeListNodeList, pNode->pNodeList);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToNodeListNode(const SJson* pJson, void* pObj) {
|
||||
SNodeListNode* pNode = (SNodeListNode*)pObj;
|
||||
|
||||
int32_t code = tjsonToObject(pJson, jkNodeListDataType, jsonToDataType, &pNode->dataType);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkNodeListNodeList, &pNode->pNodeList);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkTargetDataBlockId = "DataBlockId";
|
||||
static const char* jkTargetSlotId = "SlotId";
|
||||
static const char* jkTargetExpr = "Expr";
|
||||
|
@ -932,13 +1305,50 @@ static int32_t jsonToSlotDescNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkDownstreamSourceAddr = "Addr";
|
||||
static const char* jkDownstreamSourceTaskId = "TaskId";
|
||||
static const char* jkDownstreamSourceSchedId = "SchedId";
|
||||
|
||||
static int32_t downstreamSourceNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SDownstreamSourceNode* pNode = (const SDownstreamSourceNode*)pObj;
|
||||
|
||||
int32_t code = tjsonAddObject(pJson, jkDownstreamSourceAddr, queryNodeAddrToJson, &pNode->addr);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceTaskId, pNode->taskId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceSchedId, pNode->schedId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToDownstreamSourceNode(const SJson* pJson, void* pObj) {
|
||||
SDownstreamSourceNode* pNode = (SDownstreamSourceNode*)pObj;
|
||||
|
||||
int32_t code = tjsonToObject(pJson, jkDownstreamSourceAddr, jsonToQueryNodeAddr, &pNode->addr);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceTaskId, &pNode->taskId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceSchedId, &pNode->schedId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkDataBlockDescDataBlockId = "DataBlockId";
|
||||
static const char* jkDataBlockDescSlots = "Slots";
|
||||
static const char* jkDataBlockResultRowSize = "ResultRowSize";
|
||||
|
||||
static int32_t dataBlockDescNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SDataBlockDescNode* pNode = (const SDataBlockDescNode*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkDataBlockDescDataBlockId, pNode->dataBlockId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkDataBlockResultRowSize, pNode->resultRowSize);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkDataBlockDescSlots, pNode->pSlots);
|
||||
}
|
||||
|
@ -950,6 +1360,10 @@ static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) {
|
|||
SDataBlockDescNode* pNode = (SDataBlockDescNode*)pObj;
|
||||
|
||||
int32_t code = tjsonGetSmallIntValue(pJson, jkDataBlockDescDataBlockId, &pNode->dataBlockId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkDataBlockResultRowSize, &pNode->resultRowSize);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkDataBlockDescSlots, &pNode->pSlots);
|
||||
}
|
||||
|
@ -1030,21 +1444,32 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_STATE_WINDOW:
|
||||
case QUERY_NODE_SESSION_WINDOW:
|
||||
case QUERY_NODE_INTERVAL_WINDOW:
|
||||
break;
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
return nodeListNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_FILL:
|
||||
case QUERY_NODE_TARGET:
|
||||
return targetNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_RAW_EXPR:
|
||||
break;
|
||||
case QUERY_NODE_TARGET:
|
||||
return targetNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_DATABLOCK_DESC:
|
||||
return dataBlockDescNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return slotDescNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_COLUMN_DEF:
|
||||
break;
|
||||
case QUERY_NODE_DOWNSTREAM_SOURCE:
|
||||
return downstreamSourceNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
break;
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return selectStmtTojson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_STMT:
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
case QUERY_NODE_CREATE_DATABASE_STMT:
|
||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_USE_DATABASE_STMT:
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
case QUERY_NODE_SHOW_TABLES_STMT:
|
||||
break;
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return logicScanNodeToJson(pObj, pJson);
|
||||
|
@ -1054,19 +1479,39 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return logicAggNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_LOGIC_PLAN_PROJECT:
|
||||
return logicProjectNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
break;
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
||||
return physiTagScanNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
||||
return physiTableScanNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
||||
break;
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return physiProjectNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_JOIN:
|
||||
return physiJoinNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_AGG:
|
||||
return physiAggNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return physiExchangeNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
break;
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return physiDispatchNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||
break;
|
||||
case QUERY_NODE_PHYSICAL_SUBPLAN:
|
||||
return subplanToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN:
|
||||
return planToJson(pObj, pJson);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
nodesWarn("specificNodeToJson unknown node = %s", nodesNodeName(nodeType(pObj)));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1093,7 +1538,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
// case QUERY_NODE_STATE_WINDOW:
|
||||
// case QUERY_NODE_SESSION_WINDOW:
|
||||
// case QUERY_NODE_INTERVAL_WINDOW:
|
||||
// case QUERY_NODE_NODE_LIST:
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
return jsonToNodeListNode(pJson, pObj);
|
||||
// case QUERY_NODE_FILL:
|
||||
case QUERY_NODE_TARGET:
|
||||
return jsonToTargetNode(pJson, pObj);
|
||||
|
@ -1103,12 +1549,12 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToDataBlockDescNode(pJson, pObj);
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return jsonToSlotDescNode(pJson, pObj);
|
||||
case QUERY_NODE_DOWNSTREAM_SOURCE:
|
||||
return jsonToDownstreamSourceNode(pJson, pObj);
|
||||
// case QUERY_NODE_SET_OPERATOR:
|
||||
// break;
|
||||
// case QUERY_NODE_SELECT_STMT:
|
||||
// return jsonToSelectStmt(pJson, pObj);
|
||||
// case QUERY_NODE_SHOW_STMT:
|
||||
// break;
|
||||
// case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
// return jsonToLogicScanNode(pJson, pObj);
|
||||
// case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
|
@ -1127,13 +1573,22 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToPhysiJoinNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_AGG:
|
||||
return jsonToPhysiAggNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return jsonToPhysiExchangeNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return jsonToPhysiDispatchNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_SUBPLAN:
|
||||
return jsonToSubplan(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN:
|
||||
return jsonToPlan(pJson, pObj);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
nodesWarn("jsonToSpecificNode unknown node = %s", nodesNodeName(nodeType(pObj)));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static const char* jkNodeType = "Type";
|
||||
static const char* jkNodeType = "NodeType";
|
||||
static const char* jkNodeName = "Name";
|
||||
|
||||
static int32_t nodeToJson(const void* pObj, SJson* pJson) {
|
||||
|
@ -1141,10 +1596,13 @@ static int32_t nodeToJson(const void* pObj, SJson* pJson) {
|
|||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkNodeType, pNode->type);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkNodeName, nodeName(pNode->type));
|
||||
code = tjsonAddStringToObject(pJson, jkNodeName, nodesNodeName(pNode->type));
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, nodeName(pNode->type), specificNodeToJson, pNode);
|
||||
code = tjsonAddObject(pJson, nodesNodeName(pNode->type), specificNodeToJson, pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesError("%s ToJson error", nodesNodeName(pNode->type));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -1157,7 +1615,10 @@ static int32_t jsonToNode(const SJson* pJson, void* pObj) {
|
|||
int32_t code = tjsonGetIntValue(pJson, jkNodeType, &val);
|
||||
pNode->type = val;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, nodeName(pNode->type), jsonToSpecificNode, pNode);
|
||||
code = tjsonToObject(pJson, nodesNodeName(pNode->type), jsonToSpecificNode, pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesError("%s toNode error", nodesNodeName(pNode->type));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -1180,14 +1641,15 @@ static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode) {
|
|||
static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** pNode) {
|
||||
SJson* pJsonNode = tjsonGetObjectItem(pJson, pName);
|
||||
if (NULL == pJsonNode) {
|
||||
return TSDB_CODE_FAILED;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return makeNodeByJson(pJsonNode, pNode);
|
||||
}
|
||||
|
||||
int32_t nodesNodeToString(const SNode* pNode, bool format, char** pStr, int32_t* pLen) {
|
||||
int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen) {
|
||||
if (NULL == pNode || NULL == pStr || NULL == pLen) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
terrno = TSDB_CODE_FAILED;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SJson* pJson = tjsonCreateObject();
|
||||
|
|
|
@ -95,7 +95,7 @@ static bool functionNodeEqual(const SFunctionNode* a, const SFunctionNode* b) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool nodesEqualNode(const SNode* a, const SNode* b) {
|
||||
bool nodesEqualNode(const SNodeptr a, const SNodeptr b) {
|
||||
if (a == b) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ static EDealRes walkList(SNodeList* pNodeList, ETraversalOrder order, FNodeWalke
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
void nodesWalkNode(SNode* pNode, FNodeWalker walker, void* pContext) {
|
||||
void nodesWalkNode(SNodeptr pNode, FNodeWalker walker, void* pContext) {
|
||||
(void)walkNode(pNode, TRAVERSAL_PREORDER, walker, pContext);
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ void nodesWalkList(SNodeList* pNodeList, FNodeWalker walker, void* pContext) {
|
|||
(void)walkList(pNodeList, TRAVERSAL_PREORDER, walker, pContext);
|
||||
}
|
||||
|
||||
void nodesWalkNodePostOrder(SNode* pNode, FNodeWalker walker, void* pContext) {
|
||||
void nodesWalkNodePostOrder(SNodeptr pNode, FNodeWalker walker, void* pContext) {
|
||||
(void)walkNode(pNode, TRAVERSAL_POSTORDER, walker, pContext);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,12 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "querynodes.h"
|
||||
#include "cmdnodes.h"
|
||||
#include "nodesUtil.h"
|
||||
#include "plannodes.h"
|
||||
#include "querynodes.h"
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
#include "taos.h"
|
||||
#include "thash.h"
|
||||
|
||||
static SNode* makeNode(ENodeType type, size_t size) {
|
||||
|
@ -29,7 +30,7 @@ static SNode* makeNode(ENodeType type, size_t size) {
|
|||
return p;
|
||||
}
|
||||
|
||||
SNode* nodesMakeNode(ENodeType type) {
|
||||
SNodeptr nodesMakeNode(ENodeType type) {
|
||||
switch (type) {
|
||||
case QUERY_NODE_COLUMN:
|
||||
return makeNode(type, sizeof(SColumnNode));
|
||||
|
@ -65,12 +66,62 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SFillNode));
|
||||
case QUERY_NODE_RAW_EXPR:
|
||||
return makeNode(type, sizeof(SRawExprNode));
|
||||
case QUERY_NODE_TARGET:
|
||||
return makeNode(type, sizeof(STargetNode));
|
||||
case QUERY_NODE_DATABLOCK_DESC:
|
||||
return makeNode(type, sizeof(SDataBlockDescNode));
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return makeNode(type, sizeof(SSlotDescNode));
|
||||
case QUERY_NODE_COLUMN_DEF:
|
||||
return makeNode(type, sizeof(SColumnDefNode));
|
||||
case QUERY_NODE_DOWNSTREAM_SOURCE:
|
||||
return makeNode(type, sizeof(SDownstreamSourceNode));
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
return makeNode(type, sizeof(SSetOperator));
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return makeNode(type, sizeof(SSelectStmt));
|
||||
// case QUERY_NODE_SHOW_STMT:
|
||||
// return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
return makeNode(type, sizeof(SVnodeModifOpStmt));
|
||||
case QUERY_NODE_CREATE_DATABASE_STMT:
|
||||
return makeNode(type, sizeof(SCreateDatabaseStmt));
|
||||
case QUERY_NODE_DROP_DATABASE_STMT:
|
||||
return makeNode(type, sizeof(SDropDatabaseStmt));
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||
return makeNode(type, sizeof(SCreateTableStmt));
|
||||
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
|
||||
return makeNode(type, sizeof(SCreateSubTableClause));
|
||||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||
return makeNode(type, sizeof(SCreateMultiTableStmt));
|
||||
case QUERY_NODE_DROP_TABLE_CLAUSE:
|
||||
return makeNode(type, sizeof(SDropTableClause));
|
||||
case QUERY_NODE_DROP_TABLE_STMT:
|
||||
return makeNode(type, sizeof(SDropTableStmt));
|
||||
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||
return makeNode(type, sizeof(SDropSuperTableStmt));
|
||||
case QUERY_NODE_SHOW_TABLES_STMT:
|
||||
case QUERY_NODE_SHOW_STABLES_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_CREATE_USER_STMT:
|
||||
return makeNode(type, sizeof(SCreateUserStmt));
|
||||
case QUERY_NODE_ALTER_USER_STMT:
|
||||
return makeNode(type, sizeof(SAlterUserStmt));
|
||||
case QUERY_NODE_DROP_USER_STMT:
|
||||
return makeNode(type, sizeof(SDropUserStmt));
|
||||
case QUERY_NODE_SHOW_USERS_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_USE_DATABASE_STMT:
|
||||
return makeNode(type, sizeof(SUseDatabaseStmt));
|
||||
case QUERY_NODE_CREATE_DNODE_STMT:
|
||||
return makeNode(type, sizeof(SCreateDnodeStmt));
|
||||
case QUERY_NODE_DROP_DNODE_STMT:
|
||||
return makeNode(type, sizeof(SDropDnodeStmt));
|
||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return makeNode(type, sizeof(SScanLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
|
@ -79,33 +130,48 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SAggLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_PROJECT:
|
||||
return makeNode(type, sizeof(SProjectLogicNode));
|
||||
case QUERY_NODE_TARGET:
|
||||
return makeNode(type, sizeof(STargetNode));
|
||||
case QUERY_NODE_DATABLOCK_DESC:
|
||||
return makeNode(type, sizeof(SDataBlockDescNode));
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return makeNode(type, sizeof(SSlotDescNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
|
||||
return makeNode(type, sizeof(SVnodeModifLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
|
||||
return makeNode(type, sizeof(SExchangeLogicNode));
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return makeNode(type, sizeof(SSubLogicPlan));
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
return makeNode(type, sizeof(SQueryLogicPlan));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
||||
return makeNode(type, sizeof(STagScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
||||
return makeNode(type, sizeof(STableScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
||||
return makeNode(type, sizeof(STableSeqScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
||||
return makeNode(type, sizeof(SNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return makeNode(type, sizeof(SProjectPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_JOIN:
|
||||
return makeNode(type, sizeof(SJoinPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_AGG:
|
||||
return makeNode(type, sizeof(SAggPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return makeNode(type, sizeof(SExchangePhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return makeNode(type, sizeof(SNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return makeNode(type, sizeof(SDataDispatcherNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||
return makeNode(type, sizeof(SDataInserterNode));
|
||||
case QUERY_NODE_PHYSICAL_SUBPLAN:
|
||||
return makeNode(type, sizeof(SSubplan));
|
||||
case QUERY_NODE_PHYSICAL_PLAN:
|
||||
return makeNode(type, sizeof(SQueryPlan));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
nodesError("nodesMakeNode unknown node = %s", nodesNodeName(type));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static EDealRes destroyNode(SNode** pNode, void* pContext) {
|
||||
if (NULL == pNode || NULL == *pNode) {
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
|
||||
switch (nodeType(*pNode)) {
|
||||
case QUERY_NODE_VALUE: {
|
||||
SValueNode* pValue = (SValueNode*)*pNode;
|
||||
|
@ -118,16 +184,65 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
|
|||
break;
|
||||
}
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
nodesDestroyList(((SLogicConditionNode*)(*pNode))->pParameterList);
|
||||
nodesClearList(((SLogicConditionNode*)(*pNode))->pParameterList);
|
||||
break;
|
||||
case QUERY_NODE_FUNCTION:
|
||||
nodesDestroyList(((SFunctionNode*)(*pNode))->pParameterList);
|
||||
nodesClearList(((SFunctionNode*)(*pNode))->pParameterList);
|
||||
break;
|
||||
case QUERY_NODE_REAL_TABLE: {
|
||||
SRealTableNode* pReal = (SRealTableNode*)*pNode;
|
||||
tfree(pReal->pMeta);
|
||||
tfree(pReal->pVgroupList);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
nodesDestroyNode(((STempTableNode*)(*pNode))->pSubquery);
|
||||
break;
|
||||
case QUERY_NODE_GROUPING_SET:
|
||||
nodesDestroyList(((SGroupingSetNode*)(*pNode))->pParameterList);
|
||||
nodesClearList(((SGroupingSetNode*)(*pNode))->pParameterList);
|
||||
break;
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
nodesDestroyList(((SNodeListNode*)(*pNode))->pNodeList);
|
||||
nodesClearList(((SNodeListNode*)(*pNode))->pNodeList);
|
||||
break;
|
||||
case QUERY_NODE_SELECT_STMT: {
|
||||
SSelectStmt* pStmt = (SSelectStmt*)*pNode;
|
||||
nodesDestroyList(pStmt->pProjectionList);
|
||||
nodesDestroyNode(pStmt->pFromTable);
|
||||
nodesDestroyNode(pStmt->pWhere);
|
||||
nodesDestroyList(pStmt->pPartitionByList);
|
||||
nodesDestroyNode(pStmt->pWindow);
|
||||
nodesDestroyList(pStmt->pGroupByList);
|
||||
nodesDestroyNode(pStmt->pHaving);
|
||||
nodesDestroyList(pStmt->pOrderByList);
|
||||
nodesDestroyNode(pStmt->pLimit);
|
||||
nodesDestroyNode(pStmt->pSlimit);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_VNODE_MODIF_STMT: {
|
||||
SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)*pNode;
|
||||
size_t size = taosArrayGetSize(pStmt->pDataBlocks);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
SVgDataBlocks* pVg = taosArrayGetP(pStmt->pDataBlocks, i);
|
||||
tfree(pVg->pData);
|
||||
tfree(pVg);
|
||||
}
|
||||
taosArrayDestroy(pStmt->pDataBlocks);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_CREATE_TABLE_STMT: {
|
||||
SCreateTableStmt* pStmt = (SCreateTableStmt*)*pNode;
|
||||
nodesDestroyList(pStmt->pCols);
|
||||
nodesDestroyList(pStmt->pTags);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: {
|
||||
SCreateSubTableClause* pStmt = (SCreateSubTableClause*)*pNode;
|
||||
nodesDestroyList(pStmt->pSpecificTags);
|
||||
nodesDestroyList(pStmt->pValsOfTags);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||
nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -136,12 +251,11 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
void nodesDestroyNode(SNode* pNode) {
|
||||
void nodesDestroyNode(SNodeptr pNode) {
|
||||
if (NULL == pNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
nodesRewriteNodePostOrder(&pNode, destroyNode, NULL);
|
||||
nodesRewriteNodePostOrder((SNode**)&pNode, destroyNode, NULL);
|
||||
}
|
||||
|
||||
SNodeList* nodesMakeList() {
|
||||
|
@ -152,7 +266,7 @@ SNodeList* nodesMakeList() {
|
|||
return p;
|
||||
}
|
||||
|
||||
int32_t nodesListAppend(SNodeList* pList, SNode* pNode) {
|
||||
int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode) {
|
||||
if (NULL == pList || NULL == pNode) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -173,6 +287,17 @@ int32_t nodesListAppend(SNodeList* pList, SNode* pNode) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode) {
|
||||
if (NULL == pNode) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int32_t code = nodesListAppend(pList, pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pNode);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) {
|
||||
if (NULL == pTarget || NULL == pSrc) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -207,7 +332,7 @@ SListCell* nodesListErase(SNodeList* pList, SListCell* pCell) {
|
|||
return pNext;
|
||||
}
|
||||
|
||||
SNode* nodesListGetNode(SNodeList* pList, int32_t index) {
|
||||
SNodeptr nodesListGetNode(SNodeList* pList, int32_t index) {
|
||||
SNode* node;
|
||||
FOREACH(node, pList) {
|
||||
if (0 == index--) {
|
||||
|
@ -218,6 +343,10 @@ SNode* nodesListGetNode(SNodeList* pList, int32_t index) {
|
|||
}
|
||||
|
||||
void nodesDestroyList(SNodeList* pList) {
|
||||
if (NULL == pList) {
|
||||
return;
|
||||
}
|
||||
|
||||
SListCell* pNext = pList->pHead;
|
||||
while (NULL != pNext) {
|
||||
pNext = nodesListErase(pList, pNext);
|
||||
|
@ -225,6 +354,20 @@ void nodesDestroyList(SNodeList* pList) {
|
|||
tfree(pList);
|
||||
}
|
||||
|
||||
void nodesClearList(SNodeList* pList) {
|
||||
if (NULL == pList) {
|
||||
return;
|
||||
}
|
||||
|
||||
SListCell* pNext = pList->pHead;
|
||||
while (NULL != pNext) {
|
||||
SListCell* tmp = pNext;
|
||||
pNext = pNext->pNext;
|
||||
tfree(tmp);
|
||||
}
|
||||
tfree(pList);
|
||||
}
|
||||
|
||||
void* nodesGetValueFromNode(SValueNode *pNode) {
|
||||
switch (pNode->node.resType.type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
|
@ -243,7 +386,6 @@ void* nodesGetValueFromNode(SValueNode *pNode) {
|
|||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
return (void*)&pNode->datum.d;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
|
|
|
@ -36,15 +36,15 @@ static EDealRes rewriterTest(SNode** pNode, void* pContext) {
|
|||
}
|
||||
|
||||
TEST(NodesTest, traverseTest) {
|
||||
SNode* pRoot = nodesMakeNode(QUERY_NODE_OPERATOR);
|
||||
SNode* pRoot = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
|
||||
SOperatorNode* pOp = (SOperatorNode*)pRoot;
|
||||
SOperatorNode* pLeft = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
|
||||
pLeft->pLeft = nodesMakeNode(QUERY_NODE_VALUE);
|
||||
pLeft->pLeft = (SNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
((SValueNode*)(pLeft->pLeft))->literal = strdup("10");
|
||||
pLeft->pRight = nodesMakeNode(QUERY_NODE_VALUE);
|
||||
pLeft->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
((SValueNode*)(pLeft->pRight))->literal = strdup("5");
|
||||
pOp->pLeft = (SNode*)pLeft;
|
||||
pOp->pRight = nodesMakeNode(QUERY_NODE_VALUE);
|
||||
pOp->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
((SValueNode*)(pOp->pRight))->literal = strdup("3");
|
||||
|
||||
EXPECT_EQ(nodeType(pRoot), QUERY_NODE_OPERATOR);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* 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_AST_CREATER_H_
|
||||
#define _TD_AST_CREATER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "nodes.h"
|
||||
#include "parser.h"
|
||||
|
||||
typedef struct SAstCreateContext {
|
||||
SParseContext* pQueryCxt;
|
||||
bool notSupport;
|
||||
bool valid;
|
||||
SNode* pRootNode;
|
||||
} SAstCreateContext;
|
||||
|
||||
int32_t createAstCreateContext(SParseContext* pQueryCxt, SAstCreateContext* pCxt);
|
||||
int32_t destroyAstCreateContext(SAstCreateContext* pCxt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_AST_CREATER_H_*/
|
|
@ -1,369 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_ASTGENERATOR_H
|
||||
#define TDENGINE_ASTGENERATOR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ttoken.h"
|
||||
#include "tvariant.h"
|
||||
#include "parser.h"
|
||||
|
||||
#define ParseTOKENTYPE SToken
|
||||
|
||||
#define NON_ARITHMEIC_EXPR 0
|
||||
#define NORMAL_ARITHMETIC 1
|
||||
#define AGG_ARIGHTMEIC 2
|
||||
|
||||
enum SQL_NODE_TYPE {
|
||||
SQL_NODE_TABLE_COLUMN= 1,
|
||||
SQL_NODE_SQLFUNCTION = 2,
|
||||
SQL_NODE_VALUE = 3,
|
||||
SQL_NODE_EXPR = 4,
|
||||
};
|
||||
|
||||
enum SQL_FROM_NODE_TYPE {
|
||||
SQL_FROM_NODE_SUBQUERY = 1,
|
||||
SQL_FROM_NODE_TABLES = 2,
|
||||
};
|
||||
|
||||
enum SQL_UNION_TYPE {
|
||||
SQL_TYPE_UNIONALL = 1,
|
||||
SQL_TYPE_UNION = 2,
|
||||
};
|
||||
|
||||
extern char tTokenTypeSwitcher[13];
|
||||
|
||||
#define toTSDBType(x) \
|
||||
do { \
|
||||
if ((x) >= tListLen(tTokenTypeSwitcher)) { \
|
||||
(x) = TSDB_DATA_TYPE_BINARY; \
|
||||
} else { \
|
||||
(x) = tTokenTypeSwitcher[(x)]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TPARSER_HAS_TOKEN(_t) ((_t).n > 0)
|
||||
#define TPARSER_SET_NONE_TOKEN(_t) ((_t).n = 0)
|
||||
|
||||
typedef struct SListItem {
|
||||
SVariant pVar;
|
||||
uint8_t sortOrder;
|
||||
} SListItem;
|
||||
|
||||
typedef struct SIntervalVal {
|
||||
int32_t token;
|
||||
SToken interval;
|
||||
SToken offset;
|
||||
} SIntervalVal;
|
||||
|
||||
typedef struct SSessionWindowVal {
|
||||
SToken col;
|
||||
SToken gap;
|
||||
} SSessionWindowVal;
|
||||
|
||||
typedef struct SWindowStateVal {
|
||||
SToken col;
|
||||
} SWindowStateVal;
|
||||
|
||||
struct SRelationInfo;
|
||||
|
||||
typedef struct SSqlNode {
|
||||
struct SRelationInfo *from; // from clause SArray<SSqlNode>
|
||||
struct SArray *pSelNodeList; // select clause
|
||||
struct tSqlExpr *pWhere; // where clause [optional]
|
||||
SArray *pGroupby; // groupby clause, only for tags[optional], SArray<SListItem>
|
||||
SArray *pSortOrder; // orderby [optional], SArray<SListItem>
|
||||
SArray *fillType; // fill type[optional], SArray<SListItem>
|
||||
SIntervalVal interval; // (interval, interval_offset) [optional]
|
||||
SSessionWindowVal sessionVal; // session window [optional]
|
||||
SWindowStateVal windowstateVal; // window_state(col) [optional]
|
||||
SToken sliding; // sliding window [optional]
|
||||
SLimit limit; // limit offset [optional]
|
||||
SLimit slimit; // group limit offset [optional]
|
||||
SToken sqlstr; // sql string in select clause
|
||||
struct tSqlExpr *pHaving; // having clause [optional]
|
||||
} SSqlNode;
|
||||
|
||||
typedef struct SSubclause {
|
||||
int32_t unionType;
|
||||
SArray *node;
|
||||
} SSubclause;
|
||||
|
||||
typedef struct SRelElement {
|
||||
union {
|
||||
SToken tableName;
|
||||
SSubclause *pSubquery;
|
||||
};
|
||||
|
||||
SToken aliasName;
|
||||
} SRelElement;
|
||||
|
||||
typedef struct SRelationInfo {
|
||||
int32_t type; // nested query|table name list
|
||||
SArray *list; // SArray<SRelElement>
|
||||
} SRelationInfo;
|
||||
|
||||
typedef struct SCreatedTableInfo {
|
||||
SToken name; // table name token
|
||||
SToken stbName; // super table name token , for using clause
|
||||
SArray *pTagNames; // create by using super table, tag name
|
||||
SArray *pTagVals; // create by using super table, tag value. SArray<SToken>
|
||||
char *fullname; // table full name
|
||||
int8_t igExist; // ignore if exists
|
||||
} SCreatedTableInfo;
|
||||
|
||||
typedef struct SCreateTableSql {
|
||||
SToken name; // table name, create table [name] xxx
|
||||
int8_t type; // create normal table/from super table/ stream
|
||||
bool existCheck;
|
||||
|
||||
struct {
|
||||
SArray *pTagColumns; // SArray<SField>
|
||||
SArray *pColumns; // SArray<SField>
|
||||
} colInfo;
|
||||
|
||||
SArray *childTableInfo; // SArray<SCreatedTableInfo>
|
||||
SSqlNode *pSelect;
|
||||
} SCreateTableSql;
|
||||
|
||||
typedef struct SAlterTableInfo {
|
||||
SToken name;
|
||||
int16_t tableType;
|
||||
int16_t type;
|
||||
STagData tagData;
|
||||
SArray *pAddColumns; // SArray<SField>
|
||||
SArray *varList; // set t=val or: change src dst, SArray<SListItem>
|
||||
} SAlterTableInfo;
|
||||
|
||||
typedef struct SCreateDbInfo {
|
||||
SToken dbname;
|
||||
int32_t replica;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t numOfVgroups;
|
||||
int32_t numOfBlocks;
|
||||
int32_t daysPerFile;
|
||||
int32_t minRowsPerBlock;
|
||||
int32_t maxRowsPerBlock;
|
||||
int32_t fsyncPeriod;
|
||||
int64_t commitTime;
|
||||
int32_t walLevel;
|
||||
int32_t quorum;
|
||||
int32_t compressionLevel;
|
||||
SToken precision;
|
||||
bool ignoreExists;
|
||||
int8_t update;
|
||||
int8_t cachelast;
|
||||
SArray *keep;
|
||||
int8_t streamMode;
|
||||
} SCreateDbInfo;
|
||||
|
||||
typedef struct SCreateFuncInfo {
|
||||
SToken name;
|
||||
SToken path;
|
||||
int32_t type;
|
||||
int32_t bufSize;
|
||||
SField output;
|
||||
} SCreateFuncInfo;
|
||||
|
||||
typedef struct SCreateAcctInfo {
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int32_t maxPointsPerSecond;
|
||||
int64_t maxStorage;
|
||||
int64_t maxQueryTime;
|
||||
int32_t maxConnections;
|
||||
SToken stat;
|
||||
} SCreateAcctInfo;
|
||||
|
||||
typedef struct SShowInfo {
|
||||
uint8_t showType;
|
||||
SToken prefix;
|
||||
SToken pattern;
|
||||
} SShowInfo;
|
||||
|
||||
typedef struct SUserInfo {
|
||||
SToken user;
|
||||
SToken passwd;
|
||||
SToken privilege;
|
||||
int16_t type;
|
||||
} SUserInfo;
|
||||
|
||||
typedef struct SMiscInfo {
|
||||
SArray *a; // SArray<SToken>
|
||||
bool existsCheck;
|
||||
int16_t dbType;
|
||||
int16_t tableType;
|
||||
SUserInfo user;
|
||||
union {
|
||||
SCreateDbInfo dbOpt;
|
||||
SCreateAcctInfo acctOpt;
|
||||
SCreateFuncInfo funcOpt;
|
||||
SShowInfo showOpt;
|
||||
SToken id;
|
||||
};
|
||||
} SMiscInfo;
|
||||
|
||||
typedef struct SSqlInfo {
|
||||
int32_t type;
|
||||
bool valid;
|
||||
SSubclause sub;
|
||||
char msg[256];
|
||||
SArray *funcs;
|
||||
union {
|
||||
SCreateTableSql *pCreateTableInfo;
|
||||
SAlterTableInfo *pAlterInfo;
|
||||
SMiscInfo *pMiscInfo;
|
||||
};
|
||||
} SSqlInfo;
|
||||
|
||||
typedef struct tSqlExpr {
|
||||
uint16_t type; // sql node type
|
||||
uint32_t tokenId; // TK_LE: less than(binary expr)
|
||||
|
||||
// The complete string of the function(col, param), and the function name is kept in exprToken
|
||||
struct {
|
||||
SToken operand;
|
||||
struct SArray *paramList; // function parameters list
|
||||
} Expr;
|
||||
|
||||
SToken columnName; // table column info
|
||||
SVariant value; // the use input value
|
||||
SToken exprToken; // original sql expr string or function name of sql function
|
||||
struct tSqlExpr *pLeft; // the left child
|
||||
struct tSqlExpr *pRight; // the right child
|
||||
} tSqlExpr;
|
||||
|
||||
// used in select clause. select <SArray> from xxx
|
||||
typedef struct tSqlExprItem {
|
||||
tSqlExpr *pNode; // The list of expressions
|
||||
int32_t functionId;
|
||||
char *aliasName; // alias name, null-terminated string
|
||||
bool distinct;
|
||||
} tSqlExprItem;
|
||||
|
||||
SArray *tListItemAppend(SArray *pList, SVariant *pVar, uint8_t sortOrder);
|
||||
SArray *tListItemInsert(SArray *pList, SVariant *pVar, uint8_t sortOrder, int32_t index);
|
||||
SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrder);
|
||||
|
||||
SRelationInfo *setTableNameList(SRelationInfo *pRelationInfo, SToken *pName, SToken *pAlias);
|
||||
void * destroyRelationInfo(SRelationInfo *pFromInfo);
|
||||
SRelationInfo *addSubquery(SRelationInfo *pRelationInfo, SSubclause *pSub, SToken *pAlias);
|
||||
|
||||
// sql expr leaf node
|
||||
tSqlExpr *tSqlExprCreateIdValue(SToken *pToken, int32_t optrType);
|
||||
tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SToken *pFuncToken, SToken *endToken, int32_t optType);
|
||||
SArray * tRecordFuncName(SArray *pList, SToken *pToken);
|
||||
|
||||
tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType);
|
||||
tSqlExpr *tSqlExprClone(tSqlExpr *pSrc);
|
||||
void tSqlExprCompact(tSqlExpr **pExpr);
|
||||
bool tSqlExprIsLeaf(tSqlExpr *pExpr);
|
||||
bool tSqlExprIsParentOfLeaf(tSqlExpr *pExpr);
|
||||
void tSqlExprDestroy(tSqlExpr *pExpr);
|
||||
SArray * tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SToken *pDistinct, SToken *pToken);
|
||||
void tSqlExprListDestroy(SArray *pList);
|
||||
void tSqlExprEvaluate(tSqlExpr* pExpr);
|
||||
|
||||
SSqlNode *tSetQuerySqlNode(SToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere,
|
||||
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps,
|
||||
SWindowStateVal *pw, SToken *pSliding, SArray *pFill, SLimit *pLimit, SLimit *pgLimit, tSqlExpr *pHaving);
|
||||
int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right);
|
||||
|
||||
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type);
|
||||
|
||||
SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType);
|
||||
SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
|
||||
SToken *igExists);
|
||||
/*!
|
||||
* test
|
||||
* @param pSqlNode
|
||||
*/
|
||||
void destroyAllSqlNode(struct SSubclause *pSqlNode);
|
||||
void destroySqlNode(SSqlNode *pSql);
|
||||
void freeCreateTableInfo(void* p);
|
||||
|
||||
SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, int32_t type);
|
||||
SSubclause* setSubclause(SSubclause* sub, void *pSqlNode);
|
||||
SSubclause* appendSelectClause(SSubclause *sub, int32_t unionType, void *pSubclause);
|
||||
|
||||
void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists);
|
||||
void* destroyCreateTableSql(SCreateTableSql* pCreate);
|
||||
void setDropFuncInfo(SSqlInfo *pInfo, int32_t type, SToken* pToken);
|
||||
void setCreateFuncInfo(SSqlInfo *pInfo, int32_t type, SToken *pName, SToken *pPath, SField *output, SToken* bufSize, int32_t funcType);
|
||||
|
||||
void destroySqlInfo(SSqlInfo *pInfo);
|
||||
|
||||
void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
|
||||
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SToken* pToken, SToken* existsCheck,int16_t dbType,int16_t tableType);
|
||||
void setShowOptions(SSqlInfo *pInfo, int32_t type, SToken* prefix, SToken* pPatterns);
|
||||
|
||||
void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SToken *pToken, SCreateDbInfo *pDB, SToken *pIgExists);
|
||||
|
||||
void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SToken *pName, SToken *pPwd, SCreateAcctInfo *pAcctInfo);
|
||||
void setCreateUserSql(SSqlInfo *pInfo, SToken *pName, SToken *pPasswd);
|
||||
void setKillSql(SSqlInfo *pInfo, int32_t type, SToken *ip);
|
||||
void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SToken *pName, SToken* pPwd, SToken *pPrivilege);
|
||||
|
||||
void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam);
|
||||
|
||||
void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo);
|
||||
void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo);
|
||||
|
||||
// prefix show db.tables;
|
||||
void tSetDbName(SToken *pCpxName, SToken *pDb);
|
||||
|
||||
void tSetColumnInfo(struct SField *pField, SToken *pName, struct SField *pType);
|
||||
void tSetColumnType(struct SField *pField, SToken *type);
|
||||
|
||||
/**
|
||||
* The main parse function.
|
||||
* @param yyp The parser
|
||||
* @param yymajor The major token code number
|
||||
* @param yyminor The value for the token
|
||||
*/
|
||||
void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
|
||||
|
||||
/**
|
||||
* Free the allocated resources in case of failure.
|
||||
* @param p The parser to be deleted
|
||||
* @param freeProc Function used to reclaim memory
|
||||
*/
|
||||
void ParseFree(void *p, void (*freeProc)(void *));
|
||||
|
||||
/**
|
||||
* Allocated callback function.
|
||||
* @param mallocProc The parser allocator
|
||||
* @return
|
||||
*/
|
||||
void *ParseAlloc(void *(*mallocProc)(size_t));
|
||||
|
||||
/**
|
||||
*
|
||||
* @param str sql string
|
||||
* @return sql ast
|
||||
*/
|
||||
SSqlInfo doGenerateAST(const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_ASTGENERATOR_H
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_ASTTOMSG_H
|
||||
#define TDENGINE_ASTTOMSG_H
|
||||
|
||||
#include "parserInt.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
|
||||
char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
|
||||
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
|
||||
char* buildShowMsg(SShowInfo* pShowInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
|
||||
char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf);
|
||||
char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
|
||||
char* buildDropStableReq(SSqlInfo* pInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
|
||||
char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf);
|
||||
char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf);
|
||||
|
||||
#endif // TDENGINE_ASTTOMSG_H
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_INSERTPARSER_H
|
||||
#define TDENGINE_INSERTPARSER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int32_t parseInsertSql(SParseContext* pContext, SVnodeModifOpStmtInfo** pInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_INSERTPARSER_H
|
|
@ -1,436 +0,0 @@
|
|||
//lemon parser file to generate sql parse by using finite-state-machine code used to parse sql
|
||||
//usage: lemon sql.y
|
||||
|
||||
%name NewParse
|
||||
|
||||
%token_prefix NEW_TK_
|
||||
%token_type { SToken }
|
||||
%default_type { SNode* }
|
||||
%default_destructor { PARSER_DESTRUCTOR_TRACE; nodesDestroyNode($$); }
|
||||
|
||||
%extra_argument { SAstCreateContext* pCxt }
|
||||
|
||||
%include {
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nodes.h"
|
||||
#include "ttoken.h"
|
||||
#include "ttokendef.h"
|
||||
#include "astCreateFuncs.h"
|
||||
|
||||
#if 0
|
||||
#define PARSER_TRACE printf("lemon rule = %s\n", yyRuleName[yyruleno])
|
||||
#define PARSER_DESTRUCTOR_TRACE printf("lemon destroy token = %s\n", yyTokenName[yymajor])
|
||||
#define PARSER_COMPLETE printf("parsing complete!\n" )
|
||||
#else
|
||||
#define PARSER_TRACE
|
||||
#define PARSER_DESTRUCTOR_TRACE
|
||||
#define PARSER_COMPLETE
|
||||
#endif
|
||||
}
|
||||
|
||||
%syntax_error {
|
||||
if(TOKEN.z) {
|
||||
char msg[] = "syntax error near \"%s\"";
|
||||
int32_t sqlLen = strlen(&TOKEN.z[0]);
|
||||
|
||||
if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > pCxt->pQueryCxt->msgLen) {
|
||||
char tmpstr[128] = {0};
|
||||
memcpy(tmpstr, &TOKEN.z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1);
|
||||
sprintf(pCxt->pQueryCxt->pMsg, msg, tmpstr);
|
||||
} else {
|
||||
sprintf(pCxt->pQueryCxt->pMsg, msg, &TOKEN.z[0]);
|
||||
}
|
||||
} else {
|
||||
sprintf(pCxt->pQueryCxt->pMsg, "Incomplete SQL statement");
|
||||
}
|
||||
pCxt->valid = false;
|
||||
}
|
||||
|
||||
%parse_accept { PARSER_COMPLETE; }
|
||||
|
||||
%left OR.
|
||||
%left AND.
|
||||
//%right NOT.
|
||||
%left UNION ALL MINUS EXCEPT INTERSECT.
|
||||
//%left BITAND BITOR LSHIFT RSHIFT.
|
||||
%left NK_PLUS NK_MINUS.
|
||||
//%left DIVIDE TIMES.
|
||||
%left NK_STAR NK_SLASH NK_REM.
|
||||
//%left CONCAT.
|
||||
//%right UMINUS UPLUS BITNOT.
|
||||
|
||||
cmd ::= SHOW DATABASES. { PARSER_TRACE; createShowStmt(pCxt, SHOW_TYPE_DATABASE); }
|
||||
cmd ::= query_expression(A). { PARSER_TRACE; pCxt->pRootNode = A; }
|
||||
|
||||
/************************************************ literal *************************************************************/
|
||||
literal(A) ::= NK_INTEGER(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); }
|
||||
literal(A) ::= NK_FLOAT(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B)); }
|
||||
literal(A) ::= NK_STRING(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B)); }
|
||||
literal(A) ::= NK_BOOL(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B)); }
|
||||
literal(A) ::= TIMESTAMP(B) NK_STRING(C). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &C, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &C)); }
|
||||
literal(A) ::= duration_literal(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
duration_literal(A) ::= NK_VARIABLE(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); }
|
||||
|
||||
%type literal_list { SNodeList* }
|
||||
%destructor literal_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
literal_list(A) ::= literal(B). { PARSER_TRACE; A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
|
||||
literal_list(A) ::= literal_list(B) NK_COMMA literal(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
|
||||
|
||||
/************************************************ names and identifiers ***********************************************/
|
||||
%type db_name { SToken }
|
||||
%destructor db_name { PARSER_DESTRUCTOR_TRACE; }
|
||||
db_name(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type table_name { SToken }
|
||||
%destructor table_name { PARSER_DESTRUCTOR_TRACE; }
|
||||
table_name(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type column_name { SToken }
|
||||
%destructor column_name { PARSER_DESTRUCTOR_TRACE; }
|
||||
column_name(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type function_name { SToken }
|
||||
%destructor function_name { PARSER_DESTRUCTOR_TRACE; }
|
||||
function_name(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type table_alias { SToken }
|
||||
%destructor table_alias { PARSER_DESTRUCTOR_TRACE; }
|
||||
table_alias(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type column_alias { SToken }
|
||||
%destructor column_alias { PARSER_DESTRUCTOR_TRACE; }
|
||||
column_alias(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
/************************************************ expression **********************************************************/
|
||||
expression(A) ::= literal(B). { PARSER_TRACE; A = B; }
|
||||
//expression(A) ::= NK_QUESTION(B). { PARSER_TRACE; A = B; }
|
||||
//expression(A) ::= pseudo_column(B). { PARSER_TRACE; A = B; }
|
||||
expression(A) ::= column_reference(B). { PARSER_TRACE; A = B; }
|
||||
expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); }
|
||||
//expression(A) ::= cast_expression(B). { PARSER_TRACE; A = B; }
|
||||
//expression(A) ::= case_expression(B). { PARSER_TRACE; A = B; }
|
||||
expression(A) ::= subquery(B). { PARSER_TRACE; A = B; }
|
||||
expression(A) ::= NK_LP(B) expression(C) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &D, releaseRawExprNode(pCxt, C)); }
|
||||
expression(A) ::= NK_PLUS(B) expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken t = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &B, &t, releaseRawExprNode(pCxt, C));
|
||||
}
|
||||
expression(A) ::= NK_MINUS(B) expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken t = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &B, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, C), NULL));
|
||||
}
|
||||
expression(A) ::= expression(B) NK_PLUS expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
expression(A) ::= expression(B) NK_MINUS expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
expression(A) ::= expression(B) NK_STAR expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
expression(A) ::= expression(B) NK_SLASH expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
expression(A) ::= expression(B) NK_REM expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
|
||||
%type expression_list { SNodeList* }
|
||||
%destructor expression_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
expression_list(A) ::= expression(B). { PARSER_TRACE; A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
|
||||
expression_list(A) ::= expression_list(B) NK_COMMA expression(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
|
||||
|
||||
column_reference(A) ::= column_name(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); }
|
||||
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
|
||||
|
||||
//pseudo_column(A) ::= NK_NOW. { PARSER_TRACE; A = createFunctionNode(pCxt, NULL, NULL); }
|
||||
|
||||
/************************************************ predicate ***********************************************************/
|
||||
predicate(A) ::= expression(B) compare_op(C) expression(D). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, D);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
|
||||
}
|
||||
//predicate(A) ::= expression(B) compare_op sub_type expression(B).
|
||||
predicate(A) ::= expression(B) BETWEEN expression(C) AND expression(D). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, D);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D)));
|
||||
}
|
||||
predicate(A) ::= expression(B) NOT BETWEEN expression(C) AND expression(D). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, D);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
|
||||
}
|
||||
predicate(A) ::= expression(B) IS NULL(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, B), NULL));
|
||||
}
|
||||
predicate(A) ::= expression(B) IS NOT NULL(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, B), NULL));
|
||||
}
|
||||
predicate(A) ::= expression(B) in_op(C) in_predicate_value(D). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, D);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
|
||||
}
|
||||
|
||||
%type compare_op { EOperatorType }
|
||||
%destructor compare_op { PARSER_DESTRUCTOR_TRACE; }
|
||||
compare_op(A) ::= NK_LT. { PARSER_TRACE; A = OP_TYPE_LOWER_THAN; }
|
||||
compare_op(A) ::= NK_GT. { PARSER_TRACE; A = OP_TYPE_GREATER_THAN; }
|
||||
compare_op(A) ::= NK_LE. { PARSER_TRACE; A = OP_TYPE_LOWER_EQUAL; }
|
||||
compare_op(A) ::= NK_GE. { PARSER_TRACE; A = OP_TYPE_GREATER_EQUAL; }
|
||||
compare_op(A) ::= NK_NE. { PARSER_TRACE; A = OP_TYPE_NOT_EQUAL; }
|
||||
compare_op(A) ::= NK_EQ. { PARSER_TRACE; A = OP_TYPE_EQUAL; }
|
||||
compare_op(A) ::= LIKE. { PARSER_TRACE; A = OP_TYPE_LIKE; }
|
||||
compare_op(A) ::= NOT LIKE. { PARSER_TRACE; A = OP_TYPE_NOT_LIKE; }
|
||||
compare_op(A) ::= MATCH. { PARSER_TRACE; A = OP_TYPE_MATCH; }
|
||||
compare_op(A) ::= NMATCH. { PARSER_TRACE; A = OP_TYPE_NMATCH; }
|
||||
|
||||
%type in_op { EOperatorType }
|
||||
%destructor in_op { PARSER_DESTRUCTOR_TRACE; }
|
||||
in_op(A) ::= IN. { PARSER_TRACE; A = OP_TYPE_IN; }
|
||||
in_op(A) ::= NOT IN. { PARSER_TRACE; A = OP_TYPE_NOT_IN; }
|
||||
|
||||
in_predicate_value(A) ::= NK_LP(C) expression_list(B) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &C, &D, createNodeListNode(pCxt, B)); }
|
||||
|
||||
/************************************************ boolean_value_expression ********************************************/
|
||||
boolean_value_expression(A) ::= boolean_primary(B). { PARSER_TRACE; A = B; }
|
||||
boolean_value_expression(A) ::= NOT(C) boolean_primary(B). {
|
||||
PARSER_TRACE;
|
||||
SToken e = getTokenFromRawExprNode(pCxt, B);
|
||||
A = createRawExprNodeExt(pCxt, &C, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, B), NULL));
|
||||
}
|
||||
boolean_value_expression(A) ::=
|
||||
boolean_value_expression(B) OR boolean_value_expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
boolean_value_expression(A) ::=
|
||||
boolean_value_expression(B) AND boolean_value_expression(C). {
|
||||
PARSER_TRACE;
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
|
||||
boolean_primary(A) ::= predicate(B). { PARSER_TRACE; A = B; }
|
||||
boolean_primary(A) ::= NK_LP(C) boolean_value_expression(B) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &C, &D, releaseRawExprNode(pCxt, B)); }
|
||||
|
||||
/************************************************ common_expression ********************************************/
|
||||
common_expression(A) ::= expression(B). { A = B; }
|
||||
common_expression(A) ::= boolean_value_expression(B). { A = B; }
|
||||
|
||||
/************************************************ from_clause *********************************************************/
|
||||
from_clause(A) ::= FROM table_reference_list(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
table_reference_list(A) ::= table_reference(B). { PARSER_TRACE; A = B; }
|
||||
table_reference_list(A) ::= table_reference_list(B) NK_COMMA table_reference(C). { PARSER_TRACE; A = createJoinTableNode(pCxt, JOIN_TYPE_INNER, B, C, NULL); }
|
||||
|
||||
/************************************************ table_reference *****************************************************/
|
||||
table_reference(A) ::= table_primary(B). { PARSER_TRACE; A = B; }
|
||||
table_reference(A) ::= joined_table(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
table_primary(A) ::= table_name(B) alias_opt(C). { PARSER_TRACE; A = createRealTableNode(pCxt, NULL, &B, &C); }
|
||||
table_primary(A) ::= db_name(B) NK_DOT table_name(C) alias_opt(D). { PARSER_TRACE; A = createRealTableNode(pCxt, &B, &C, &D); }
|
||||
table_primary(A) ::= subquery(B) alias_opt(C). { PARSER_TRACE; A = createTempTableNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||
table_primary(A) ::= parenthesized_joined_table(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type alias_opt { SToken }
|
||||
%destructor alias_opt { PARSER_DESTRUCTOR_TRACE; }
|
||||
alias_opt(A) ::= . { PARSER_TRACE; A = nil_token; }
|
||||
alias_opt(A) ::= table_alias(B). { PARSER_TRACE; A = B; }
|
||||
alias_opt(A) ::= AS table_alias(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
parenthesized_joined_table(A) ::= NK_LP joined_table(B) NK_RP. { PARSER_TRACE; A = B; }
|
||||
parenthesized_joined_table(A) ::= NK_LP parenthesized_joined_table(B) NK_RP. { PARSER_TRACE; A = B; }
|
||||
|
||||
/************************************************ joined_table ********************************************************/
|
||||
joined_table(A) ::=
|
||||
table_reference(B) join_type(C) JOIN table_reference(D) ON search_condition(E). { PARSER_TRACE; A = createJoinTableNode(pCxt, C, B, D, E); }
|
||||
|
||||
%type join_type { EJoinType }
|
||||
%destructor join_type { PARSER_DESTRUCTOR_TRACE; }
|
||||
join_type(A) ::= . { PARSER_TRACE; A = JOIN_TYPE_INNER; }
|
||||
join_type(A) ::= INNER. { PARSER_TRACE; A = JOIN_TYPE_INNER; }
|
||||
|
||||
/************************************************ query_specification *************************************************/
|
||||
query_specification(A) ::=
|
||||
SELECT set_quantifier_opt(B) select_list(C) from_clause(D) where_clause_opt(E)
|
||||
partition_by_clause_opt(F) twindow_clause_opt(G)
|
||||
group_by_clause_opt(H) having_clause_opt(I). {
|
||||
PARSER_TRACE;
|
||||
A = createSelectStmt(pCxt, B, C, D);
|
||||
A = addWhereClause(pCxt, A, E);
|
||||
A = addPartitionByClause(pCxt, A, F);
|
||||
A = addWindowClauseClause(pCxt, A, G);
|
||||
A = addGroupByClause(pCxt, A, H);
|
||||
A = addHavingClause(pCxt, A, I);
|
||||
}
|
||||
|
||||
%type set_quantifier_opt { bool }
|
||||
%destructor set_quantifier_opt { PARSER_DESTRUCTOR_TRACE; }
|
||||
set_quantifier_opt(A) ::= . { PARSER_TRACE; A = false; }
|
||||
set_quantifier_opt(A) ::= DISTINCT. { PARSER_TRACE; A = true; }
|
||||
set_quantifier_opt(A) ::= ALL. { PARSER_TRACE; A = false; }
|
||||
|
||||
%type select_list { SNodeList* }
|
||||
%destructor select_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
select_list(A) ::= NK_STAR. { PARSER_TRACE; A = NULL; }
|
||||
select_list(A) ::= select_sublist(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type select_sublist { SNodeList* }
|
||||
%destructor select_sublist { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
select_sublist(A) ::= select_item(B). { PARSER_TRACE; A = createNodeList(pCxt, B); }
|
||||
select_sublist(A) ::= select_sublist(B) NK_COMMA select_item(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
|
||||
|
||||
select_item(A) ::= common_expression(B). {
|
||||
PARSER_TRACE;
|
||||
SToken t = getTokenFromRawExprNode(pCxt, B);
|
||||
A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &t);
|
||||
}
|
||||
select_item(A) ::= common_expression(B) column_alias(C). { PARSER_TRACE; A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||
select_item(A) ::= common_expression(B) AS column_alias(C). { PARSER_TRACE; A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||
select_item(A) ::= table_name(B) NK_DOT NK_STAR(C). { PARSER_TRACE; A = createColumnNode(pCxt, &B, &C); }
|
||||
|
||||
where_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
where_clause_opt(A) ::= WHERE search_condition(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type partition_by_clause_opt { SNodeList* }
|
||||
%destructor partition_by_clause_opt { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
partition_by_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
partition_by_clause_opt(A) ::= PARTITION BY expression_list(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
twindow_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
twindow_clause_opt(A) ::=
|
||||
SESSION NK_LP column_reference(B) NK_COMMA NK_INTEGER(C) NK_RP. { PARSER_TRACE; A = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||
twindow_clause_opt(A) ::= STATE_WINDOW NK_LP column_reference(B) NK_RP. { PARSER_TRACE; A = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, B)); }
|
||||
twindow_clause_opt(A) ::=
|
||||
INTERVAL NK_LP duration_literal(B) NK_RP sliding_opt(C) fill_opt(D). { PARSER_TRACE; A = createIntervalWindowNode(pCxt, B, NULL, C, D); }
|
||||
twindow_clause_opt(A) ::=
|
||||
INTERVAL NK_LP duration_literal(B) NK_COMMA duration_literal(C) NK_RP
|
||||
sliding_opt(D) fill_opt(E). { PARSER_TRACE; A = createIntervalWindowNode(pCxt, B, C, D, E); }
|
||||
|
||||
sliding_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
sliding_opt(A) ::= SLIDING NK_LP duration_literal(B) NK_RP. { PARSER_TRACE; A = B; }
|
||||
|
||||
fill_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
fill_opt(A) ::= FILL NK_LP fill_mode(B) NK_RP. { PARSER_TRACE; A = createFillNode(pCxt, B, NULL); }
|
||||
fill_opt(A) ::= FILL NK_LP VALUE NK_COMMA literal_list(B) NK_RP. { PARSER_TRACE; A = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, B)); }
|
||||
|
||||
%type fill_mode { EFillMode }
|
||||
%destructor fill_mode { PARSER_DESTRUCTOR_TRACE; }
|
||||
fill_mode(A) ::= NONE. { PARSER_TRACE; A = FILL_MODE_NONE; }
|
||||
fill_mode(A) ::= PREV. { PARSER_TRACE; A = FILL_MODE_PREV; }
|
||||
fill_mode(A) ::= NULL. { PARSER_TRACE; A = FILL_MODE_NULL; }
|
||||
fill_mode(A) ::= LINEAR. { PARSER_TRACE; A = FILL_MODE_LINEAR; }
|
||||
fill_mode(A) ::= NEXT. { PARSER_TRACE; A = FILL_MODE_NEXT; }
|
||||
|
||||
%type group_by_clause_opt { SNodeList* }
|
||||
%destructor group_by_clause_opt { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
group_by_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
group_by_clause_opt(A) ::= GROUP BY group_by_list(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
%type group_by_list { SNodeList* }
|
||||
%destructor group_by_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
group_by_list(A) ::= expression(B). { PARSER_TRACE; A = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, B))); }
|
||||
group_by_list(A) ::= group_by_list(B) NK_COMMA expression(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, C))); }
|
||||
|
||||
having_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
having_clause_opt(A) ::= HAVING search_condition(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
/************************************************ query_expression ****************************************************/
|
||||
query_expression(A) ::=
|
||||
query_expression_body(B)
|
||||
order_by_clause_opt(C) slimit_clause_opt(D) limit_clause_opt(E). {
|
||||
PARSER_TRACE;
|
||||
A = addOrderByClause(pCxt, B, C);
|
||||
A = addSlimitClause(pCxt, A, D);
|
||||
A = addLimitClause(pCxt, A, E);
|
||||
}
|
||||
|
||||
query_expression_body(A) ::= query_primary(B). { PARSER_TRACE; A = B; }
|
||||
query_expression_body(A) ::=
|
||||
query_expression_body(B) UNION ALL query_expression_body(D). { PARSER_TRACE; A = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, B, D); }
|
||||
|
||||
query_primary(A) ::= query_specification(B). { PARSER_TRACE; A = B; }
|
||||
//query_primary(A) ::=
|
||||
// NK_LP query_expression_body(B)
|
||||
// order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { PARSER_TRACE; A = B;}
|
||||
|
||||
%type order_by_clause_opt { SNodeList* }
|
||||
%destructor order_by_clause_opt { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
order_by_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
order_by_clause_opt(A) ::= ORDER BY sort_specification_list(B). { PARSER_TRACE; A = B; }
|
||||
|
||||
slimit_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(B). { PARSER_TRACE; A = createLimitNode(pCxt, &B, NULL); }
|
||||
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(B) SOFFSET NK_INTEGER(C). { PARSER_TRACE; A = createLimitNode(pCxt, &B, &C); }
|
||||
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { PARSER_TRACE; A = createLimitNode(pCxt, &B, &C); }
|
||||
|
||||
limit_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||
limit_clause_opt(A) ::= LIMIT NK_INTEGER(B). { PARSER_TRACE; A = createLimitNode(pCxt, &B, NULL); }
|
||||
limit_clause_opt(A) ::= LIMIT NK_INTEGER(B) OFFSET NK_INTEGER(C). { PARSER_TRACE; A = createLimitNode(pCxt, &B, &C); }
|
||||
limit_clause_opt(A) ::= LIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { PARSER_TRACE; A = createLimitNode(pCxt, &B, &C); }
|
||||
|
||||
/************************************************ subquery ************************************************************/
|
||||
subquery(A) ::= NK_LP(B) query_expression(C) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &D, C); }
|
||||
|
||||
/************************************************ search_condition ****************************************************/
|
||||
search_condition(A) ::= common_expression(B). { PARSER_TRACE; A = releaseRawExprNode(pCxt, B); }
|
||||
|
||||
/************************************************ sort_specification_list *********************************************/
|
||||
%type sort_specification_list { SNodeList* }
|
||||
%destructor sort_specification_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||
sort_specification_list(A) ::= sort_specification(B). { PARSER_TRACE; A = createNodeList(pCxt, B); }
|
||||
sort_specification_list(A) ::=
|
||||
sort_specification_list(B) NK_COMMA sort_specification(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
|
||||
|
||||
sort_specification(A) ::=
|
||||
expression(B) ordering_specification_opt(C) null_ordering_opt(D). { PARSER_TRACE; A = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, B), C, D); }
|
||||
|
||||
%type ordering_specification_opt EOrder
|
||||
%destructor ordering_specification_opt { PARSER_DESTRUCTOR_TRACE; }
|
||||
ordering_specification_opt(A) ::= . { PARSER_TRACE; A = ORDER_ASC; }
|
||||
ordering_specification_opt(A) ::= ASC. { PARSER_TRACE; A = ORDER_ASC; }
|
||||
ordering_specification_opt(A) ::= DESC. { PARSER_TRACE; A = ORDER_DESC; }
|
||||
|
||||
%type null_ordering_opt ENullOrder
|
||||
%destructor null_ordering_opt { PARSER_DESTRUCTOR_TRACE; }
|
||||
null_ordering_opt(A) ::= . { PARSER_TRACE; A = NULL_ORDER_DEFAULT; }
|
||||
null_ordering_opt(A) ::= NULLS FIRST. { PARSER_TRACE; A = NULL_ORDER_FIRST; }
|
||||
null_ordering_opt(A) ::= NULLS LAST. { PARSER_TRACE; A = NULL_ORDER_LAST; }
|
|
@ -20,13 +20,55 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "cmdnodes.h"
|
||||
#include "parser.h"
|
||||
#include "parToken.h"
|
||||
#include "parUtil.h"
|
||||
#include "querynodes.h"
|
||||
#include "nodesShowStmts.h"
|
||||
#include "astCreateContext.h"
|
||||
#include "ttoken.h"
|
||||
|
||||
typedef struct SAstCreateContext {
|
||||
SParseContext* pQueryCxt;
|
||||
SMsgBuf msgBuf;
|
||||
bool notSupport;
|
||||
bool valid;
|
||||
SNode* pRootNode;
|
||||
} SAstCreateContext;
|
||||
|
||||
typedef enum EDatabaseOptionType {
|
||||
DB_OPTION_BLOCKS = 0,
|
||||
DB_OPTION_CACHE,
|
||||
DB_OPTION_CACHELAST,
|
||||
DB_OPTION_COMP,
|
||||
DB_OPTION_DAYS,
|
||||
DB_OPTION_FSYNC,
|
||||
DB_OPTION_MAXROWS,
|
||||
DB_OPTION_MINROWS,
|
||||
DB_OPTION_KEEP,
|
||||
DB_OPTION_PRECISION,
|
||||
DB_OPTION_QUORUM,
|
||||
DB_OPTION_REPLICA,
|
||||
DB_OPTION_TTL,
|
||||
DB_OPTION_WAL,
|
||||
DB_OPTION_VGROUPS,
|
||||
DB_OPTION_SINGLESTABLE,
|
||||
DB_OPTION_STREAMMODE,
|
||||
|
||||
DB_OPTION_MAX
|
||||
} EDatabaseOptionType;
|
||||
|
||||
typedef enum ETableOptionType {
|
||||
TABLE_OPTION_KEEP = 0,
|
||||
TABLE_OPTION_TTL,
|
||||
TABLE_OPTION_COMMENT,
|
||||
TABLE_OPTION_SMA,
|
||||
|
||||
TABLE_OPTION_MAX
|
||||
} ETableOptionType;
|
||||
|
||||
extern SToken nil_token;
|
||||
|
||||
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt);
|
||||
|
||||
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode);
|
||||
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode);
|
||||
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode);
|
||||
|
@ -67,8 +109,29 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
|
|||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
||||
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, EShowStmtType type);
|
||||
|
||||
SDatabaseOptions* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
|
||||
SDatabaseOptions* setDatabaseOption(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, EDatabaseOptionType type, const SToken* pVal);
|
||||
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SDatabaseOptions* pOptions);
|
||||
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName);
|
||||
STableOptions* createDefaultTableOptions(SAstCreateContext* pCxt);
|
||||
STableOptions* setTableOption(SAstCreateContext* pCxt, STableOptions* pOptions, ETableOptionType type, const SToken* pVal);
|
||||
STableOptions* setTableSmaOption(SAstCreateContext* pCxt, STableOptions* pOptions, SNodeList* pSma);
|
||||
SNode* createColumnDefNode(SAstCreateContext* pCxt, const 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, STableOptions* 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* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName);
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDbName);
|
||||
SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword);
|
||||
SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int8_t alterType, const SToken* pVal);
|
||||
SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName);
|
||||
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -13,21 +13,21 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_PARSER_IMPL_H_
|
||||
#define _TD_PARSER_IMPL_H_
|
||||
#ifndef _TD_PARSER_INT_H_
|
||||
#define _TD_PARSER_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "querynodes.h"
|
||||
#include "newParser.h"
|
||||
#include "parser.h"
|
||||
|
||||
int32_t doParse(SParseContext* pParseCxt, SQuery* pQuery);
|
||||
int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery);
|
||||
int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery);
|
||||
int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_PARSER_IMPL_H_*/
|
||||
#endif /*_TD_PARSER_INT_H_*/
|
|
@ -36,7 +36,7 @@ typedef struct SToken {
|
|||
* @return
|
||||
*/
|
||||
#define isNumber(tk) \
|
||||
((tk)->type == TK_INTEGER || (tk)->type == TK_FLOAT || (tk)->type == TK_HEX || (tk)->type == TK_BIN)
|
||||
((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_NK_HEX || (tk)->type == TK_NK_BIN)
|
||||
|
||||
/**
|
||||
* tokenizer for sql string
|
||||
|
@ -67,11 +67,11 @@ bool taosIsKeyWordToken(const char *z, int32_t len);
|
|||
/**
|
||||
* check if it is a token or not
|
||||
* @param pToken
|
||||
* @return token type, if it is not a number, TK_ILLEGAL will return
|
||||
* @return token type, if it is not a number, TK_NK_ILLEGAL will return
|
||||
*/
|
||||
static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
||||
const char* z = pToken->z;
|
||||
int32_t type = TK_ILLEGAL;
|
||||
int32_t type = TK_NK_ILLEGAL;
|
||||
|
||||
uint32_t i = 0;
|
||||
for(; i < pToken->n; ++i) {
|
||||
|
@ -88,7 +88,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
* .123e4
|
||||
*/
|
||||
if (!isdigit(z[i+1])) {
|
||||
return TK_ILLEGAL;
|
||||
return TK_NK_ILLEGAL;
|
||||
}
|
||||
|
||||
for (i += 2; isdigit(z[i]); i++) {
|
||||
|
@ -102,20 +102,20 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
}
|
||||
}
|
||||
|
||||
type = TK_FLOAT;
|
||||
type = TK_NK_FLOAT;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
case '0': {
|
||||
char next = z[i + 1];
|
||||
if (next == 'b') { // bin number
|
||||
type = TK_BIN;
|
||||
type = TK_NK_BIN;
|
||||
for (i += 2; (z[i] == '0' || z[i] == '1'); ++i) {
|
||||
}
|
||||
|
||||
goto _end;
|
||||
} else if (next == 'x') { //hex number
|
||||
type = TK_HEX;
|
||||
type = TK_NK_HEX;
|
||||
for (i += 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) {
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
case '7':
|
||||
case '8':
|
||||
case '9': {
|
||||
type = TK_INTEGER;
|
||||
type = TK_NK_INTEGER;
|
||||
for (; isdigit(z[i]); i++) {
|
||||
}
|
||||
|
||||
|
@ -144,11 +144,11 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
}
|
||||
|
||||
seg++;
|
||||
type = TK_FLOAT;
|
||||
type = TK_NK_FLOAT;
|
||||
}
|
||||
|
||||
if (seg > 1) {
|
||||
return TK_ILLEGAL;
|
||||
return TK_NK_ILLEGAL;
|
||||
}
|
||||
|
||||
if ((z[i] == 'e' || z[i] == 'E') &&
|
||||
|
@ -158,18 +158,18 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
i++;
|
||||
}
|
||||
|
||||
type = TK_FLOAT;
|
||||
type = TK_NK_FLOAT;
|
||||
}
|
||||
|
||||
goto _end;
|
||||
}
|
||||
default:
|
||||
return TK_ILLEGAL;
|
||||
return TK_NK_ILLEGAL;
|
||||
}
|
||||
}
|
||||
|
||||
_end:
|
||||
return (i < pToken->n)? TK_ILLEGAL:type;
|
||||
return (i < pToken->n)? TK_NK_ILLEGAL:type;
|
||||
}
|
||||
|
||||
void taosCleanupKeywordsTable();
|
|
@ -13,38 +13,36 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_QUERYINFOUTIL_H
|
||||
#define TDENGINE_QUERYINFOUTIL_H
|
||||
#ifndef TDENGINE_PARSER_UTIL_H
|
||||
#define TDENGINE_PARSER_UTIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "parserInt.h"
|
||||
|
||||
SSchema* getTbnameColumnSchema();
|
||||
#include "os.h"
|
||||
#include "query.h"
|
||||
|
||||
int32_t getNumOfColumns(const STableMeta* pTableMeta);
|
||||
int32_t getNumOfTags(const STableMeta* pTableMeta);
|
||||
typedef struct SMsgBuf {
|
||||
int32_t len;
|
||||
char *buf;
|
||||
} SMsgBuf;
|
||||
|
||||
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
|
||||
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
|
||||
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr);
|
||||
|
||||
STableMeta* tableMetaDup(const STableMeta* pTableMeta);
|
||||
SSchema *getTableColumnSchema(const STableMeta *pTableMeta);
|
||||
SSchema *getTableTagSchema(const STableMeta* pTableMeta);
|
||||
|
||||
SArray *getCurrentExprList(SQueryStmtInfo* pQueryInfo);
|
||||
size_t getNumOfExprs(SQueryStmtInfo* pQueryInfo);
|
||||
|
||||
void addExprInfo(SArray* pExprList, int32_t index, SExprInfo* pExprInfo, int32_t level);
|
||||
void updateExprInfo(SExprInfo* pExprInfo, int16_t functionId, int32_t colId, int16_t srcColumnIndex, int16_t resType, int16_t resSize);
|
||||
|
||||
SExprInfo* getExprInfo(SQueryStmtInfo* pQueryInfo, int32_t index);
|
||||
|
||||
void addExprInfoParam(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes);
|
||||
|
||||
void cleanupFieldInfo(SFieldInfo* pFieldInfo);
|
||||
|
||||
int32_t getNumOfColumns(const STableMeta* pTableMeta);
|
||||
int32_t getNumOfTags(const STableMeta* pTableMeta);
|
||||
STableComInfo getTableInfo(const STableMeta* pTableMeta);
|
||||
SArray *extractFunctionList(SArray* pExprInfoList);
|
||||
|
||||
int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_QUERYINFOUTIL_H
|
||||
#endif // TDENGINE_PARSER_UTIL_H
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* 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_PARSER_INT_H_
|
||||
#define _TD_PARSER_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "catalog.h"
|
||||
#include "tname.h"
|
||||
#include "astGenerator.h"
|
||||
|
||||
struct SSqlNode;
|
||||
|
||||
|
||||
typedef struct SInternalField {
|
||||
TAOS_FIELD field;
|
||||
bool visible;
|
||||
SExprInfo *pExpr;
|
||||
} SInternalField;
|
||||
|
||||
typedef struct SMsgBuf {
|
||||
int32_t len;
|
||||
char *buf;
|
||||
} SMsgBuf;
|
||||
|
||||
void clearTableMetaInfo(STableMetaInfo* pTableMetaInfo);
|
||||
|
||||
void clearAllTableMetaInfo(SQueryStmtInfo* pQueryInfo, bool removeMeta, uint64_t id);
|
||||
|
||||
/**
|
||||
* Validate the sql info, according to the corresponding metadata info from catalog.
|
||||
* @param pCtx
|
||||
* @param pInfo
|
||||
* @param pQueryInfo
|
||||
* @param msgBuf
|
||||
* @param msgBufLen
|
||||
* @return
|
||||
*/
|
||||
int32_t qParserValidateSqlNode(SParseContext *pCtx, SSqlInfo* pInfo, SQueryStmtInfo* pQueryInfo, char* msgBuf, int32_t msgBufLen);
|
||||
|
||||
/**
|
||||
* validate the ddl ast, and convert the ast to the corresponding message format
|
||||
* @param pSqlInfo
|
||||
* @param output
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, char* msgBuf, int32_t msgBufLen);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pInfo
|
||||
* @param pCtx
|
||||
* @param msgBuf
|
||||
* @param msgBufLen
|
||||
* @return
|
||||
*/
|
||||
SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, char* msgBuf, int32_t msgBufLen);
|
||||
|
||||
/**
|
||||
* Evaluate the numeric and timestamp arithmetic expression in the WHERE clause.
|
||||
* @param pNode
|
||||
* @param tsPrecision
|
||||
* @param msg
|
||||
* @param msgBufLen
|
||||
* @return
|
||||
*/
|
||||
int32_t evaluateSqlNode(SSqlNode* pNode, int32_t tsPrecision, SMsgBuf* pMsgBuf);
|
||||
|
||||
int32_t validateSqlNode(SSqlNode* pSqlNode, SQueryStmtInfo* pQueryInfo, SMsgBuf* pMsgBuf);
|
||||
|
||||
SQueryStmtInfo* createQueryInfo();
|
||||
|
||||
void destroyQueryInfo(SQueryStmtInfo* pQueryInfo);
|
||||
|
||||
int32_t checkForInvalidExpr(SQueryStmtInfo* pQueryInfo, SMsgBuf* pMsgBuf);
|
||||
|
||||
/**
|
||||
* Extract request meta info from the sql statement
|
||||
* @param pSqlInfo
|
||||
* @param pMetaInfo
|
||||
* @param msg
|
||||
* @param msgBufLen
|
||||
* @return
|
||||
*/
|
||||
int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SCatalogReq* pMetaInfo, SParseContext *pCtx, char* msg, int32_t msgBufLen);
|
||||
|
||||
/**
|
||||
* Destroy the meta data request structure.
|
||||
* @param pMetaInfo
|
||||
*/
|
||||
void qParserCleanupMetaRequestInfo(SCatalogReq* pMetaInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_PARSER_INT_H_*/
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* 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 TDENGINE_PARSERUTIL_H
|
||||
#define TDENGINE_PARSERUTIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
#include "ttoken.h"
|
||||
#include "parserInt.h"
|
||||
|
||||
#define UTIL_TABLE_IS_SUPER_TABLE(metaInfo) \
|
||||
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_SUPER_TABLE))
|
||||
|
||||
#define UTIL_TABLE_IS_CHILD_TABLE(metaInfo) \
|
||||
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_CHILD_TABLE))
|
||||
|
||||
#define UTIL_TABLE_IS_NORMAL_TABLE(metaInfo) \
|
||||
(!(UTIL_TABLE_IS_SUPER_TABLE(metaInfo) || UTIL_TABLE_IS_CHILD_TABLE(metaInfo)))
|
||||
|
||||
#define UTIL_TABLE_IS_TMP_TABLE(metaInfo) \
|
||||
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_TEMP_TABLE))
|
||||
|
||||
TAOS_FIELD createField(const SSchema* pSchema);
|
||||
void setColumn(SColumn* pColumn, uint64_t uid, const char* tableName, int8_t flag, const SSchema* pSchema);
|
||||
SColumn createColumn(uint64_t uid, const char* tableName, int8_t flag, const SSchema* pSchema);
|
||||
|
||||
SInternalField* insertFieldInfo(SFieldInfo* pFieldInfo, int32_t index, SSchema* field);
|
||||
int32_t getNumOfFields(SFieldInfo* pFieldInfo);
|
||||
SInternalField* getInternalField(SFieldInfo* pFieldInfo, int32_t index);
|
||||
|
||||
int32_t parserValidateIdToken(SToken* pToken);
|
||||
int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf);
|
||||
int32_t parserValidateNameToken(SToken* pToken);
|
||||
|
||||
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
|
||||
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr);
|
||||
|
||||
STableMetaInfo* addEmptyMetaInfo(SQueryStmtInfo* pQueryInfo);
|
||||
|
||||
void columnListCopyAll(SArray* dst, const SArray* src);
|
||||
|
||||
SColumn* columnListInsert(SArray* pColumnList, uint64_t uid, SSchema* pSchema, int32_t flag);
|
||||
SColumn* insertPrimaryTsColumn(SArray* pColumnList, const char* colName, uint64_t tableUid);
|
||||
|
||||
void cleanupTagCond(STagCond* pTagCond);
|
||||
void cleanupColumnCond(SArray** pCond);
|
||||
|
||||
uint32_t convertRelationalOperator(SToken *pToken);
|
||||
int32_t getExprFunctionId(SExprInfo *pExprInfo);
|
||||
|
||||
STableMeta* tableMetaDup(const STableMeta* pTableMeta);
|
||||
|
||||
bool isDclSqlStatement(SSqlInfo* pSqlInfo);
|
||||
bool isDdlSqlStatement(SSqlInfo* pSqlInfo);
|
||||
bool isDqlSqlStatement(SSqlInfo* pSqlInfo);
|
||||
|
||||
typedef struct SKvParam {
|
||||
SKVRowBuilder *builder;
|
||||
SSchema *schema;
|
||||
char buf[TSDB_MAX_TAGS_LEN];
|
||||
} SKvParam;
|
||||
|
||||
int32_t KvRowAppend(const void *value, int32_t len, void *param);
|
||||
|
||||
typedef int32_t (*_row_append_fn_t)(const void *value, int32_t len, void *param);
|
||||
int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int16_t timePrec, char* tmpTokenBuf, _row_append_fn_t func, void* param, SMsgBuf* pMsgBuf);
|
||||
|
||||
int32_t createSName(SName* pName, SToken* pTableName, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_PARSERUTIL_H
|
File diff suppressed because it is too large
Load Diff
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* 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 "ttoken.h"
|
||||
#include "astCreateContext.h"
|
||||
|
||||
int32_t createAstCreateContext(SParseContext* pQueryCxt, SAstCreateContext* pCxt) {
|
||||
pCxt->pQueryCxt = pQueryCxt;
|
||||
pCxt->notSupport = false;
|
||||
pCxt->valid = true;
|
||||
pCxt->pRootNode = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t destroyAstCreateContext(SAstCreateContext* pCxt) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -1,384 +0,0 @@
|
|||
|
||||
/*
|
||||
* 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 "astCreateFuncs.h"
|
||||
|
||||
#define CHECK_OUT_OF_MEM(p) \
|
||||
do { \
|
||||
if (NULL == (p)) { \
|
||||
pCxt->valid = false; \
|
||||
return NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_RAW_EXPR_NODE(node) \
|
||||
do { \
|
||||
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
|
||||
pCxt->valid = false; \
|
||||
return NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
SToken nil_token = { .type = TK_NIL, .n = 0, .z = NULL };
|
||||
|
||||
static bool checkDbName(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||
if (NULL == pDbName) {
|
||||
return true;
|
||||
}
|
||||
pCxt->valid = pDbName->n < TSDB_DB_NAME_LEN ? true : false;
|
||||
return pCxt->valid;
|
||||
}
|
||||
|
||||
static bool checkTableName(SAstCreateContext* pCxt, const SToken* pTableName) {
|
||||
if (NULL == pTableName) {
|
||||
return true;
|
||||
}
|
||||
pCxt->valid = pTableName->n < TSDB_TABLE_NAME_LEN ? true : false;
|
||||
return pCxt->valid;
|
||||
}
|
||||
|
||||
static bool checkColumnName(SAstCreateContext* pCxt, const SToken* pColumnName) {
|
||||
if (NULL == pColumnName) {
|
||||
return true;
|
||||
}
|
||||
pCxt->valid = pColumnName->n < TSDB_COL_NAME_LEN ? true : false;
|
||||
return pCxt->valid;
|
||||
}
|
||||
|
||||
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode) {
|
||||
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
||||
CHECK_OUT_OF_MEM(target);
|
||||
target->p = pToken->z;
|
||||
target->n = pToken->n;
|
||||
target->pNode = pNode;
|
||||
return (SNode*)target;
|
||||
}
|
||||
|
||||
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode) {
|
||||
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
||||
CHECK_OUT_OF_MEM(target);
|
||||
target->p = pStart->z;
|
||||
target->n = (pEnd->z + pEnd->n) - pStart->z;
|
||||
target->pNode = pNode;
|
||||
return (SNode*)target;
|
||||
}
|
||||
|
||||
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||
CHECK_RAW_EXPR_NODE(pNode);
|
||||
SNode* tmp = ((SRawExprNode*)pNode)->pNode;
|
||||
tfree(pNode);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||
if (NULL == pNode || QUERY_NODE_RAW_EXPR != nodeType(pNode)) {
|
||||
pCxt->valid = false;
|
||||
return nil_token;
|
||||
}
|
||||
SRawExprNode* target = (SRawExprNode*)pNode;
|
||||
SToken t = { .type = 0, .z = target->p, .n = target->n};
|
||||
return t;
|
||||
}
|
||||
|
||||
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
|
||||
SNodeList* list = nodesMakeList();
|
||||
CHECK_OUT_OF_MEM(list);
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(list, pNode)) {
|
||||
pCxt->valid = false;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode) {
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, pNode)) {
|
||||
pCxt->valid = false;
|
||||
}
|
||||
return pList;
|
||||
}
|
||||
|
||||
SNode* createColumnNode(SAstCreateContext* pCxt, const SToken* pTableAlias, const SToken* pColumnName) {
|
||||
if (!checkTableName(pCxt, pTableAlias) || !checkColumnName(pCxt, pColumnName)) {
|
||||
return NULL;
|
||||
}
|
||||
SColumnNode* col = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_OUT_OF_MEM(col);
|
||||
if (NULL != pTableAlias) {
|
||||
strncpy(col->tableAlias, pTableAlias->z, pTableAlias->n);
|
||||
}
|
||||
strncpy(col->colName, pColumnName->z, pColumnName->n);
|
||||
return (SNode*)col;
|
||||
}
|
||||
|
||||
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral) {
|
||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
CHECK_OUT_OF_MEM(val);
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
CHECK_OUT_OF_MEM(val->literal);
|
||||
val->node.resType.type = dataType;
|
||||
val->node.resType.bytes = tDataTypes[dataType].bytes;
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP == dataType) {
|
||||
val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
|
||||
}
|
||||
return (SNode*)val;
|
||||
}
|
||||
|
||||
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
|
||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
CHECK_OUT_OF_MEM(val);
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
CHECK_OUT_OF_MEM(val->literal);
|
||||
val->isDuration = true;
|
||||
val->node.resType.type = TSDB_DATA_TYPE_BIGINT;
|
||||
val->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
|
||||
val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
|
||||
return (SNode*)val;
|
||||
}
|
||||
|
||||
SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType type, SNode* pParam1, SNode* pParam2) {
|
||||
SLogicConditionNode* cond = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
||||
CHECK_OUT_OF_MEM(cond);
|
||||
cond->condType = type;
|
||||
cond->pParameterList = nodesMakeList();
|
||||
nodesListAppend(cond->pParameterList, pParam1);
|
||||
nodesListAppend(cond->pParameterList, pParam2);
|
||||
return (SNode*)cond;
|
||||
}
|
||||
|
||||
SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pLeft, SNode* pRight) {
|
||||
SOperatorNode* op = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
|
||||
CHECK_OUT_OF_MEM(op);
|
||||
op->opType = type;
|
||||
op->pLeft = pLeft;
|
||||
op->pRight = pRight;
|
||||
return (SNode*)op;
|
||||
}
|
||||
|
||||
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, 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, pExpr, pRight));
|
||||
}
|
||||
|
||||
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) {
|
||||
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_OUT_OF_MEM(func);
|
||||
strncpy(func->functionName, pFuncName->z, pFuncName->n);
|
||||
func->pParameterList = pParameterList;
|
||||
return (SNode*)func;
|
||||
}
|
||||
|
||||
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList) {
|
||||
SNodeListNode* list = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
CHECK_OUT_OF_MEM(list);
|
||||
list->pNodeList = pList;
|
||||
return (SNode*)list;
|
||||
}
|
||||
|
||||
SNode* createRealTableNode(SAstCreateContext* pCxt, const SToken* pDbName, const SToken* pTableName, const SToken* pTableAlias) {
|
||||
if (!checkDbName(pCxt, pDbName) || !checkTableName(pCxt, pTableName)) {
|
||||
return NULL;
|
||||
}
|
||||
SRealTableNode* realTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
||||
CHECK_OUT_OF_MEM(realTable);
|
||||
if (NULL != pDbName) {
|
||||
strncpy(realTable->table.dbName, pDbName->z, pDbName->n);
|
||||
} else {
|
||||
strcpy(realTable->table.dbName, pCxt->pQueryCxt->db);
|
||||
}
|
||||
if (NULL != pTableAlias && TK_NIL != pTableAlias->type) {
|
||||
strncpy(realTable->table.tableAlias, pTableAlias->z, pTableAlias->n);
|
||||
} else {
|
||||
strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n);
|
||||
}
|
||||
strncpy(realTable->table.tableName, pTableName->z, pTableName->n);
|
||||
return (SNode*)realTable;
|
||||
}
|
||||
|
||||
SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const SToken* pTableAlias) {
|
||||
STempTableNode* tempTable = (STempTableNode*)nodesMakeNode(QUERY_NODE_TEMP_TABLE);
|
||||
CHECK_OUT_OF_MEM(tempTable);
|
||||
tempTable->pSubquery = pSubquery;
|
||||
if (NULL != pTableAlias && TK_NIL != pTableAlias->type) {
|
||||
strncpy(tempTable->table.tableAlias, pTableAlias->z, pTableAlias->n);
|
||||
}
|
||||
return (SNode*)tempTable;
|
||||
}
|
||||
|
||||
SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft, SNode* pRight, SNode* pJoinCond) {
|
||||
SJoinTableNode* joinTable = (SJoinTableNode*)nodesMakeNode(QUERY_NODE_JOIN_TABLE);
|
||||
CHECK_OUT_OF_MEM(joinTable);
|
||||
joinTable->joinType = type;
|
||||
joinTable->pLeft = pLeft;
|
||||
joinTable->pRight = pRight;
|
||||
joinTable->pOnCond = pJoinCond;
|
||||
return (SNode*)joinTable;
|
||||
}
|
||||
|
||||
SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset) {
|
||||
SLimitNode* limitNode = (SLimitNode*)nodesMakeNode(QUERY_NODE_LIMIT);
|
||||
CHECK_OUT_OF_MEM(limitNode);
|
||||
// limitNode->limit = limit;
|
||||
// limitNode->offset = offset;
|
||||
return (SNode*)limitNode;
|
||||
}
|
||||
|
||||
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder) {
|
||||
SOrderByExprNode* orderByExpr = (SOrderByExprNode*)nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR);
|
||||
CHECK_OUT_OF_MEM(orderByExpr);
|
||||
orderByExpr->pExpr = pExpr;
|
||||
orderByExpr->order = order;
|
||||
if (NULL_ORDER_DEFAULT == nullOrder) {
|
||||
nullOrder = (ORDER_ASC == order ? NULL_ORDER_FIRST : NULL_ORDER_LAST);
|
||||
}
|
||||
orderByExpr->nullOrder = nullOrder;
|
||||
return (SNode*)orderByExpr;
|
||||
}
|
||||
|
||||
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, const SToken* pVal) {
|
||||
SSessionWindowNode* session = (SSessionWindowNode*)nodesMakeNode(QUERY_NODE_SESSION_WINDOW);
|
||||
CHECK_OUT_OF_MEM(session);
|
||||
session->pCol = pCol;
|
||||
// session->gap = getInteger(pVal);
|
||||
return (SNode*)session;
|
||||
}
|
||||
|
||||
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pCol) {
|
||||
SStateWindowNode* state = (SStateWindowNode*)nodesMakeNode(QUERY_NODE_STATE_WINDOW);
|
||||
CHECK_OUT_OF_MEM(state);
|
||||
state->pCol = pCol;
|
||||
return (SNode*)state;
|
||||
}
|
||||
|
||||
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->pInterval = pInterval;
|
||||
interval->pOffset = pOffset;
|
||||
interval->pSliding = pSliding;
|
||||
interval->pFill = pFill;
|
||||
return (SNode*)interval;
|
||||
}
|
||||
|
||||
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) {
|
||||
SFillNode* fill = (SFillNode*)nodesMakeNode(QUERY_NODE_FILL);
|
||||
CHECK_OUT_OF_MEM(fill);
|
||||
fill->mode = mode;
|
||||
fill->pValues = pValues;
|
||||
return (SNode*)fill;
|
||||
}
|
||||
|
||||
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||
SGroupingSetNode* groupingSet = (SGroupingSetNode*)nodesMakeNode(QUERY_NODE_GROUPING_SET);
|
||||
CHECK_OUT_OF_MEM(groupingSet);
|
||||
groupingSet->groupingSetType = GP_TYPE_NORMAL;
|
||||
groupingSet->pParameterList = nodesMakeList();
|
||||
nodesListAppend(groupingSet->pParameterList, pNode);
|
||||
return (SNode*)groupingSet;
|
||||
}
|
||||
|
||||
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) {
|
||||
if (NULL == pNode || !pCxt->valid) {
|
||||
return pNode;
|
||||
}
|
||||
uint32_t maxLen = sizeof(((SExprNode*)pNode)->aliasName);
|
||||
strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, pAlias->n > maxLen ? maxLen : pAlias->n);
|
||||
return pNode;
|
||||
}
|
||||
|
||||
SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pWhere = pWhere;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pPartitionByList = pPartitionByList;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* addWindowClauseClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWindow) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pWindow = pWindow;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* addGroupByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pGroupByList) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pGroupByList = pGroupByList;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pHaving = pHaving;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pOrderByList = pOrderByList;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pSlimit = pSlimit;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pLimit = pLimit;
|
||||
}
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable) {
|
||||
SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
|
||||
CHECK_OUT_OF_MEM(select);
|
||||
select->isDistinct = isDistinct;
|
||||
select->pProjectionList = pProjectionList;
|
||||
select->pFromTable = pTable;
|
||||
return (SNode*)select;
|
||||
}
|
||||
|
||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight) {
|
||||
SSetOperator* setOp = (SSetOperator*)nodesMakeNode(QUERY_NODE_SET_OPERATOR);
|
||||
CHECK_OUT_OF_MEM(setOp);
|
||||
setOp->opType = type;
|
||||
setOp->pLeft = pLeft;
|
||||
setOp->pRight = pRight;
|
||||
return (SNode*)setOp;
|
||||
}
|
||||
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, EShowStmtType type) {
|
||||
SShowStmt* show = (SShowStmt*)nodesMakeNode(QUERY_NODE_SHOW_STMT);
|
||||
CHECK_OUT_OF_MEM(show);
|
||||
show->showType = type;
|
||||
return (SNode*)show;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,520 +0,0 @@
|
|||
/*
|
||||
* 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 "astGenerator.h"
|
||||
#include "parserInt.h"
|
||||
#include "parserUtil.h"
|
||||
|
||||
char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) {
|
||||
SCreateUserReq createReq = {0};
|
||||
|
||||
SUserInfo* pUser = &pInfo->pMiscInfo->user;
|
||||
strncpy(createReq.user, pUser->user.z, pUser->user.n);
|
||||
createReq.createType = pUser->type;
|
||||
createReq.superUser = (int8_t)pUser->type;
|
||||
|
||||
if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
|
||||
// pMsg->privilege = (char)pCmd->count;
|
||||
} else {
|
||||
strncpy(createReq.pass, pUser->passwd.z, pUser->passwd.n);
|
||||
}
|
||||
|
||||
int32_t tlen = tSerializeSCreateUserReq(NULL, 0, &createReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSCreateUserReq(pReq, tlen, &createReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) {
|
||||
SCreateAcctReq createReq = {0};
|
||||
|
||||
SToken* pName = &pInfo->pMiscInfo->user.user;
|
||||
SToken* pPwd = &pInfo->pMiscInfo->user.passwd;
|
||||
|
||||
strncpy(createReq.user, pName->z, pName->n);
|
||||
strncpy(createReq.pass, pPwd->z, pPwd->n);
|
||||
|
||||
SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt;
|
||||
|
||||
createReq.maxUsers = pAcctOpt->maxUsers;
|
||||
createReq.maxDbs = pAcctOpt->maxDbs;
|
||||
createReq.maxTimeSeries = pAcctOpt->maxTimeSeries;
|
||||
createReq.maxStreams = pAcctOpt->maxStreams;
|
||||
createReq.maxStorage = pAcctOpt->maxStorage;
|
||||
|
||||
if (pAcctOpt->stat.n == 0) {
|
||||
createReq.accessState = -1;
|
||||
} else {
|
||||
if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) {
|
||||
createReq.accessState = TSDB_VN_READ_ACCCESS;
|
||||
} else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) {
|
||||
createReq.accessState = TSDB_VN_WRITE_ACCCESS;
|
||||
} else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) {
|
||||
createReq.accessState = TSDB_VN_ALL_ACCCESS;
|
||||
} else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) {
|
||||
createReq.accessState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tlen = tSerializeSCreateAcctReq(NULL, 0, &createReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSCreateAcctReq(pReq, tlen, &createReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgBufLen) {
|
||||
SDropUserReq dropReq = {0};
|
||||
|
||||
SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0);
|
||||
if (pName->n >= TSDB_USER_LEN) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(dropReq.user, pName->z, pName->n);
|
||||
|
||||
int32_t tlen = tSerializeSDropUserReq(NULL, 0, &dropReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSDropUserReq(pReq, tlen, &dropReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
char* buildShowMsg(SShowInfo* pShowInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf) {
|
||||
SShowReq showReq = {.type = pShowInfo->showType};
|
||||
|
||||
if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) {
|
||||
SToken* pPattern = &pShowInfo->pattern;
|
||||
if (pPattern->type > 0) { // only show tables support wildcard query
|
||||
showReq.payloadLen = pPattern->n;
|
||||
showReq.payload = malloc(showReq.payloadLen);
|
||||
strncpy(showReq.payload, pPattern->z, pPattern->n);
|
||||
}
|
||||
} else {
|
||||
SToken* pEpAddr = &pShowInfo->prefix;
|
||||
assert(pEpAddr->n > 0 && pEpAddr->type > 0);
|
||||
showReq.payloadLen = pEpAddr->n;
|
||||
showReq.payload = malloc(showReq.payloadLen);
|
||||
strncpy(showReq.payload, pEpAddr->z, pEpAddr->n);
|
||||
}
|
||||
|
||||
if (pShowInfo->showType == TSDB_MGMT_TABLE_STB || pShowInfo->showType == TSDB_MGMT_TABLE_VGROUP) {
|
||||
SName n = {0};
|
||||
|
||||
if (pShowInfo->prefix.n > 0) {
|
||||
if (pShowInfo->prefix.n >= TSDB_DB_FNAME_LEN) {
|
||||
terrno = buildInvalidOperationMsg(pMsgBuf, "prefix name is too long");
|
||||
tFreeSShowReq(&showReq);
|
||||
return NULL;
|
||||
}
|
||||
tNameSetDbName(&n, pCtx->acctId, pShowInfo->prefix.z, pShowInfo->prefix.n);
|
||||
} else if (pCtx->db == NULL || strlen(pCtx->db) == 0) {
|
||||
terrno = buildInvalidOperationMsg(pMsgBuf, "database is not specified");
|
||||
tFreeSShowReq(&showReq);
|
||||
return NULL;
|
||||
} else {
|
||||
tNameSetDbName(&n, pCtx->acctId, pCtx->db, strlen(pCtx->db));
|
||||
}
|
||||
|
||||
tNameGetFullDbName(&n, showReq.db);
|
||||
}
|
||||
|
||||
int32_t tlen = tSerializeSShowReq(NULL, 0, &showReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSShowReq(pReq, tlen, &showReq);
|
||||
tFreeSShowReq(&showReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
static int32_t setKeepOption(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "invalid number of keep options";
|
||||
const char* msg2 = "invalid keep value";
|
||||
const char* msg3 = "invalid keep value, should be keep0 <= keep1 <= keep2";
|
||||
|
||||
pMsg->daysToKeep0 = -1;
|
||||
pMsg->daysToKeep1 = -1;
|
||||
pMsg->daysToKeep2 = -1;
|
||||
|
||||
SArray* pKeep = pCreateDb->keep;
|
||||
if (pKeep != NULL) {
|
||||
size_t s = taosArrayGetSize(pKeep);
|
||||
#ifdef _STORAGE
|
||||
if (s >= 4 || s <= 0) {
|
||||
#else
|
||||
if (s != 1) {
|
||||
#endif
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
// tListI* p0 = taosArrayGet(pKeep, 0);
|
||||
// tVariantListItem* p1 = (s > 1) ? taosArrayGet(pKeep, 1) : p0;
|
||||
// tVariantListItem* p2 = (s > 2) ? taosArrayGet(pKeep, 2) : p1;
|
||||
//
|
||||
// if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) {
|
||||
// return buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
// }
|
||||
// if (!(((int32_t)p0->pVar.i64 <= (int32_t)p1->pVar.i64) && ((int32_t)p1->pVar.i64 <= (int32_t)p2->pVar.i64))) {
|
||||
// return buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
// }
|
||||
//
|
||||
// pMsg->daysToKeep0 = htonl((int32_t)p0->pVar.i64);
|
||||
// pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
|
||||
// pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setTimePrecision(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDbInfo, SMsgBuf* pMsgBuf) {
|
||||
const char* msg = "invalid time precision";
|
||||
|
||||
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
|
||||
|
||||
SToken* pToken = (SToken*)&pCreateDbInfo->precision;
|
||||
if (pToken->n > 0) {
|
||||
pToken->n = strdequote(pToken->z);
|
||||
|
||||
if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 &&
|
||||
strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) {
|
||||
// time precision for this db: million second
|
||||
pMsg->precision = TSDB_TIME_PRECISION_MILLI;
|
||||
} else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 &&
|
||||
strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) {
|
||||
pMsg->precision = TSDB_TIME_PRECISION_MICRO;
|
||||
} else if (strncmp(pToken->z, TSDB_TIME_PRECISION_NANO_STR, pToken->n) == 0 &&
|
||||
strlen(TSDB_TIME_PRECISION_NANO_STR) == pToken->n) {
|
||||
pMsg->precision = TSDB_TIME_PRECISION_NANO;
|
||||
} else {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void doSetDbOptions(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb) {
|
||||
pMsg->cacheBlockSize = pCreateDb->cacheBlockSize;
|
||||
pMsg->totalBlocks = pCreateDb->numOfBlocks;
|
||||
pMsg->daysPerFile = pCreateDb->daysPerFile;
|
||||
pMsg->commitTime = (int32_t)pCreateDb->commitTime;
|
||||
pMsg->minRows = pCreateDb->minRowsPerBlock;
|
||||
pMsg->maxRows = pCreateDb->maxRowsPerBlock;
|
||||
pMsg->fsyncPeriod = pCreateDb->fsyncPeriod;
|
||||
pMsg->compression = (int8_t)pCreateDb->compressionLevel;
|
||||
pMsg->walLevel = (char)pCreateDb->walLevel;
|
||||
pMsg->replications = pCreateDb->replica;
|
||||
pMsg->quorum = pCreateDb->quorum;
|
||||
pMsg->ignoreExist = pCreateDb->ignoreExists;
|
||||
pMsg->update = pCreateDb->update;
|
||||
pMsg->cacheLastRow = pCreateDb->cachelast;
|
||||
pMsg->numOfVgroups = pCreateDb->numOfVgroups;
|
||||
pMsg->streamMode = pCreateDb->streamMode;
|
||||
}
|
||||
|
||||
int32_t setDbOptions(SCreateDbReq* pCreateDbMsg, const SCreateDbInfo* pCreateDbSql, SMsgBuf* pMsgBuf) {
|
||||
doSetDbOptions(pCreateDbMsg, pCreateDbSql);
|
||||
|
||||
if (setKeepOption(pCreateDbMsg, pCreateDbSql, pMsgBuf) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
if (setTimePrecision(pCreateDbMsg, pCreateDbSql, pMsgBuf) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// can only perform the parameters based on the macro definitation
|
||||
static int32_t doCheckDbOptions(SCreateDbReq* pCreate, SMsgBuf* pMsgBuf) {
|
||||
char msg[512] = {0};
|
||||
|
||||
if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
if (pCreate->replications != -1 &&
|
||||
(pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications,
|
||||
TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
int32_t blocks = pCreate->totalBlocks;
|
||||
if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks,
|
||||
TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
if (pCreate->quorum != -1 &&
|
||||
(pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum,
|
||||
TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
int32_t val = pCreate->daysPerFile;
|
||||
if (val != -1 && (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, TSDB_MIN_DAYS_PER_FILE,
|
||||
TSDB_MAX_DAYS_PER_FILE);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
val = pCreate->cacheBlockSize;
|
||||
if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val,
|
||||
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO &&
|
||||
pCreate->precision != TSDB_TIME_PRECISION_NANO) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision,
|
||||
TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
val = pCreate->commitTime;
|
||||
if (val != -1 && (val < TSDB_MIN_COMMIT_TIME || val > TSDB_MAX_COMMIT_TIME)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, TSDB_MIN_COMMIT_TIME,
|
||||
TSDB_MAX_COMMIT_TIME);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
val = pCreate->fsyncPeriod;
|
||||
if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, TSDB_MIN_FSYNC_PERIOD,
|
||||
TSDB_MAX_FSYNC_PERIOD);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
if (pCreate->compression != -1 &&
|
||||
(pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression,
|
||||
TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
}
|
||||
|
||||
val = pCreate->numOfVgroups;
|
||||
if (val < TSDB_MIN_VNODES_PER_DB || val > TSDB_MAX_VNODES_PER_DB) {
|
||||
snprintf(msg, tListLen(msg), "invalid number of vgroups for DB:%d valid range: [%d, %d]", val,
|
||||
TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB);
|
||||
}
|
||||
|
||||
val = pCreate->maxRows;
|
||||
if (val < TSDB_MIN_MAX_ROW_FBLOCK || val > TSDB_MAX_MAX_ROW_FBLOCK) {
|
||||
snprintf(msg, tListLen(msg), "invalid number of max rows in file block for DB:%d valid range: [%d, %d]", val,
|
||||
TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK);
|
||||
}
|
||||
|
||||
val = pCreate->minRows;
|
||||
if (val < TSDB_MIN_MIN_ROW_FBLOCK || val > TSDB_MAX_MIN_ROW_FBLOCK) {
|
||||
snprintf(msg, tListLen(msg), "invalid number of min rows in file block for DB:%d valid range: [%d, %d]", val,
|
||||
TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf) {
|
||||
SCreateDbReq createReq = {0};
|
||||
|
||||
if (setDbOptions(&createReq, pCreateDbInfo, pMsgBuf) != TSDB_CODE_SUCCESS) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SName name = {0};
|
||||
int32_t ret = tNameSetDbName(&name, pCtx->acctId, pCreateDbInfo->dbname.z, pCreateDbInfo->dbname.n);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
terrno = ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tNameGetFullDbName(&name, createReq.db);
|
||||
|
||||
if (doCheckDbOptions(&createReq, pMsgBuf) != TSDB_CODE_SUCCESS) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t tlen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSCreateDbReq(pReq, tlen, &createReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* outputLen, SParseContext* pParseCtx,
|
||||
SMsgBuf* pMsgBuf) {
|
||||
SMCreateStbReq createReq = {0};
|
||||
createReq.igExists = pCreateTableSql->existCheck ? 1 : 0;
|
||||
createReq.pColumns = pCreateTableSql->colInfo.pColumns;
|
||||
createReq.pTags = pCreateTableSql->colInfo.pTagColumns;
|
||||
createReq.numOfColumns = (int32_t)taosArrayGetSize(pCreateTableSql->colInfo.pColumns);
|
||||
createReq.numOfTags = (int32_t)taosArrayGetSize(pCreateTableSql->colInfo.pTagColumns);
|
||||
|
||||
SName n = {0};
|
||||
if (createSName(&n, &pCreateTableSql->name, pParseCtx, pMsgBuf) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (tNameExtractFullName(&n, createReq.name) != 0) {
|
||||
buildInvalidOperationMsg(pMsgBuf, "invalid table name or database not specified");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t tlen = tSerializeSMCreateStbReq(NULL, 0, &createReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSMCreateStbReq(pReq, tlen, &createReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
char* buildDropStableReq(SSqlInfo* pInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) {
|
||||
SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0);
|
||||
|
||||
SName name = {0};
|
||||
int32_t code = createSName(&name, tableName, pParseCtx, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = buildInvalidOperationMsg(pMsgBuf, "invalid table name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SMDropStbReq dropReq = {0};
|
||||
code = tNameExtractFullName(&name, dropReq.name);
|
||||
|
||||
assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_TABLE_NAME_T);
|
||||
dropReq.igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0;
|
||||
|
||||
int32_t tlen = tSerializeSMDropStbReq(NULL, 0, &dropReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSMDropStbReq(pReq, tlen, &dropReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "invalid host name (name too long, maximum length 128)";
|
||||
const char* msg2 = "dnode name can not be string";
|
||||
const char* msg3 = "port should be an integer that is less than 65535 and greater than 0";
|
||||
const char* msg4 = "failed prepare create dnode message";
|
||||
|
||||
if (taosArrayGetSize(pInfo->pMiscInfo->a) != 2) {
|
||||
buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SToken* id = taosArrayGet(pInfo->pMiscInfo->a, 0);
|
||||
if (id->type != TK_ID && id->type != TK_IPTOKEN) {
|
||||
buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SToken* port = taosArrayGet(pInfo->pMiscInfo->a, 1);
|
||||
if (port->type != TK_INTEGER) {
|
||||
buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool isSign = false;
|
||||
int64_t val = 0;
|
||||
|
||||
toInteger(port->z, port->n, 10, &val, &isSign);
|
||||
if (val >= UINT16_MAX || val <= 0) {
|
||||
buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SCreateDnodeReq createReq = {0};
|
||||
|
||||
strncpy(createReq.fqdn, id->z, id->n);
|
||||
createReq.port = val;
|
||||
|
||||
int32_t tlen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSCreateDnodeReq(pReq, tlen, &createReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf) {
|
||||
SDropDnodeReq dropReq = {0};
|
||||
|
||||
SToken* pzName = taosArrayGet(pInfo->pMiscInfo->a, 0);
|
||||
|
||||
char* end = NULL;
|
||||
dropReq.dnodeId = strtoll(pzName->z, &end, 10);
|
||||
|
||||
if (end - pzName->z != pzName->n) {
|
||||
buildInvalidOperationMsg(pMsgBuf, "invalid dnode id");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t tlen = tSerializeSDropDnodeReq(NULL, 0, &dropReq);
|
||||
void* pReq = malloc(tlen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSDropDnodeReq(pReq, tlen, &dropReq);
|
||||
*outputLen = tlen;
|
||||
return pReq;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,905 +0,0 @@
|
|||
#include "tmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "parserInt.h"
|
||||
#include "ttime.h"
|
||||
#include "astToMsg.h"
|
||||
#include "astGenerator.h"
|
||||
#include "parserUtil.h"
|
||||
#include "queryInfoUtil.h"
|
||||
|
||||
/* is contained in pFieldList or not */
|
||||
static bool has(SArray* pFieldList, int32_t startIndex, const char* name) {
|
||||
size_t numOfCols = taosArrayGetSize(pFieldList);
|
||||
for (int32_t j = startIndex; j < numOfCols; ++j) {
|
||||
TAOS_FIELD* field = taosArrayGet(pFieldList, j);
|
||||
if (strncasecmp(name, field->name, sizeof(field->name) - 1) == 0) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int32_t setShowInfo(SShowInfo* pShowInfo, SParseContext* pCtx, void** output, int32_t* outputLen,
|
||||
SEpSet* pEpSet, void** pExtension, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "invalid name";
|
||||
const char* msg2 = "wildcard string should be less than %d characters";
|
||||
const char* msg3 = "database name too long";
|
||||
const char* msg4 = "pattern is invalid";
|
||||
const char* msg5 = "database name is empty";
|
||||
const char* msg6 = "pattern string is empty";
|
||||
const char* msg7 = "database not specified";
|
||||
/*
|
||||
* database prefix in pInfo->pMiscInfo->a[0]
|
||||
* wildcard in like clause in pInfo->pMiscInfo->a[1]
|
||||
*/
|
||||
int16_t showType = pShowInfo->showType;
|
||||
if (showType == TSDB_MGMT_TABLE_TABLE) {
|
||||
SArray* array = NULL;
|
||||
SName name = {0};
|
||||
|
||||
if (pCtx->db == NULL && pShowInfo->prefix.n == 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg7);
|
||||
}
|
||||
|
||||
SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq));
|
||||
if (pShowInfo->prefix.n > 0) {
|
||||
tNameSetDbName(&name, pCtx->acctId, pShowInfo->prefix.z, pShowInfo->prefix.n);
|
||||
} else {
|
||||
tNameSetDbName(&name, pCtx->acctId, pCtx->db, strlen(pCtx->db));
|
||||
}
|
||||
|
||||
char dbFname[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(&name, dbFname);
|
||||
|
||||
int32_t code = catalogGetDBVgInfo(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, dbFname, false, &array);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
SVgroupInfo* info = taosArrayGet(array, 0);
|
||||
pShowReq->head.vgId = htonl(info->vgId);
|
||||
*pEpSet = info->epSet;
|
||||
|
||||
*outputLen = sizeof(SVShowTablesReq);
|
||||
*output = pShowReq;
|
||||
*pExtension = array;
|
||||
} else {
|
||||
if (showType == TSDB_MGMT_TABLE_STB || showType == TSDB_MGMT_TABLE_VGROUP) {
|
||||
SToken* pDbPrefixToken = &pShowInfo->prefix;
|
||||
if (pDbPrefixToken->type != 0) {
|
||||
if (pDbPrefixToken->n >= TSDB_DB_NAME_LEN) { // db name is too long
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
}
|
||||
|
||||
if (pDbPrefixToken->n <= 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg5);
|
||||
}
|
||||
|
||||
if (parserValidateIdToken(pDbPrefixToken) != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
// int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pRequest->pTsc), pDbPrefixToken);
|
||||
// if (ret != TSDB_CODE_SUCCESS) {
|
||||
// return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
// }
|
||||
}
|
||||
|
||||
// show table/stable like 'xxxx', set the like pattern for show tables
|
||||
SToken* pPattern = &pShowInfo->pattern;
|
||||
if (pPattern->type != 0) {
|
||||
if (pPattern->type == TK_ID && pPattern->z[0] == TS_ESCAPE_CHAR) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg4);
|
||||
}
|
||||
|
||||
pPattern->n = strdequote(pPattern->z);
|
||||
if (pPattern->n <= 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg6);
|
||||
}
|
||||
|
||||
if (pPattern->n > tsMaxWildCardsLen) {
|
||||
char tmp[64] = {0};
|
||||
sprintf(tmp, msg2, tsMaxWildCardsLen);
|
||||
return buildInvalidOperationMsg(pMsgBuf, tmp);
|
||||
}
|
||||
}
|
||||
} else if (showType == TSDB_MGMT_TABLE_VNODES) {
|
||||
if (pShowInfo->prefix.type == 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, "No specified dnode ep");
|
||||
}
|
||||
|
||||
if (pShowInfo->prefix.type == TK_STRING) {
|
||||
pShowInfo->prefix.n = strdequote(pShowInfo->prefix.z);
|
||||
}
|
||||
}
|
||||
|
||||
*pEpSet = pCtx->mgmtEpSet;
|
||||
*output = buildShowMsg(pShowInfo, outputLen, pCtx, pMsgBuf);
|
||||
if (*output == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t validateTableColumns(SArray* pFieldList, int32_t maxRowLength, int32_t maxColumns, SMsgBuf* pMsgBuf) {
|
||||
const char* msg2 = "row length exceeds max length";
|
||||
const char* msg3 = "duplicated column names";
|
||||
const char* msg4 = "invalid data type";
|
||||
const char* msg5 = "invalid binary/nchar column length";
|
||||
const char* msg6 = "invalid column name";
|
||||
const char* msg7 = "too many columns";
|
||||
const char* msg8 = "illegal number of columns";
|
||||
|
||||
size_t numOfCols = taosArrayGetSize(pFieldList);
|
||||
if (numOfCols > maxColumns) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg7);
|
||||
}
|
||||
|
||||
int32_t rowLen = 0;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
TAOS_FIELD* pField = taosArrayGet(pFieldList, i);
|
||||
if (!isValidDataType(pField->type)) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg4);
|
||||
}
|
||||
|
||||
if (pField->bytes == 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg5);
|
||||
}
|
||||
|
||||
if ((pField->type == TSDB_DATA_TYPE_BINARY && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_BINARY_LEN)) ||
|
||||
(pField->type == TSDB_DATA_TYPE_NCHAR && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_NCHAR_LEN))) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg5);
|
||||
}
|
||||
|
||||
SToken nameToken = {.z = pField->name, .n = strlen(pField->name), .type = TK_ID};
|
||||
if (parserValidateNameToken(&nameToken) != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg6);
|
||||
}
|
||||
|
||||
// field name must be unique
|
||||
if (has(pFieldList, i + 1, pField->name) == true) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
}
|
||||
|
||||
rowLen += pField->bytes;
|
||||
}
|
||||
|
||||
// max row length must be less than TSDB_MAX_BYTES_PER_ROW
|
||||
if (rowLen > maxRowLength) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) {
|
||||
assert(pFieldList != NULL && pMsgBuf != NULL);
|
||||
|
||||
const char* msg1 = "first column must be timestamp";
|
||||
const char* msg2 = "illegal number of columns";
|
||||
|
||||
// first column must be timestamp
|
||||
SField* pField = taosArrayGet(pFieldList, 0);
|
||||
if (pField->type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
// number of fields no less than 2
|
||||
size_t numOfCols = taosArrayGetSize(pFieldList);
|
||||
if (numOfCols <= 1) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
}
|
||||
|
||||
return validateTableColumns(pFieldList, TSDB_MAX_BYTES_PER_ROW, TSDB_MAX_COLUMNS, pMsgBuf);
|
||||
}
|
||||
|
||||
static int32_t validateTagParams(SArray* pTagsList, SArray* pFieldList, SMsgBuf* pMsgBuf) {
|
||||
assert(pTagsList != NULL);
|
||||
|
||||
const char* msg1 = "invalid number of tag columns";
|
||||
const char* msg3 = "duplicated column names";
|
||||
|
||||
// number of fields at least 1
|
||||
size_t numOfTags = taosArrayGetSize(pTagsList);
|
||||
if (numOfTags < 1) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
// field name must be unique
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
SField* p = taosArrayGet(pTagsList, i);
|
||||
if (has(pFieldList, 0, p->name) == true) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
}
|
||||
}
|
||||
|
||||
return validateTableColumns(pFieldList, TSDB_MAX_TAGS_LEN, TSDB_MAX_TAGS, pMsgBuf);
|
||||
}
|
||||
|
||||
int32_t doCheckForCreateTable(SCreateTableSql* pCreateTable, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "invalid table name";
|
||||
|
||||
SArray* pFieldList = pCreateTable->colInfo.pColumns;
|
||||
SArray* pTagList = pCreateTable->colInfo.pTagColumns;
|
||||
assert(pFieldList != NULL);
|
||||
|
||||
// if sql specifies db, use it, otherwise use default db
|
||||
SToken* pNameToken = &(pCreateTable->name);
|
||||
|
||||
if (parserValidateIdToken(pNameToken) != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
if (validateTableColumnInfo(pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS ||
|
||||
(pTagList != NULL && validateTagParams(pTagList, pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS)) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef struct SVgroupTablesBatch {
|
||||
SVCreateTbBatchReq req;
|
||||
SVgroupInfo info;
|
||||
} SVgroupTablesBatch;
|
||||
|
||||
static SArray* doSerializeVgroupCreateTableInfo(SHashObj* pVgroupHashmap);
|
||||
|
||||
static int32_t doParseSerializeTagValue(SSchema* pTagSchema, int32_t numOfInputTag, SKVRowBuilder* pKvRowBuilder,
|
||||
SArray* pTagValList, int32_t tsPrecision, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "illegal value or data overflow";
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
for (int32_t i = 0; i < numOfInputTag; ++i) {
|
||||
SSchema* pSchema = &pTagSchema[i];
|
||||
|
||||
char* endPtr = NULL;
|
||||
char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0};
|
||||
SKvParam param = {.builder = pKvRowBuilder, .schema = pSchema};
|
||||
|
||||
SToken* pItem = taosArrayGet(pTagValList, i);
|
||||
if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP && pItem->z[0] == '\'') {
|
||||
pItem->z += 1;
|
||||
}
|
||||
|
||||
code = parseValueToken(&endPtr, pItem, pSchema, tsPrecision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static void addCreateTbReqIntoVgroup(SHashObj* pVgroupHashmap, const SName* pTableName, SKVRow row, uint64_t suid, SVgroupInfo* pVgInfo) {
|
||||
struct SVCreateTbReq req = {0};
|
||||
req.type = TD_CHILD_TABLE;
|
||||
req.name = strdup(tNameGetTableName(pTableName));
|
||||
req.ctbCfg.suid = suid;
|
||||
req.ctbCfg.pTag = row;
|
||||
|
||||
SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId));
|
||||
if (pTableBatch == NULL) {
|
||||
SVgroupTablesBatch tBatch = {0};
|
||||
tBatch.info = *pVgInfo;
|
||||
|
||||
tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq));
|
||||
taosArrayPush(tBatch.req.pArray, &req);
|
||||
|
||||
taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch));
|
||||
} else { // add to the correct vgroup
|
||||
assert(pVgInfo->vgId == pTableBatch->info.vgId);
|
||||
taosArrayPush(pTableBatch->req.pArray, &req);
|
||||
}
|
||||
}
|
||||
|
||||
static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) {
|
||||
size_t size = taosArrayGetSize(pTbBatch->req.pArray);
|
||||
for(int32_t i = 0; i < size; ++i) {
|
||||
SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i);
|
||||
tfree(pTableReq->name);
|
||||
|
||||
if (pTableReq->type == TSDB_NORMAL_TABLE) {
|
||||
tfree(pTableReq->ntbCfg.pSchema);
|
||||
} else if (pTableReq->type == TSDB_CHILD_TABLE) {
|
||||
tfree(pTableReq->ctbCfg.pTag);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTbBatch->req.pArray);
|
||||
}
|
||||
|
||||
static int32_t doCheckAndBuildCreateCTableReq(SCreateTableSql* pCreateTable, SParseContext* pCtx, SMsgBuf* pMsgBuf, SArray** pBufArray) {
|
||||
const char* msg1 = "invalid table name";
|
||||
const char* msg2 = "tags number not matched";
|
||||
const char* msg3 = "tag value too long";
|
||||
const char* msg4 = "illegal value or data overflow";
|
||||
|
||||
int32_t code = 0;
|
||||
STableMeta* pSuperTableMeta = NULL;
|
||||
|
||||
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
|
||||
// super table name, create table by using dst
|
||||
size_t numOfTables = taosArrayGetSize(pCreateTable->childTableInfo);
|
||||
for (int32_t j = 0; j < numOfTables; ++j) {
|
||||
SCreatedTableInfo* pCreateTableInfo = taosArrayGet(pCreateTable->childTableInfo, j);
|
||||
|
||||
SToken* pSTableNameToken = &pCreateTableInfo->stbName;
|
||||
code = parserValidateNameToken(pSTableNameToken);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SName name = {0};
|
||||
code = createSName(&name, pSTableNameToken, pCtx, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SKVRowBuilder kvRowBuilder = {0};
|
||||
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
|
||||
code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SArray* pValList = pCreateTableInfo->pTagVals;
|
||||
size_t numOfInputTag = taosArrayGetSize(pValList);
|
||||
|
||||
code = catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &name, &pSuperTableMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
assert(pSuperTableMeta != NULL);
|
||||
|
||||
// too long tag values will return invalid sql, not be truncated automatically
|
||||
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
|
||||
STableComInfo tinfo = getTableInfo(pSuperTableMeta);
|
||||
|
||||
SArray* pNameList = NULL;
|
||||
size_t numOfBoundTags = 0;
|
||||
int32_t schemaSize = getNumOfTags(pSuperTableMeta);
|
||||
|
||||
if (pCreateTableInfo->pTagNames) {
|
||||
pNameList = pCreateTableInfo->pTagNames;
|
||||
numOfBoundTags = taosArrayGetSize(pNameList);
|
||||
|
||||
if (numOfInputTag != numOfBoundTags || schemaSize < numOfInputTag) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
bool findColumnIndex = false;
|
||||
for (int32_t i = 0; i < numOfBoundTags; ++i) {
|
||||
SToken* sToken = taosArrayGet(pNameList, i);
|
||||
|
||||
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // create tmp buf to avoid alter orginal sqlstr
|
||||
strncpy(tmpTokenBuf, sToken->z, sToken->n);
|
||||
sToken->z = tmpTokenBuf;
|
||||
|
||||
// if (TK_STRING == sToken->type) {
|
||||
// tscDequoteAndTrimToken(sToken);
|
||||
// }
|
||||
|
||||
// if (TK_ID == sToken->type) {
|
||||
// tscRmEscapeAndTrimToken(sToken);
|
||||
// }
|
||||
|
||||
SListItem* pItem = taosArrayGet(pValList, i);
|
||||
|
||||
findColumnIndex = false;
|
||||
|
||||
// todo speedup by using hash list
|
||||
for (int32_t t = 0; t < schemaSize; ++t) {
|
||||
if (strncmp(sToken->z, pTagSchema[t].name, sToken->n) == 0 && strlen(pTagSchema[t].name) == sToken->n) {
|
||||
SSchema* pSchema = &pTagSchema[t];
|
||||
|
||||
char tagVal[TSDB_MAX_TAGS_LEN] = {0};
|
||||
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (pItem->pVar.nLen > pSchema->bytes) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
goto _error;
|
||||
}
|
||||
} else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) {
|
||||
// code = convertTimestampStrToInt64(&(pItem->pVar), tinfo.precision);
|
||||
// if (code != TSDB_CODE_SUCCESS) {
|
||||
// return buildInvalidOperationMsg(pMsgBuf, msg4);
|
||||
// }
|
||||
} else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
pItem->pVar.i = convertTimePrecision(pItem->pVar.i, TSDB_TIME_PRECISION_NANO, tinfo.precision);
|
||||
}
|
||||
}
|
||||
|
||||
code = taosVariantDump(&(pItem->pVar), tagVal, pSchema->type, true);
|
||||
|
||||
// check again after the convert since it may be converted from binary to nchar.
|
||||
if (IS_VAR_DATA_TYPE(pSchema->type)) {
|
||||
int16_t len = varDataTLen(tagVal);
|
||||
if (len > pSchema->bytes) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg4);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal);
|
||||
|
||||
findColumnIndex = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!findColumnIndex) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
// return buildInvalidOperationMsg(pMsgBuf, "invalid tag name", sToken->z);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (schemaSize != numOfInputTag) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
code = doParseSerializeTagValue(pTagSchema, numOfInputTag, &kvRowBuilder, pValList, tinfo.precision, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
||||
SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder);
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
if (row == NULL) {
|
||||
code = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
tdSortKVRowByColIdx(row);
|
||||
|
||||
SName tableName = {0};
|
||||
code = createSName(&tableName, &pCreateTableInfo->name, pCtx, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
// Find a appropriate vgroup to accommodate this table , according to the table name
|
||||
SVgroupInfo info = {0};
|
||||
code = catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
addCreateTbReqIntoVgroup(pVgroupHashmap, &tableName, row, pSuperTableMeta->uid, &info);
|
||||
tfree(pSuperTableMeta);
|
||||
}
|
||||
|
||||
*pBufArray = doSerializeVgroupCreateTableInfo(pVgroupHashmap);
|
||||
if (*pBufArray == NULL) {
|
||||
code = terrno;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_error:
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
tfree(pSuperTableMeta);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t serializeVgroupTablesBatchImpl(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) {
|
||||
int tlen = sizeof(SMsgHead) + tSerializeSVCreateTbBatchReq(NULL, &(pTbBatch->req));
|
||||
void* buf = malloc(tlen);
|
||||
if (buf == NULL) {
|
||||
// TODO: handle error
|
||||
}
|
||||
|
||||
((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId);
|
||||
((SMsgHead*)buf)->contLen = htonl(tlen);
|
||||
|
||||
void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
tSerializeSVCreateTbBatchReq(&pBuf, &(pTbBatch->req));
|
||||
|
||||
SVgDataBlocks* pVgData = calloc(1, sizeof(SVgDataBlocks));
|
||||
pVgData->vg = pTbBatch->info;
|
||||
pVgData->pData = buf;
|
||||
pVgData->size = tlen;
|
||||
pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray);
|
||||
|
||||
taosArrayPush(pBufArray, &pVgData);
|
||||
}
|
||||
|
||||
static int32_t doBuildSingleTableBatchReq(SName* pTableName, SArray* pColumns, SVgroupInfo* pVgroupInfo, SVgroupTablesBatch* pBatch) {
|
||||
struct SVCreateTbReq req = {0};
|
||||
req.type = TD_NORMAL_TABLE;
|
||||
req.name = strdup(tNameGetTableName(pTableName));
|
||||
|
||||
req.ntbCfg.nCols = taosArrayGetSize(pColumns);
|
||||
int32_t num = req.ntbCfg.nCols;
|
||||
|
||||
req.ntbCfg.pSchema = calloc(num, sizeof(SSchema));
|
||||
for(int32_t i = 0; i < num; ++i) {
|
||||
SSchema* pSchema = taosArrayGet(pColumns, i);
|
||||
memcpy(&req.ntbCfg.pSchema[i], pSchema, sizeof(SSchema));
|
||||
}
|
||||
|
||||
pBatch->info = *pVgroupInfo;
|
||||
pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq));
|
||||
if (pBatch->req.pArray == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
taosArrayPush(pBatch->req.pArray, &req);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t doCheckAndBuildCreateTableReq(SCreateTableSql* pCreateTable, SParseContext* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) {
|
||||
SArray* pBufArray = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
// it is a sql statement to create a normal table
|
||||
if (pCreateTable->childTableInfo == NULL) {
|
||||
assert(taosArrayGetSize(pCreateTable->colInfo.pColumns) > 0 && pCreateTable->colInfo.pTagColumns == NULL);
|
||||
code = doCheckForCreateTable(pCreateTable, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SName tableName = {0};
|
||||
code = createSName(&tableName, &pCreateTable->name, pCtx, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SVgroupInfo info = {0};
|
||||
catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info);
|
||||
|
||||
SVgroupTablesBatch tbatch = {0};
|
||||
code = doBuildSingleTableBatchReq(&tableName, pCreateTable->colInfo.pColumns, &info, &tbatch);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pBufArray = taosArrayInit(1, POINTER_BYTES);
|
||||
if (pBufArray == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
serializeVgroupTablesBatchImpl(&tbatch, pBufArray);
|
||||
destroyCreateTbReqBatch(&tbatch);
|
||||
} else { // it is a child table, created according to a super table
|
||||
code = doCheckAndBuildCreateCTableReq(pCreateTable, pCtx, pMsgBuf, &pBufArray);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
SVnodeModifOpStmtInfo* pStmtInfo = calloc(1, sizeof(SVnodeModifOpStmtInfo));
|
||||
pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE;
|
||||
pStmtInfo->pDataBlocks = pBufArray;
|
||||
|
||||
*pOutput = (char*) pStmtInfo;
|
||||
*len = sizeof(SVnodeModifOpStmtInfo);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SArray* doSerializeVgroupCreateTableInfo(SHashObj* pVgroupHashmap) {
|
||||
SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*));
|
||||
|
||||
SVgroupTablesBatch* pTbBatch = NULL;
|
||||
do {
|
||||
pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch);
|
||||
if (pTbBatch == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
/*int32_t code = */serializeVgroupTablesBatchImpl(pTbBatch, pBufArray);
|
||||
destroyCreateTbReqBatch(pTbBatch);
|
||||
} while (true);
|
||||
|
||||
return pBufArray;
|
||||
}
|
||||
|
||||
SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, char* msgBuf, int32_t msgBufLen) {
|
||||
int32_t code = 0;
|
||||
|
||||
SDclStmtInfo* pDcl = calloc(1, sizeof(SDclStmtInfo));
|
||||
|
||||
SMsgBuf m = {.buf = msgBuf, .len = msgBufLen};
|
||||
SMsgBuf* pMsgBuf = &m;
|
||||
|
||||
pDcl->epSet = pCtx->mgmtEpSet;
|
||||
|
||||
switch (pInfo->type) {
|
||||
case TSDB_SQL_CREATE_USER:
|
||||
case TSDB_SQL_ALTER_USER: {
|
||||
const char* msg1 = "not support options";
|
||||
const char* msg2 = "invalid user/account name";
|
||||
const char* msg3 = "name too long";
|
||||
const char* msg4 = "invalid user rights";
|
||||
|
||||
SUserInfo* pUser = &pInfo->pMiscInfo->user;
|
||||
SToken* pName = &pUser->user;
|
||||
SToken* pPwd = &pUser->passwd;
|
||||
|
||||
if (pName->n >= TSDB_USER_LEN) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (parserValidateIdToken(pName) != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (pInfo->type == TSDB_SQL_CREATE_USER) {
|
||||
if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
goto _error;
|
||||
}
|
||||
} else {
|
||||
if (pUser->type == TSDB_ALTER_USER_PASSWD) {
|
||||
if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
goto _error;
|
||||
}
|
||||
} else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
|
||||
assert(pPwd->type == TSDB_DATA_TYPE_NULL);
|
||||
|
||||
SToken* pPrivilege = &pUser->privilege;
|
||||
if (strncasecmp(pPrivilege->z, "super", 5) == 0 && pPrivilege->n == 5) {
|
||||
// pCmd->count = 1;
|
||||
} else if (strncasecmp(pPrivilege->z, "normal", 4) == 0 && pPrivilege->n == 4) {
|
||||
// pCmd->count = 2;
|
||||
} else {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg4);
|
||||
goto _error;
|
||||
}
|
||||
} else {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
||||
pDcl->pMsg = (char*)buildUserManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen);
|
||||
pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_USER) ? TDMT_MND_CREATE_USER : TDMT_MND_ALTER_USER;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_CREATE_ACCT:
|
||||
case TSDB_SQL_ALTER_ACCT: {
|
||||
const char* msg1 = "invalid state option, available options[no, r, w, all]";
|
||||
const char* msg2 = "invalid user/account name";
|
||||
const char* msg3 = "name too long";
|
||||
|
||||
SToken* pName = &pInfo->pMiscInfo->user.user;
|
||||
SToken* pPwd = &pInfo->pMiscInfo->user.passwd;
|
||||
|
||||
if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (pName->n >= TSDB_USER_LEN) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (parserValidateNameToken(pName) != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt;
|
||||
if (pAcctOpt->stat.n > 0) {
|
||||
if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) {
|
||||
} else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) {
|
||||
} else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) {
|
||||
} else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) {
|
||||
} else {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
||||
pDcl->pMsg = (char*)buildAcctManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen);
|
||||
pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_ACCT) ? TDMT_MND_CREATE_ACCT : TDMT_MND_ALTER_ACCT;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_DROP_ACCT:
|
||||
case TSDB_SQL_DROP_USER: {
|
||||
pDcl->pMsg = (char*)buildDropUserMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen);
|
||||
pDcl->msgType = (pInfo->type == TSDB_SQL_DROP_ACCT) ? TDMT_MND_DROP_ACCT : TDMT_MND_DROP_USER;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_SHOW: {
|
||||
SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt;
|
||||
code = setShowInfo(pShowInfo, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet, &pDcl->pExtension, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pDcl->msgType = (pShowInfo->showType == TSDB_MGMT_TABLE_TABLE) ? TDMT_VND_SHOW_TABLES : TDMT_MND_SHOW;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_USE_DB: {
|
||||
const char* msg = "invalid db name";
|
||||
|
||||
SToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0);
|
||||
if (parserValidateNameToken(pToken) != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SName n = {0};
|
||||
int32_t ret = tNameSetDbName(&n, pCtx->acctId, pToken->z, pToken->n);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SUseDbReq usedbReq = {0};
|
||||
tNameExtractFullName(&n, usedbReq.db);
|
||||
catalogGetDBVgVersion(pCtx->pCatalog, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId);
|
||||
|
||||
int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
|
||||
void* pBuf = malloc(bufLen);
|
||||
tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
|
||||
|
||||
pDcl->pMsg = pBuf;
|
||||
pDcl->msgLen = bufLen;
|
||||
pDcl->msgType = TDMT_MND_USE_DB;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_ALTER_DB:
|
||||
case TSDB_SQL_CREATE_DB: {
|
||||
const char* msg1 = "invalid db name";
|
||||
const char* msg2 = "name too long";
|
||||
|
||||
SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt);
|
||||
if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
char buf[TSDB_DB_NAME_LEN] = {0};
|
||||
SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf));
|
||||
|
||||
if (parserValidateNameToken(&token) != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
int32_t bufLen = 0;
|
||||
char* pBuf = buildCreateDbMsg(pCreateDB, &bufLen, pCtx, pMsgBuf);
|
||||
|
||||
pDcl->pMsg = pBuf;
|
||||
pDcl->msgLen = bufLen;
|
||||
pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB) ? TDMT_MND_CREATE_DB : TDMT_MND_ALTER_DB;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_DROP_DB: {
|
||||
const char* msg1 = "invalid database name";
|
||||
|
||||
assert(taosArrayGetSize(pInfo->pMiscInfo->a) == 1);
|
||||
SToken* dbName = taosArrayGet(pInfo->pMiscInfo->a, 0);
|
||||
|
||||
SName name = {0};
|
||||
code = tNameSetDbName(&name, pCtx->acctId, dbName->z, dbName->n);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SDropDbReq dropdbReq = {0};
|
||||
code = tNameExtractFullName(&name, dropdbReq.db);
|
||||
dropdbReq.ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0;
|
||||
assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_DB_NAME_T);
|
||||
|
||||
int32_t bufLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
|
||||
void* pBuf = malloc(bufLen);
|
||||
tSerializeSDropDbReq(pBuf, bufLen, &dropdbReq);
|
||||
|
||||
pDcl->msgType = TDMT_MND_DROP_DB;
|
||||
pDcl->msgLen = bufLen;
|
||||
pDcl->pMsg = pBuf;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_CREATE_STABLE: {
|
||||
SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo;
|
||||
if ((code = doCheckForCreateTable(pCreateTable, pMsgBuf)) != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pDcl->pMsg = buildCreateStbReq(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf);
|
||||
pDcl->msgType = TDMT_MND_CREATE_STB;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_DROP_TABLE: {
|
||||
pDcl->pMsg = buildDropStableReq(pInfo, &pDcl->msgLen, pCtx, pMsgBuf);
|
||||
if (pDcl->pMsg == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pDcl->msgType = TDMT_MND_DROP_STB;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_CREATE_DNODE: {
|
||||
pDcl->pMsg = (char*)buildCreateDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf);
|
||||
if (pDcl->pMsg == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pDcl->msgType = TDMT_MND_CREATE_DNODE;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_DROP_DNODE: {
|
||||
pDcl->pMsg = (char*)buildDropDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf);
|
||||
if (pDcl->pMsg == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pDcl->msgType = TDMT_MND_DROP_DNODE;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return pDcl;
|
||||
|
||||
_error:
|
||||
terrno = code;
|
||||
tfree(pDcl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, char* msgBuf, int32_t msgBufLen) {
|
||||
SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo;
|
||||
assert(pCreateTable->type == TSDB_SQL_CREATE_TABLE);
|
||||
|
||||
SMsgBuf m = {.buf = msgBuf, .len = msgBufLen};
|
||||
SMsgBuf* pMsgBuf = &m;
|
||||
|
||||
SVnodeModifOpStmtInfo* pModifSqlStmt = NULL;
|
||||
|
||||
int32_t msgLen = 0;
|
||||
int32_t code = doCheckAndBuildCreateTableReq(pCreateTable, pCtx, pMsgBuf, (char**) &pModifSqlStmt, &msgLen);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
tfree(pModifSqlStmt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pModifSqlStmt;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue