提交 d63f0e7f 编写于 作者: S slguan

Fix issue #91, remove assert for illegal filtering conditions

上级 932da9d5
......@@ -3055,6 +3055,29 @@ static int32_t setMetersIDForMetricQuery(SSqlObj* pSql, char* tmpTagCondBuf) {
return TSDB_CODE_SUCCESS;
}
static bool validateFilterExpr(SSqlCmd* pCmd) {
for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) {
SColumnBase* pColBase = &pCmd->colList.pColList[i];
if (pColBase->filterOn > 0) {
int32_t lowerOptr = pColBase->lowerRelOptr;
int32_t upperOptr = pColBase->upperRelOptr;
if ((lowerOptr == TSDB_RELATION_LARGE_EQUAL || lowerOptr == TSDB_RELATION_LARGE) &&
(upperOptr == TSDB_RELATION_LESS_EQUAL || upperOptr == TSDB_RELATION_LESS)) {
continue;
}
// there must be at least two range, not support yet.
if (lowerOptr * upperOptr != TSDB_RELATION_INVALID) {
return false;
}
}
}
return true;
}
int32_t buildQueryCond(SSqlObj* pSql, tSQLExpr* pExpr) {
SSqlCmd* pCmd = &pSql->cmd;
......@@ -3064,6 +3087,7 @@ int32_t buildQueryCond(SSqlObj* pSql, tSQLExpr* pExpr) {
char msg1[] = "invalid expression";
char msg2[] = "meter is not allowed";
char msg3[] = "invalid filter expression";
tSQLExpr* pLeft = pExpr->pLeft;
tSQLExpr* pRight = pExpr->pRight;
......@@ -3112,6 +3136,11 @@ int32_t buildQueryCond(SSqlObj* pSql, tSQLExpr* pExpr) {
pCmd->tagCond.pData[pCmd->tagCond.len] = 0;
}
if (!validateFilterExpr(pCmd)) {
setErrMsg(pCmd, msg3, tListLen(msg3));
return TSDB_CODE_INVALID_SQL;
}
return ret;
}
......
......@@ -869,9 +869,7 @@ void tscKillMetricQuery(SSqlObj *pSql) {
tscTrace("%p metric query is cancelled", pSql);
}
static SSqlObj* tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport,
SSqlObj* prevSqlObj) {
static SSqlObj* tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj* prevSqlObj) {
SSqlCmd *pCmd = &pSql->cmd;
SSqlObj *pNew = (SSqlObj *)calloc(1, sizeof(SSqlObj));
......@@ -916,7 +914,6 @@ static SSqlObj* tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsu
assert(pNew->cmd.pMeterMeta != NULL && pNew->cmd.pMetricMeta != NULL);
return pNew;
}
void tscRetrieveDataRes(void *param, TAOS_RES *tres, int retCode) {
......
......@@ -74,6 +74,7 @@ enum _syncstatus {
#define TSDB_KEYSIZE sizeof(TSKEY)
#define TSDB_NCHAR_SIZE sizeof(wchar_t)
#define TSDB_RELATION_INVALID 0
#define TSDB_RELATION_LESS 1
#define TSDB_RELATION_LARGE 2
#define TSDB_RELATION_EQUAL 3
......
......@@ -63,7 +63,7 @@ void vnodeFreeFields(SQuery *pQuery);
void vnodeUpdateFilterColumnIndex(SQuery* pQuery);
void vnodeUpdateQueryColumnIndex(SQuery* pQuery, SMeterObj* pMeterObj);
int32_t vnodeCreateFilterInfo(SQuery *pQuery);
int32_t vnodeCreateFilterInfo(void* pQInfo, SQuery *pQuery);
bool vnodeFilterData(SQuery* pQuery, int32_t* numOfActualRead, int32_t index);
bool vnodeDoFilterData(SQuery* pQuery, int32_t elemPos);
......
......@@ -216,7 +216,7 @@ static SQInfo *vnodeAllocateQInfoCommon(SQueryMeterMsg *pQueryMsg, SMeterObj *pM
pQuery->pSelectExpr = pExprs;
int32_t ret = vnodeCreateFilterInfo(pQuery);
int32_t ret = vnodeCreateFilterInfo(pQInfo, pQuery);
if (ret != TSDB_CODE_SUCCESS) {
goto _clean_memory;
}
......
......@@ -246,7 +246,11 @@ SSqlFunctionExpr* vnodeCreateSqlFunctionExpr(SQueryMeterMsg* pQueryMsg, int32_t*
// tag column schema is kept in pQueryMsg->pTagSchema
if (pColumnIndexExInfo->isTag) {
assert(pColumnIndexExInfo->colIdx < pQueryMsg->numOfTagsCols);
if (pColumnIndexExInfo->colIdx >= pQueryMsg->numOfTagsCols) {
*code = TSDB_CODE_INVALID_QUERY_MSG;
tfree(pExprs);
break;
}
type = pTagSchema[pColumnIndexExInfo->colIdx].type;
bytes = pTagSchema[pColumnIndexExInfo->colIdx].bytes;
......@@ -356,7 +360,7 @@ void vnodeUpdateFilterColumnIndex(SQuery* pQuery) {
}
// TODO support k<12 and k<>9
int32_t vnodeCreateFilterInfo(SQuery* pQuery) {
int32_t vnodeCreateFilterInfo(void* pQInfo, SQuery* pQuery) {
for (int32_t i = 0; i < pQuery->numOfCols; ++i) {
if (pQuery->colList[i].data.filterOn > 0) {
pQuery->numOfFilterCols++;
......@@ -384,8 +388,8 @@ int32_t vnodeCreateFilterInfo(SQuery* pQuery) {
__filter_func_t* filterArray = vnodeGetValueFilterFuncArray(type);
if (rangeFilterArray == NULL && filterArray == NULL) {
dError("QInfo:%p failed to get filter function, invalid data type:%d", type);
return TSDB_CODE_APP_ERROR;
dError("QInfo:%p failed to get filter function, invalid data type:%d", pQInfo, type);
return TSDB_CODE_INVALID_QUERY_MSG;
}
if ((lower == TSDB_RELATION_LARGE_EQUAL || lower == TSDB_RELATION_LARGE) &&
......@@ -406,9 +410,13 @@ int32_t vnodeCreateFilterInfo(SQuery* pQuery) {
}
}
} else { // set callback filter function
if (lower != 0) {
if (lower != TSDB_RELATION_INVALID) {
pFilterInfo->fp = filterArray[lower];
assert(upper == 0);
if (upper != TSDB_RELATION_INVALID) {
dError("pQInfo:%p failed to get filter function, invalid filter condition", pQInfo, type);
return TSDB_CODE_INVALID_QUERY_MSG;
}
} else {
pFilterInfo->fp = filterArray[upper];
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册