Merge branch '3.0' into feature/TD-14481-3.0
This commit is contained in:
commit
0ff1ae9fc8
|
@ -292,7 +292,6 @@ typedef struct {
|
|||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t igExists;
|
||||
float xFilesFactor;
|
||||
int32_t aggregationMethod;
|
||||
int32_t delay;
|
||||
int32_t ttl;
|
||||
int32_t numOfColumns;
|
||||
|
@ -1512,10 +1511,8 @@ typedef struct {
|
|||
int32_t delay;
|
||||
int32_t qmsg1Len;
|
||||
int32_t qmsg2Len;
|
||||
func_id_t* pFuncIds;
|
||||
char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1
|
||||
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||
int8_t nFuncIds;
|
||||
} SRSmaParam;
|
||||
|
||||
typedef struct SVCreateTbReq {
|
||||
|
|
|
@ -125,15 +125,15 @@ typedef struct SFmGetFuncInfoParam {
|
|||
struct SCatalog* pCtg;
|
||||
void *pRpc;
|
||||
const SEpSet* pMgmtEps;
|
||||
char* pErrBuf;
|
||||
int32_t errBufLen;
|
||||
} SFmGetFuncInfoParam;
|
||||
|
||||
int32_t fmFuncMgtInit();
|
||||
|
||||
void fmFuncMgtDestroy();
|
||||
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType);
|
||||
|
||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc);
|
||||
|
||||
bool fmIsAggFunc(int32_t funcId);
|
||||
bool fmIsScalarFunc(int32_t funcId);
|
||||
|
|
|
@ -46,7 +46,7 @@ typedef struct SExprNode {
|
|||
ENodeType type;
|
||||
SDataType resType;
|
||||
char aliasName[TSDB_COL_NAME_LEN];
|
||||
SNodeList* pAssociationList;
|
||||
SArray* pAssociation;
|
||||
} SExprNode;
|
||||
|
||||
typedef enum EColumnType {
|
||||
|
@ -81,7 +81,6 @@ typedef struct SValueNode {
|
|||
char* literal;
|
||||
bool isDuration;
|
||||
bool translate;
|
||||
bool genByCalc;
|
||||
int16_t placeholderNo;
|
||||
union {
|
||||
bool b;
|
||||
|
@ -119,6 +118,7 @@ typedef struct SFunctionNode {
|
|||
int32_t funcId;
|
||||
int32_t funcType;
|
||||
SNodeList* pParameterList;
|
||||
int32_t udfBufSize;
|
||||
} SFunctionNode;
|
||||
|
||||
typedef struct STableNode {
|
||||
|
@ -135,7 +135,7 @@ typedef struct SRealTableNode {
|
|||
STableNode table; // QUERY_NODE_REAL_TABLE
|
||||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
char useDbName[TSDB_DB_NAME_LEN];
|
||||
char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
|
||||
double ratio;
|
||||
} SRealTableNode;
|
||||
|
||||
|
|
|
@ -573,7 +573,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602)
|
||||
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
|
||||
#define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||
#define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605)
|
||||
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608)
|
||||
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609)
|
||||
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
|
||||
|
@ -633,6 +632,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
|
||||
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
|
||||
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803)
|
||||
#define TSDB_CODE_FUNC_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ const char *taos_errstr(TAOS_RES *res) {
|
|||
return (const char *)tstrerror(terrno);
|
||||
}
|
||||
|
||||
if (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) {
|
||||
if (NULL != pRequest->msgBuf && (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR)) {
|
||||
return pRequest->msgBuf;
|
||||
} else {
|
||||
return (const char *)tstrerror(pRequest->code);
|
||||
|
|
|
@ -522,10 +522,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
|
||||
}
|
||||
tlen += taosEncodeFixedI32(buf, param->qmsg1Len);
|
||||
if (param->qmsg1Len > 0) {
|
||||
tlen += taosEncodeString(buf, param->qmsg1);
|
||||
|
@ -555,10 +551,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -601,13 +593,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||
buf = taosDecodeFixedI8(buf, ¶m->nFuncIds);
|
||||
if (param->nFuncIds > 0) {
|
||||
param->pFuncIds = (func_id_t *)taosMemoryCalloc(param->nFuncIds, sizeof(func_id_t));
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
|
||||
}
|
||||
}
|
||||
buf = taosDecodeFixedI32(buf, ¶m->qmsg1Len);
|
||||
if (param->qmsg1Len > 0) {
|
||||
buf = taosDecodeString(buf, ¶m->qmsg1);
|
||||
|
@ -641,15 +626,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||
buf = taosDecodeFixedI8(buf, ¶m->nFuncIds);
|
||||
if (param->nFuncIds > 0) {
|
||||
param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t));
|
||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
||||
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
|
||||
}
|
||||
} else {
|
||||
param->pFuncIds = NULL;
|
||||
}
|
||||
} else {
|
||||
pReq->ntbCfg.pRSmaParam = NULL;
|
||||
}
|
||||
|
@ -712,7 +688,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
|||
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
||||
if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->aggregationMethod) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->delay) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1;
|
||||
|
@ -767,7 +742,6 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
||||
if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->aggregationMethod) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1;
|
||||
|
|
|
@ -350,7 +350,6 @@ typedef struct {
|
|||
int32_t version;
|
||||
int32_t nextColId;
|
||||
float xFilesFactor;
|
||||
int32_t aggregationMethod;
|
||||
int32_t delay;
|
||||
int32_t ttl;
|
||||
int32_t numOfColumns;
|
||||
|
|
|
@ -87,7 +87,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pStb->version, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->aggregationMethod, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER)
|
||||
|
@ -175,7 +174,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
int32_t xFilesFactor = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER)
|
||||
pStb->xFilesFactor = xFilesFactor / 10000.0f;
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->aggregationMethod, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER)
|
||||
|
@ -404,7 +402,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
req.name = (char *)tNameGetTableName(&name);
|
||||
req.ttl = 0;
|
||||
req.keep = 0;
|
||||
req.rollup = pStb->aggregationMethod > -1 ? 1 : 0;
|
||||
req.rollup = pStb->pAst1 > 0 ? 1 : 0;
|
||||
req.type = TD_SUPER_TABLE;
|
||||
req.stbCfg.suid = pStb->uid;
|
||||
req.stbCfg.nCols = pStb->numOfColumns;
|
||||
|
@ -433,20 +431,8 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
|
||||
pRSmaParam->xFilesFactor = pStb->xFilesFactor;
|
||||
pRSmaParam->delay = pStb->delay;
|
||||
pRSmaParam->nFuncIds = 1; // only 1 aggregation method supported currently
|
||||
pRSmaParam->pFuncIds = (func_id_t *)taosMemoryCalloc(pRSmaParam->nFuncIds, sizeof(func_id_t));
|
||||
if (pRSmaParam->pFuncIds == NULL) {
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
for (int32_t f = 0; f < pRSmaParam->nFuncIds; ++f) {
|
||||
*(pRSmaParam->pFuncIds + f) = pStb->aggregationMethod;
|
||||
}
|
||||
if (pStb->ast1Len > 0) {
|
||||
if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
return NULL;
|
||||
|
@ -454,7 +440,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
}
|
||||
if (pStb->ast2Len > 0) {
|
||||
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
|
@ -469,7 +454,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
||||
if (pHead == NULL) {
|
||||
if (pRSmaParam) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||
taosMemoryFreeClear(pRSmaParam);
|
||||
|
@ -487,7 +471,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
|
||||
*pContLen = contLen;
|
||||
if (pRSmaParam) {
|
||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||
taosMemoryFreeClear(pRSmaParam);
|
||||
|
@ -705,7 +688,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
|
|||
stbObj.version = 1;
|
||||
stbObj.nextColId = 1;
|
||||
stbObj.xFilesFactor = pCreate->xFilesFactor;
|
||||
stbObj.aggregationMethod = pCreate->aggregationMethod;
|
||||
stbObj.delay = pCreate->delay;
|
||||
stbObj.ttl = pCreate->ttl;
|
||||
stbObj.numOfColumns = pCreate->numOfColumns;
|
||||
|
|
|
@ -287,7 +287,6 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
|
|||
taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
|
||||
if (vCreateTbReq.stbCfg.pRSmaParam) {
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg1);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg2);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam);
|
||||
|
@ -334,7 +333,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
taosMemoryFree(pCreateTbReq->stbCfg.pSchema);
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema);
|
||||
if (pCreateTbReq->stbCfg.pRSmaParam) {
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam);
|
||||
}
|
||||
} else if (pCreateTbReq->type == TD_CHILD_TABLE) {
|
||||
|
@ -342,7 +340,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
} else {
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pSchema);
|
||||
if (pCreateTbReq->ntbCfg.pRSmaParam) {
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam);
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +370,6 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) {
|
|||
taosMemoryFree(vAlterTbReq.stbCfg.pSchema);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema);
|
||||
if (vAlterTbReq.stbCfg.pRSmaParam) {
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam);
|
||||
}
|
||||
taosMemoryFree(vAlterTbReq.name);
|
||||
|
|
|
@ -41,7 +41,9 @@ extern "C" {
|
|||
|
||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
#define FUNC_UDF_ID_START_OFFSET_VAL 5000
|
||||
#define FUNC_UDF_ID_START 5000
|
||||
#define FUNC_AGGREGATE_UDF_ID 5001
|
||||
#define FUNC_SCALAR_UDF_ID 5002
|
||||
|
||||
extern const int funcMgtUdfNum;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
typedef struct SFuncMgtService {
|
||||
SHashObj* pFuncNameHashTable;
|
||||
SArray* pUdfTable; // SUdfInfo
|
||||
} SFuncMgtService;
|
||||
|
||||
typedef struct SUdfInfo {
|
||||
|
@ -49,18 +48,12 @@ static void doInitFunctionTable() {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gFunMgtService.pUdfTable = NULL;
|
||||
}
|
||||
|
||||
static int8_t getUdfType(int32_t funcId) {
|
||||
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
|
||||
return pUdf->funcType;
|
||||
}
|
||||
|
||||
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
||||
if (fmIsUserDefinedFunc(funcId)) {
|
||||
return getUdfType(funcId);
|
||||
return FUNC_MGT_AGG_FUNC == classification ? FUNC_AGGREGATE_UDF_ID == funcId :
|
||||
(FUNC_MGT_SCALAR_FUNC == classification ? FUNC_SCALAR_UDF_ID == funcId : false);
|
||||
}
|
||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return false;
|
||||
|
@ -68,33 +61,23 @@ static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
|||
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
|
||||
}
|
||||
|
||||
static int32_t getUdfId(SFmGetFuncInfoParam* pParam, const char* pFuncName) {
|
||||
static int32_t getUdfInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
|
||||
SFuncInfo* pInfo = NULL;
|
||||
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFuncName, &pInfo);
|
||||
if (TSDB_CODE_SUCCESS != code || NULL == pInfo) {
|
||||
return -1;
|
||||
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFunc->functionName, &pInfo);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (NULL == gFunMgtService.pUdfTable) {
|
||||
gFunMgtService.pUdfTable = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SUdfInfo));
|
||||
if (NULL == pInfo) {
|
||||
snprintf(pParam->pErrBuf, pParam->errBufLen, "Invalid function name: %s", pFunc->functionName);
|
||||
return TSDB_CODE_FUNC_INVALID_FUNTION;
|
||||
}
|
||||
SUdfInfo info = { .outputDt.type = pInfo->outputType, .outputDt.bytes = pInfo->outputLen, .funcType = pInfo->funcType };
|
||||
taosArrayPush(gFunMgtService.pUdfTable, &info);
|
||||
pFunc->funcType = FUNCTION_TYPE_UDF;
|
||||
pFunc->funcId = TSDB_FUNC_TYPE_AGGREGATE == pInfo->funcType ? FUNC_AGGREGATE_UDF_ID : FUNC_SCALAR_UDF_ID;
|
||||
pFunc->node.resType.type = pInfo->outputType;
|
||||
pFunc->node.resType.bytes = pInfo->outputLen;
|
||||
pFunc->udfBufSize = pInfo->bufSize;
|
||||
tFreeSFuncInfo(pInfo);
|
||||
taosMemoryFree(pInfo);
|
||||
return taosArrayGetSize(gFunMgtService.pUdfTable) + FUNC_UDF_ID_START_OFFSET_VAL;
|
||||
}
|
||||
|
||||
static int32_t getFuncId(SFmGetFuncInfoParam* pParam, const char* pFuncName) {
|
||||
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFuncName, strlen(pFuncName));
|
||||
if (NULL == pVal) {
|
||||
return getUdfId(pParam, pFuncName);
|
||||
}
|
||||
return *(int32_t*)pVal;
|
||||
}
|
||||
|
||||
static int32_t getUdfResultType(SFunctionNode* pFunc) {
|
||||
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, pFunc->funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
|
||||
pFunc->node.resType = pUdf->outputDt;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -103,28 +86,14 @@ int32_t fmFuncMgtInit() {
|
|||
return initFunctionCode;
|
||||
}
|
||||
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) {
|
||||
*pFuncId = getFuncId(pParam, pFuncName);
|
||||
if (*pFuncId < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
|
||||
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
|
||||
if (NULL != pVal) {
|
||||
pFunc->funcId = *(int32_t*)pVal;
|
||||
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pParam->pErrBuf, pParam->errBufLen);
|
||||
}
|
||||
if (fmIsUserDefinedFunc(*pFuncId)) {
|
||||
*pFuncType = FUNCTION_TYPE_UDF;
|
||||
} else {
|
||||
*pFuncType = funcMgtBuiltins[*pFuncId].type;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (fmIsUserDefinedFunc(pFunc->funcId)) {
|
||||
return getUdfResultType(pFunc);
|
||||
}
|
||||
|
||||
if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pErrBuf, len);
|
||||
return getUdfInfo(pParam, pFunc);
|
||||
}
|
||||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||
|
@ -194,7 +163,7 @@ bool fmIsMultiResFunc(int32_t funcId) {
|
|||
}
|
||||
|
||||
bool fmIsUserDefinedFunc(int32_t funcId) {
|
||||
return funcId > FUNC_UDF_ID_START_OFFSET_VAL;
|
||||
return funcId > FUNC_UDF_ID_START;
|
||||
}
|
||||
|
||||
void fmFuncMgtDestroy() {
|
||||
|
|
|
@ -1663,7 +1663,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkValueGenByCalc = "GenByCalc";
|
||||
static const char* jkValueLiteralSize = "LiteralSize";
|
||||
static const char* jkValueLiteral = "Literal";
|
||||
static const char* jkValueDuration = "Duration";
|
||||
static const char* jkValueTranslate = "Translate";
|
||||
|
@ -1717,9 +1717,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
|
|||
|
||||
int32_t code = exprNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkValueGenByCalc, pNode->genByCalc);
|
||||
code = tjsonAddIntegerToObject(pJson, jkValueLiteralSize, NULL != pNode->literal ? strlen(pNode->literal) : 0);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) {
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pNode->literal) {
|
||||
code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->literal);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -1789,10 +1789,11 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
|
|||
SValueNode* pNode = (SValueNode*)pObj;
|
||||
|
||||
int32_t code = jsonToExprNode(pJson, pObj);
|
||||
int32_t literalSize = 0;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkValueGenByCalc, &pNode->genByCalc);
|
||||
code = tjsonGetIntValue(pJson, jkValueLiteralSize, &literalSize);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) {
|
||||
if (TSDB_CODE_SUCCESS == code && literalSize > 0) {
|
||||
code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->literal);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
|
|
@ -95,7 +95,6 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
|
|||
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
|
||||
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
|
||||
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList);
|
||||
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName);
|
||||
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt);
|
||||
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList);
|
||||
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2);
|
||||
|
|
|
@ -498,6 +498,7 @@ signed_literal(A) ::= NK_BOOL(B).
|
|||
signed_literal(A) ::= TIMESTAMP NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); }
|
||||
signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); }
|
||||
signed_literal(A) ::= NULL. { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); }
|
||||
signed_literal(A) ::= literal_func(B). { A = releaseRawExprNode(pCxt, B); }
|
||||
|
||||
%type literal_list { SNodeList* }
|
||||
%destructor literal_list { nodesDestroyList($$); }
|
||||
|
@ -610,8 +611,10 @@ pseudo_column(A) ::= WDURATION(B).
|
|||
function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
function_expression(A) ::= star_func(B) NK_LP star_func_para_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
function_expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); }
|
||||
function_expression(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNodeNoArg(pCxt, &B)); }
|
||||
//function_expression(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
function_expression(A) ::= literal_func(B). { A = B; }
|
||||
|
||||
literal_func(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNode(pCxt, &B, NULL)); }
|
||||
literal_func(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
|
||||
%type noarg_func { SToken }
|
||||
%destructor noarg_func { }
|
||||
|
|
|
@ -368,39 +368,6 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod
|
|||
return (SNode*)func;
|
||||
}
|
||||
|
||||
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName) {
|
||||
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_OUT_OF_MEM(func);
|
||||
char buf[64] = {0};
|
||||
|
||||
int32_t dataType;
|
||||
switch (pFuncName->type) {
|
||||
case TK_NOW: {
|
||||
int64_t ts = taosGetTimestamp(TSDB_TIME_PRECISION_MILLI);
|
||||
snprintf(buf, sizeof(buf), "%"PRId64, ts);
|
||||
dataType = TSDB_DATA_TYPE_BIGINT;
|
||||
break;
|
||||
}
|
||||
case TK_TODAY: {
|
||||
int64_t ts = taosGetTimestampToday(TSDB_TIME_PRECISION_MILLI);
|
||||
snprintf(buf, sizeof(buf), "%"PRId64, ts);
|
||||
dataType = TSDB_DATA_TYPE_BIGINT;
|
||||
break;
|
||||
}
|
||||
case TK_TIMEZONE: {
|
||||
strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr));
|
||||
dataType = TSDB_DATA_TYPE_BINARY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SToken token = {.type = pFuncName->type, .n = strlen(buf), .z = buf};
|
||||
|
||||
SNodeList *pParameterList = createNodeList(pCxt, createValueNode(pCxt, dataType, &token));
|
||||
strncpy(func->functionName, pFuncName->z, pFuncName->n);
|
||||
func->pParameterList = pParameterList;
|
||||
return (SNode*)func;
|
||||
}
|
||||
|
||||
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) {
|
||||
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_OUT_OF_MEM(func);
|
||||
|
@ -443,10 +410,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa
|
|||
} else {
|
||||
strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n);
|
||||
}
|
||||
strncpy(realTable->table.tableName, pTableName->z, pTableName->n);
|
||||
if (NULL != pCxt->pQueryCxt->db) {
|
||||
strcpy(realTable->useDbName, pCxt->pQueryCxt->db);
|
||||
}
|
||||
strncpy(realTable->table.tableName, pTableName->z, pTableName->n);
|
||||
return (SNode*)realTable;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,109 +24,37 @@ typedef struct SCalcConstContext {
|
|||
int32_t code;
|
||||
} SCalcConstContext;
|
||||
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt);
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery);
|
||||
|
||||
static int32_t calcConstSubquery(SCalcConstContext* pCxt, STempTableNode* pTempTable) {
|
||||
return calcConstQuery(pCxt, pTempTable->pSubquery, true);
|
||||
}
|
||||
|
||||
static int32_t calcConstNode(SNode** pNode) {
|
||||
if (NULL == *pNode) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static EDealRes doCalcConst(SNode** pNode, SCalcConstContext* pCxt) {
|
||||
SNode* pNew = NULL;
|
||||
pCxt->code = scalarCalculateConstants(*pNode, &pNew);
|
||||
if (TSDB_CODE_SUCCESS != pCxt->code) {
|
||||
return DEAL_RES_ERROR;
|
||||
int32_t code = scalarCalculateConstants(*pNode, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pNode = pNew;
|
||||
}
|
||||
((SValueNode*)pNew)->genByCalc = true;
|
||||
((SValueNode*)pNew)->translate = true;
|
||||
*pNode = pNew;
|
||||
return DEAL_RES_CONTINUE;
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool isTimestampCol(SNode* pNode) {
|
||||
if (NULL == pNode) {
|
||||
return false;
|
||||
}
|
||||
return (QUERY_NODE_COLUMN == nodeType(pNode) && TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode*)pNode)->resType.type);
|
||||
}
|
||||
|
||||
static EDealRes stringToTimestamp(SCalcConstContext* pCxt, uint8_t precision, SValueNode* pVal) {
|
||||
switch (pVal->node.resType.type) {
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY: {
|
||||
int64_t val = 0;
|
||||
if (TSDB_CODE_SUCCESS != convertStringToTimestamp(pVal->node.resType.type, pVal->datum.p, precision, &val)) {
|
||||
pCxt->code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCORRECT_TIMESTAMP_VAL, varDataVal(pVal->datum.p));
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
pVal->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
||||
taosMemoryFreeClear(pVal->datum.p);
|
||||
pVal->datum.i = val;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes calcConstOperator(SOperatorNode** pNode, void* pContext) {
|
||||
SCalcConstContext* pCxt = pContext;
|
||||
SOperatorNode* pOp = *pNode;
|
||||
if (QUERY_NODE_VALUE == nodeType(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) {
|
||||
return doCalcConst((SNode**)pNode, pCxt);
|
||||
}
|
||||
if (isTimestampCol(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) {
|
||||
return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pLeft)->node.resType.precision, (SValueNode*)pOp->pRight);
|
||||
} else if (isTimestampCol(pOp->pRight) && QUERY_NODE_VALUE == nodeType(pOp->pLeft)) {
|
||||
return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pRight)->node.resType.precision, (SValueNode*)pOp->pLeft);
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes calcConstFunction(SFunctionNode** pNode, void* pContext) {
|
||||
SFunctionNode* pFunc = *pNode;
|
||||
if (!fmIsScalarFunc(pFunc->funcId) || fmIsUserDefinedFunc(pFunc->funcId)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
SNode* pParam = NULL;
|
||||
FOREACH(pParam, pFunc->pParameterList) {
|
||||
if (QUERY_NODE_VALUE != nodeType(pParam)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
static int32_t calcConstList(SNodeList* pList) {
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
SNode* pNew = NULL;
|
||||
int32_t code = scalarCalculateConstants(pNode, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pNew);
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext);
|
||||
}
|
||||
|
||||
static EDealRes calcConstLogicCond(SLogicConditionNode** pNode, void* pContext) {
|
||||
SLogicConditionNode* pCond = *pNode;
|
||||
SNode* pParam = NULL;
|
||||
FOREACH(pParam, pCond->pParameterList) {
|
||||
// todo calc "true and c1 > 10"
|
||||
if (QUERY_NODE_VALUE != nodeType(pParam)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
}
|
||||
return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext);
|
||||
}
|
||||
|
||||
static EDealRes calcConstSubquery(STempTableNode** pNode, void* pContext) {
|
||||
SCalcConstContext* pCxt = pContext;
|
||||
pCxt->code = calcConstQuery(pCxt, (*pNode)->pSubquery);
|
||||
return (TSDB_CODE_SUCCESS == pCxt->code ? DEAL_RES_CONTINUE : DEAL_RES_ERROR);
|
||||
}
|
||||
|
||||
static EDealRes calcConst(SNode** pNode, void* pContext) {
|
||||
switch (nodeType(*pNode)) {
|
||||
case QUERY_NODE_OPERATOR:
|
||||
return calcConstOperator((SOperatorNode**)pNode, pContext);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return calcConstFunction((SFunctionNode**)pNode, pContext);
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
return calcConstLogicCond((SLogicConditionNode**)pNode, pContext);
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
return calcConstSubquery((STempTableNode**)pNode, pContext);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isCondition(const SNode* pNode) {
|
||||
|
@ -174,18 +102,41 @@ static int32_t rewriteCondition(SCalcConstContext* pCxt, SNode** pNode) {
|
|||
return pCxt->code;
|
||||
}
|
||||
|
||||
static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTable) {
|
||||
if (QUERY_NODE_JOIN_TABLE == nodeType(pTable)) {
|
||||
SJoinTableNode* pJoin = (SJoinTableNode*)pTable;
|
||||
pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pLeft);
|
||||
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);
|
||||
}
|
||||
static int32_t calcConstCondition(SCalcConstContext* pCxt, SNode** pNode) {
|
||||
int32_t code = rewriteCondition(pCxt, pNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstNode(pNode);
|
||||
}
|
||||
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) {
|
||||
|
@ -200,77 +151,133 @@ static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t calcConstFromTable(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
|
||||
pCxt->code = rewriteConditionForFromTable(pCxt, pSelect->pFromTable);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprPostOrder(&pSelect->pFromTable, calcConst, pCxt);
|
||||
}
|
||||
return pCxt->code;
|
||||
}
|
||||
|
||||
static int32_t calcConstCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) {
|
||||
static int32_t calcConstSelectCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) {
|
||||
if (NULL == *pCond) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pCxt->code = rewriteCondition(pCxt, pCond);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
nodesRewriteExprPostOrder(pCond, calcConst, pCxt);
|
||||
int32_t code = rewriteCondition(pCxt, pCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstNode(pCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
rewriteConstCondition(pSelect, pCond);
|
||||
}
|
||||
return pCxt->code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
|
||||
nodesRewriteExprsPostOrder(pSelect->pProjectionList, calcConst, pCxt);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
pCxt->code = calcConstFromTable(pCxt, pSelect);
|
||||
static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
|
||||
SArray* pAssociation = NULL;
|
||||
if (NULL != ((SExprNode*)pProject)->pAssociation) {
|
||||
pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation);
|
||||
if (NULL == pAssociation) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code) {
|
||||
pCxt->code = calcConstCondition(pCxt, pSelect, &pSelect->pWhere);
|
||||
|
||||
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) {
|
||||
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;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return calcConstSelect(pCxt, (SSelectStmt*)pStmt);
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return calcConstQuery(pCxt, ((SExplainStmt*)pStmt)->pQuery);
|
||||
default:
|
||||
break;
|
||||
static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProjections, bool subquery) {
|
||||
SNode* pProj = NULL;
|
||||
WHERE_EACH(pProj, pProjections) {
|
||||
if (subquery && NULL == ((SExprNode*)pProj)->pAssociation) {
|
||||
ERASE_NODE(pProjections);
|
||||
continue;
|
||||
}
|
||||
SNode* pNew = NULL;
|
||||
int32_t code = calcConstProject(pProj, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pNew);
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
WHERE_NEXT;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isEmptyResultQuery(SNode* pStmt) {
|
||||
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)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return ((SSelectStmt*)pStmt)->isEmptyResult;
|
||||
code = calcConstSelect(pCxt, (SSelectStmt*)pStmt, subquery);
|
||||
break;
|
||||
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:
|
||||
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) {
|
||||
|
@ -280,9 +287,9 @@ int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
|
|||
.msgBuf.len = pParseCxt->msgLen,
|
||||
.code = TSDB_CODE_SUCCESS
|
||||
};
|
||||
int32_t code = calcConstQuery(&cxt, pQuery->pRoot);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pQuery->execMode = isEmptyResultQuery(pQuery->pRoot) ? QUERY_EXEC_MODE_EMPTY_RESULT : pQuery->execMode;
|
||||
int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false);
|
||||
if (TSDB_CODE_SUCCESS == code && isEmptyResultQuery(pQuery->pRoot)) {
|
||||
pQuery->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "cmdnodes.h"
|
||||
#include "functionMgt.h"
|
||||
#include "parUtil.h"
|
||||
#include "scalar.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
|
||||
|
@ -305,7 +306,10 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
|
|||
|
||||
static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) {
|
||||
pCol->pProjectRef = (SNode*)pExpr;
|
||||
nodesListAppend(pExpr->pAssociationList, (SNode*)pCol);
|
||||
if (NULL == pExpr->pAssociation) {
|
||||
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
|
||||
}
|
||||
taosArrayPush(pExpr->pAssociation, &pCol);
|
||||
if (NULL != pTable) {
|
||||
strcpy(pCol->tableAlias, pTable->tableAlias);
|
||||
} else if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||
|
@ -587,13 +591,14 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
|
|||
}
|
||||
|
||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog,
|
||||
.pRpc = pCxt->pParseCxt->pTransporter,
|
||||
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet};
|
||||
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(¶m, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName);
|
||||
}
|
||||
pCxt->errCode = fmGetFuncResultType(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
||||
SFmGetFuncInfoParam param = {
|
||||
.pCtg = pCxt->pParseCxt->pCatalog,
|
||||
.pRpc = pCxt->pParseCxt->pTransporter,
|
||||
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet,
|
||||
.pErrBuf = pCxt->msgBuf.buf,
|
||||
.errBufLen = pCxt->msgBuf.len
|
||||
};
|
||||
pCxt->errCode = fmGetFuncInfo(¶m, pFunc);
|
||||
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
@ -759,6 +764,19 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) {
|
||||
if (NULL == *pVgroupList) {
|
||||
*pVgroupList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVgroupInfo));
|
||||
if (NULL == *pVgroupList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
SVgroupInfo vg = { .vgId = MNODE_HANDLE };
|
||||
memcpy(&vg.epSet, pEpSet, sizeof(SEpSet));
|
||||
taosArrayPush(*pVgroupList, &vg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) {
|
||||
if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -766,12 +784,20 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea
|
|||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SArray* vgroupList = NULL;
|
||||
if ('\0' != pRealTable->useDbName[0]) {
|
||||
code = getDBVgInfo(pCxt, pRealTable->useDbName, &vgroupList);
|
||||
if ('\0' != pRealTable->qualDbName[0]) {
|
||||
// todo release after mnode can be processed
|
||||
// if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) {
|
||||
code = getDBVgInfo(pCxt, pRealTable->qualDbName, &vgroupList);
|
||||
// }
|
||||
} else {
|
||||
code = getDBVgInfoImpl(pCxt, pName, &vgroupList);
|
||||
}
|
||||
|
||||
// todo release after mnode can be processed
|
||||
// if (TSDB_CODE_SUCCESS == code) {
|
||||
// code = addMnodeToVgroupList(&pCxt->pParseCxt->mgmtEpSet, &vgroupList);
|
||||
// }
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList);
|
||||
}
|
||||
|
@ -1965,13 +1991,6 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs
|
|||
if (1 != LIST_LENGTH(pFuncs)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROLLUP_OPTION);
|
||||
}
|
||||
SFunctionNode* pFunc = nodesListGetNode(pFuncs, 0);
|
||||
SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog,
|
||||
.pRpc = pCxt->pParseCxt->pTransporter,
|
||||
.pMgmtEps = &pCxt->pParseCxt->mgmtEpSet};
|
||||
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(¶m, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -2001,13 +2020,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t getAggregationMethod(SNodeList* pFuncs) {
|
||||
if (NULL == pFuncs) {
|
||||
return -1;
|
||||
}
|
||||
return ((SFunctionNode*)nodesListGetNode(pFuncs, 0))->funcId;
|
||||
}
|
||||
|
||||
static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) {
|
||||
int8_t flags = 0;
|
||||
if (pCol->sma) {
|
||||
|
@ -2229,7 +2241,6 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
|
|||
|
||||
static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) {
|
||||
pReq->igExists = pStmt->ignoreExists;
|
||||
pReq->aggregationMethod = getAggregationMethod(pStmt->pOptions->pFuncs);
|
||||
pReq->xFilesFactor = GET_OPTION_VAL(pStmt->pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR);
|
||||
pReq->delay = GET_OPTION_VAL(pStmt->pOptions->pDelay, TSDB_DEFAULT_DB_DELAY);
|
||||
columnDefNodeToField(pStmt->pCols, &pReq->pColumns);
|
||||
|
@ -3193,7 +3204,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect)
|
|||
}
|
||||
|
||||
if (NULL != pShow->pDbName) {
|
||||
strcpy(((SRealTableNode*)pSelect->pFromTable)->useDbName, ((SValueNode*)pShow->pDbName)->literal);
|
||||
strcpy(((SRealTableNode*)pSelect->pFromTable)->qualDbName, ((SValueNode*)pShow->pDbName)->literal);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -3235,14 +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->xFilesFactor = GET_OPTION_VAL(pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR);
|
||||
pReq->ntbCfg.pRSmaParam->nFuncIds = LIST_LENGTH(pOptions->pFuncs);
|
||||
pReq->ntbCfg.pRSmaParam->pFuncIds = taosMemoryCalloc(pReq->ntbCfg.pRSmaParam->nFuncIds, sizeof(func_id_t));
|
||||
if (NULL == pReq->ntbCfg.pRSmaParam->pFuncIds) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int32_t index = 0;
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pOptions->pFuncs) { pReq->ntbCfg.pRSmaParam->pFuncIds[index++] = ((SFunctionNode*)pFunc)->funcId; }
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -3428,10 +3431,6 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
|
|||
return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId);
|
||||
}
|
||||
|
||||
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
|
||||
return pCxt->errCode;
|
||||
}
|
||||
|
||||
if (pVal->node.resType.type == TSDB_DATA_TYPE_NULL) {
|
||||
// todo
|
||||
} else {
|
||||
|
@ -3442,6 +3441,23 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createValueFromFunction(STranslateContext* pCxt, SFunctionNode* pFunc, SValueNode** pVal) {
|
||||
if (DEAL_RES_ERROR == translateFunction(pCxt, pFunc)) {
|
||||
return pCxt->errCode;
|
||||
}
|
||||
return scalarCalculateConstants((SNode*)pFunc, (SNode**)pVal);
|
||||
}
|
||||
|
||||
static int32_t translateTagVal(STranslateContext* pCxt, SNode* pNode, SValueNode** pVal) {
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
|
||||
return createValueFromFunction(pCxt, (SFunctionNode*)pNode, pVal);
|
||||
} else if (QUERY_NODE_VALUE == nodeType(pNode)) {
|
||||
return (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode) ? pCxt->errCode : TSDB_CODE_SUCCESS);
|
||||
} else {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
||||
SKVRowBuilder* pBuilder) {
|
||||
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
|
||||
|
@ -3451,8 +3467,8 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
}
|
||||
|
||||
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
|
||||
SNode * pTag, *pVal;
|
||||
FORBOTH(pTag, pStmt->pSpecificTags, pVal, pStmt->pValsOfTags) {
|
||||
SNode * pTag, *pNode;
|
||||
FORBOTH(pTag, pStmt->pSpecificTags, pNode, pStmt->pValsOfTags) {
|
||||
SColumnNode* pCol = (SColumnNode*)pTag;
|
||||
SSchema* pSchema = NULL;
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
|
@ -3464,7 +3480,18 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
if (NULL == pSchema) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName);
|
||||
}
|
||||
int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pSchema, pBuilder);
|
||||
SValueNode* pVal = NULL;
|
||||
int32_t code = translateTagVal(pCxt, pNode, &pVal);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (NULL == pVal) {
|
||||
pVal = (SValueNode*)pNode;
|
||||
} else {
|
||||
REPLACE_LIST2_NODE(pVal);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addValToKVRow(pCxt, pVal, pSchema, pBuilder);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3480,10 +3507,21 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
|||
}
|
||||
|
||||
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
|
||||
SNode* pVal;
|
||||
SNode* pNode;
|
||||
int32_t index = 0;
|
||||
FOREACH(pVal, pStmt->pValsOfTags) {
|
||||
int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pTagSchema + index++, pBuilder);
|
||||
FOREACH(pNode, pStmt->pValsOfTags) {
|
||||
SValueNode* pVal = NULL;
|
||||
int32_t code = translateTagVal(pCxt, pNode, &pVal);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (NULL == pVal) {
|
||||
pVal = (SValueNode*)pNode;
|
||||
} else {
|
||||
REPLACE_NODE(pVal);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addValToKVRow(pCxt, pVal, pTagSchema + index++, pBuilder);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
return "Column ambiguously defined: %s";
|
||||
case TSDB_CODE_PAR_WRONG_VALUE_TYPE:
|
||||
return "Invalid value type: %s";
|
||||
case TSDB_CODE_PAR_INVALID_FUNTION:
|
||||
return "Invalid function name: %s";
|
||||
case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION:
|
||||
return "There mustn't be aggregation";
|
||||
case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -353,7 +353,7 @@ TEST_F(ParserTest, selectSemanticError) {
|
|||
|
||||
// TSDB_CODE_PAR_INVALID_FUNTION
|
||||
bind("SELECT cnt(*) FROM t1");
|
||||
ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_FUNTION));
|
||||
ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_FUNC_INVALID_FUNTION));
|
||||
|
||||
// TSDB_CODE_PAR_FUNTION_PARA_NUM
|
||||
// TSDB_CODE_PAR_FUNTION_PARA_TYPE
|
||||
|
|
|
@ -486,7 +486,7 @@ _return:
|
|||
EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
|
||||
SFunctionNode *node = (SFunctionNode *)*pNode;
|
||||
SNode* tnode = NULL;
|
||||
if (fmIsUserDefinedFunc(node->funcId)) {
|
||||
if (!fmIsScalarFunc(node->funcId)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -511,6 +511,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
|
|||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
res->translate = true;
|
||||
|
||||
if (colDataIsNull_s(output.columnData, 0)) {
|
||||
res->node.resType.type = TSDB_DATA_TYPE_NULL;
|
||||
} else {
|
||||
|
@ -553,6 +555,7 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
|
|||
}
|
||||
|
||||
res->node.resType = node->node.resType;
|
||||
res->translate = true;
|
||||
|
||||
int32_t type = output.columnData->info.type;
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
|
@ -595,6 +598,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
|
|||
}
|
||||
|
||||
res->node.resType = node->node.resType;
|
||||
res->translate = true;
|
||||
|
||||
int32_t type = output.columnData->info.type;
|
||||
if (IS_VAR_DATA_TYPE(type)) { // todo refactor
|
||||
|
@ -612,10 +616,6 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
|
|||
}
|
||||
|
||||
EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
|
||||
if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
SScalarCtx *ctx = (SScalarCtx *)pContext;
|
||||
|
||||
if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
|
||||
|
@ -629,10 +629,8 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
|
|||
if (QUERY_NODE_OPERATOR == nodeType(*pNode)) {
|
||||
return sclRewriteOperator(pNode, ctx);
|
||||
}
|
||||
|
||||
sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode));
|
||||
ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return DEAL_RES_ERROR;
|
||||
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) {
|
||||
|
|
|
@ -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())
|
|
@ -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())
|
|
@ -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())
|
|
@ -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())
|
|
@ -4,4 +4,10 @@ set -e
|
|||
#python3 ./test.py -f 2-query/between.py
|
||||
#python3 ./test.py -f 2-query/distinct.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
|
||||
|
||||
|
|
Loading…
Reference in New Issue