提交 8d0a4d61 编写于 作者: Y yihaoDeng

[TD-4426]<fix> fix in operator bug

上级 0924b6f7
...@@ -63,7 +63,7 @@ static SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int3 ...@@ -63,7 +63,7 @@ static SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int3
static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo); static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
static char* getAccountId(SSqlObj* pSql); static char* getAccountId(SSqlObj* pSql);
static bool serializeExprListToVariant(SArray* pList, tVariant **dest); static bool serializeExprListToVariant(SArray* pList, tVariant **dest, int8_t colType);
static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType); static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType);
static bool has(SArray* pFieldList, int32_t startIdx, const char* name); static bool has(SArray* pFieldList, int32_t startIdx, const char* name);
...@@ -148,32 +148,42 @@ int16_t getNewResColId(SSqlCmd* pCmd) { ...@@ -148,32 +148,42 @@ int16_t getNewResColId(SSqlCmd* pCmd) {
// serialize expr in exprlist to binary // serialize expr in exprlist to binary
// formate "type | size | value" // formate "type | size | value"
bool serializeExprListToVariant(SArray* pList, tVariant **dst) { bool serializeExprListToVariant(SArray* pList, tVariant **dst, int8_t colType) {
bool ret = false; bool ret = false;
if (!pList || pList->size <= 0) { if (!pList || pList->size <= 0) {
return ret; return ret;
} }
tSqlExprItem* item = (tSqlExprItem *)taosArrayGet(pList, 0);
int32_t firstTokenType = item->pNode->token.type;
int32_t type = firstTokenType;
//nchar to binary and
toTSDBType(type);
if (colType >= 0) {
if (type != colType && (type != TSDB_DATA_TYPE_BINARY || colType != TSDB_DATA_TYPE_NCHAR)) {
return false;
}
type = colType;
}
SBufferWriter bw = tbufInitWriter( NULL, false ); SBufferWriter bw = tbufInitWriter( NULL, false );
tbufEnsureCapacity(&bw, 512); tbufEnsureCapacity(&bw, 512);
tSqlExprItem* item = (tSqlExprItem *)taosArrayGet(pList, 0);
int32_t size = pList->size; int32_t size = pList->size;
int32_t type = item->pNode->token.type;
toTSDBType(type);
tbufWriteUint32(&bw, type); tbufWriteUint32(&bw, type);
tbufWriteInt32(&bw, size); tbufWriteInt32(&bw, size);
for (int32_t i = 0; i < size; i++) { for (int32_t i = 0; i < size; i++) {
tSqlExpr* pSub = ((tSqlExprItem*)(taosArrayGet(pList, i)))->pNode; tSqlExpr* pSub = ((tSqlExprItem*)(taosArrayGet(pList, i)))->pNode;
// type in exprList is same or not // check all the token type in expr list same or not
toTSDBType(pSub->token.type); if (firstTokenType != pSub->token.type) {
if (type != pSub->token.type) {
break; break;
} }
toTSDBType(pSub->token.type);
tVariant var; tVariant var;
tVariantCreate(&var, &pSub->token); tVariantCreate(&var, &pSub->token);
if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT
...@@ -181,8 +191,17 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst) { ...@@ -181,8 +191,17 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst) {
tbufWriteInt64(&bw, var.i64); tbufWriteInt64(&bw, var.i64);
} else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) { } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) {
tbufWriteDouble(&bw, var.dKey); tbufWriteDouble(&bw, var.dKey);
} else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { } else if (type == TSDB_DATA_TYPE_BINARY){
tbufWriteBinary(&bw, var.pz, var.nLen); tbufWriteBinary(&bw, var.pz, var.nLen);
} else if (type == TSDB_DATA_TYPE_NCHAR) {
char *buf = (char *)calloc(1, (var.nLen + 1)*TSDB_NCHAR_SIZE);
if (tVariantDump(&var, buf, type, false) != TSDB_CODE_SUCCESS) {
free(buf);
tVariantDestroy(&var);
break;
}
tbufWriteBinary(&bw, buf, twcslen((wchar_t *)buf) * TSDB_NCHAR_SIZE);
free(buf);
} }
tVariantDestroy(&var); tVariantDestroy(&var);
...@@ -204,9 +223,8 @@ static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType) { ...@@ -204,9 +223,8 @@ static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType) {
if (pVar->nType != TSDB_DATA_TYPE_BINARY) { if (pVar->nType != TSDB_DATA_TYPE_BINARY) {
return -1; return -1;
} }
return 0; SBufferReader br = tbufInitReader(pVar->pz, pVar->nLen, false);
//SBufferReader br = tbufInitReader(pVar->pz, pVar->nLen, false); return colType == TSDB_DATA_TYPE_NCHAR ? 0 : (tbufReadUint32(&br) == colType ? 0: -1);
//return tbufReadUint32(&br) == colType ? 0: -1;
} }
static uint8_t convertOptr(SStrToken *pToken) { static uint8_t convertOptr(SStrToken *pToken) {
...@@ -229,6 +247,7 @@ static uint8_t convertOptr(SStrToken *pToken) { ...@@ -229,6 +247,7 @@ static uint8_t convertOptr(SStrToken *pToken) {
return TSDB_RELATION_EQUAL; return TSDB_RELATION_EQUAL;
case TK_PLUS: case TK_PLUS:
return TSDB_BINARY_OP_ADD; return TSDB_BINARY_OP_ADD;
case TK_MINUS: case TK_MINUS:
return TSDB_BINARY_OP_SUBTRACT; return TSDB_BINARY_OP_SUBTRACT;
case TK_STAR: case TK_STAR:
...@@ -3276,7 +3295,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, ...@@ -3276,7 +3295,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
// TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd
} else if (pExpr->tokenId == TK_IN) { } else if (pExpr->tokenId == TK_IN) {
tVariant *pVal; tVariant *pVal;
if (pRight->tokenId != TK_SET || !serializeExprListToVariant(pRight->pParam, &pVal)) { if (pRight->tokenId != TK_SET || !serializeExprListToVariant(pRight->pParam, &pVal, colType) || colType == TSDB_DATA_TYPE_TIMESTAMP) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
} }
if (validateParamOfRelationIn(pVal, colType) != TSDB_CODE_SUCCESS) { if (validateParamOfRelationIn(pVal, colType) != TSDB_CODE_SUCCESS) {
...@@ -8007,7 +8026,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS ...@@ -8007,7 +8026,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (pSqlExpr->tokenId == TK_SET) { } else if (pSqlExpr->tokenId == TK_SET) {
tVariant *pVal; tVariant *pVal;
if (serializeExprListToVariant(pSqlExpr->pParam, &pVal) == false) { if (serializeExprListToVariant(pSqlExpr->pParam, &pVal, -1) == false) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression"); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression");
} }
*pExpr = calloc(1, sizeof(tExprNode)); *pExpr = calloc(1, sizeof(tExprNode));
......
...@@ -485,7 +485,9 @@ void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) { ...@@ -485,7 +485,9 @@ void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) {
taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy)); taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy));
} else if (type == TSDB_DATA_TYPE_NCHAR) { } else if (type == TSDB_DATA_TYPE_NCHAR) {
size_t t = 0;
const char *val = tbufReadBinary(&br, &t);
taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy));
} }
} }
*q = (void *)pObj; *q = (void *)pObj;
......
...@@ -6956,6 +6956,9 @@ int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfF ...@@ -6956,6 +6956,9 @@ int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfF
void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols) { void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols) {
for (int32_t i = 0; i < numOfFilterCols; ++i) { for (int32_t i = 0; i < numOfFilterCols; ++i) {
if (pFilterInfo[i].numOfFilters > 0) { if (pFilterInfo[i].numOfFilters > 0) {
if (pFilterInfo[i].pFilters->filterInfo.lowerRelOptr == TSDB_RELATION_IN) {
taosHashCleanup((SHashObj *)(pFilterInfo[i].pFilters->q));
}
tfree(pFilterInfo[i].pFilters); tfree(pFilterInfo[i].pFilters);
} }
} }
......
...@@ -269,7 +269,7 @@ bool inOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxv ...@@ -269,7 +269,7 @@ bool inOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxv
} else if (type == TSDB_DATA_TYPE_BINARY) { } else if (type == TSDB_DATA_TYPE_BINARY) {
return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval)); return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval));
} else if (type == TSDB_DATA_TYPE_NCHAR){ } else if (type == TSDB_DATA_TYPE_NCHAR){
return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval)/TSDB_NCHAR_SIZE); return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval));
} }
return false; return false;
......
...@@ -2397,6 +2397,8 @@ static void destroyHelper(void* param) { ...@@ -2397,6 +2397,8 @@ static void destroyHelper(void* param) {
tQueryInfo* pInfo = (tQueryInfo*)param; tQueryInfo* pInfo = (tQueryInfo*)param;
if (pInfo->optr != TSDB_RELATION_IN) { if (pInfo->optr != TSDB_RELATION_IN) {
tfree(pInfo->q); tfree(pInfo->q);
} else {
taosHashCleanup((SHashObj *)(pInfo->q));
} }
free(param); free(param);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册