提交 36670708 编写于 作者: dengyihao's avatar dengyihao

add create index msg

上级 628096b3
...@@ -273,11 +273,11 @@ typedef struct { ...@@ -273,11 +273,11 @@ typedef struct {
char name[TSDB_COL_NAME_LEN]; char name[TSDB_COL_NAME_LEN];
} SSchemaEx; } SSchemaEx;
#define SSCHMEA_TYPE(s) ((s)->type) #define SSCHMEA_TYPE(s) ((s)->type)
#define SSCHMEA_SMA(s) ((s)->sma) #define SSCHMEA_SMA(s) ((s)->sma)
#define SSCHMEA_COLID(s) ((s)->colId) #define SSCHMEA_COLID(s) ((s)->colId)
#define SSCHMEA_BYTES(s) ((s)->bytes) #define SSCHMEA_BYTES(s) ((s)->bytes)
#define SSCHMEA_NAME(s) ((s)->name) #define SSCHMEA_NAME(s) ((s)->name)
typedef struct { typedef struct {
char name[TSDB_TABLE_FNAME_LEN]; char name[TSDB_TABLE_FNAME_LEN];
...@@ -934,12 +934,12 @@ typedef struct SExplainExecInfo { ...@@ -934,12 +934,12 @@ typedef struct SExplainExecInfo {
uint64_t startupCost; uint64_t startupCost;
uint64_t totalCost; uint64_t totalCost;
uint64_t numOfRows; uint64_t numOfRows;
void *verboseInfo; void* verboseInfo;
} SExplainExecInfo; } SExplainExecInfo;
typedef struct { typedef struct {
int32_t numOfPlans; int32_t numOfPlans;
SExplainExecInfo *subplanInfo; SExplainExecInfo* subplanInfo;
} SExplainRsp; } SExplainRsp;
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp); int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
...@@ -989,8 +989,8 @@ int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq ...@@ -989,8 +989,8 @@ int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
} SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq, SMCreateSnodeReq, SMDropSnodeReq, } SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq, SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq, SMCreateBnodeReq,
SDCreateSnodeReq, SDDropSnodeReq, SMCreateBnodeReq, SMDropBnodeReq, SDCreateBnodeReq, SDDropBnodeReq; SMDropBnodeReq, SDCreateBnodeReq, SDDropBnodeReq;
int32_t tSerializeSMCreateDropQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq); int32_t tSerializeSMCreateDropQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
int32_t tDeserializeSMCreateDropQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq); int32_t tDeserializeSMCreateDropQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
...@@ -1432,12 +1432,12 @@ typedef struct SVCreateTbReq { ...@@ -1432,12 +1432,12 @@ typedef struct SVCreateTbReq {
}; };
union { union {
struct { struct {
tb_uid_t suid; tb_uid_t suid;
col_id_t nCols; col_id_t nCols;
col_id_t nBSmaCols; col_id_t nBSmaCols;
SSchemaEx* pSchema; SSchemaEx* pSchema;
col_id_t nTagCols; col_id_t nTagCols;
SSchema* pTagSchema; SSchema* pTagSchema;
SRSmaParam* pRSmaParam; SRSmaParam* pRSmaParam;
} stbCfg; } stbCfg;
struct { struct {
...@@ -1445,9 +1445,9 @@ typedef struct SVCreateTbReq { ...@@ -1445,9 +1445,9 @@ typedef struct SVCreateTbReq {
SKVRow pTag; SKVRow pTag;
} ctbCfg; } ctbCfg;
struct { struct {
col_id_t nCols; col_id_t nCols;
col_id_t nBSmaCols; col_id_t nBSmaCols;
SSchemaEx* pSchema; SSchemaEx* pSchema;
SRSmaParam* pRSmaParam; SRSmaParam* pRSmaParam;
} ntbCfg; } ntbCfg;
}; };
...@@ -2224,6 +2224,13 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) { ...@@ -2224,6 +2224,13 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) {
return buf; return buf;
} }
typedef struct {
} SMCreateFullTextReq;
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
void tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
typedef struct { typedef struct {
int8_t mqMsgType; int8_t mqMsgType;
int32_t code; int32_t code;
...@@ -2293,9 +2300,7 @@ static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) { ...@@ -2293,9 +2300,7 @@ static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
return buf; return buf;
} }
static FORCE_INLINE void tDeleteSMqCMGetSubEpRsp(SMqCMGetSubEpRsp* pRsp) { static FORCE_INLINE void tDeleteSMqCMGetSubEpRsp(SMqCMGetSubEpRsp* pRsp) { taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp); }
taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp);
}
static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp) { static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp) {
int32_t tlen = 0; int32_t tlen = 0;
......
...@@ -385,7 +385,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { ...@@ -385,7 +385,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
if (pReq->rollup) { if (pReq->rollup) {
pReq->stbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam)); pReq->stbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam));
SRSmaParam *param = pReq->stbCfg.pRSmaParam; SRSmaParam *param = pReq->stbCfg.pRSmaParam;
buf = taosDecodeBinaryTo(buf, (void*)&param->xFilesFactor, sizeof(param->xFilesFactor)); buf = taosDecodeBinaryTo(buf, (void *)&param->xFilesFactor, sizeof(param->xFilesFactor));
buf = taosDecodeFixedI32(buf, &param->delay); buf = taosDecodeFixedI32(buf, &param->delay);
buf = taosDecodeFixedI8(buf, &param->nFuncIds); buf = taosDecodeFixedI8(buf, &param->nFuncIds);
if (param->nFuncIds > 0) { if (param->nFuncIds > 0) {
...@@ -418,7 +418,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { ...@@ -418,7 +418,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
if (pReq->rollup) { if (pReq->rollup) {
pReq->ntbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam)); pReq->ntbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam));
SRSmaParam *param = pReq->ntbCfg.pRSmaParam; SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
buf = taosDecodeBinaryTo(buf, (void*)&param->xFilesFactor, sizeof(param->xFilesFactor)); buf = taosDecodeBinaryTo(buf, (void *)&param->xFilesFactor, sizeof(param->xFilesFactor));
buf = taosDecodeFixedI32(buf, &param->delay); buf = taosDecodeFixedI32(buf, &param->delay);
buf = taosDecodeFixedI8(buf, &param->nFuncIds); buf = taosDecodeFixedI8(buf, &param->nFuncIds);
if (param->nFuncIds > 0) { if (param->nFuncIds > 0) {
...@@ -808,6 +808,30 @@ int32_t tDeserializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq) ...@@ -808,6 +808,30 @@ int32_t tDeserializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq)
tCoderClear(&decoder); tCoderClear(&decoder);
return 0; return 0;
} }
int32_t tSerializeSMCreateFullTextReq(void *buf, int32_t bufLen, SMCreateFullTextReq *pReq) {
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen;
}
int32_t tDeserializeSMCreateFullTextReq(void *buf, int32_t bufLen, SMCreateFullTextReq *pReq) {
SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
}
void tFreeSMCreateFullTextReq(SMCreateFullTextReq *pReq) {
// impl later
return;
}
int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
SCoder encoder = {0}; SCoder encoder = {0};
...@@ -2769,7 +2793,7 @@ int32_t tDecodeSMqCMCommitOffsetReq(SCoder *decoder, SMqCMCommitOffsetReq *pReq) ...@@ -2769,7 +2793,7 @@ int32_t tDecodeSMqCMCommitOffsetReq(SCoder *decoder, SMqCMCommitOffsetReq *pReq)
return 0; return 0;
} }
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp) { int32_t tSerializeSExplainRsp(void *buf, int32_t bufLen, SExplainRsp *pRsp) {
SCoder encoder = {0}; SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
...@@ -2789,7 +2813,7 @@ int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp) { ...@@ -2789,7 +2813,7 @@ int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp) {
return tlen; return tlen;
} }
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp) { int32_t tDeserializeSExplainRsp(void *buf, int32_t bufLen, SExplainRsp *pRsp) {
SCoder decoder = {0}; SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
......
...@@ -22,16 +22,16 @@ ...@@ -22,16 +22,16 @@
#include "ttime.h" #include "ttime.h"
typedef struct STranslateContext { typedef struct STranslateContext {
SParseContext* pParseCxt; SParseContext* pParseCxt;
int32_t errCode; int32_t errCode;
SMsgBuf msgBuf; SMsgBuf msgBuf;
SArray* pNsLevel; // element is SArray*, the element of this subarray is STableNode* SArray* pNsLevel; // element is SArray*, the element of this subarray is STableNode*
int32_t currLevel; int32_t currLevel;
ESqlClause currClause; ESqlClause currClause;
SSelectStmt* pCurrStmt; SSelectStmt* pCurrStmt;
SCmdMsgInfo* pCmdMsg; SCmdMsgInfo* pCmdMsg;
SHashObj* pDbs; SHashObj* pDbs;
SHashObj* pTables; SHashObj* pTables;
SExplainOptions* pExplainOpt; SExplainOptions* pExplainOpt;
} STranslateContext; } STranslateContext;
...@@ -42,19 +42,15 @@ typedef struct SFullDatabaseName { ...@@ -42,19 +42,15 @@ typedef struct SFullDatabaseName {
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode); static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode);
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode); static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode);
static bool afterGroupBy(ESqlClause clause) { static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_BY; }
return clause > SQL_CLAUSE_GROUP_BY;
}
static bool beforeHaving(ESqlClause clause) { static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; }
return clause < SQL_CLAUSE_HAVING;
}
#define generateDealNodeErrMsg(pCxt, code, ...) \ #define generateDealNodeErrMsg(pCxt, code, ...) \
({ \ ({ \
generateSyntaxErrMsg(&pCxt->msgBuf, code, ##__VA_ARGS__); \ generateSyntaxErrMsg(&pCxt->msgBuf, code, ##__VA_ARGS__); \
pCxt->errCode = code; \ pCxt->errCode = code; \
DEAL_RES_ERROR; \ DEAL_RES_ERROR; \
}) })
static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { static int32_t addNamespace(STranslateContext* pCxt, void* pTable) {
...@@ -103,7 +99,7 @@ static int32_t collectUseTable(const SName* pName, SHashObj* pDbs) { ...@@ -103,7 +99,7 @@ static int32_t collectUseTable(const SName* pName, SHashObj* pDbs) {
static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta) { static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta) {
SParseContext* pParCxt = pCxt->pParseCxt; SParseContext* pParCxt = pCxt->pParseCxt;
int32_t code = collectUseDatabase(pName, pCxt->pDbs); int32_t code = collectUseDatabase(pName, pCxt->pDbs);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = collectUseTable(pName, pCxt->pTables); code = collectUseTable(pName, pCxt->pTables);
} }
...@@ -111,13 +107,14 @@ static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STa ...@@ -111,13 +107,14 @@ static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STa
code = catalogGetTableMeta(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pMeta); code = catalogGetTableMeta(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pMeta);
} }
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
parserError("catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", tstrerror(code), pName->dbname, pName->tname); parserError("catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", tstrerror(code), pName->dbname,
pName->tname);
} }
return code; return code;
} }
static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const char* pTableName, STableMeta** pMeta) { static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const char* pTableName, STableMeta** pMeta) {
SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pDbName); strcpy(name.dbname, pDbName);
strcpy(name.tname, pTableName); strcpy(name.tname, pTableName);
return getTableMetaImpl(pCxt, &name, pMeta); return getTableMetaImpl(pCxt, &name, pMeta);
...@@ -125,7 +122,7 @@ static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const ...@@ -125,7 +122,7 @@ static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const
static int32_t getTableDistVgInfo(STranslateContext* pCxt, const SName* pName, SArray** pVgInfo) { static int32_t getTableDistVgInfo(STranslateContext* pCxt, const SName* pName, SArray** pVgInfo) {
SParseContext* pParCxt = pCxt->pParseCxt; SParseContext* pParCxt = pCxt->pParseCxt;
int32_t code = collectUseDatabase(pName, pCxt->pDbs); int32_t code = collectUseDatabase(pName, pCxt->pDbs);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = collectUseTable(pName, pCxt->pTables); code = collectUseTable(pName, pCxt->pTables);
} }
...@@ -133,14 +130,15 @@ static int32_t getTableDistVgInfo(STranslateContext* pCxt, const SName* pName, S ...@@ -133,14 +130,15 @@ static int32_t getTableDistVgInfo(STranslateContext* pCxt, const SName* pName, S
code = catalogGetTableDistVgInfo(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pVgInfo); code = catalogGetTableDistVgInfo(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pVgInfo);
} }
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
parserError("catalogGetTableDistVgInfo error, code:%s, dbName:%s, tbName:%s", tstrerror(code), pName->dbname, pName->tname); parserError("catalogGetTableDistVgInfo error, code:%s, dbName:%s, tbName:%s", tstrerror(code), pName->dbname,
pName->tname);
} }
return code; return code;
} }
static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArray** pVgInfo) { static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArray** pVgInfo) {
SParseContext* pParCxt = pCxt->pParseCxt; SParseContext* pParCxt = pCxt->pParseCxt;
char fullDbName[TSDB_DB_FNAME_LEN]; char fullDbName[TSDB_DB_FNAME_LEN];
tNameGetFullDbName(pName, fullDbName); tNameGetFullDbName(pName, fullDbName);
int32_t code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs); int32_t code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
...@@ -162,7 +160,7 @@ static int32_t getDBVgInfo(STranslateContext* pCxt, const char* pDbName, SArray* ...@@ -162,7 +160,7 @@ static int32_t getDBVgInfo(STranslateContext* pCxt, const char* pDbName, SArray*
static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pName, SVgroupInfo* pInfo) { static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pName, SVgroupInfo* pInfo) {
SParseContext* pParCxt = pCxt->pParseCxt; SParseContext* pParCxt = pCxt->pParseCxt;
int32_t code = collectUseDatabase(pName, pCxt->pDbs); int32_t code = collectUseDatabase(pName, pCxt->pDbs);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = collectUseTable(pName, pCxt->pTables); code = collectUseTable(pName, pCxt->pTables);
} }
...@@ -170,21 +168,24 @@ static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pNam ...@@ -170,21 +168,24 @@ static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pNam
code = catalogGetTableHashVgroup(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pInfo); code = catalogGetTableHashVgroup(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pInfo);
} }
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
parserError("catalogGetTableHashVgroup error, code:%s, dbName:%s, tbName:%s", tstrerror(code), pName->dbname, pName->tname); parserError("catalogGetTableHashVgroup error, code:%s, dbName:%s, tbName:%s", tstrerror(code), pName->dbname,
pName->tname);
} }
return code; return code;
} }
static int32_t getTableHashVgroup(STranslateContext* pCxt, const char* pDbName, const char* pTableName, SVgroupInfo* pInfo) { static int32_t getTableHashVgroup(STranslateContext* pCxt, const char* pDbName, const char* pTableName,
SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SVgroupInfo* pInfo) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pDbName); strcpy(name.dbname, pDbName);
strcpy(name.tname, pTableName); strcpy(name.tname, pTableName);
return getTableHashVgroupImpl(pCxt, &name, pInfo); return getTableHashVgroupImpl(pCxt, &name, pInfo);
} }
static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, int32_t* pTableNum) { static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
int32_t* pTableNum) {
SParseContext* pParCxt = pCxt->pParseCxt; SParseContext* pParCxt = pCxt->pParseCxt;
int32_t code = collectUseDatabaseImpl(pDbFName, pCxt->pDbs); int32_t code = collectUseDatabaseImpl(pDbFName, pCxt->pDbs);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = catalogGetDBVgVersion(pParCxt->pCatalog, pDbFName, pVersion, pDbId, pTableNum); code = catalogGetDBVgVersion(pParCxt->pCatalog, pDbFName, pVersion, pDbId, pTableNum);
} }
...@@ -214,7 +215,8 @@ static SNodeList* getProjectList(SNode* pNode) { ...@@ -214,7 +215,8 @@ static SNodeList* getProjectList(SNode* pNode) {
return NULL; return NULL;
} }
static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* pColSchema, bool isTag, SColumnNode* pCol) { static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* pColSchema, bool isTag,
SColumnNode* pCol) {
strcpy(pCol->dbName, pTable->table.dbName); strcpy(pCol->dbName, pTable->table.dbName);
strcpy(pCol->tableAlias, pTable->table.tableAlias); strcpy(pCol->tableAlias, pTable->table.tableAlias);
strcpy(pCol->tableName, pTable->table.tableName); strcpy(pCol->tableName, pTable->table.tableName);
...@@ -251,7 +253,8 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol ...@@ -251,7 +253,8 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol
static int32_t createColumnNodeByTable(STranslateContext* pCxt, const STableNode* pTable, SNodeList* pList) { static int32_t createColumnNodeByTable(STranslateContext* pCxt, const STableNode* pTable, SNodeList* pList) {
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta; const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta;
int32_t nums = pMeta->tableInfo.numOfColumns + ((TSDB_SUPER_TABLE == pMeta->tableType) ? pMeta->tableInfo.numOfTags : 0); int32_t nums =
pMeta->tableInfo.numOfColumns + ((TSDB_SUPER_TABLE == pMeta->tableType) ? pMeta->tableInfo.numOfTags : 0);
for (int32_t i = 0; i < nums; ++i) { for (int32_t i = 0; i < nums; ++i) {
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
if (NULL == pCol) { if (NULL == pCol) {
...@@ -262,7 +265,7 @@ static int32_t createColumnNodeByTable(STranslateContext* pCxt, const STableNode ...@@ -262,7 +265,7 @@ static int32_t createColumnNodeByTable(STranslateContext* pCxt, const STableNode
} }
} else { } else {
SNodeList* pProjectList = getProjectList(((STempTableNode*)pTable)->pSubquery); SNodeList* pProjectList = getProjectList(((STempTableNode*)pTable)->pSubquery);
SNode* pNode; SNode* pNode;
FOREACH(pNode, pProjectList) { FOREACH(pNode, pProjectList) {
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
if (NULL == pCol) { if (NULL == pCol) {
...@@ -293,7 +296,7 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) { ...@@ -293,7 +296,7 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
} }
} else { } else {
SNodeList* pProjectList = getProjectList(((STempTableNode*)pTable)->pSubquery); SNodeList* pProjectList = getProjectList(((STempTableNode*)pTable)->pSubquery);
SNode* pNode; SNode* pNode;
FOREACH(pNode, pProjectList) { FOREACH(pNode, pProjectList) {
SExprNode* pExpr = (SExprNode*)pNode; SExprNode* pExpr = (SExprNode*)pNode;
if (0 == strcmp(pCol->colName, pExpr->aliasName)) { if (0 == strcmp(pCol->colName, pExpr->aliasName)) {
...@@ -308,8 +311,8 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) { ...@@ -308,8 +311,8 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode* pCol) { static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode* pCol) {
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
size_t nums = taosArrayGetSize(pTables); size_t nums = taosArrayGetSize(pTables);
bool foundTable = false; bool foundTable = false;
for (size_t i = 0; i < nums; ++i) { for (size_t i = 0; i < nums; ++i) {
STableNode* pTable = taosArrayGetP(pTables, i); STableNode* pTable = taosArrayGetP(pTables, i);
if (belongTable(pCxt->pParseCxt->db, pCol, pTable)) { if (belongTable(pCxt->pParseCxt->db, pCol, pTable)) {
...@@ -328,8 +331,8 @@ static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode* ...@@ -328,8 +331,8 @@ static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode*
static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNode* pCol) { static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNode* pCol) {
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
size_t nums = taosArrayGetSize(pTables); size_t nums = taosArrayGetSize(pTables);
bool found = false; bool found = false;
for (size_t i = 0; i < nums; ++i) { for (size_t i = 0; i < nums; ++i) {
STableNode* pTable = taosArrayGetP(pTables, i); STableNode* pTable = taosArrayGetP(pTables, i);
if (findAndSetColumn(pCol, pTable)) { if (findAndSetColumn(pCol, pTable)) {
...@@ -347,12 +350,12 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod ...@@ -347,12 +350,12 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
static bool translateColumnUseAlias(STranslateContext* pCxt, SColumnNode* pCol) { static bool translateColumnUseAlias(STranslateContext* pCxt, SColumnNode* pCol) {
SNodeList* pProjectionList = pCxt->pCurrStmt->pProjectionList; SNodeList* pProjectionList = pCxt->pCurrStmt->pProjectionList;
SNode* pNode; SNode* pNode;
FOREACH(pNode, pProjectionList) { FOREACH(pNode, pProjectionList) {
SExprNode* pExpr = (SExprNode*)pNode; SExprNode* pExpr = (SExprNode*)pNode;
if (0 == strcmp(pCol->colName, pExpr->aliasName)) { if (0 == strcmp(pCol->colName, pExpr->aliasName)) {
setColumnInfoByExpr(NULL, pExpr, pCol); setColumnInfoByExpr(NULL, pExpr, pCol);
return true; return true;
} }
} }
return false; return false;
...@@ -375,7 +378,8 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) { ...@@ -375,7 +378,8 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
if (pVal->isDuration) { if (pVal->isDuration) {
if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, pVal->node.resType.precision) != TSDB_CODE_SUCCESS) { if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit,
pVal->node.resType.precision) != TSDB_CODE_SUCCESS) {
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal);
} }
} else { } else {
...@@ -419,7 +423,8 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { ...@@ -419,7 +423,8 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
break; break;
} }
case TSDB_DATA_TYPE_TIMESTAMP: { case TSDB_DATA_TYPE_TIMESTAMP: {
if (taosParseTime(pVal->literal, &pVal->datum.i, pVal->node.resType.bytes, pVal->node.resType.precision, tsDaylight) != TSDB_CODE_SUCCESS) { if (taosParseTime(pVal->literal, &pVal->datum.i, pVal->node.resType.bytes, pVal->node.resType.precision,
tsDaylight) != TSDB_CODE_SUCCESS) {
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal);
} }
break; break;
...@@ -450,15 +455,15 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { ...@@ -450,15 +455,15 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
if (nodesIsArithmeticOp(pOp)) { if (nodesIsArithmeticOp(pOp)) {
if (TSDB_DATA_TYPE_JSON == ldt.type || TSDB_DATA_TYPE_BLOB == ldt.type || if (TSDB_DATA_TYPE_JSON == ldt.type || TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_JSON == rdt.type ||
TSDB_DATA_TYPE_JSON == rdt.type || TSDB_DATA_TYPE_BLOB == rdt.type) { TSDB_DATA_TYPE_BLOB == rdt.type) {
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName);
} }
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
} else if (nodesIsComparisonOp(pOp)) { } else if (nodesIsComparisonOp(pOp)) {
if (TSDB_DATA_TYPE_JSON == ldt.type || TSDB_DATA_TYPE_BLOB == ldt.type || if (TSDB_DATA_TYPE_JSON == ldt.type || TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_JSON == rdt.type ||
TSDB_DATA_TYPE_JSON == rdt.type || TSDB_DATA_TYPE_BLOB == rdt.type) { TSDB_DATA_TYPE_BLOB == rdt.type) {
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName);
} }
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
...@@ -524,9 +529,7 @@ static int32_t translateExprList(STranslateContext* pCxt, SNodeList* pList) { ...@@ -524,9 +529,7 @@ static int32_t translateExprList(STranslateContext* pCxt, SNodeList* pList) {
return pCxt->errCode; return pCxt->errCode;
} }
static bool isAliasColumn(SColumnNode* pCol) { static bool isAliasColumn(SColumnNode* pCol) { return ('\0' == pCol->tableAlias[0]); }
return ('\0' == pCol->tableAlias[0]);
}
static bool isDistinctOrderBy(STranslateContext* pCxt) { static bool isDistinctOrderBy(STranslateContext* pCxt) {
return (SQL_CLAUSE_ORDER_BY == pCxt->currClause && pCxt->pCurrStmt->isDistinct); return (SQL_CLAUSE_ORDER_BY == pCxt->currClause && pCxt->pCurrStmt->isDistinct);
...@@ -558,7 +561,8 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) { ...@@ -558,7 +561,8 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) {
if (!nodesIsExprNode(pNode) || (QUERY_NODE_COLUMN == nodeType(pNode) && isAliasColumn((SColumnNode*)pNode))) { if (!nodesIsExprNode(pNode) || (QUERY_NODE_COLUMN == nodeType(pNode) && isAliasColumn((SColumnNode*)pNode))) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
if (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsAggFunc(((SFunctionNode*)pNode)->funcId) && !isDistinctOrderBy(pCxt)) { if (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsAggFunc(((SFunctionNode*)pNode)->funcId) &&
!isDistinctOrderBy(pCxt)) {
return DEAL_RES_IGNORE_CHILD; return DEAL_RES_IGNORE_CHILD;
} }
SNode* pGroupNode; SNode* pGroupNode;
...@@ -568,7 +572,8 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) { ...@@ -568,7 +572,8 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) {
} }
} }
if (QUERY_NODE_COLUMN == nodeType(pNode) || if (QUERY_NODE_COLUMN == nodeType(pNode) ||
(QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsAggFunc(((SFunctionNode*)pNode)->funcId) && isDistinctOrderBy(pCxt))) { (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsAggFunc(((SFunctionNode*)pNode)->funcId) &&
isDistinctOrderBy(pCxt))) {
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt)); return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt));
} }
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
...@@ -589,8 +594,8 @@ static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SNodeList* pList ...@@ -589,8 +594,8 @@ static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SNodeList* pList
typedef struct CheckAggColCoexistCxt { typedef struct CheckAggColCoexistCxt {
STranslateContext* pTranslateCxt; STranslateContext* pTranslateCxt;
bool existAggFunc; bool existAggFunc;
bool existCol; bool existCol;
} CheckAggColCoexistCxt; } CheckAggColCoexistCxt;
static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) { static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) {
...@@ -609,7 +614,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) ...@@ -609,7 +614,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
if (NULL != pSelect->pGroupByList) { if (NULL != pSelect->pGroupByList) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
CheckAggColCoexistCxt cxt = { .pTranslateCxt = pCxt, .existAggFunc = false, .existCol = false }; CheckAggColCoexistCxt cxt = {.pTranslateCxt = pCxt, .existAggFunc = false, .existCol = false};
nodesWalkExprs(pSelect->pProjectionList, doCheckAggColCoexist, &cxt); nodesWalkExprs(pSelect->pProjectionList, doCheckAggColCoexist, &cxt);
if (!pSelect->isDistinct) { if (!pSelect->isDistinct) {
nodesWalkExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt); nodesWalkExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt);
...@@ -628,7 +633,7 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) { ...@@ -628,7 +633,7 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) {
} }
(*pVgsInfo)->numOfVgroups = vgroupNum; (*pVgsInfo)->numOfVgroups = vgroupNum;
for (int32_t i = 0; i < vgroupNum; ++i) { for (int32_t i = 0; i < vgroupNum; ++i) {
SVgroupInfo *vg = taosArrayGet(pVgs, i); SVgroupInfo* vg = taosArrayGet(pVgs, i);
(*pVgsInfo)->vgroups[i] = *vg; (*pVgsInfo)->vgroups[i] = *vg;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -688,8 +693,9 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { ...@@ -688,8 +693,9 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
SRealTableNode* pRealTable = (SRealTableNode*)pTable; SRealTableNode* pRealTable = (SRealTableNode*)pTable;
pRealTable->ratio = (NULL != pCxt->pExplainOpt ? pCxt->pExplainOpt->ratio : 1.0); pRealTable->ratio = (NULL != pCxt->pExplainOpt ? pCxt->pExplainOpt->ratio : 1.0);
SName name; SName name;
code = getTableMetaImpl(pCxt, code = getTableMetaImpl(
toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name), &(pRealTable->pMeta)); pCxt, toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name),
&(pRealTable->pMeta));
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, pRealTable->table.tableName); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, pRealTable->table.tableName);
} }
...@@ -725,16 +731,16 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { ...@@ -725,16 +731,16 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
} }
static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect, bool* pIsSelectStar) { static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect, bool* pIsSelectStar) {
if (NULL == pSelect->pProjectionList) { // select * ... if (NULL == pSelect->pProjectionList) { // select * ...
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
size_t nums = taosArrayGetSize(pTables); size_t nums = taosArrayGetSize(pTables);
pSelect->pProjectionList = nodesMakeList(); pSelect->pProjectionList = nodesMakeList();
if (NULL == pSelect->pProjectionList) { if (NULL == pSelect->pProjectionList) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
} }
for (size_t i = 0; i < nums; ++i) { for (size_t i = 0; i < nums; ++i) {
STableNode* pTable = taosArrayGetP(pTables, i); STableNode* pTable = taosArrayGetP(pTables, i);
int32_t code = createColumnNodeByTable(pCxt, pTable, pSelect->pProjectionList); int32_t code = createColumnNodeByTable(pCxt, pTable, pSelect->pProjectionList);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
} }
...@@ -769,14 +775,15 @@ static int32_t getPositionValue(const SValueNode* pVal) { ...@@ -769,14 +775,15 @@ static int32_t getPositionValue(const SValueNode* pVal) {
case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_USMALLINT:
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
return pVal->datum.u; return pVal->datum.u;
default: default:
break; break;
} }
return -1; return -1;
} }
static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pProjectionList, SNodeList* pOrderByList, bool* pOther) { static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pProjectionList, SNodeList* pOrderByList,
bool* pOther) {
*pOther = false; *pOther = false;
SNode* pNode; SNode* pNode;
FOREACH(pNode, pOrderByList) { FOREACH(pNode, pOrderByList) {
...@@ -809,7 +816,7 @@ static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pPro ...@@ -809,7 +816,7 @@ static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pPro
} }
static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) { static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
bool other; bool other;
int32_t code = translateOrderByPosition(pCxt, pSelect->pProjectionList, pSelect->pOrderByList, &other); int32_t code = translateOrderByPosition(pCxt, pSelect->pProjectionList, pSelect->pOrderByList, &other);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
...@@ -826,7 +833,7 @@ static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) { ...@@ -826,7 +833,7 @@ static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
} }
static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect) { static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect) {
bool isSelectStar = false; bool isSelectStar = false;
int32_t code = translateStar(pCxt, pSelect, &isSelectStar); int32_t code = translateStar(pCxt, pSelect, &isSelectStar);
if (TSDB_CODE_SUCCESS == code && !isSelectStar) { if (TSDB_CODE_SUCCESS == code && !isSelectStar) {
pCxt->currClause = SQL_CLAUSE_SELECT; pCxt->currClause = SQL_CLAUSE_SELECT;
...@@ -868,7 +875,7 @@ static int32_t translateIntervalWindow(STranslateContext* pCxt, SIntervalWindowN ...@@ -868,7 +875,7 @@ static int32_t translateIntervalWindow(STranslateContext* pCxt, SIntervalWindowN
static int32_t doTranslateWindow(STranslateContext* pCxt, SNode* pWindow) { static int32_t doTranslateWindow(STranslateContext* pCxt, SNode* pWindow) {
switch (nodeType(pWindow)) { switch (nodeType(pWindow)) {
case QUERY_NODE_INTERVAL_WINDOW: case QUERY_NODE_INTERVAL_WINDOW:
return translateIntervalWindow(pCxt, (SIntervalWindowNode*)pWindow); return translateIntervalWindow(pCxt, (SIntervalWindowNode*)pWindow);
default: default:
break; break;
} }
...@@ -940,19 +947,15 @@ static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbRe ...@@ -940,19 +947,15 @@ static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbRe
} }
SValueNode* pFreq = NULL; SValueNode* pFreq = NULL;
SValueNode* pKeep = NULL; SValueNode* pKeep = NULL;
SNode* pNode = NULL; SNode* pNode = NULL;
int32_t index = 0; int32_t index = 0;
FOREACH(pNode, pRetentions) { FOREACH(pNode, pRetentions) {
if (0 == ((index++) & 1)) { if (0 == ((index++) & 1)) {
pFreq = (SValueNode*)pNode; pFreq = (SValueNode*)pNode;
} else { } else {
pKeep = (SValueNode*)pNode; pKeep = (SValueNode*)pNode;
SRetention retention = { SRetention retention = {
.freq = pFreq->datum.i, .freq = pFreq->datum.i, .freqUnit = pFreq->unit, .keep = pKeep->datum.i, .keepUnit = pKeep->unit};
.freqUnit = pFreq->unit,
.keep = pKeep->datum.i,
.keepUnit = pKeep->unit
};
taosArrayPush(pReq->pRetensions, &retention); taosArrayPush(pReq->pRetensions, &retention);
} }
} }
...@@ -1028,7 +1031,7 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS ...@@ -1028,7 +1031,7 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS
static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* pStmt) { static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* pStmt) {
SDropDbReq dropReq = {0}; SDropDbReq dropReq = {0};
SName name = {0}; SName name = {0};
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
tNameGetFullDbName(&name, dropReq.db); tNameGetFullDbName(&name, dropReq.db);
dropReq.ignoreNotExists = pStmt->ignoreNotExists; dropReq.ignoreNotExists = pStmt->ignoreNotExists;
...@@ -1100,7 +1103,7 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray) { ...@@ -1100,7 +1103,7 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray) {
SNode* pNode; SNode* pNode;
FOREACH(pNode, pList) { FOREACH(pNode, pList) {
SColumnDefNode* pCol = (SColumnDefNode*)pNode; SColumnDefNode* pCol = (SColumnDefNode*)pNode;
SField field = { .type = pCol->dataType.type, .bytes = calcTypeBytes(pCol->dataType) }; SField field = {.type = pCol->dataType.type, .bytes = calcTypeBytes(pCol->dataType)};
strcpy(field.name, pCol->colName); strcpy(field.name, pCol->colName);
taosArrayPush(*pArray, &field); taosArrayPush(*pArray, &field);
} }
...@@ -1112,7 +1115,7 @@ static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { ...@@ -1112,7 +1115,7 @@ static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) {
SNode* pNode; SNode* pNode;
FOREACH(pNode, pList) { FOREACH(pNode, pList) {
SColumnNode* pCol = (SColumnNode*)pNode; SColumnNode* pCol = (SColumnNode*)pNode;
SField field = { .type = pCol->node.resType.type, .bytes = calcTypeBytes(pCol->node.resType) }; SField field = {.type = pCol->node.resType.type, .bytes = calcTypeBytes(pCol->node.resType)};
strcpy(field.name, pCol->colName); strcpy(field.name, pCol->colName);
taosArrayPush(*pArray, &field); taosArrayPush(*pArray, &field);
} }
...@@ -1132,11 +1135,9 @@ static SColumnDefNode* findColDef(SNodeList* pCols, const SColumnNode* pCol) { ...@@ -1132,11 +1135,9 @@ static SColumnDefNode* findColDef(SNodeList* pCols, const SColumnNode* pCol) {
static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) {
if (NULL != pStmt->pOptions->pSma) { if (NULL != pStmt->pOptions->pSma) {
SNode* pNode = NULL; SNode* pNode = NULL;
FOREACH(pNode, pStmt->pCols) { FOREACH(pNode, pStmt->pCols) { ((SColumnDefNode*)pNode)->sma = false; }
((SColumnDefNode*)pNode)->sma = false;
}
FOREACH(pNode, pStmt->pOptions->pSma) { FOREACH(pNode, pStmt->pOptions->pSma) {
SColumnNode* pSmaCol = (SColumnNode*)pNode; SColumnNode* pSmaCol = (SColumnNode*)pNode;
SColumnDefNode* pColDef = findColDef(pStmt->pCols, pSmaCol); SColumnDefNode* pColDef = findColDef(pStmt->pCols, pSmaCol);
if (NULL == pColDef) { if (NULL == pColDef) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMN, pSmaCol->colName); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMN, pSmaCol->colName);
...@@ -1184,7 +1185,7 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt ...@@ -1184,7 +1185,7 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt
createReq.numOfSmas = LIST_LENGTH(pStmt->pOptions->pSma); createReq.numOfSmas = LIST_LENGTH(pStmt->pOptions->pSma);
} }
SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SName tableName = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(tableName.dbname, pStmt->dbName); strcpy(tableName.dbname, pStmt->dbName);
strcpy(tableName.tname, pStmt->tableName); strcpy(tableName.tname, pStmt->tableName);
tNameExtractFullName(&tableName, createReq.name); tNameExtractFullName(&tableName, createReq.name);
...@@ -1233,8 +1234,8 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt ...@@ -1233,8 +1234,8 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt
SDropTableClause* pClause = nodesListGetNode(pStmt->pTables, 0); SDropTableClause* pClause = nodesListGetNode(pStmt->pTables, 0);
STableMeta* pTableMeta = NULL; STableMeta* pTableMeta = NULL;
SName tableName; SName tableName;
int32_t code = getTableMetaImpl( int32_t code = getTableMetaImpl(
pCxt, toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName), &pTableMeta); pCxt, toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName), &pTableMeta);
if ((TSDB_CODE_TDB_INVALID_TABLE_ID == code || TSDB_CODE_VND_TB_NOT_EXIST == code) && pClause->ignoreNotExists) { if ((TSDB_CODE_TDB_INVALID_TABLE_ID == code || TSDB_CODE_VND_TB_NOT_EXIST == code) && pClause->ignoreNotExists) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1253,7 +1254,7 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt ...@@ -1253,7 +1254,7 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt
} }
static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableStmt* pStmt) { static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableStmt* pStmt) {
SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SName tableName = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(tableName.dbname, pStmt->dbName); strcpy(tableName.dbname, pStmt->dbName);
strcpy(tableName.tname, pStmt->tableName); strcpy(tableName.tname, pStmt->tableName);
return doTranslateDropSuperTable(pCxt, &tableName, pStmt->ignoreNotExists); return doTranslateDropSuperTable(pCxt, &tableName, pStmt->ignoreNotExists);
...@@ -1272,7 +1273,7 @@ static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAltertbReq* pAlterRe ...@@ -1272,7 +1273,7 @@ static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAltertbReq* pAlterRe
case TSDB_ALTER_TABLE_DROP_COLUMN: case TSDB_ALTER_TABLE_DROP_COLUMN:
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES: { case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES: {
TAOS_FIELD field = { .type = pStmt->dataType.type, .bytes = pStmt->dataType.bytes }; TAOS_FIELD field = {.type = pStmt->dataType.type, .bytes = pStmt->dataType.bytes};
strcpy(field.name, pStmt->colName); strcpy(field.name, pStmt->colName);
taosArrayPush(pAlterReq->pFields, &field); taosArrayPush(pAlterReq->pFields, &field);
break; break;
...@@ -1296,7 +1297,7 @@ static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAltertbReq* pAlterRe ...@@ -1296,7 +1297,7 @@ static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAltertbReq* pAlterRe
static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) { static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) {
SMAltertbReq alterReq = {0}; SMAltertbReq alterReq = {0};
SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SName tableName = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(tableName.dbname, pStmt->dbName); strcpy(tableName.dbname, pStmt->dbName);
strcpy(tableName.tname, pStmt->tableName); strcpy(tableName.tname, pStmt->tableName);
tNameExtractFullName(&tableName, alterReq.name); tNameExtractFullName(&tableName, alterReq.name);
...@@ -1328,7 +1329,7 @@ static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pSt ...@@ -1328,7 +1329,7 @@ static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pSt
static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) { static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) {
SUseDbReq usedbReq = {0}; SUseDbReq usedbReq = {0};
SName name = {0}; SName name = {0};
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
tNameExtractFullName(&name, usedbReq.db); tNameExtractFullName(&name, usedbReq.db);
int32_t code = getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable); int32_t code = getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable);
...@@ -1398,7 +1399,7 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt ...@@ -1398,7 +1399,7 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt
} }
tSerializeSAlterUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); tSerializeSAlterUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t translateDropUser(STranslateContext* pCxt, SDropUserStmt* pStmt) { static int32_t translateDropUser(STranslateContext* pCxt, SDropUserStmt* pStmt) {
...@@ -1489,7 +1490,7 @@ static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pSt ...@@ -1489,7 +1490,7 @@ static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pSt
static int32_t nodeTypeToShowType(ENodeType nt) { static int32_t nodeTypeToShowType(ENodeType nt) {
switch (nt) { switch (nt) {
case QUERY_NODE_SHOW_APPS_STMT: case QUERY_NODE_SHOW_APPS_STMT:
return 0; // todo return 0; // todo
case QUERY_NODE_SHOW_CONNECTIONS_STMT: case QUERY_NODE_SHOW_CONNECTIONS_STMT:
return TSDB_MGMT_TABLE_CONNS; return TSDB_MGMT_TABLE_CONNS;
case QUERY_NODE_SHOW_LICENCE_STMT: case QUERY_NODE_SHOW_LICENCE_STMT:
...@@ -1497,9 +1498,9 @@ static int32_t nodeTypeToShowType(ENodeType nt) { ...@@ -1497,9 +1498,9 @@ static int32_t nodeTypeToShowType(ENodeType nt) {
case QUERY_NODE_SHOW_QUERIES_STMT: case QUERY_NODE_SHOW_QUERIES_STMT:
return TSDB_MGMT_TABLE_QUERIES; return TSDB_MGMT_TABLE_QUERIES;
case QUERY_NODE_SHOW_SCORES_STMT: case QUERY_NODE_SHOW_SCORES_STMT:
return 0; // todo return 0; // todo
case QUERY_NODE_SHOW_TOPICS_STMT: case QUERY_NODE_SHOW_TOPICS_STMT:
return 0; // todo return 0; // todo
case QUERY_NODE_SHOW_VARIABLE_STMT: case QUERY_NODE_SHOW_VARIABLE_STMT:
return TSDB_MGMT_TABLE_VARIABLES; return TSDB_MGMT_TABLE_VARIABLES;
default: default:
...@@ -1509,7 +1510,7 @@ static int32_t nodeTypeToShowType(ENodeType nt) { ...@@ -1509,7 +1510,7 @@ static int32_t nodeTypeToShowType(ENodeType nt) {
} }
static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) {
SShowReq showReq = { .type = nodeTypeToShowType(nodeType(pStmt)) }; SShowReq showReq = {.type = nodeTypeToShowType(nodeType(pStmt))};
pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo));
if (NULL == pCxt->pCmdMsg) { if (NULL == pCxt->pCmdMsg) {
...@@ -1529,7 +1530,7 @@ static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { ...@@ -1529,7 +1530,7 @@ static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) {
static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, char* pTableName, int32_t* pVgId) { static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, char* pTableName, int32_t* pVgId) {
SVgroupInfo vg = {0}; SVgroupInfo vg = {0};
int32_t code = getTableHashVgroup(pCxt, pCxt->pParseCxt->db, pTableName, &vg); int32_t code = getTableHashVgroup(pCxt, pCxt->pParseCxt->db, pTableName, &vg);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
*pVgId = vg.vgId; *pVgId = vg.vgId;
} }
...@@ -1571,9 +1572,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS ...@@ -1571,9 +1572,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SNode* pProject = NULL; SNode* pProject = NULL;
FOREACH(pProject, pSelect->pProjectionList) { FOREACH(pProject, pSelect->pProjectionList) { sprintf(((SExprNode*)pProject)->aliasName, "#sma_%p", pProject); }
sprintf(((SExprNode*)pProject)->aliasName, "#sma_%p", pProject);
}
SIntervalWindowNode* pInterval = nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW); SIntervalWindowNode* pInterval = nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
if (NULL == pInterval) { if (NULL == pInterval) {
...@@ -1585,7 +1584,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS ...@@ -1585,7 +1584,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
pInterval->pInterval = nodesCloneNode(pStmt->pOptions->pInterval); pInterval->pInterval = nodesCloneNode(pStmt->pOptions->pInterval);
pInterval->pOffset = nodesCloneNode(pStmt->pOptions->pOffset); pInterval->pOffset = nodesCloneNode(pStmt->pOptions->pOffset);
pInterval->pSliding = nodesCloneNode(pStmt->pOptions->pSliding); pInterval->pSliding = nodesCloneNode(pStmt->pOptions->pSliding);
if (NULL == pInterval->pCol || NULL == pInterval->pInterval || if (NULL == pInterval->pCol || NULL == pInterval->pInterval ||
(NULL != pStmt->pOptions->pOffset && NULL == pInterval->pOffset) || (NULL != pStmt->pOptions->pOffset && NULL == pInterval->pOffset) ||
(NULL != pStmt->pOptions->pSliding && NULL == pInterval->pSliding)) { (NULL != pStmt->pOptions->pSliding && NULL == pInterval->pSliding)) {
nodesDestroyNode(pSelect); nodesDestroyNode(pSelect);
...@@ -1603,7 +1602,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS ...@@ -1603,7 +1602,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
} }
static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SMCreateSmaReq* pReq) { static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SMCreateSmaReq* pReq) {
SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pCxt->pParseCxt->db); strcpy(name.dbname, pCxt->pParseCxt->db);
strcpy(name.tname, pStmt->indexName); strcpy(name.tname, pStmt->indexName);
tNameExtractFullName(&name, pReq->name); tNameExtractFullName(&name, pReq->name);
...@@ -1614,8 +1613,10 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm ...@@ -1614,8 +1613,10 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm
pReq->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i; pReq->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
pReq->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit; pReq->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit;
pReq->offset = (NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0); pReq->offset = (NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0);
pReq->sliding = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pReq->interval); pReq->sliding =
pReq->slidingUnit = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pReq->intervalUnit); (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pReq->interval);
pReq->slidingUnit =
(NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pReq->intervalUnit);
int32_t code = getSmaIndexDstVgId(pCxt, pStmt->tableName, &pReq->dstVgId); int32_t code = getSmaIndexDstVgId(pCxt, pStmt->tableName, &pReq->dstVgId);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
...@@ -1633,13 +1634,15 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm ...@@ -1633,13 +1634,15 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm
static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) {
if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pInterval) || if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pInterval) ||
(NULL != pStmt->pOptions->pOffset && DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pOffset)) || (NULL != pStmt->pOptions->pOffset &&
(NULL != pStmt->pOptions->pSliding && DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pSliding))) { DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pOffset)) ||
(NULL != pStmt->pOptions->pSliding &&
DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pSliding))) {
return pCxt->errCode; return pCxt->errCode;
} }
SMCreateSmaReq createSmaReq = {0}; SMCreateSmaReq createSmaReq = {0};
int32_t code = buildCreateSmaReq(pCxt, pStmt, &createSmaReq); int32_t code = buildCreateSmaReq(pCxt, pStmt, &createSmaReq);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
} }
...@@ -1660,11 +1663,12 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt ...@@ -1660,11 +1663,12 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t translateCreateFullTextIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) {}
static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) {
if (INDEX_TYPE_SMA == pStmt->indexType) { if (INDEX_TYPE_SMA == pStmt->indexType) {
return translateCreateSmaIndex(pCxt, pStmt); return translateCreateSmaIndex(pCxt, pStmt);
} else { } else if (INDEX_TYPE_FULLTEXT == pStmt->indexType) {
// todo fulltext index // todo fulltext index
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -1692,7 +1696,7 @@ static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt ...@@ -1692,7 +1696,7 @@ static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt
} }
static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* pStmt) { static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* pStmt) {
SMCreateQnodeReq createReq = { .dnodeId = pStmt->dnodeId }; SMCreateQnodeReq createReq = {.dnodeId = pStmt->dnodeId};
pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo));
if (NULL == pCxt->pCmdMsg) { if (NULL == pCxt->pCmdMsg) {
...@@ -1711,7 +1715,7 @@ static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* p ...@@ -1711,7 +1715,7 @@ static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* p
} }
static int32_t translateDropQnode(STranslateContext* pCxt, SDropQnodeStmt* pStmt) { static int32_t translateDropQnode(STranslateContext* pCxt, SDropQnodeStmt* pStmt) {
SDDropQnodeReq dropReq = { .dnodeId = pStmt->dnodeId }; SDDropQnodeReq dropReq = {.dnodeId = pStmt->dnodeId};
pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo));
if (NULL == pCxt->pCmdMsg) { if (NULL == pCxt->pCmdMsg) {
...@@ -1738,19 +1742,19 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p ...@@ -1738,19 +1742,19 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = nodesNodeToString(pStmt->pQuery, false, &createReq.ast, NULL); code = nodesNodeToString(pStmt->pQuery, false, &createReq.ast, NULL);
} }
if (TSDB_CODE_SUCCESS != code ) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
} }
} else { } else {
strcpy(createReq.subscribeDbName, pStmt->subscribeDbName); strcpy(createReq.subscribeDbName, pStmt->subscribeDbName);
} }
createReq.sql = strdup(pCxt->pParseCxt->pSql); createReq.sql = strdup(pCxt->pParseCxt->pSql);
if (NULL == createReq.sql) { if (NULL == createReq.sql) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pCxt->pParseCxt->db); strcpy(name.dbname, pCxt->pParseCxt->db);
strcpy(name.tname, pStmt->topicName); strcpy(name.tname, pStmt->topicName);
tNameExtractFullName(&name, createReq.name); tNameExtractFullName(&name, createReq.name);
...@@ -1776,7 +1780,7 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p ...@@ -1776,7 +1780,7 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p
static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt) { static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt) {
SMDropTopicReq dropReq = {0}; SMDropTopicReq dropReq = {0};
SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pCxt->pParseCxt->db); strcpy(name.dbname, pCxt->pParseCxt->db);
strcpy(name.tname, pStmt->topicName); strcpy(name.tname, pStmt->topicName);
tNameExtractFullName(&name, dropReq.name); tNameExtractFullName(&name, dropReq.name);
...@@ -1911,9 +1915,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { ...@@ -1911,9 +1915,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) { static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
++(pCxt->currLevel); ++(pCxt->currLevel);
ESqlClause currClause = pCxt->currClause; ESqlClause currClause = pCxt->currClause;
SSelectStmt* pCurrStmt = pCxt->pCurrStmt; SSelectStmt* pCurrStmt = pCxt->pCurrStmt;
int32_t code = translateQuery(pCxt, pNode); int32_t code = translateQuery(pCxt, pNode);
--(pCxt->currLevel); --(pCxt->currLevel);
pCxt->currClause = currClause; pCxt->currClause = currClause;
pCxt->pCurrStmt = pCurrStmt; pCxt->pCurrStmt = pCurrStmt;
...@@ -1927,7 +1931,7 @@ static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* nu ...@@ -1927,7 +1931,7 @@ static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* nu
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SNode* pNode; SNode* pNode;
int32_t index = 0; int32_t index = 0;
FOREACH(pNode, pSelect->pProjectionList) { FOREACH(pNode, pSelect->pProjectionList) {
SExprNode* pExpr = (SExprNode*)pNode; SExprNode* pExpr = (SExprNode*)pNode;
...@@ -1935,7 +1939,7 @@ static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* nu ...@@ -1935,7 +1939,7 @@ static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* nu
(*pSchema)[index].bytes = pExpr->resType.bytes; (*pSchema)[index].bytes = pExpr->resType.bytes;
(*pSchema)[index].colId = index + 1; (*pSchema)[index].colId = index + 1;
strcpy((*pSchema)[index].name, pExpr->aliasName); strcpy((*pSchema)[index].name, pExpr->aliasName);
index +=1; index += 1;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -2122,7 +2126,8 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) ...@@ -2122,7 +2126,8 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect)
SNode* pDbCond = NULL; SNode* pDbCond = NULL;
SNode* pTbCond = NULL; SNode* pTbCond = NULL;
if (TSDB_CODE_SUCCESS != createOperatorNode(OP_TYPE_EQUAL, "db_name", pShow->pDbName, &pDbCond) || if (TSDB_CODE_SUCCESS != createOperatorNode(OP_TYPE_EQUAL, "db_name", pShow->pDbName, &pDbCond) ||
TSDB_CODE_SUCCESS != createOperatorNode(OP_TYPE_LIKE, getTbNameColName(nodeType(pShow)), pShow->pTbNamePattern, &pTbCond)) { TSDB_CODE_SUCCESS !=
createOperatorNode(OP_TYPE_LIKE, getTbNameColName(nodeType(pShow)), pShow->pTbNamePattern, &pTbCond)) {
nodesDestroyNode(pDbCond); nodesDestroyNode(pDbCond);
nodesDestroyNode(pTbCond); nodesDestroyNode(pTbCond);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
...@@ -2147,7 +2152,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) ...@@ -2147,7 +2152,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect)
static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) { static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) {
SSelectStmt* pStmt = NULL; SSelectStmt* pStmt = NULL;
int32_t code = createSelectStmtForShow(nodeType(pQuery->pRoot), &pStmt); int32_t code = createSelectStmtForShow(nodeType(pQuery->pRoot), &pStmt);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = createShowCondition((SShowStmt*)pQuery->pRoot, pStmt); code = createShowCondition((SShowStmt*)pQuery->pRoot, pStmt);
} }
...@@ -2196,17 +2201,16 @@ static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) { ...@@ -2196,17 +2201,16 @@ static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
int32_t index = 0; int32_t index = 0;
SNode* pFunc = NULL; SNode* pFunc = NULL;
FOREACH(pFunc, pOptions->pFuncs) { FOREACH(pFunc, pOptions->pFuncs) { pReq->ntbCfg.pRSmaParam->pFuncIds[index++] = ((SFunctionNode*)pFunc)->funcId; }
pReq->ntbCfg.pRSmaParam->pFuncIds[index++] = ((SFunctionNode*)pFunc)->funcId;
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pVgroupInfo, SVgroupTablesBatch* pBatch) { static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pVgroupInfo,
char dbFName[TSDB_DB_FNAME_LEN] = {0}; SVgroupTablesBatch* pBatch) {
SName name = { .type = TSDB_DB_NAME_T, .acctId = acctId }; char dbFName[TSDB_DB_FNAME_LEN] = {0};
SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
strcpy(name.dbname, pStmt->dbName); strcpy(name.dbname, pStmt->dbName);
tNameGetFullDbName(&name, dbFName); tNameGetFullDbName(&name, dbFName);
...@@ -2220,7 +2224,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* ...@@ -2220,7 +2224,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
destroyCreateTbReq(&req); destroyCreateTbReq(&req);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SNode* pCol; SNode* pCol;
col_id_t index = 0; col_id_t index = 0;
FOREACH(pCol, pStmt->pCols) { FOREACH(pCol, pStmt->pCols) {
toSchemaEx((SColumnDefNode*)pCol, index + 1, req.ntbCfg.pSchema + index); toSchemaEx((SColumnDefNode*)pCol, index + 1, req.ntbCfg.pSchema + index);
...@@ -2244,7 +2248,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* ...@@ -2244,7 +2248,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
} }
static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) { static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) {
int tlen = sizeof(SMsgHead) + tSerializeSVCreateTbBatchReq(NULL, &(pTbBatch->req)); int tlen = sizeof(SMsgHead) + tSerializeSVCreateTbBatchReq(NULL, &(pTbBatch->req));
void* buf = taosMemoryMalloc(tlen); void* buf = taosMemoryMalloc(tlen);
if (NULL == buf) { if (NULL == buf) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
...@@ -2258,10 +2262,10 @@ static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* ...@@ -2258,10 +2262,10 @@ static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray*
if (NULL == pVgData) { if (NULL == pVgData) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
pVgData->vg = pTbBatch->info; pVgData->vg = pTbBatch->info;
pVgData->pData = buf; pVgData->pData = buf;
pVgData->size = tlen; pVgData->size = tlen;
pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray); pVgData->numOfTables = (int32_t)taosArrayGetSize(pTbBatch->req.pArray);
taosArrayPush(pBufArray, &pVgData); taosArrayPush(pBufArray, &pVgData);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -2269,7 +2273,7 @@ static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* ...@@ -2269,7 +2273,7 @@ static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray*
static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) {
size_t size = taosArrayGetSize(pTbBatch->req.pArray); size_t size = taosArrayGetSize(pTbBatch->req.pArray);
for(int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i); SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i);
taosMemoryFreeClear(pTableReq->dbFName); taosMemoryFreeClear(pTableReq->dbFName);
taosMemoryFreeClear(pTableReq->name); taosMemoryFreeClear(pTableReq->name);
...@@ -2306,14 +2310,15 @@ static void destroyCreateTbReqArray(SArray* pArray) { ...@@ -2306,14 +2310,15 @@ static void destroyCreateTbReqArray(SArray* pArray) {
taosArrayDestroy(pArray); taosArrayDestroy(pArray);
} }
static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pInfo, SArray** pBufArray) { static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pInfo,
SArray** pBufArray) {
*pBufArray = taosArrayInit(1, POINTER_BYTES); *pBufArray = taosArrayInit(1, POINTER_BYTES);
if (NULL == *pBufArray) { if (NULL == *pBufArray) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SVgroupTablesBatch tbatch = {0}; SVgroupTablesBatch tbatch = {0};
int32_t code = buildNormalTableBatchReq(acctId, pStmt, pInfo, &tbatch); int32_t code = buildNormalTableBatchReq(acctId, pStmt, pInfo, &tbatch);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = serializeVgroupTablesBatch(&tbatch, *pBufArray); code = serializeVgroupTablesBatch(&tbatch, *pBufArray);
} }
...@@ -2328,7 +2333,7 @@ static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt* ...@@ -2328,7 +2333,7 @@ static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt*
static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) {
SCreateTableStmt* pStmt = (SCreateTableStmt*)pQuery->pRoot; SCreateTableStmt* pStmt = (SCreateTableStmt*)pQuery->pRoot;
int32_t code = checkCreateTable(pCxt, pStmt); int32_t code = checkCreateTable(pCxt, pStmt);
SVgroupInfo info = {0}; SVgroupInfo info = {0};
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = getTableHashVgroup(pCxt, pStmt->dbName, pStmt->tableName, &info); code = getTableHashVgroup(pCxt, pStmt->dbName, pStmt->tableName, &info);
...@@ -2347,17 +2352,17 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { ...@@ -2347,17 +2352,17 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) {
return code; return code;
} }
static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, const char* pDbName,
const char* pDbName, const char* pTableName, SKVRow row, uint64_t suid, SVgroupInfo* pVgInfo) { const char* pTableName, SKVRow row, uint64_t suid, SVgroupInfo* pVgInfo) {
char dbFName[TSDB_DB_FNAME_LEN] = {0}; char dbFName[TSDB_DB_FNAME_LEN] = {0};
SName name = { .type = TSDB_DB_NAME_T, .acctId = acctId }; SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
strcpy(name.dbname, pDbName); strcpy(name.dbname, pDbName);
tNameGetFullDbName(&name, dbFName); tNameGetFullDbName(&name, dbFName);
struct SVCreateTbReq req = {0}; struct SVCreateTbReq req = {0};
req.type = TD_CHILD_TABLE; req.type = TD_CHILD_TABLE;
req.dbFName = strdup(dbFName); req.dbFName = strdup(dbFName);
req.name = strdup(pTableName); req.name = strdup(pTableName);
req.ctbCfg.suid = suid; req.ctbCfg.suid = suid;
req.ctbCfg.pTag = row; req.ctbCfg.pTag = row;
...@@ -2376,13 +2381,14 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, ...@@ -2376,13 +2381,14 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap,
} }
} }
static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SSchema* pSchema, SKVRowBuilder* pBuilder) { static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SSchema* pSchema,
SKVRowBuilder* pBuilder) {
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode; return pCxt->errCode;
} }
SVariant var; SVariant var;
valueNodeToVariant(pVal, &var); valueNodeToVariant(pVal, &var);
char tagVal[TSDB_MAX_TAGS_LEN] = {0}; char tagVal[TSDB_MAX_TAGS_LEN] = {0};
int32_t code = taosVariantDump(&var, tagVal, pSchema->type, true); int32_t code = taosVariantDump(&var, tagVal, pSchema->type, true);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
tdAddColToKVRow(pBuilder, pSchema->colId, pSchema->type, tagVal); tdAddColToKVRow(pBuilder, pSchema->colId, pSchema->type, tagVal);
...@@ -2390,21 +2396,23 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS ...@@ -2390,21 +2396,23 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
return code; return code;
} }
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta, SKVRowBuilder* pBuilder) { static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
SKVRowBuilder* pBuilder) {
int32_t numOfTags = getNumOfTags(pSuperTableMeta); int32_t numOfTags = getNumOfTags(pSuperTableMeta);
if (LIST_LENGTH(pStmt->pValsOfTags) != LIST_LENGTH(pStmt->pSpecificTags) || numOfTags < LIST_LENGTH(pStmt->pValsOfTags)) { if (LIST_LENGTH(pStmt->pValsOfTags) != LIST_LENGTH(pStmt->pSpecificTags) ||
numOfTags < LIST_LENGTH(pStmt->pValsOfTags)) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAGS_NOT_MATCHED); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAGS_NOT_MATCHED);
} }
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
SNode* pTag, *pVal; SNode * pTag, *pVal;
FORBOTH(pTag, pStmt->pSpecificTags, pVal, pStmt->pValsOfTags) { FORBOTH(pTag, pStmt->pSpecificTags, pVal, pStmt->pValsOfTags) {
SColumnNode* pCol = (SColumnNode*)pTag; SColumnNode* pCol = (SColumnNode*)pTag;
SSchema* pSchema = NULL; SSchema* pSchema = NULL;
for (int32_t i = 0; i < numOfTags; ++i) { for (int32_t i = 0; i < numOfTags; ++i) {
if (0 == strcmp(pCol->colName, pTagSchema[i].name)) { if (0 == strcmp(pCol->colName, pTagSchema[i].name)) {
pSchema = pTagSchema + i; pSchema = pTagSchema + i;
break; break;
} }
} }
if (NULL == pSchema) { if (NULL == pSchema) {
...@@ -2419,14 +2427,15 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla ...@@ -2419,14 +2427,15 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta, SKVRowBuilder* pBuilder) { static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
SKVRowBuilder* pBuilder) {
if (getNumOfTags(pSuperTableMeta) != LIST_LENGTH(pStmt->pValsOfTags)) { if (getNumOfTags(pSuperTableMeta) != LIST_LENGTH(pStmt->pValsOfTags)) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAGS_NOT_MATCHED); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAGS_NOT_MATCHED);
} }
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
SNode* pVal; SNode* pVal;
int32_t index = 0; int32_t index = 0;
FOREACH(pVal, pStmt->pValsOfTags) { FOREACH(pVal, pStmt->pValsOfTags) {
int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pTagSchema + index++, pBuilder); int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pTagSchema + index++, pBuilder);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
...@@ -2439,7 +2448,8 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau ...@@ -2439,7 +2448,8 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
static int32_t checkCreateSubTable(STranslateContext* pCxt, SCreateSubTableClause* pStmt) { static int32_t checkCreateSubTable(STranslateContext* pCxt, SCreateSubTableClause* pStmt) {
if (0 != strcmp(pStmt->dbName, pStmt->useDbName)) { if (0 != strcmp(pStmt->dbName, pStmt->useDbName)) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR);; return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR);
;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -2458,9 +2468,9 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla ...@@ -2458,9 +2468,9 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
if (NULL != pStmt->pSpecificTags) { if (NULL != pStmt->pSpecificTags) {
code = buildKVRowForBindTags(pCxt, pStmt, pSuperTableMeta, &kvRowBuilder); code = buildKVRowForBindTags(pCxt, pStmt, pSuperTableMeta, &kvRowBuilder);
} else { } else {
code = buildKVRowForAllTags(pCxt, pStmt, pSuperTableMeta, &kvRowBuilder); code = buildKVRowForAllTags(pCxt, pStmt, pSuperTableMeta, &kvRowBuilder);
} }
} }
...@@ -2472,14 +2482,15 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla ...@@ -2472,14 +2482,15 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla
} else { } else {
tdSortKVRowByColIdx(row); tdSortKVRowByColIdx(row);
} }
} }
SVgroupInfo info = {0}; SVgroupInfo info = {0};
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = getTableHashVgroup(pCxt, pStmt->dbName, pStmt->tableName, &info); code = getTableHashVgroup(pCxt, pStmt->dbName, pStmt->tableName, &info);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
addCreateTbReqIntoVgroup(pCxt->pParseCxt->acctId, pVgroupHashmap, pStmt->dbName, pStmt->tableName, row, pSuperTableMeta->uid, &info); addCreateTbReqIntoVgroup(pCxt->pParseCxt->acctId, pVgroupHashmap, pStmt->dbName, pStmt->tableName, row,
pSuperTableMeta->uid, &info);
} }
taosMemoryFreeClear(pSuperTableMeta); taosMemoryFreeClear(pSuperTableMeta);
...@@ -2493,7 +2504,7 @@ static SArray* serializeVgroupsTablesBatch(int32_t acctId, SHashObj* pVgroupHash ...@@ -2493,7 +2504,7 @@ static SArray* serializeVgroupsTablesBatch(int32_t acctId, SHashObj* pVgroupHash
return NULL; return NULL;
} }
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SVgroupTablesBatch* pTbBatch = NULL; SVgroupTablesBatch* pTbBatch = NULL;
do { do {
pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch); pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch);
...@@ -2517,7 +2528,7 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) ...@@ -2517,7 +2528,7 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
} }
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SNode* pNode; SNode* pNode;
FOREACH(pNode, pStmt->pSubTables) { FOREACH(pNode, pStmt->pSubTables) {
code = rewriteCreateSubTable(pCxt, (SCreateSubTableClause*)pNode, pVgroupHashmap); code = rewriteCreateSubTable(pCxt, (SCreateSubTableClause*)pNode, pVgroupHashmap);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
...@@ -2607,7 +2618,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { ...@@ -2607,7 +2618,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
} }
if (NULL != pCxt->pDbs) { if (NULL != pCxt->pDbs) {
pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN); pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN);
if (NULL == pQuery->pDbList) { if (NULL == pQuery->pDbList) {
...@@ -2637,15 +2648,14 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { ...@@ -2637,15 +2648,14 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
int32_t translate(SParseContext* pParseCxt, SQuery* pQuery) { int32_t translate(SParseContext* pParseCxt, SQuery* pQuery) {
STranslateContext cxt = { STranslateContext cxt = {
.pParseCxt = pParseCxt, .pParseCxt = pParseCxt,
.errCode = TSDB_CODE_SUCCESS, .errCode = TSDB_CODE_SUCCESS,
.msgBuf = { .buf = pParseCxt->pMsg, .len = pParseCxt->msgLen }, .msgBuf = {.buf = pParseCxt->pMsg, .len = pParseCxt->msgLen},
.pNsLevel = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES), .pNsLevel = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES),
.currLevel = 0, .currLevel = 0,
.currClause = 0, .currClause = 0,
.pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK), .pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK),
.pTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK) .pTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)};
};
if (NULL == cxt.pNsLevel) { if (NULL == cxt.pNsLevel) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册