From ba6b1a7022a4da9ffd0b7c386065115592126438 Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Thu, 3 Jun 2021 16:39:52 +0800 Subject: [PATCH] check primary cloumn must timestamp type on project query --- src/client/src/tscSQLParser.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f8aa444d9e..4c94123a03 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6664,6 +6664,8 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { const char* msg5 = "sql too long"; // todo ADD support const char* msg6 = "from missing in subclause"; const char* msg7 = "time interval is required"; + const char* msg8 = "query column is required"; + const char* msg9 = "the first column should be primary timestamp column"; SSqlCmd* pCmd = &pSql->cmd; SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); @@ -6721,8 +6723,26 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } - if (!tscIsProjectionQuery(pQueryInfo) && pQueryInfo->interval.interval == 0) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7); + // project query primary column must be timestamp type + if (tscIsProjectionQuery(pQueryInfo)) { + size_t size = tscSqlExprNumOfExprs(pQueryInfo); + // check zero + if(size == 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg8); + } + + // check primary column is timestamp + SSqlExpr* pSqlExpr = tscSqlExprGet(pQueryInfo, 0); + if(pSqlExpr == NULL) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg8); + } + if( pSqlExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg9); + } + } else { + if (pQueryInfo->interval.interval == 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7); + } } // set the created table[stream] name -- GitLab