From b1d649bab56d0655ffe4164ab53d2aa665b9f234 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/client/src/tscSQLParser.c | 13 +++++++++---- src/common/inc/texpr.h | 2 +- src/common/src/tarithoperator.c | 2 ++ src/common/src/texpr.c | 10 +++++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index e80f78c963..5055f95867 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -10126,6 +10126,10 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS (*pExpr)->pVal = calloc(1, sizeof(tVariant)); tVariantAssign((*pExpr)->pVal, &pSqlExpr->value); + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pQueryInfo->curTableIdx); + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); + (*pExpr)->precision = tinfo.precision; + STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, pQueryInfo->curTableIdx)->pTableMeta; if (pCols != NULL) { size_t colSize = taosArrayGetSize(pCols); @@ -10288,6 +10292,11 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS *pExpr = calloc(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_FUNC; (*pExpr)->_func.functionId = pSqlExpr->functionId; + + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pQueryInfo->curTableIdx); + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); + (*pExpr)->precision = tinfo.precision; + SArray* paramList = pSqlExpr->Expr.paramList; size_t paramSize = paramList ? taosArrayGetSize(paramList) : 0; if (paramSize > 0) { @@ -10302,10 +10311,6 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS return ret; } } - //set precision - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pQueryInfo->curTableIdx); - STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - (*pExpr)->_func.precision = tinfo.precision; } else { // arithmetic expression on the results of aggregation functions *pExpr = calloc(1, sizeof(tExprNode)); diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h index ca692a2135..30e46baeb0 100644 --- a/src/common/inc/texpr.h +++ b/src/common/inc/texpr.h @@ -135,13 +135,13 @@ typedef struct tExprNode { int16_t functionId; int32_t numChildren; struct tExprNode **pChildren; - int32_t precision; } _func; TAOS_FIELD *pType; }; int16_t resultType; int16_t resultBytes; + int32_t precision; } tExprNode; typedef struct SExprTraverseSupp { diff --git a/src/common/src/tarithoperator.c b/src/common/src/tarithoperator.c index 65f170ff68..79f521dbc0 100644 --- a/src/common/src/tarithoperator.c +++ b/src/common/src/tarithoperator.c @@ -114,6 +114,8 @@ _arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) { p = getVectorDoubleValue_FLOAT; }else if(srcType==TSDB_DATA_TYPE_DOUBLE) { p = getVectorDoubleValue_DOUBLE; + }else if(srcType==TSDB_DATA_TYPE_TIMESTAMP) { + p = getVectorDoubleValue_BIGINT; }else { assert(0); } diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 3d47fbeb94..b4bc1ab30f 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -495,9 +495,13 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI _arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr); OperatorFn(leftIn, leftNum, leftType, rightIn, rightNum, rightType, output->data, fnOrder); - + output->numOfRows = MAX(leftNum, rightNum); - output->type = TSDB_DATA_TYPE_DOUBLE; + if(leftType == TSDB_DATA_TYPE_TIMESTAMP || rightType == TSDB_DATA_TYPE_TIMESTAMP) { + output->type = TSDB_DATA_TYPE_BIGINT; + } else { + output->type = TSDB_DATA_TYPE_DOUBLE; + } output->bytes = tDataTypes[output->type].bytes; tfree(ltmp); @@ -1197,7 +1201,7 @@ int32_t exprValidateTimeNode(tExprNode *pExpr) { } else { timeValMs = taosGetTimestampToday() * 1000; } - child->pVal->i64 = convertTimePrecision(timeValMs, TSDB_TIME_PRECISION_MILLI, pExpr->_func.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