From d5b0ac80c3657330d683925b4b61226b32e06eac Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Jun 2021 22:28:13 +0800 Subject: [PATCH] [TD-3086] add test case --- src/client/src/tscSQLParser.c | 47 ++++++++++++------- tests/pytest/functions/function_operations.py | 2 +- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ea1e50e72c..fcb549a66a 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -286,29 +286,33 @@ static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) { return tscInvalidOperationMsg(dstBuffer, errMsg, NULL); } -static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tVariant* pVar) { +static int convertTimestampStrToInt64(tVariant *pVar, int32_t precision) { int64_t time = 0; - const char* msg = "invalid timestamp"; - strdequote(pVar->pz); - char* seg = strnchr(pVar->pz, '-', pVar->nLen, false); - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - + char* seg = strnchr(pVar->pz, '-', pVar->nLen, false); if (seg != NULL) { - if (taosParseTime(pVar->pz, &time, pVar->nLen, tinfo.precision, tsDaylight) != TSDB_CODE_SUCCESS) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + if (taosParseTime(pVar->pz, &time, pVar->nLen, precision, tsDaylight) != TSDB_CODE_SUCCESS) { + return -1; } } else { if (tVariantDump(pVar, (char*)&time, TSDB_DATA_TYPE_BIGINT, true)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + return -1; } } - tVariantDestroy(pVar); tVariantCreateFromBinary(pVar, (char*)&time, 0, TSDB_DATA_TYPE_BIGINT); + return 0; +} +static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tVariant* pVar) { + const char* msg = "invalid timestamp"; + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); + if (convertTimestampStrToInt64(pVar, tinfo.precision) < -1) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + } return TSDB_CODE_SUCCESS; } @@ -6886,11 +6890,16 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } } else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) { - pItem->pVar.i64 = - convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); + if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) { + ret = convertTimestampStrToInt64(&(pItem->pVar), tinfo.precision); + if (ret != TSDB_CODE_SUCCESS) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + } + } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { + pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); + } } - ret = tVariantDump(&(pItem->pVar), tagVal, pSchema->type, true); // check again after the convert since it may be converted from binary to nchar. @@ -6936,8 +6945,14 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } } else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) { - pItem->pVar.i64 = - convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); + if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) { + ret = convertTimestampStrToInt64(&(pItem->pVar), tinfo.precision); + if (ret != TSDB_CODE_SUCCESS) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + } + } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { + pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); + } } diff --git a/tests/pytest/functions/function_operations.py b/tests/pytest/functions/function_operations.py index 859cd78a3d..3e90d1d3ea 100644 --- a/tests/pytest/functions/function_operations.py +++ b/tests/pytest/functions/function_operations.py @@ -16,7 +16,7 @@ import taos from util.log import * from util.cases import * from util.sql import * -import numpy as np +#import numpy as np class TDTestCase: -- GitLab