From c8262d44d16890b551ee463d8a641bcb653f2528 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 21 Apr 2021 19:08:03 +0800 Subject: [PATCH] fix bug --- src/client/src/tscSQLParser.c | 15 ++++++++++++--- src/query/inc/qSqlparser.h | 7 ++++++- src/query/src/qSqlParser.c | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f83e7fe79d..3ede49c71e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3078,7 +3078,7 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumn* pColumn) { return pColFilterInfo; } -static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnFilterInfo* pColumnFilter, +static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, STableMeta* pTableMeta, SColumnFilterInfo* pColumnFilter, int16_t colType, tSqlExpr* pExpr) { const char* msg = "not supported filter condition"; @@ -3093,6 +3093,12 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, if (TSDB_CODE_SUCCESS != retVal) { return retVal; } + } else if ((colType == TSDB_DATA_TYPE_TIMESTAMP) && (TSDB_DATA_TYPE_BIGINT == pRight->value.nType)) { + STableComInfo tinfo = tscGetTableInfo(pTableMeta); + + if ((tinfo.precision == TSDB_TIME_PRECISION_MILLI) && (pRight->flags & (1 << EXPR_FLAG_NOW))) { + pRight->value.i64 /= 1000; + } } int32_t retVal = TSDB_CODE_SUCCESS; @@ -3291,7 +3297,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC int16_t colType = pSchema->type; - return doExtractColumnFilterInfo(pCmd, pQueryInfo, pColFilter, colType, pExpr); + return doExtractColumnFilterInfo(pCmd, pQueryInfo, pTableMeta, pColFilter, colType, pExpr); } static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pTableCond, SStringBuilder* sb) { @@ -6927,7 +6933,10 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t } } - int32_t ret = doExtractColumnFilterInfo(pCmd, pQueryInfo, pColFilter, pInfo->field.type, pExpr); + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; + + int32_t ret = doExtractColumnFilterInfo(pCmd, pQueryInfo, pTableMeta, pColFilter, pInfo->field.type, pExpr); if (ret) { return ret; } diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index c5ee172c40..8c96ac2b94 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -44,6 +44,10 @@ enum SQL_NODE_FROM_TYPE { SQL_NODE_FROM_NAMELIST = 2, }; +enum SQL_EXPR_FLAG { + EXPR_FLAG_NOW = 1 +}; + extern char tTokenTypeSwitcher[13]; #define toTSDBType(x) \ @@ -237,7 +241,8 @@ typedef struct tSqlExpr { SStrToken colInfo; // table column info tVariant value; // the use input value SStrToken token; // original sql expr string - + uint32_t flags; + struct tSqlExpr *pLeft; // left child struct tSqlExpr *pRight; // right child struct SArray *pParam; // function parameters list diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index b75032967a..1dde47e876 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -144,6 +144,7 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) { pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT; pSqlExpr->tokenId = TK_TIMESTAMP; // TK_TIMESTAMP used to denote the time value is in microsecond pSqlExpr->type = SQL_NODE_VALUE; + pSqlExpr->flags |= 1 << EXPR_FLAG_NOW; } else if (optrType == TK_VARIABLE) { int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64); if (ret != TSDB_CODE_SUCCESS) { @@ -217,6 +218,7 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) { pExpr->value.nType = TSDB_DATA_TYPE_BIGINT; pExpr->tokenId = pLeft->tokenId; pExpr->type = SQL_NODE_VALUE; + pExpr->flags = pLeft->flags | pRight->flags; switch (optrType) { case TK_PLUS: { -- GitLab