Merge branch '3.0' into feature/TD-14481-3.0

This commit is contained in:
Cary Xu 2022-04-26 12:44:43 +08:00
commit 0ff1ae9fc8
26 changed files with 2695 additions and 1934 deletions

View File

@ -292,7 +292,6 @@ typedef struct {
char name[TSDB_TABLE_FNAME_LEN]; char name[TSDB_TABLE_FNAME_LEN];
int8_t igExists; int8_t igExists;
float xFilesFactor; float xFilesFactor;
int32_t aggregationMethod;
int32_t delay; int32_t delay;
int32_t ttl; int32_t ttl;
int32_t numOfColumns; int32_t numOfColumns;
@ -1512,10 +1511,8 @@ typedef struct {
int32_t delay; int32_t delay;
int32_t qmsg1Len; int32_t qmsg1Len;
int32_t qmsg2Len; int32_t qmsg2Len;
func_id_t* pFuncIds;
char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1 char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2 char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
int8_t nFuncIds;
} SRSmaParam; } SRSmaParam;
typedef struct SVCreateTbReq { typedef struct SVCreateTbReq {

View File

@ -125,15 +125,15 @@ typedef struct SFmGetFuncInfoParam {
struct SCatalog* pCtg; struct SCatalog* pCtg;
void *pRpc; void *pRpc;
const SEpSet* pMgmtEps; const SEpSet* pMgmtEps;
char* pErrBuf;
int32_t errBufLen;
} SFmGetFuncInfoParam; } SFmGetFuncInfoParam;
int32_t fmFuncMgtInit(); int32_t fmFuncMgtInit();
void fmFuncMgtDestroy(); void fmFuncMgtDestroy();
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType); int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc);
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
bool fmIsAggFunc(int32_t funcId); bool fmIsAggFunc(int32_t funcId);
bool fmIsScalarFunc(int32_t funcId); bool fmIsScalarFunc(int32_t funcId);

View File

@ -46,7 +46,7 @@ typedef struct SExprNode {
ENodeType type; ENodeType type;
SDataType resType; SDataType resType;
char aliasName[TSDB_COL_NAME_LEN]; char aliasName[TSDB_COL_NAME_LEN];
SNodeList* pAssociationList; SArray* pAssociation;
} SExprNode; } SExprNode;
typedef enum EColumnType { typedef enum EColumnType {
@ -81,7 +81,6 @@ typedef struct SValueNode {
char* literal; char* literal;
bool isDuration; bool isDuration;
bool translate; bool translate;
bool genByCalc;
int16_t placeholderNo; int16_t placeholderNo;
union { union {
bool b; bool b;
@ -119,6 +118,7 @@ typedef struct SFunctionNode {
int32_t funcId; int32_t funcId;
int32_t funcType; int32_t funcType;
SNodeList* pParameterList; SNodeList* pParameterList;
int32_t udfBufSize;
} SFunctionNode; } SFunctionNode;
typedef struct STableNode { typedef struct STableNode {
@ -135,7 +135,7 @@ typedef struct SRealTableNode {
STableNode table; // QUERY_NODE_REAL_TABLE STableNode table; // QUERY_NODE_REAL_TABLE
struct STableMeta* pMeta; struct STableMeta* pMeta;
SVgroupsInfo* pVgroupList; SVgroupsInfo* pVgroupList;
char useDbName[TSDB_DB_NAME_LEN]; char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
double ratio; double ratio;
} SRealTableNode; } SRealTableNode;

View File

@ -573,7 +573,6 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602) #define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602)
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603) #define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
#define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604) #define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604)
#define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605)
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608) #define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608)
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609) #define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609)
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A) #define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
@ -633,6 +632,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801) #define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802) #define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803) #define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803)
#define TSDB_CODE_FUNC_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2604)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -120,7 +120,7 @@ const char *taos_errstr(TAOS_RES *res) {
return (const char *)tstrerror(terrno); return (const char *)tstrerror(terrno);
} }
if (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) { if (NULL != pRequest->msgBuf && (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR)) {
return pRequest->msgBuf; return pRequest->msgBuf;
} else { } else {
return (const char *)tstrerror(pRequest->code); return (const char *)tstrerror(pRequest->code);

View File

@ -522,10 +522,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
SRSmaParam *param = pReq->stbCfg.pRSmaParam; SRSmaParam *param = pReq->stbCfg.pRSmaParam;
tlen += taosEncodeBinary(buf, (const void *)&param->xFilesFactor, sizeof(param->xFilesFactor)); tlen += taosEncodeBinary(buf, (const void *)&param->xFilesFactor, sizeof(param->xFilesFactor));
tlen += taosEncodeFixedI32(buf, param->delay); tlen += taosEncodeFixedI32(buf, param->delay);
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
for (int8_t i = 0; i < param->nFuncIds; ++i) {
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
}
tlen += taosEncodeFixedI32(buf, param->qmsg1Len); tlen += taosEncodeFixedI32(buf, param->qmsg1Len);
if (param->qmsg1Len > 0) { if (param->qmsg1Len > 0) {
tlen += taosEncodeString(buf, param->qmsg1); tlen += taosEncodeString(buf, param->qmsg1);
@ -555,10 +551,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
SRSmaParam *param = pReq->ntbCfg.pRSmaParam; SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
tlen += taosEncodeBinary(buf, (const void *)&param->xFilesFactor, sizeof(param->xFilesFactor)); tlen += taosEncodeBinary(buf, (const void *)&param->xFilesFactor, sizeof(param->xFilesFactor));
tlen += taosEncodeFixedI32(buf, param->delay); tlen += taosEncodeFixedI32(buf, param->delay);
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
for (int8_t i = 0; i < param->nFuncIds; ++i) {
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
}
} }
break; break;
default: default:
@ -601,13 +593,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
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);
if (param->nFuncIds > 0) {
param->pFuncIds = (func_id_t *)taosMemoryCalloc(param->nFuncIds, sizeof(func_id_t));
for (int8_t i = 0; i < param->nFuncIds; ++i) {
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
}
}
buf = taosDecodeFixedI32(buf, &param->qmsg1Len); buf = taosDecodeFixedI32(buf, &param->qmsg1Len);
if (param->qmsg1Len > 0) { if (param->qmsg1Len > 0) {
buf = taosDecodeString(buf, &param->qmsg1); buf = taosDecodeString(buf, &param->qmsg1);
@ -641,15 +626,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
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);
if (param->nFuncIds > 0) {
param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t));
for (int8_t i = 0; i < param->nFuncIds; ++i) {
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
}
} else {
param->pFuncIds = NULL;
}
} else { } else {
pReq->ntbCfg.pRSmaParam = NULL; pReq->ntbCfg.pRSmaParam = NULL;
} }
@ -712,7 +688,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1; if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1;
if (tEncodeI32(&encoder, pReq->aggregationMethod) < 0) return -1;
if (tEncodeI32(&encoder, pReq->delay) < 0) return -1; if (tEncodeI32(&encoder, pReq->delay) < 0) return -1;
if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1; if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1;
@ -767,7 +742,6 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1; if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->aggregationMethod) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1; if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1; if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1;

View File

@ -350,7 +350,6 @@ typedef struct {
int32_t version; int32_t version;
int32_t nextColId; int32_t nextColId;
float xFilesFactor; float xFilesFactor;
int32_t aggregationMethod;
int32_t delay; int32_t delay;
int32_t ttl; int32_t ttl;
int32_t numOfColumns; int32_t numOfColumns;

View File

@ -87,7 +87,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
SDB_SET_INT32(pRaw, dataPos, pStb->version, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->version, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER)
SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER) SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->aggregationMethod, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER)
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER)
@ -175,7 +174,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
int32_t xFilesFactor = 0; int32_t xFilesFactor = 0;
SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER) SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER)
pStb->xFilesFactor = xFilesFactor / 10000.0f; pStb->xFilesFactor = xFilesFactor / 10000.0f;
SDB_GET_INT32(pRaw, dataPos, &pStb->aggregationMethod, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER)
@ -404,7 +402,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
req.name = (char *)tNameGetTableName(&name); req.name = (char *)tNameGetTableName(&name);
req.ttl = 0; req.ttl = 0;
req.keep = 0; req.keep = 0;
req.rollup = pStb->aggregationMethod > -1 ? 1 : 0; req.rollup = pStb->pAst1 > 0 ? 1 : 0;
req.type = TD_SUPER_TABLE; req.type = TD_SUPER_TABLE;
req.stbCfg.suid = pStb->uid; req.stbCfg.suid = pStb->uid;
req.stbCfg.nCols = pStb->numOfColumns; req.stbCfg.nCols = pStb->numOfColumns;
@ -433,20 +431,8 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
pRSmaParam->xFilesFactor = pStb->xFilesFactor; pRSmaParam->xFilesFactor = pStb->xFilesFactor;
pRSmaParam->delay = pStb->delay; pRSmaParam->delay = pStb->delay;
pRSmaParam->nFuncIds = 1; // only 1 aggregation method supported currently
pRSmaParam->pFuncIds = (func_id_t *)taosMemoryCalloc(pRSmaParam->nFuncIds, sizeof(func_id_t));
if (pRSmaParam->pFuncIds == NULL) {
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
taosMemoryFreeClear(req.stbCfg.pSchema);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
for (int32_t f = 0; f < pRSmaParam->nFuncIds; ++f) {
*(pRSmaParam->pFuncIds + f) = pStb->aggregationMethod;
}
if (pStb->ast1Len > 0) { if (pStb->ast1Len > 0) {
if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) { if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) {
taosMemoryFreeClear(pRSmaParam->pFuncIds);
taosMemoryFreeClear(req.stbCfg.pRSmaParam); taosMemoryFreeClear(req.stbCfg.pRSmaParam);
taosMemoryFreeClear(req.stbCfg.pSchema); taosMemoryFreeClear(req.stbCfg.pSchema);
return NULL; return NULL;
@ -454,7 +440,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
} }
if (pStb->ast2Len > 0) { if (pStb->ast2Len > 0) {
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) { if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
taosMemoryFreeClear(pRSmaParam->pFuncIds);
taosMemoryFreeClear(pRSmaParam->qmsg1); taosMemoryFreeClear(pRSmaParam->qmsg1);
taosMemoryFreeClear(req.stbCfg.pRSmaParam); taosMemoryFreeClear(req.stbCfg.pRSmaParam);
taosMemoryFreeClear(req.stbCfg.pSchema); taosMemoryFreeClear(req.stbCfg.pSchema);
@ -469,7 +454,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
SMsgHead *pHead = taosMemoryMalloc(contLen); SMsgHead *pHead = taosMemoryMalloc(contLen);
if (pHead == NULL) { if (pHead == NULL) {
if (pRSmaParam) { if (pRSmaParam) {
taosMemoryFreeClear(pRSmaParam->pFuncIds);
taosMemoryFreeClear(pRSmaParam->qmsg1); taosMemoryFreeClear(pRSmaParam->qmsg1);
taosMemoryFreeClear(pRSmaParam->qmsg2); taosMemoryFreeClear(pRSmaParam->qmsg2);
taosMemoryFreeClear(pRSmaParam); taosMemoryFreeClear(pRSmaParam);
@ -487,7 +471,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
*pContLen = contLen; *pContLen = contLen;
if (pRSmaParam) { if (pRSmaParam) {
taosMemoryFreeClear(pRSmaParam->pFuncIds);
taosMemoryFreeClear(pRSmaParam->qmsg1); taosMemoryFreeClear(pRSmaParam->qmsg1);
taosMemoryFreeClear(pRSmaParam->qmsg2); taosMemoryFreeClear(pRSmaParam->qmsg2);
taosMemoryFreeClear(pRSmaParam); taosMemoryFreeClear(pRSmaParam);
@ -705,7 +688,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
stbObj.version = 1; stbObj.version = 1;
stbObj.nextColId = 1; stbObj.nextColId = 1;
stbObj.xFilesFactor = pCreate->xFilesFactor; stbObj.xFilesFactor = pCreate->xFilesFactor;
stbObj.aggregationMethod = pCreate->aggregationMethod;
stbObj.delay = pCreate->delay; stbObj.delay = pCreate->delay;
stbObj.ttl = pCreate->ttl; stbObj.ttl = pCreate->ttl;
stbObj.numOfColumns = pCreate->numOfColumns; stbObj.numOfColumns = pCreate->numOfColumns;

View File

@ -287,7 +287,6 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
taosMemoryFree(vCreateTbReq.stbCfg.pSchema); taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
if (vCreateTbReq.stbCfg.pRSmaParam) { if (vCreateTbReq.stbCfg.pRSmaParam) {
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds);
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg1); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg1);
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg2); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg2);
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam);
@ -334,7 +333,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
taosMemoryFree(pCreateTbReq->stbCfg.pSchema); taosMemoryFree(pCreateTbReq->stbCfg.pSchema);
taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema);
if (pCreateTbReq->stbCfg.pRSmaParam) { if (pCreateTbReq->stbCfg.pRSmaParam) {
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds);
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam);
} }
} else if (pCreateTbReq->type == TD_CHILD_TABLE) { } else if (pCreateTbReq->type == TD_CHILD_TABLE) {
@ -342,7 +340,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
} else { } else {
taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); taosMemoryFree(pCreateTbReq->ntbCfg.pSchema);
if (pCreateTbReq->ntbCfg.pRSmaParam) { if (pCreateTbReq->ntbCfg.pRSmaParam) {
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds);
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam);
} }
} }
@ -373,7 +370,6 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) {
taosMemoryFree(vAlterTbReq.stbCfg.pSchema); taosMemoryFree(vAlterTbReq.stbCfg.pSchema);
taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema);
if (vAlterTbReq.stbCfg.pRSmaParam) { if (vAlterTbReq.stbCfg.pRSmaParam) {
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds);
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam);
} }
taosMemoryFree(vAlterTbReq.name); taosMemoryFree(vAlterTbReq.name);

View File

@ -41,7 +41,9 @@ extern "C" {
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
#define FUNC_UDF_ID_START_OFFSET_VAL 5000 #define FUNC_UDF_ID_START 5000
#define FUNC_AGGREGATE_UDF_ID 5001
#define FUNC_SCALAR_UDF_ID 5002
extern const int funcMgtUdfNum; extern const int funcMgtUdfNum;

View File

@ -24,7 +24,6 @@
typedef struct SFuncMgtService { typedef struct SFuncMgtService {
SHashObj* pFuncNameHashTable; SHashObj* pFuncNameHashTable;
SArray* pUdfTable; // SUdfInfo
} SFuncMgtService; } SFuncMgtService;
typedef struct SUdfInfo { typedef struct SUdfInfo {
@ -49,18 +48,12 @@ static void doInitFunctionTable() {
return; return;
} }
} }
gFunMgtService.pUdfTable = NULL;
}
static int8_t getUdfType(int32_t funcId) {
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
return pUdf->funcType;
} }
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) { static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
if (fmIsUserDefinedFunc(funcId)) { if (fmIsUserDefinedFunc(funcId)) {
return getUdfType(funcId); return FUNC_MGT_AGG_FUNC == classification ? FUNC_AGGREGATE_UDF_ID == funcId :
(FUNC_MGT_SCALAR_FUNC == classification ? FUNC_SCALAR_UDF_ID == funcId : false);
} }
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
return false; return false;
@ -68,33 +61,23 @@ static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification); return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
} }
static int32_t getUdfId(SFmGetFuncInfoParam* pParam, const char* pFuncName) { static int32_t getUdfInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
SFuncInfo* pInfo = NULL; SFuncInfo* pInfo = NULL;
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFuncName, &pInfo); int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFunc->functionName, &pInfo);
if (TSDB_CODE_SUCCESS != code || NULL == pInfo) { if (TSDB_CODE_SUCCESS != code) {
return -1; return code;
} }
if (NULL == gFunMgtService.pUdfTable) { if (NULL == pInfo) {
gFunMgtService.pUdfTable = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SUdfInfo)); snprintf(pParam->pErrBuf, pParam->errBufLen, "Invalid function name: %s", pFunc->functionName);
return TSDB_CODE_FUNC_INVALID_FUNTION;
} }
SUdfInfo info = { .outputDt.type = pInfo->outputType, .outputDt.bytes = pInfo->outputLen, .funcType = pInfo->funcType }; pFunc->funcType = FUNCTION_TYPE_UDF;
taosArrayPush(gFunMgtService.pUdfTable, &info); pFunc->funcId = TSDB_FUNC_TYPE_AGGREGATE == pInfo->funcType ? FUNC_AGGREGATE_UDF_ID : FUNC_SCALAR_UDF_ID;
pFunc->node.resType.type = pInfo->outputType;
pFunc->node.resType.bytes = pInfo->outputLen;
pFunc->udfBufSize = pInfo->bufSize;
tFreeSFuncInfo(pInfo); tFreeSFuncInfo(pInfo);
taosMemoryFree(pInfo); taosMemoryFree(pInfo);
return taosArrayGetSize(gFunMgtService.pUdfTable) + FUNC_UDF_ID_START_OFFSET_VAL;
}
static int32_t getFuncId(SFmGetFuncInfoParam* pParam, const char* pFuncName) {
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFuncName, strlen(pFuncName));
if (NULL == pVal) {
return getUdfId(pParam, pFuncName);
}
return *(int32_t*)pVal;
}
static int32_t getUdfResultType(SFunctionNode* pFunc) {
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, pFunc->funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
pFunc->node.resType = pUdf->outputDt;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -103,28 +86,14 @@ int32_t fmFuncMgtInit() {
return initFunctionCode; return initFunctionCode;
} }
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) { int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
*pFuncId = getFuncId(pParam, pFuncName); void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
if (*pFuncId < 0) { if (NULL != pVal) {
return TSDB_CODE_FAILED; pFunc->funcId = *(int32_t*)pVal;
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pParam->pErrBuf, pParam->errBufLen);
} }
if (fmIsUserDefinedFunc(*pFuncId)) { return getUdfInfo(pParam, pFunc);
*pFuncType = FUNCTION_TYPE_UDF;
} else {
*pFuncType = funcMgtBuiltins[*pFuncId].type;
}
return TSDB_CODE_SUCCESS;
}
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
if (fmIsUserDefinedFunc(pFunc->funcId)) {
return getUdfResultType(pFunc);
}
if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
return TSDB_CODE_FAILED;
}
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pErrBuf, len);
} }
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
@ -194,7 +163,7 @@ bool fmIsMultiResFunc(int32_t funcId) {
} }
bool fmIsUserDefinedFunc(int32_t funcId) { bool fmIsUserDefinedFunc(int32_t funcId) {
return funcId > FUNC_UDF_ID_START_OFFSET_VAL; return funcId > FUNC_UDF_ID_START;
} }
void fmFuncMgtDestroy() { void fmFuncMgtDestroy() {

View File

@ -1663,7 +1663,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
return code; return code;
} }
static const char* jkValueGenByCalc = "GenByCalc"; static const char* jkValueLiteralSize = "LiteralSize";
static const char* jkValueLiteral = "Literal"; static const char* jkValueLiteral = "Literal";
static const char* jkValueDuration = "Duration"; static const char* jkValueDuration = "Duration";
static const char* jkValueTranslate = "Translate"; static const char* jkValueTranslate = "Translate";
@ -1717,9 +1717,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
int32_t code = exprNodeToJson(pObj, pJson); int32_t code = exprNodeToJson(pObj, pJson);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddBoolToObject(pJson, jkValueGenByCalc, pNode->genByCalc); code = tjsonAddIntegerToObject(pJson, jkValueLiteralSize, NULL != pNode->literal ? strlen(pNode->literal) : 0);
} }
if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) { if (TSDB_CODE_SUCCESS == code && NULL != pNode->literal) {
code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->literal); code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->literal);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -1789,10 +1789,11 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
SValueNode* pNode = (SValueNode*)pObj; SValueNode* pNode = (SValueNode*)pObj;
int32_t code = jsonToExprNode(pJson, pObj); int32_t code = jsonToExprNode(pJson, pObj);
int32_t literalSize = 0;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetBoolValue(pJson, jkValueGenByCalc, &pNode->genByCalc); code = tjsonGetIntValue(pJson, jkValueLiteralSize, &literalSize);
} }
if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) { if (TSDB_CODE_SUCCESS == code && literalSize > 0) {
code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->literal); code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->literal);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {

View File

@ -95,7 +95,6 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList); SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList);
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName);
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt); SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt);
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList); SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList);
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2); SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2);

View File

@ -498,6 +498,7 @@ signed_literal(A) ::= NK_BOOL(B).
signed_literal(A) ::= TIMESTAMP NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); } signed_literal(A) ::= TIMESTAMP NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); }
signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); } signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); }
signed_literal(A) ::= NULL. { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } signed_literal(A) ::= NULL. { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); }
signed_literal(A) ::= literal_func(B). { A = releaseRawExprNode(pCxt, B); }
%type literal_list { SNodeList* } %type literal_list { SNodeList* }
%destructor literal_list { nodesDestroyList($$); } %destructor literal_list { nodesDestroyList($$); }
@ -610,8 +611,10 @@ pseudo_column(A) ::= WDURATION(B).
function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
function_expression(A) ::= star_func(B) NK_LP star_func_para_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } function_expression(A) ::= star_func(B) NK_LP star_func_para_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
function_expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); } function_expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); }
function_expression(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNodeNoArg(pCxt, &B)); } function_expression(A) ::= literal_func(B). { A = B; }
//function_expression(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
literal_func(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNode(pCxt, &B, NULL)); }
literal_func(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
%type noarg_func { SToken } %type noarg_func { SToken }
%destructor noarg_func { } %destructor noarg_func { }

View File

@ -368,39 +368,6 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod
return (SNode*)func; return (SNode*)func;
} }
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName) {
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
CHECK_OUT_OF_MEM(func);
char buf[64] = {0};
int32_t dataType;
switch (pFuncName->type) {
case TK_NOW: {
int64_t ts = taosGetTimestamp(TSDB_TIME_PRECISION_MILLI);
snprintf(buf, sizeof(buf), "%"PRId64, ts);
dataType = TSDB_DATA_TYPE_BIGINT;
break;
}
case TK_TODAY: {
int64_t ts = taosGetTimestampToday(TSDB_TIME_PRECISION_MILLI);
snprintf(buf, sizeof(buf), "%"PRId64, ts);
dataType = TSDB_DATA_TYPE_BIGINT;
break;
}
case TK_TIMEZONE: {
strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr));
dataType = TSDB_DATA_TYPE_BINARY;
break;
}
}
SToken token = {.type = pFuncName->type, .n = strlen(buf), .z = buf};
SNodeList *pParameterList = createNodeList(pCxt, createValueNode(pCxt, dataType, &token));
strncpy(func->functionName, pFuncName->z, pFuncName->n);
func->pParameterList = pParameterList;
return (SNode*)func;
}
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) { SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) {
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
CHECK_OUT_OF_MEM(func); CHECK_OUT_OF_MEM(func);
@ -443,10 +410,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa
} else { } else {
strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n); strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n);
} }
strncpy(realTable->table.tableName, pTableName->z, pTableName->n); strncpy(realTable->table.tableName, pTableName->z, pTableName->n);
if (NULL != pCxt->pQueryCxt->db) {
strcpy(realTable->useDbName, pCxt->pQueryCxt->db);
}
return (SNode*)realTable; return (SNode*)realTable;
} }

View File

@ -24,109 +24,37 @@ typedef struct SCalcConstContext {
int32_t code; int32_t code;
} SCalcConstContext; } SCalcConstContext;
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt); static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery);
static int32_t calcConstSubquery(SCalcConstContext* pCxt, STempTableNode* pTempTable) {
return calcConstQuery(pCxt, pTempTable->pSubquery, true);
}
static int32_t calcConstNode(SNode** pNode) {
if (NULL == *pNode) {
return TSDB_CODE_SUCCESS;
}
static EDealRes doCalcConst(SNode** pNode, SCalcConstContext* pCxt) {
SNode* pNew = NULL; SNode* pNew = NULL;
pCxt->code = scalarCalculateConstants(*pNode, &pNew); int32_t code = scalarCalculateConstants(*pNode, &pNew);
if (TSDB_CODE_SUCCESS != pCxt->code) { if (TSDB_CODE_SUCCESS == code) {
return DEAL_RES_ERROR; *pNode = pNew;
} }
((SValueNode*)pNew)->genByCalc = true; return code;
((SValueNode*)pNew)->translate = true;
*pNode = pNew;
return DEAL_RES_CONTINUE;
} }
static bool isTimestampCol(SNode* pNode) { static int32_t calcConstList(SNodeList* pList) {
if (NULL == pNode) { SNode* pNode = NULL;
return false; FOREACH(pNode, pList) {
} SNode* pNew = NULL;
return (QUERY_NODE_COLUMN == nodeType(pNode) && TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode*)pNode)->resType.type); int32_t code = scalarCalculateConstants(pNode, &pNew);
} if (TSDB_CODE_SUCCESS == code) {
REPLACE_NODE(pNew);
static EDealRes stringToTimestamp(SCalcConstContext* pCxt, uint8_t precision, SValueNode* pVal) { } else {
switch (pVal->node.resType.type) { return code;
case TSDB_DATA_TYPE_VARCHAR:
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_VARBINARY: {
int64_t val = 0;
if (TSDB_CODE_SUCCESS != convertStringToTimestamp(pVal->node.resType.type, pVal->datum.p, precision, &val)) {
pCxt->code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCORRECT_TIMESTAMP_VAL, varDataVal(pVal->datum.p));
return DEAL_RES_ERROR;
}
pVal->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
taosMemoryFreeClear(pVal->datum.p);
pVal->datum.i = val;
break;
}
default:
break;
}
return DEAL_RES_CONTINUE;
}
static EDealRes calcConstOperator(SOperatorNode** pNode, void* pContext) {
SCalcConstContext* pCxt = pContext;
SOperatorNode* pOp = *pNode;
if (QUERY_NODE_VALUE == nodeType(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) {
return doCalcConst((SNode**)pNode, pCxt);
}
if (isTimestampCol(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) {
return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pLeft)->node.resType.precision, (SValueNode*)pOp->pRight);
} else if (isTimestampCol(pOp->pRight) && QUERY_NODE_VALUE == nodeType(pOp->pLeft)) {
return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pRight)->node.resType.precision, (SValueNode*)pOp->pLeft);
}
return DEAL_RES_CONTINUE;
}
static EDealRes calcConstFunction(SFunctionNode** pNode, void* pContext) {
SFunctionNode* pFunc = *pNode;
if (!fmIsScalarFunc(pFunc->funcId) || fmIsUserDefinedFunc(pFunc->funcId)) {
return DEAL_RES_CONTINUE;
}
SNode* pParam = NULL;
FOREACH(pParam, pFunc->pParameterList) {
if (QUERY_NODE_VALUE != nodeType(pParam)) {
return DEAL_RES_CONTINUE;
} }
} }
return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext); return TSDB_CODE_SUCCESS;
}
static EDealRes calcConstLogicCond(SLogicConditionNode** pNode, void* pContext) {
SLogicConditionNode* pCond = *pNode;
SNode* pParam = NULL;
FOREACH(pParam, pCond->pParameterList) {
// todo calc "true and c1 > 10"
if (QUERY_NODE_VALUE != nodeType(pParam)) {
return DEAL_RES_CONTINUE;
}
}
return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext);
}
static EDealRes calcConstSubquery(STempTableNode** pNode, void* pContext) {
SCalcConstContext* pCxt = pContext;
pCxt->code = calcConstQuery(pCxt, (*pNode)->pSubquery);
return (TSDB_CODE_SUCCESS == pCxt->code ? DEAL_RES_CONTINUE : DEAL_RES_ERROR);
}
static EDealRes calcConst(SNode** pNode, void* pContext) {
switch (nodeType(*pNode)) {
case QUERY_NODE_OPERATOR:
return calcConstOperator((SOperatorNode**)pNode, pContext);
case QUERY_NODE_FUNCTION:
return calcConstFunction((SFunctionNode**)pNode, pContext);
case QUERY_NODE_LOGIC_CONDITION:
return calcConstLogicCond((SLogicConditionNode**)pNode, pContext);
case QUERY_NODE_TEMP_TABLE:
return calcConstSubquery((STempTableNode**)pNode, pContext);
default:
break;
}
return DEAL_RES_CONTINUE;
} }
static bool isCondition(const SNode* pNode) { static bool isCondition(const SNode* pNode) {
@ -174,18 +102,41 @@ static int32_t rewriteCondition(SCalcConstContext* pCxt, SNode** pNode) {
return pCxt->code; return pCxt->code;
} }
static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTable) { static int32_t calcConstCondition(SCalcConstContext* pCxt, SNode** pNode) {
if (QUERY_NODE_JOIN_TABLE == nodeType(pTable)) { int32_t code = rewriteCondition(pCxt, pNode);
SJoinTableNode* pJoin = (SJoinTableNode*)pTable; if (TSDB_CODE_SUCCESS == code) {
pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pLeft); code = calcConstNode(pNode);
if (TSDB_CODE_SUCCESS == pCxt->code) {
pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pRight);
}
if (TSDB_CODE_SUCCESS == pCxt->code && NULL != pJoin->pOnCond) {
pCxt->code = rewriteCondition(pCxt, &pJoin->pOnCond);
}
} }
return pCxt->code; return code;
}
static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTable) {
int32_t code = TSDB_CODE_SUCCESS;
switch (nodeType(pTable)) {
case QUERY_NODE_TEMP_TABLE: {
code = calcConstSubquery(pCxt, (STempTableNode*)pTable);
break;
}
case QUERY_NODE_JOIN_TABLE: {
SJoinTableNode* pJoin = (SJoinTableNode*)pTable;
code = rewriteConditionForFromTable(pCxt, pJoin->pLeft);
if (TSDB_CODE_SUCCESS == code) {
code = rewriteConditionForFromTable(pCxt, pJoin->pRight);
}
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->pOnCond) {
code = calcConstCondition(pCxt, &pJoin->pOnCond);
}
// todo empty table
break;
}
default:
break;
}
return code;
}
static int32_t calcConstFromTable(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
return rewriteConditionForFromTable(pCxt, pSelect->pFromTable);
} }
static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) { static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) {
@ -200,77 +151,133 @@ static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) {
} }
} }
static int32_t calcConstFromTable(SCalcConstContext* pCxt, SSelectStmt* pSelect) { static int32_t calcConstSelectCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) {
pCxt->code = rewriteConditionForFromTable(pCxt, pSelect->pFromTable);
if (TSDB_CODE_SUCCESS == pCxt->code) {
nodesRewriteExprPostOrder(&pSelect->pFromTable, calcConst, pCxt);
}
return pCxt->code;
}
static int32_t calcConstCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) {
if (NULL == *pCond) { if (NULL == *pCond) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
pCxt->code = rewriteCondition(pCxt, pCond); int32_t code = rewriteCondition(pCxt, pCond);
if (TSDB_CODE_SUCCESS == pCxt->code) { if (TSDB_CODE_SUCCESS == code) {
nodesRewriteExprPostOrder(pCond, calcConst, pCxt); code = calcConstNode(pCond);
} }
if (TSDB_CODE_SUCCESS == pCxt->code) { if (TSDB_CODE_SUCCESS == code) {
rewriteConstCondition(pSelect, pCond); rewriteConstCondition(pSelect, pCond);
} }
return pCxt->code; return code;
} }
static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect) { static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
nodesRewriteExprsPostOrder(pSelect->pProjectionList, calcConst, pCxt); SArray* pAssociation = NULL;
if (TSDB_CODE_SUCCESS == pCxt->code) { if (NULL != ((SExprNode*)pProject)->pAssociation) {
pCxt->code = calcConstFromTable(pCxt, pSelect); pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation);
if (NULL == pAssociation) {
return TSDB_CODE_OUT_OF_MEMORY;
}
} }
if (TSDB_CODE_SUCCESS == pCxt->code) {
pCxt->code = calcConstCondition(pCxt, pSelect, &pSelect->pWhere); int32_t code = scalarCalculateConstants(pProject, pNew);
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE == nodeType(pNew) && NULL != pAssociation) {
int32_t size = taosArrayGetSize(pAssociation);
for (int32_t i = 0; i < size; ++i) {
SNode** pCol = taosArrayGet(pAssociation, i);
*pCol = nodesCloneNode(pNew);
if (NULL == *pCol) {
return TSDB_CODE_OUT_OF_MEMORY;
}
}
} }
if (TSDB_CODE_SUCCESS == pCxt->code) { return code;
nodesRewriteExprsPostOrder(pSelect->pPartitionByList, calcConst, pCxt);
}
if (TSDB_CODE_SUCCESS == pCxt->code) {
nodesRewriteExprPostOrder(&pSelect->pWindow, calcConst, pCxt);
}
if (TSDB_CODE_SUCCESS == pCxt->code) {
nodesRewriteExprsPostOrder(pSelect->pGroupByList, calcConst, pCxt);
}
if (TSDB_CODE_SUCCESS == pCxt->code) {
pCxt->code = calcConstCondition(pCxt, pSelect, &pSelect->pHaving);
}
if (TSDB_CODE_SUCCESS == pCxt->code) {
nodesRewriteExprsPostOrder(pSelect->pOrderByList, calcConst, pCxt);
}
return pCxt->code;
} }
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt) { static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProjections, bool subquery) {
switch (nodeType(pStmt)) { SNode* pProj = NULL;
case QUERY_NODE_SELECT_STMT: WHERE_EACH(pProj, pProjections) {
return calcConstSelect(pCxt, (SSelectStmt*)pStmt); if (subquery && NULL == ((SExprNode*)pProj)->pAssociation) {
case QUERY_NODE_EXPLAIN_STMT: ERASE_NODE(pProjections);
return calcConstQuery(pCxt, ((SExplainStmt*)pStmt)->pQuery); continue;
default: }
break; SNode* pNew = NULL;
int32_t code = calcConstProject(pProj, &pNew);
if (TSDB_CODE_SUCCESS == code) {
REPLACE_NODE(pNew);
} else {
return code;
}
WHERE_NEXT;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static bool isEmptyResultQuery(SNode* pStmt) { static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) {
int32_t code = calcConstProjections(pCxt, pSelect->pProjectionList, subquery);
if (TSDB_CODE_SUCCESS == code) {
code = calcConstFromTable(pCxt, pSelect);
}
if (TSDB_CODE_SUCCESS == code) {
code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pWhere);
}
if (TSDB_CODE_SUCCESS == code) {
code = calcConstList(pSelect->pPartitionByList);
}
if (TSDB_CODE_SUCCESS == code) {
code = calcConstNode(&pSelect->pWindow);
}
if (TSDB_CODE_SUCCESS == code) {
code = calcConstList(pSelect->pGroupByList);
}
if (TSDB_CODE_SUCCESS == code) {
code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pHaving);
}
if (TSDB_CODE_SUCCESS == code) {
code = calcConstList(pSelect->pOrderByList);
}
return code;
}
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery) {
int32_t code = TSDB_CODE_SUCCESS;
switch (nodeType(pStmt)) { switch (nodeType(pStmt)) {
case QUERY_NODE_SELECT_STMT: case QUERY_NODE_SELECT_STMT:
return ((SSelectStmt*)pStmt)->isEmptyResult; code = calcConstSelect(pCxt, (SSelectStmt*)pStmt, subquery);
break;
case QUERY_NODE_EXPLAIN_STMT: case QUERY_NODE_EXPLAIN_STMT:
return isEmptyResultQuery(((SExplainStmt*)pStmt)->pQuery); code = calcConstQuery(pCxt, ((SExplainStmt*)pStmt)->pQuery, subquery);
break;
case QUERY_NODE_SET_OPERATOR: {
SSetOperator* pSetOp = (SSetOperator*)pStmt;
code = calcConstQuery(pCxt, pSetOp->pLeft, subquery);
if (TSDB_CODE_SUCCESS == code) {
code = calcConstQuery(pCxt, pSetOp->pRight, subquery);
}
break;
}
default: default:
break; break;
} }
return false; return code;
}
static bool isEmptyResultQuery(SNode* pStmt) {
bool isEmptyResult = false;
switch (nodeType(pStmt)) {
case QUERY_NODE_SELECT_STMT:
isEmptyResult = ((SSelectStmt*)pStmt)->isEmptyResult;
break;
case QUERY_NODE_EXPLAIN_STMT:
isEmptyResult = isEmptyResultQuery(((SExplainStmt*)pStmt)->pQuery);
break;
case QUERY_NODE_SET_OPERATOR: {
SSetOperator* pSetOp = (SSetOperator*)pStmt;
isEmptyResult = isEmptyResultQuery(pSetOp->pLeft);
if (isEmptyResult) {
isEmptyResult = isEmptyResultQuery(pSetOp->pRight);
}
break;
}
default:
break;
}
return isEmptyResult;
} }
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) { int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
@ -280,9 +287,9 @@ int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
.msgBuf.len = pParseCxt->msgLen, .msgBuf.len = pParseCxt->msgLen,
.code = TSDB_CODE_SUCCESS .code = TSDB_CODE_SUCCESS
}; };
int32_t code = calcConstQuery(&cxt, pQuery->pRoot); int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code && isEmptyResultQuery(pQuery->pRoot)) {
pQuery->execMode = isEmptyResultQuery(pQuery->pRoot) ? QUERY_EXEC_MODE_EMPTY_RESULT : pQuery->execMode; pQuery->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
} }
return code; return code;
} }

View File

@ -19,6 +19,7 @@
#include "cmdnodes.h" #include "cmdnodes.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "parUtil.h" #include "parUtil.h"
#include "scalar.h"
#include "tglobal.h" #include "tglobal.h"
#include "ttime.h" #include "ttime.h"
@ -305,7 +306,10 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) { static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) {
pCol->pProjectRef = (SNode*)pExpr; pCol->pProjectRef = (SNode*)pExpr;
nodesListAppend(pExpr->pAssociationList, (SNode*)pCol); if (NULL == pExpr->pAssociation) {
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
}
taosArrayPush(pExpr->pAssociation, &pCol);
if (NULL != pTable) { if (NULL != pTable) {
strcpy(pCol->tableAlias, pTable->tableAlias); strcpy(pCol->tableAlias, pTable->tableAlias);
} else if (QUERY_NODE_COLUMN == nodeType(pExpr)) { } else if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
@ -587,13 +591,14 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
} }
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) { static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog, SFmGetFuncInfoParam param = {
.pRpc = pCxt->pParseCxt->pTransporter, .pCtg = pCxt->pParseCxt->pCatalog,
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet}; .pRpc = pCxt->pParseCxt->pTransporter,
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(&param, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) { .pMgmtEps = &pCxt->pParseCxt->mgmtEpSet,
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName); .pErrBuf = pCxt->msgBuf.buf,
} .errBufLen = pCxt->msgBuf.len
pCxt->errCode = fmGetFuncResultType(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len); };
pCxt->errCode = fmGetFuncInfo(&param, pFunc);
if (TSDB_CODE_SUCCESS != pCxt->errCode) { if (TSDB_CODE_SUCCESS != pCxt->errCode) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
@ -759,6 +764,19 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) {
if (NULL == *pVgroupList) {
*pVgroupList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVgroupInfo));
if (NULL == *pVgroupList) {
return TSDB_CODE_OUT_OF_MEMORY;
}
}
SVgroupInfo vg = { .vgId = MNODE_HANDLE };
memcpy(&vg.epSet, pEpSet, sizeof(SEpSet));
taosArrayPush(*pVgroupList, &vg);
return TSDB_CODE_SUCCESS;
}
static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) {
if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) { if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -766,12 +784,20 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SArray* vgroupList = NULL; SArray* vgroupList = NULL;
if ('\0' != pRealTable->useDbName[0]) { if ('\0' != pRealTable->qualDbName[0]) {
code = getDBVgInfo(pCxt, pRealTable->useDbName, &vgroupList); // todo release after mnode can be processed
// if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) {
code = getDBVgInfo(pCxt, pRealTable->qualDbName, &vgroupList);
// }
} else { } else {
code = getDBVgInfoImpl(pCxt, pName, &vgroupList); code = getDBVgInfoImpl(pCxt, pName, &vgroupList);
} }
// todo release after mnode can be processed
// if (TSDB_CODE_SUCCESS == code) {
// code = addMnodeToVgroupList(&pCxt->pParseCxt->mgmtEpSet, &vgroupList);
// }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList); code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList);
} }
@ -1965,13 +1991,6 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs
if (1 != LIST_LENGTH(pFuncs)) { if (1 != LIST_LENGTH(pFuncs)) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROLLUP_OPTION); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROLLUP_OPTION);
} }
SFunctionNode* pFunc = nodesListGetNode(pFuncs, 0);
SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog,
.pRpc = pCxt->pParseCxt->pTransporter,
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet};
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(&param, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName);
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -2001,13 +2020,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt
return code; return code;
} }
static int32_t getAggregationMethod(SNodeList* pFuncs) {
if (NULL == pFuncs) {
return -1;
}
return ((SFunctionNode*)nodesListGetNode(pFuncs, 0))->funcId;
}
static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) { static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) {
int8_t flags = 0; int8_t flags = 0;
if (pCol->sma) { if (pCol->sma) {
@ -2229,7 +2241,6 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) { static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) {
pReq->igExists = pStmt->ignoreExists; pReq->igExists = pStmt->ignoreExists;
pReq->aggregationMethod = getAggregationMethod(pStmt->pOptions->pFuncs);
pReq->xFilesFactor = GET_OPTION_VAL(pStmt->pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR); pReq->xFilesFactor = GET_OPTION_VAL(pStmt->pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR);
pReq->delay = GET_OPTION_VAL(pStmt->pOptions->pDelay, TSDB_DEFAULT_DB_DELAY); pReq->delay = GET_OPTION_VAL(pStmt->pOptions->pDelay, TSDB_DEFAULT_DB_DELAY);
columnDefNodeToField(pStmt->pCols, &pReq->pColumns); columnDefNodeToField(pStmt->pCols, &pReq->pColumns);
@ -3193,7 +3204,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect)
} }
if (NULL != pShow->pDbName) { if (NULL != pShow->pDbName) {
strcpy(((SRealTableNode*)pSelect->pFromTable)->useDbName, ((SValueNode*)pShow->pDbName)->literal); strcpy(((SRealTableNode*)pSelect->pFromTable)->qualDbName, ((SValueNode*)pShow->pDbName)->literal);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -3235,14 +3246,6 @@ static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) {
} }
pReq->ntbCfg.pRSmaParam->delay = GET_OPTION_VAL(pOptions->pDelay, TSDB_DEFAULT_DB_DELAY); pReq->ntbCfg.pRSmaParam->delay = GET_OPTION_VAL(pOptions->pDelay, TSDB_DEFAULT_DB_DELAY);
pReq->ntbCfg.pRSmaParam->xFilesFactor = GET_OPTION_VAL(pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR); pReq->ntbCfg.pRSmaParam->xFilesFactor = GET_OPTION_VAL(pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR);
pReq->ntbCfg.pRSmaParam->nFuncIds = LIST_LENGTH(pOptions->pFuncs);
pReq->ntbCfg.pRSmaParam->pFuncIds = taosMemoryCalloc(pReq->ntbCfg.pRSmaParam->nFuncIds, sizeof(func_id_t));
if (NULL == pReq->ntbCfg.pRSmaParam->pFuncIds) {
return TSDB_CODE_OUT_OF_MEMORY;
}
int32_t index = 0;
SNode* pFunc = NULL;
FOREACH(pFunc, pOptions->pFuncs) { pReq->ntbCfg.pRSmaParam->pFuncIds[index++] = ((SFunctionNode*)pFunc)->funcId; }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -3428,10 +3431,6 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId); return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId);
} }
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode;
}
if (pVal->node.resType.type == TSDB_DATA_TYPE_NULL) { if (pVal->node.resType.type == TSDB_DATA_TYPE_NULL) {
// todo // todo
} else { } else {
@ -3442,6 +3441,23 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t createValueFromFunction(STranslateContext* pCxt, SFunctionNode* pFunc, SValueNode** pVal) {
if (DEAL_RES_ERROR == translateFunction(pCxt, pFunc)) {
return pCxt->errCode;
}
return scalarCalculateConstants((SNode*)pFunc, (SNode**)pVal);
}
static int32_t translateTagVal(STranslateContext* pCxt, SNode* pNode, SValueNode** pVal) {
if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
return createValueFromFunction(pCxt, (SFunctionNode*)pNode, pVal);
} else if (QUERY_NODE_VALUE == nodeType(pNode)) {
return (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode) ? pCxt->errCode : TSDB_CODE_SUCCESS);
} else {
return TSDB_CODE_FAILED;
}
}
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta, static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
SKVRowBuilder* pBuilder) { SKVRowBuilder* pBuilder) {
int32_t numOfTags = getNumOfTags(pSuperTableMeta); int32_t numOfTags = getNumOfTags(pSuperTableMeta);
@ -3451,8 +3467,8 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
} }
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
SNode * pTag, *pVal; SNode * pTag, *pNode;
FORBOTH(pTag, pStmt->pSpecificTags, pVal, pStmt->pValsOfTags) { FORBOTH(pTag, pStmt->pSpecificTags, pNode, 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) {
@ -3464,7 +3480,18 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
if (NULL == pSchema) { if (NULL == pSchema) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName);
} }
int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pSchema, pBuilder); SValueNode* pVal = NULL;
int32_t code = translateTagVal(pCxt, pNode, &pVal);
if (TSDB_CODE_SUCCESS == code) {
if (NULL == pVal) {
pVal = (SValueNode*)pNode;
} else {
REPLACE_LIST2_NODE(pVal);
}
}
if (TSDB_CODE_SUCCESS == code) {
code = addValToKVRow(pCxt, pVal, pSchema, pBuilder);
}
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
} }
@ -3480,10 +3507,21 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
} }
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
SNode* pVal; SNode* pNode;
int32_t index = 0; int32_t index = 0;
FOREACH(pVal, pStmt->pValsOfTags) { FOREACH(pNode, pStmt->pValsOfTags) {
int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pTagSchema + index++, pBuilder); SValueNode* pVal = NULL;
int32_t code = translateTagVal(pCxt, pNode, &pVal);
if (TSDB_CODE_SUCCESS == code) {
if (NULL == pVal) {
pVal = (SValueNode*)pNode;
} else {
REPLACE_NODE(pVal);
}
}
if (TSDB_CODE_SUCCESS == code) {
code = addValToKVRow(pCxt, pVal, pTagSchema + index++, pBuilder);
}
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
} }

View File

@ -30,8 +30,6 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return "Column ambiguously defined: %s"; return "Column ambiguously defined: %s";
case TSDB_CODE_PAR_WRONG_VALUE_TYPE: case TSDB_CODE_PAR_WRONG_VALUE_TYPE:
return "Invalid value type: %s"; return "Invalid value type: %s";
case TSDB_CODE_PAR_INVALID_FUNTION:
return "Invalid function name: %s";
case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION: case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION:
return "There mustn't be aggregation"; return "There mustn't be aggregation";
case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT: case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT:

File diff suppressed because it is too large Load Diff

View File

@ -353,7 +353,7 @@ TEST_F(ParserTest, selectSemanticError) {
// TSDB_CODE_PAR_INVALID_FUNTION // TSDB_CODE_PAR_INVALID_FUNTION
bind("SELECT cnt(*) FROM t1"); bind("SELECT cnt(*) FROM t1");
ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_FUNTION)); ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_FUNC_INVALID_FUNTION));
// TSDB_CODE_PAR_FUNTION_PARA_NUM // TSDB_CODE_PAR_FUNTION_PARA_NUM
// TSDB_CODE_PAR_FUNTION_PARA_TYPE // TSDB_CODE_PAR_FUNTION_PARA_TYPE

View File

@ -486,7 +486,7 @@ _return:
EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
SFunctionNode *node = (SFunctionNode *)*pNode; SFunctionNode *node = (SFunctionNode *)*pNode;
SNode* tnode = NULL; SNode* tnode = NULL;
if (fmIsUserDefinedFunc(node->funcId)) { if (!fmIsScalarFunc(node->funcId)) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -511,6 +511,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
res->translate = true;
if (colDataIsNull_s(output.columnData, 0)) { if (colDataIsNull_s(output.columnData, 0)) {
res->node.resType.type = TSDB_DATA_TYPE_NULL; res->node.resType.type = TSDB_DATA_TYPE_NULL;
} else { } else {
@ -553,6 +555,7 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
} }
res->node.resType = node->node.resType; res->node.resType = node->node.resType;
res->translate = true;
int32_t type = output.columnData->info.type; int32_t type = output.columnData->info.type;
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
@ -595,6 +598,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
} }
res->node.resType = node->node.resType; res->node.resType = node->node.resType;
res->translate = true;
int32_t type = output.columnData->info.type; int32_t type = output.columnData->info.type;
if (IS_VAR_DATA_TYPE(type)) { // todo refactor if (IS_VAR_DATA_TYPE(type)) { // todo refactor
@ -612,10 +616,6 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
} }
EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode)) {
return DEAL_RES_CONTINUE;
}
SScalarCtx *ctx = (SScalarCtx *)pContext; SScalarCtx *ctx = (SScalarCtx *)pContext;
if (QUERY_NODE_FUNCTION == nodeType(*pNode)) { if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
@ -629,10 +629,8 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { if (QUERY_NODE_OPERATOR == nodeType(*pNode)) {
return sclRewriteOperator(pNode, ctx); return sclRewriteOperator(pNode, ctx);
} }
sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode)); return DEAL_RES_CONTINUE;
ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR;
} }
EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) {

View File

@ -0,0 +1,310 @@
from util.dnodes import *
from util.log import *
from util.sql import *
from util.cases import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
def run(self): # sourcery skip: extract-duplicate-method
# for func now() , today(), timezone()
tdSql.prepare()
today_date = datetime.datetime.strptime(
datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d")
tdLog.printNoPrefix("==========step1:create tables==========")
tdSql.execute(
'''create table if not exists ntb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)
'''
)
tdSql.execute(
'''create table if not exists stb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)
'''
)
tdSql.execute(
'''create table if not exists stb_1 using stb tags(100)
'''
)
tdLog.printNoPrefix("==========step2:insert data into ntb==========")
tdSql.execute(
'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.execute(
'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdLog.printNoPrefix("==========step2:query test of ntb ==========")
# test function now()
# ntable
tdSql.query("select now() from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1w from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1w from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1d from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1d from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1h from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1h from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1m from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1m from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1s from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1s from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1a from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1a from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1u from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1u from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1b from ntb")
tdSql.checkRows(3)
tdSql.query("select now() +1b from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1w from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1w from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1d from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1d from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1h from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1h from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1m from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1m from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1s from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1s from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1a from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1a from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1u from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1u from db.ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1b from ntb")
tdSql.checkRows(3)
tdSql.query("select now() -1b from db.ntb")
tdSql.checkRows(3)
tdSql.query("select * from ntb where ts<now()")
tdSql.checkRows(3)
tdSql.checkData(1, 1, 3)
tdSql.query("select * from ntb where ts<=now()")
tdSql.checkRows(3)
tdSql.checkData(2, 1, 1)
tdSql.query("select c1 from ntb where ts=now()")
tdSql.checkRows(0)
tdSql.query("select * from ntb where ts>=now()")
tdSql.checkRows(0)
tdSql.query("select * from ntb where ts>now()")
tdSql.checkRows(0)
tdSql.query("select now() from ntb where ts=today()")
tdSql.checkRows(1)
# stable
tdSql.query("select now() from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1w from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1w from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() +1d from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1d from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() +1h from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1h from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() +1m from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1m from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() +1s from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1s from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() +1a from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1a from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() +1u from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1u from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() +1b from stb")
tdSql.checkRows(3)
tdSql.query("select now() +1b from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1w from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1w from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1d from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1d from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1h from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1h from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1m from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1m from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1s from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1s from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1a from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1a from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1u from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1u from db.stb")
tdSql.checkRows(3)
tdSql.query("select now() -1b from stb")
tdSql.checkRows(3)
tdSql.query("select now() -1b from db.stb")
tdSql.checkRows(3)
# tdSql.query("select * from stb where ts<now()")
# tdSql.checkRows(3)
# tdSql.checkData(1,1,3)
# tdSql.query("select * from stb where ts<=now()")
# tdSql.checkRows(3)
# tdSql.checkData(2,1,1)
tdSql.query("select c1 from stb where ts=now()")
tdSql.checkRows(0)
# tdSql.query("select * from stb where ts>=now()")
# tdSql.checkRows(0)
# tdSql.query("select * from stb where ts>now()")
# tdSql.checkRows(0)
tdSql.query("select now() from stb where ts=today()")
tdSql.checkRows(1)
# table
tdSql.query("select now() from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1w from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1w from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1d from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1d from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1h from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1h from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1m from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1m from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1s from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1s from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1a from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1a from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1u from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1u from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1b from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() +1b from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1w from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1w from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1d from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1d from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1h from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1h from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1m from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1m from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1s from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1s from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1a from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1a from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1u from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1u from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1b from stb_1")
tdSql.checkRows(3)
tdSql.query("select now() -1b from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select * from stb_1 where ts<now()")
tdSql.checkRows(3)
tdSql.checkData(1, 1, 3)
tdSql.query("select * from stb_1 where ts<=now()")
tdSql.checkRows(3)
tdSql.checkData(2, 1, 1)
tdSql.query("select c1 from stb_1 where ts=now()")
tdSql.checkRows(0)
tdSql.query("select * from stb_1 where ts>=now()")
tdSql.checkRows(0)
tdSql.query("select * from stb_1 where ts>now()")
tdSql.checkRows(0)
# tdSql.query("select * from stb_1 where ts<now")
# tdSql.checkRows(3)
# tdSql.checkData(1, 1, 3)
# tdSql.query("select * from stb_1 where ts<=now")
# tdSql.checkRows(3)
# tdSql.checkData(2, 1, 1)
# tdSql.query("select c1 from stb_1 where ts=now")
# tdSql.checkRows(0)
# tdSql.query("select * from stb_1 where ts>=now")
# tdSql.checkRows(0)
# tdSql.query("select * from stb_1 where ts>now")
# tdSql.checkRows(0)
tdSql.query("select now() from stb_1 where ts=today()")
tdSql.checkRows(1)
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -0,0 +1,78 @@
from time import sleep
from util.log import *
from util.sql import *
from util.cases import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
def run(self): # sourcery skip: extract-duplicate-method
tdSql.prepare()
# get system timezone
today_date = datetime.datetime.strptime(
datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d")
tdLog.printNoPrefix("==========step1:create tables==========")
tdSql.execute(
'''create table if not exists ntb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)
'''
)
tdSql.execute(
'''create table if not exists stb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)
'''
)
tdSql.execute(
'''create table if not exists stb_1 using stb tags(100)
'''
)
tdLog.printNoPrefix("==========step2:insert data==========")
tdSql.execute('insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.execute('insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.query("select to_iso8601(ts) from ntb")
tdSql.checkRows(3)
tdSql.query("select c1 from ntb where ts = to_iso8601(1577808000000)")
tdSql.checkRows(1)
tdSql.checkData(0,0,10)
tdSql.query("select * from ntb where ts = to_iso8601(1577808000000)")
tdSql.checkRows(1)
tdSql.query("select to_iso8601(ts) from ntb where ts=today()")
tdSql.checkRows(1)
# tdSql.checkData(0,0,10)
for i in range(1,10):
tdSql.query("select to_iso8601(1) from ntb")
tdSql.checkData(0,0,"1970-01-01T08:00:01+0800")
i+=1
sleep(0.2)
tdSql.checkRows(3)
tdSql.query("select to_iso8601(ts) from ntb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(ts) from db.ntb")
tdSql.query("select to_iso8601(today()) from ntb")
tdSql.checkRows(3)
tdSql.query("select to_iso8601(now()) from ntb")
tdSql.checkRows(3)
tdSql.error("select to_iso8601(timezone()) from ntb")
tdSql.error("select to_iso8601('abc') from ntb")
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -0,0 +1,318 @@
from util.dnodes import *
from util.log import *
from util.sql import *
from util.cases import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
def run(self): # sourcery skip: extract-duplicate-method
# for func now() , today(), timezone()
tdSql.prepare()
today_date = datetime.datetime.strptime(
datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d")
tdLog.printNoPrefix("==========step1:create tables==========")
tdSql.execute(
'''create table if not exists ntb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)
'''
)
tdSql.execute(
'''create table if not exists stb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)
'''
)
tdSql.execute(
'''create table if not exists stb_1 using stb tags(100)
'''
)
tdLog.printNoPrefix("==========step2:insert data into ntb==========")
tdSql.execute(
'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdSql.execute(
'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
tdLog.printNoPrefix("==========step2:query test of ntb ==========")
# test function today()
# normal table
tdSql.query("select today() from ntb")
tdSql.checkRows(3)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select today() from db.ntb")
tdSql.checkRows(3)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select today() +1w from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1w from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1d from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1d from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1h from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1h from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1m from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1m from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1s from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1s from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1a from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1a from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1u from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1u from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1b from ntb")
tdSql.checkRows(3)
tdSql.query("select today() +1b from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1w from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1w from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1d from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1d from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1h from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1h from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1m from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1m from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1s from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1s from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1a from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1a from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1u from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1u from db.ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1b from ntb")
tdSql.checkRows(3)
tdSql.query("select today() -1b from db.ntb")
tdSql.checkRows(3)
tdSql.query("select * from ntb where ts=today()")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 3)
tdSql.query("select * from ntb where ts<=today()")
tdSql.checkRows(2)
tdSql.checkData(0, 1, 10)
# for bug
# tdSql.query("select * from ntb where ts<today()")
# tdSql.checkRows(1)
tdSql.query("select * from ntb where ts>=today()")
tdSql.checkRows(2)
tdSql.checkData(0, 1, 3)
# tdSql.query("select * from ntb where ts>today()")
# tdSql.checkRows(1)
tdSql.query("select c4 from ntb where c4=today()")
tdSql.checkRows(1)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select today() from ntb where ts<now()")
tdSql.checkRows(3)
tdSql.checkData(0, 0, str(today_date))
# stable
tdSql.query("select today() from stb")
tdSql.checkRows(3)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select today() +1w from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1w from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() +1d from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1d from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() +1h from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1h from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() +1m from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1m from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() +1s from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1s from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() +1a from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1a from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() +1u from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1u from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() +1b from stb")
tdSql.checkRows(3)
tdSql.query("select today() +1b from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1w from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1w from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1d from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1d from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1h from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1h from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1m from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1m from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1s from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1s from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1a from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1a from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1u from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1u from db.stb")
tdSql.checkRows(3)
tdSql.query("select today() -1b from stb")
tdSql.checkRows(3)
tdSql.query("select today() -1b from db.stb")
tdSql.checkRows(3)
tdSql.query("select ts from stb where ts=today()")
tdSql.checkRows(1)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select ts from stb where ts<=today()")
tdSql.checkRows(2)
#
# tdSql.query("select * from ntb where ts<today()")
# tdSql.checkRows(1)
# tdSql.query("select * from stb where ts>=today()")
# tdSql.checkRows(2)
# tdSql.query("select * from ntb where ts>today()")
# tdSql.checkRows(1)
tdSql.query("select c4 from stb where c4=today()")
tdSql.checkRows(1)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select today() from stb where ts<now()")
tdSql.checkRows(3)
# table
tdSql.query("select today() from stb_1")
tdSql.checkRows(3)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select today() from db.stb_1")
tdSql.checkRows(3)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select today() +1w from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1w from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1d from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1d from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1h from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1h from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1m from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1m from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1s from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1s from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1a from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1a from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1u from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1u from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1b from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() +1b from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1w from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1w from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1d from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1d from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1h from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1h from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1m from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1m from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1s from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1s from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1a from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1a from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1u from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1u from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1b from stb_1")
tdSql.checkRows(3)
tdSql.query("select today() -1b from db.stb_1")
tdSql.checkRows(3)
tdSql.query("select ts from stb_1 where ts=today()")
tdSql.checkRows(1)
tdSql.checkData(0, 0, str(today_date))
tdSql.query("select ts from stb_1 where ts<=today()")
tdSql.checkRows(2)
# for bug
tdSql.query("select * from ntb where ts<today()")
tdSql.checkRows(1)
tdSql.checkData(0,0,"2020-1-1 00:00:00")
tdSql.query("select * from stb_1 where ts>=today()")
tdSql.checkRows(2)
tdSql.query("select * from ntb where ts>today()")
tdSql.checkRows(1)
tdSql.query("select c4 from stb_1 where c4=today()")
tdSql.checkRows(1)
tdSql.query("select today() from stb_1 where ts<now()")
tdSql.checkRows(3)
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -0,0 +1,83 @@
from util.log import *
from util.sql import *
from util.cases import *
import os
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
def run(self): # sourcery skip: extract-duplicate-method
tdSql.prepare()
# get system timezone
time_zone = os.popen('timedatectl | grep zone').read(
).strip().split(':')[1].lstrip()
tdLog.printNoPrefix("==========step1:create tables==========")
tdSql.execute(
'''create table if not exists ntb
(ts timestamp, c1 int, c2 float,c3 double)
'''
)
tdSql.execute(
'''create table if not exists stb
(ts timestamp, c1 int, c2 float,c3 double) tags(t0 int)
'''
)
tdSql.execute(
'''create table if not exists stb_1 using stb tags(100)
'''
)
tdLog.printNoPrefix("==========step2:insert data==========")
tdSql.execute(
"insert into ntb values(now,10,99.99,11.111111)(today(),100,11.111,22.222222)")
tdSql.execute(
"insert into stb_1 values(now,111,99.99,11.111111)(today(),1,11.111,22.222222)")
tdLog.printNoPrefix("==========step3:query data==========")
tdSql.query("select timezone() from ntb")
tdSql.checkRows(2)
tdSql.checkData(0, 0, time_zone)
tdSql.query("select timezone() from db.ntb")
tdSql.checkRows(2)
tdSql.checkData(0, 0, time_zone)
tdSql.query("select timezone() from stb")
tdSql.checkRows(2)
tdSql.checkData(0, 0, time_zone)
tdSql.query("select timezone() from db.stb")
tdSql.checkRows(2)
tdSql.checkData(0, 0, time_zone)
tdSql.query("select timezone() from stb_1")
tdSql.checkRows(2)
tdSql.checkData(0, 0, time_zone)
tdSql.query("select timezone() from db.stb_1 ")
tdSql.checkRows(2)
tdSql.checkData(0, 0, time_zone)
tdSql.error("select timezone(1) from ntb")
tdSql.error("select timezone(now()) from stb")
tdSql.query(f"select * from ntb where timezone()='{time_zone}'")
tdSql.checkRows(2)
tdSql.query("select timezone()+1 from ntb")
tdSql.checkRows(2)
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -4,4 +4,10 @@ set -e
#python3 ./test.py -f 2-query/between.py #python3 ./test.py -f 2-query/between.py
#python3 ./test.py -f 2-query/distinct.py #python3 ./test.py -f 2-query/distinct.py
python3 ./test.py -f 2-query/varchar.py python3 ./test.py -f 2-query/varchar.py
python3 ./test.py -f 2-query/timezone.py
python3 ./test.py -f 2-query/Now.py
python3 ./test.py -f 2-query/Today.py
#python3 ./test.py -f 2-query/cast.py #python3 ./test.py -f 2-query/cast.py