From 13a9620122c172b32590b6b598ea9956f798c0aa 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 | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index bc497f57b1..bd77828412 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -1205,13 +1205,31 @@ int32_t exprValidateTimeNode(tExprNode *pExpr) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } child->pVal->nType = TSDB_DATA_TYPE_TIMESTAMP; - int64_t timeValMs; + int64_t timeVal; if (pExpr->_func.functionId == TSDB_FUNC_SCALAR_NOW) { - timeValMs = taosGetTimestampMs(); + switch(pExpr->precision) { + case TSDB_TIME_PRECISION_MILLI: { + timeVal = taosGetTimestampMs(); + break; + } + case TSDB_TIME_PRECISION_MICRO: { + timeVal = taosGetTimestampUs(); + break; + } + case TSDB_TIME_PRECISION_NANO: { + timeVal = taosGetTimestampNs(); + break; + } + default: { + assert(false); + break; + } + } + child->pVal->i64 = timeVal; } else { - timeValMs = taosGetTimestampToday() * 1000; + timeVal = taosGetTimestampToday() * 1000; + child->pVal->i64 = convertTimePrecision(timeVal, TSDB_TIME_PRECISION_MILLI, pExpr->precision); } - child->pVal->i64 = convertTimePrecision(timeValMs, TSDB_TIME_PRECISION_MILLI, pExpr->precision); pExpr->resultType = TSDB_DATA_TYPE_TIMESTAMP; pExpr->resultBytes = (int16_t)tDataTypes[pExpr->resultType].bytes; break; -- GitLab