提交 6ff602ca 编写于 作者: wmmhello's avatar wmmhello

fix var data problems in unique function

上级 a7ae8256
......@@ -5199,8 +5199,12 @@ static bool unique_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pRes
return true;
}
static void do_unique_function(SQLFunctionCtx *pCtx, SUniqueFuncInfo *pInfo, TSKEY timestamp, char *pData, char *tag, int32_t bytes){
UniqueUnit **unique = taosHashGet(*pCtx->pUniqueSet, pData, bytes);
static void do_unique_function(SQLFunctionCtx *pCtx, SUniqueFuncInfo *pInfo, TSKEY timestamp, char *pData, char *tag, int32_t bytes, int16_t type){
int32_t hashKeyBytes = bytes;
if(IS_VAR_DATA_TYPE(type)){
hashKeyBytes = varDataTLen(pData);
}
UniqueUnit **unique = taosHashGet(*pCtx->pUniqueSet, pData, hashKeyBytes);
if (unique == NULL) {
size_t size = sizeof(UniqueUnit) + bytes + pCtx->tagInfo.tagsLen;
char *tmp = pInfo->res + pInfo->num * size;
......@@ -5226,7 +5230,7 @@ static void do_unique_function(SQLFunctionCtx *pCtx, SUniqueFuncInfo *pInfo, TSK
}
}
taosHashPut(*pCtx->pUniqueSet, pData, bytes, &tmp, sizeof(UniqueUnit*));
taosHashPut(*pCtx->pUniqueSet, pData, hashKeyBytes, &tmp, sizeof(UniqueUnit*));
pInfo->num++;
}else if((*unique)->timestamp > timestamp){
(*unique)->timestamp = timestamp;
......@@ -5242,7 +5246,7 @@ static void unique_function(SQLFunctionCtx *pCtx) {
if (pCtx->ptsList != NULL) {
k = GET_TS_DATA(pCtx, i);
}
do_unique_function(pCtx, pInfo, k, pData, NULL, pCtx->inputBytes);
do_unique_function(pCtx, pInfo, k, pData, NULL, pCtx->inputBytes, pCtx->inputType);
if (sizeof(SUniqueFuncInfo) + pInfo->num * (sizeof(UniqueUnit) + pCtx->inputBytes + pCtx->tagInfo.tagsLen) >= MAX_UNIQUE_RESULT_SIZE){
GET_RES_INFO(pCtx)->numOfRes = -1; // mark out of memory
......@@ -5262,7 +5266,7 @@ static void unique_function_merge(SQLFunctionCtx *pCtx) {
TSKEY timestamp = ((UniqueUnit*)tmp)->timestamp;
char *data = tmp + sizeof(UniqueUnit);
char *tags = tmp + sizeof(UniqueUnit) + pCtx->outputBytes;
do_unique_function(pCtx, pOutput, timestamp, data, tags, pCtx->outputBytes);
do_unique_function(pCtx, pOutput, timestamp, data, tags, pCtx->outputBytes, pCtx->outputType);
if (sizeof(SUniqueFuncInfo) + pOutput->num * (sizeof(UniqueUnit) + pCtx->outputBytes + pCtx->tagInfo.tagsLen) >= MAX_UNIQUE_RESULT_SIZE){
GET_RES_INFO(pCtx)->numOfRes = -1; // mark out of memory
......
......@@ -1759,7 +1759,6 @@ static int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t c
// todo refactor, only copy one-by-one
for (int32_t k = start; k < num + start; ++k) {
const char* p = tdGetColDataOfRow(src, k);
memset(dst, 0, bytes);
memcpy(dst, p, varDataTLen(p));
dst += bytes;
}
......@@ -1772,7 +1771,6 @@ static int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t c
char* dst = pData;
for(int32_t k = start; k < num + start; ++k) {
memset(dst, 0, bytes);
setVardataNull(dst, pColInfo->info.type);
dst += bytes;
}
......@@ -1795,7 +1793,6 @@ static int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t c
char* dst = pData;
for(int32_t k = start; k < num + start; ++k) {
memset(pData, 0, pColInfo->info.bytes);
setVardataNull(dst, pColInfo->info.type);
dst += pColInfo->info.bytes;
}
......@@ -1863,7 +1860,6 @@ static void mergeTwoRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity,
} else {
pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes;
}
memset(pData, 0, pColInfo->info.bytes);
int32_t colIdOfRow1;
if(j >= numOfColsOfRow1) {
......@@ -1999,7 +1995,6 @@ static void mergeTwoRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity,
} else {
pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes;
}
memset(pData, 0, pColInfo->info.bytes);
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
setVardataNull(pData, pColInfo->info.type);
......@@ -3155,7 +3150,6 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) {
}
pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;
memset(pData, 0, pColInfo->info.bytes);
if (pTable->lastCols[j].bytes > 0) {
void* value = pTable->lastCols[j].pData;
switch (pColInfo->info.type) {
......@@ -3210,7 +3204,6 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) {
pColInfo = taosArrayGet(pQueryHandle->pColumns, n);
pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;;
memset(pData, 0, pColInfo->info.bytes);
if (pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
*(TSKEY *)pData = pTable->lastCols[j].ts;
continue;
......@@ -3236,7 +3229,6 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) {
if (priKey != TSKEY_INITIAL_VAL) {
pColInfo = taosArrayGet(pQueryHandle->pColumns, priIdx);
pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;
memset(pData, 0, pColInfo->info.bytes);
*(TSKEY *)pData = priKey;
......@@ -3247,7 +3239,6 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) {
pColInfo = taosArrayGet(pQueryHandle->pColumns, n);
pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;;
memset(pData, 0, pColInfo->info.bytes);
assert (pColInfo->info.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册