diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index d8524c3e03a615a250eac3f72f75c72b8f209c84..9426303a7c3327cc2ef62ad23c3889c58b8ec185 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 33dab51633b244326b0490c6bf7b784bc41fe77f..1168eeb231fec49907b7ced9f019f55af2b085a8 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 fbb59e4a728724fd2fc2638d6d754cf2347350b6..07403699245ff767f17e7d373c8a1eae0b1a9b8a 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 395903f75ef4a0cb4626baf9416c17a9b8221052..e6b40f40d681ec274292a1246bb41eef54fb50c9 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);