Merge pull request #6361 from taosdata/cq

PR check primary column type must timestamp if project query
This commit is contained in:
haojun Liao 2021-06-04 15:58:50 +08:00 committed by GitHub
commit 94acb5af14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 2 deletions

View File

@ -6674,6 +6674,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 must be timestamp type";
SSqlCmd* pCmd = &pSql->cmd;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
@ -6731,8 +6733,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