From 472342a3cea256d1105f0f2f32d6716011f5dfad Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 8 Feb 2022 14:29:41 +0800 Subject: [PATCH] [TD-11220](query): time related functions --- src/common/src/texpr.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 8f7056cc7d..1d3ddab2d6 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -1363,13 +1363,24 @@ int32_t exprValidateTimeNode(char *msgbuf, tExprNode *pExpr) { return TSDB_CODE_TSC_INVALID_OPERATION; } - if (child0->nodeType == TSQL_NODE_VALUE) { + if (child0->nodeType == TSQL_NODE_VALUE) { /* datetime format or epoch */ if (child0->pVal->nType != TSDB_DATA_TYPE_BIGINT && child0->pVal->nType != TSDB_DATA_TYPE_BINARY && child0->pVal->nType != TSDB_DATA_TYPE_NCHAR) { return TSDB_CODE_TSC_INVALID_OPERATION; } - } else if (child0->nodeType == TSQL_NODE_COL) { + if (child0->pVal->nType == TSDB_DATA_TYPE_BIGINT) { + char fraction[32] = {0}; + NUM_TO_STRING(child0->resultType, &child0->pVal->i64, sizeof(fraction), fraction); + int32_t tsDigits = strlen(fraction); + if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS && + tsDigits != TSDB_TIME_PRECISION_MILLI_DIGITS && + tsDigits != TSDB_TIME_PRECISION_MICRO_DIGITS && + tsDigits != TSDB_TIME_PRECISION_NANO_DIGITS) { + return exprInvalidOperationMsg(msgbuf, msg1); + } + } + } else if (child0->nodeType == TSQL_NODE_COL) { /* ts column */ if (child0->pSchema->type != TSDB_DATA_TYPE_TIMESTAMP) { return TSDB_CODE_TSC_INVALID_OPERATION; } -- GitLab