From 78f303144aedf1a794a51ca0fca6cdae35e0702e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 15 Jun 2021 17:23:50 +0800 Subject: [PATCH] [TD-3086] tag support timestamp --- src/client/src/tscSQLParser.c | 38 +++++++++++++++++++++++++---------- src/common/src/tvariant.c | 4 ++++ src/query/inc/sql.y | 1 + src/query/src/qExecutor.c | 4 +++- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index d8524c3e03..9426303a7c 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1276,7 +1276,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC const char* msg1 = "invalid number of tag columns"; const char* msg2 = "tag length too long"; const char* msg3 = "duplicated column names"; - const char* msg4 = "timestamp not allowed in tags"; + //const char* msg4 = "timestamp not allowed in tags"; const char* msg5 = "invalid data type in tags"; const char* msg6 = "invalid tag name"; const char* msg7 = "invalid binary/nchar tag length"; @@ -1292,10 +1292,10 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC for (int32_t i = 0; i < numOfTags; ++i) { TAOS_FIELD* p = taosArrayGet(pTagsList, i); - if (p->type == TSDB_DATA_TYPE_TIMESTAMP) { - invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); - return false; - } + //if (p->type == TSDB_DATA_TYPE_TIMESTAMP) { + // invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + // return false; + //} if (!isValidDataType(p->type)) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); @@ -1353,7 +1353,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC * tags name /column name is truncated in sql.y */ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) { - const char* msg1 = "timestamp not allowed in tags"; + //const char* msg1 = "timestamp not allowed in tags"; const char* msg2 = "duplicated column names"; const char* msg3 = "tag length too long"; const char* msg4 = "invalid tag name"; @@ -1376,10 +1376,10 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) { } // no timestamp allowable - if (pTagField->type == TSDB_DATA_TYPE_TIMESTAMP) { - invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); - return false; - } + //if (pTagField->type == TSDB_DATA_TYPE_TIMESTAMP) { + // invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + // return false; + //} if ((pTagField->type < TSDB_DATA_TYPE_BOOL) || (pTagField->type > TSDB_DATA_TYPE_UBIGINT)) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); @@ -8001,8 +8001,24 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS *pExpr = calloc(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_VALUE; (*pExpr)->pVal = calloc(1, sizeof(tVariant)); - tVariantAssign((*pExpr)->pVal, &pSqlExpr->value); + + int32_t type = -1; + STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; + if (pCols != NULL) { + SColIndex* idx = taosArrayGet(pCols, 0); + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); + if (pSchema != NULL) { + type = pSchema->type; + } + } + if (type == TSDB_DATA_TYPE_TIMESTAMP) { + int32_t ret = setColumnFilterInfoForTimestamp(pCmd, pQueryInfo, (*pExpr)->pVal); + if (ret != TSDB_CODE_SUCCESS) { + return ret; + } + } + return TSDB_CODE_SUCCESS; } else if (pSqlExpr->type == SQL_NODE_SQLFUNCTION) { // arithmetic expression on the results of aggregation functions diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index 33dab51633..1168eeb231 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -77,6 +77,10 @@ void tVariantCreate(tVariant *pVar, SStrToken *token) { pVar->nLen = strRmquote(pVar->pz, token->n); break; } + case TSDB_DATA_TYPE_TIMESTAMP: { + pVar->i64 = taosGetTimestamp(TSDB_TIME_PRECISION_NANO); + break; + } default: { // nType == 0 means the null value type = TSDB_DATA_TYPE_NULL; diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index fbb59e4a72..0740369924 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -433,6 +433,7 @@ tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); tVariantCreate(&A, &X); } tagitem(A) ::= STRING(X). { toTSDBType(X.type); tVariantCreate(&A, &X); } tagitem(A) ::= BOOL(X). { toTSDBType(X.type); tVariantCreate(&A, &X); } tagitem(A) ::= NULL(X). { X.type = 0; tVariantCreate(&A, &X); } +tagitem(A) ::= NOW(X). { X.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&A, &X);} tagitem(A) ::= MINUS(X) INTEGER(Y).{ X.n += Y.n; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 395903f75e..e6b40f40d6 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2889,7 +2889,9 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt doSetTagValueInParam(pTable, pLocalExprInfo->base.colInfo.colId, &pCtx[idx].tag, pLocalExprInfo->base.resType, pLocalExprInfo->base.resBytes); - if (IS_NUMERIC_TYPE(pLocalExprInfo->base.resType) || pLocalExprInfo->base.resType == TSDB_DATA_TYPE_BOOL) { + if (IS_NUMERIC_TYPE(pLocalExprInfo->base.resType) + || pLocalExprInfo->base.resType == TSDB_DATA_TYPE_BOOL + || pLocalExprInfo->base.resType == TSDB_DATA_TYPE_TIMESTAMP) { memcpy(pRuntimeEnv->tagVal + offset, &pCtx[idx].tag.i64, pLocalExprInfo->base.resBytes); } else { memcpy(pRuntimeEnv->tagVal + offset, pCtx[idx].tag.pz, pCtx[idx].tag.nLen); -- GitLab