Merge pull request #20885 from taosdata/fix/TS-3108
fix: fix timestamp constant comparison precision error
This commit is contained in:
commit
d4cb608505
|
@ -189,7 +189,7 @@ bool fmIsScalarFunc(int32_t funcId);
|
|||
bool fmIsVectorFunc(int32_t funcId);
|
||||
bool fmIsIndefiniteRowsFunc(int32_t funcId);
|
||||
bool fmIsStringFunc(int32_t funcId);
|
||||
bool fmIsDatetimeFunc(int32_t funcId);
|
||||
bool fmIsDateTimeFunc(int32_t funcId);
|
||||
bool fmIsSelectFunc(int32_t funcId);
|
||||
bool fmIsTimelineFunc(int32_t funcId);
|
||||
bool fmIsTimeorderFunc(int32_t funcId);
|
||||
|
|
|
@ -174,6 +174,8 @@ bool fmIsSelectFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC
|
|||
|
||||
bool fmIsTimelineFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_TIMELINE_FUNC); }
|
||||
|
||||
bool fmIsDateTimeFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_DATETIME_FUNC); }
|
||||
|
||||
bool fmIsPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PSEUDO_COLUMN_FUNC); }
|
||||
|
||||
bool fmIsScanPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCAN_PC_FUNC); }
|
||||
|
@ -184,6 +186,7 @@ bool fmIsWindowClauseFunc(int32_t funcId) { return fmIsAggFunc(funcId) || fmIsWi
|
|||
|
||||
bool fmIsIndefiniteRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INDEFINITE_ROWS_FUNC); }
|
||||
|
||||
|
||||
bool fmIsSpecialDataRequiredFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_SPECIAL_DATA_REQUIRED);
|
||||
}
|
||||
|
|
|
@ -1569,6 +1569,21 @@ static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFu
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateDateTimeFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
if (!fmIsDateTimeFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (!isSelectStmt(pCxt->pCurrStmt)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
||||
pFunc->node.resType.precision = pSelect->precision;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool hasFillClause(SNode* pCurrStmt) {
|
||||
if (!isSelectStmt(pCurrStmt)) {
|
||||
return false;
|
||||
|
@ -1708,6 +1723,7 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
|
|||
SSelectStmt* pSelect = (SSelectStmt*)pCurrStmt;
|
||||
pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId);
|
||||
pSelect->hasRepeatScanFuncs = pSelect->hasRepeatScanFuncs ? true : fmIsRepeatScanFunc(pFunc->funcId);
|
||||
|
||||
if (fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
||||
pSelect->hasIndefiniteRowsFunc = true;
|
||||
pSelect->returnRows = fmGetFuncReturnRows(pFunc);
|
||||
|
@ -1856,6 +1872,9 @@ static int32_t translateNormalFunction(STranslateContext* pCxt, SFunctionNode* p
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateTimelineFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateDateTimeFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateBlockDistFunc(pCxt, pFunc);
|
||||
}
|
||||
|
|
|
@ -1038,23 +1038,40 @@ bool sclContainsAggFuncNode(SNode *pNode) {
|
|||
return aggFunc;
|
||||
}
|
||||
|
||||
static uint8_t sclGetOpValueNodeTsPrecision(SNode *pLeft, SNode *pRight) {
|
||||
uint8_t lPrec = ((SExprNode *)pLeft)->resType.precision;
|
||||
uint8_t rPrec = ((SExprNode *)pRight)->resType.precision;
|
||||
|
||||
uint8_t lType = ((SExprNode *)pLeft)->resType.type;
|
||||
uint8_t rType = ((SExprNode *)pRight)->resType.type;
|
||||
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP == lType && TSDB_DATA_TYPE_TIMESTAMP == rType) {
|
||||
return TMAX(lPrec, rPrec);
|
||||
} else if (TSDB_DATA_TYPE_TIMESTAMP == lType && TSDB_DATA_TYPE_TIMESTAMP != rType) {
|
||||
return lPrec;
|
||||
} else if (TSDB_DATA_TYPE_TIMESTAMP == rType && TSDB_DATA_TYPE_TIMESTAMP != lType) {
|
||||
return rPrec;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sclConvertOpValueNodeTs(SOperatorNode *node, SScalarCtx *ctx) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (node->pLeft && SCL_IS_VAR_VALUE_NODE(node->pLeft)) {
|
||||
if (node->pRight && (TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode *)node->pRight)->resType.type)) {
|
||||
SCL_ERR_JRET(sclConvertToTsValueNode(((SExprNode *)node->pRight)->resType.precision, (SValueNode*)node->pLeft));
|
||||
SCL_ERR_JRET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, node->pRight), (SValueNode*)node->pLeft));
|
||||
}
|
||||
} else if (node->pRight && SCL_IS_NOTNULL_CONST_NODE(node->pRight)) {
|
||||
if (node->pLeft && (TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode *)node->pLeft)->resType.type)) {
|
||||
if (SCL_IS_VAR_VALUE_NODE(node->pRight)) {
|
||||
SCL_ERR_JRET(sclConvertToTsValueNode(((SExprNode *)node->pLeft)->resType.precision, (SValueNode*)node->pRight));
|
||||
SCL_ERR_JRET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, node->pRight), (SValueNode*)node->pRight));
|
||||
} else if (QUERY_NODE_NODE_LIST == node->pRight->type) {
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, ((SNodeListNode*)node->pRight)->pNodeList) {
|
||||
if (SCL_IS_VAR_VALUE_NODE(pNode)) {
|
||||
SCL_ERR_JRET(sclConvertToTsValueNode(((SExprNode *)node->pLeft)->resType.precision, (SValueNode*)pNode));
|
||||
SCL_ERR_JRET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, pNode), (SValueNode*)pNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue