未验证 提交 72f6b934 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #18108 from taosdata/fix/TD-20366

fix: runtime error (division by zero in builtinsimpl.c)
...@@ -269,7 +269,7 @@ typedef struct SModeInfo { ...@@ -269,7 +269,7 @@ typedef struct SModeInfo {
STuplePos nullTuplePos; STuplePos nullTuplePos;
bool nullTupleSaved; bool nullTupleSaved;
char pItems[]; char pItems[];
} SModeInfo; } SModeInfo;
typedef struct SDerivInfo { typedef struct SDerivInfo {
...@@ -911,7 +911,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { ...@@ -911,7 +911,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
float* plist = (float*)pCol->pData; float* plist = (float*)pCol->pData;
// float val = 0; // float val = 0;
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue; continue;
...@@ -919,9 +919,9 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { ...@@ -919,9 +919,9 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
numOfElem += 1; numOfElem += 1;
pAvgRes->count += 1; pAvgRes->count += 1;
pAvgRes->sum.dsum += plist[i]; pAvgRes->sum.dsum += plist[i];
} }
// pAvgRes->sum.dsum = val; // pAvgRes->sum.dsum = val;
break; break;
} }
...@@ -3011,7 +3011,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) { ...@@ -3011,7 +3011,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
} }
} }
#else #else
int64_t* pts = (int64_t*) pInput->pPTS->pData; int64_t* pts = (int64_t*)pInput->pPTS->pData;
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) { for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) { if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
continue; continue;
...@@ -3115,61 +3115,61 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { ...@@ -3115,61 +3115,61 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
} }
} }
#else #else
if (!pInputCol->hasNull) { if (!pInputCol->hasNull) {
numOfElems = 1; numOfElems = 1;
int32_t round = pInput->numOfRows >> 2; int32_t round = pInput->numOfRows >> 2;
int32_t reminder = pInput->numOfRows & 0x03; int32_t reminder = pInput->numOfRows & 0x03;
int32_t tick = 0; int32_t tick = 0;
for (int32_t i = pInput->startRowIndex; tick < round; i += 4, tick += 1) { for (int32_t i = pInput->startRowIndex; tick < round; i += 4, tick += 1) {
int64_t cts = pts[i]; int64_t cts = pts[i];
int32_t chosen = i; int32_t chosen = i;
if (cts < pts[i + 1]) { if (cts < pts[i + 1]) {
cts = pts[i + 1]; cts = pts[i + 1];
chosen = i + 1; chosen = i + 1;
} }
if (cts < pts[i + 2]) { if (cts < pts[i + 2]) {
cts = pts[i + 2]; cts = pts[i + 2];
chosen = i + 2; chosen = i + 2;
} }
if (cts < pts[i + 3]) { if (cts < pts[i + 3]) {
cts = pts[i + 3]; cts = pts[i + 3];
chosen = i + 3; chosen = i + 3;
} }
if (pResInfo->numOfRes == 0 || pInfo->ts < cts) { if (pResInfo->numOfRes == 0 || pInfo->ts < cts) {
char* data = colDataGetData(pInputCol, chosen); char* data = colDataGetData(pInputCol, chosen);
doSaveCurrentVal(pCtx, i, cts, type, data); doSaveCurrentVal(pCtx, i, cts, type, data);
pResInfo->numOfRes = 1; pResInfo->numOfRes = 1;
}
} }
}
for (int32_t i = pInput->startRowIndex + round * 4; i < pInput->startRowIndex + pInput->numOfRows; ++i) { for (int32_t i = pInput->startRowIndex + round * 4; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) { if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) {
char* data = colDataGetData(pInputCol, i); char* data = colDataGetData(pInputCol, i);
doSaveCurrentVal(pCtx, i, pts[i], type, data); doSaveCurrentVal(pCtx, i, pts[i], type, data);
pResInfo->numOfRes = 1; pResInfo->numOfRes = 1;
} }
}
} else {
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
continue;
} }
} else {
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
continue;
}
numOfElems++; numOfElems++;
if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) { if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) {
char* data = colDataGetData(pInputCol, i); char* data = colDataGetData(pInputCol, i);
doSaveCurrentVal(pCtx, i, pts[i], type, data); doSaveCurrentVal(pCtx, i, pts[i], type, data);
pResInfo->numOfRes = 1; pResInfo->numOfRes = 1;
}
} }
} }
}
#endif #endif
#endif #endif
...@@ -3179,7 +3179,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { ...@@ -3179,7 +3179,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo); firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo);
} }
// SET_VAL(pResInfo, numOfElems, 1); // SET_VAL(pResInfo, numOfElems, 1);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -5280,7 +5280,6 @@ int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { ...@@ -5280,7 +5280,6 @@ int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return pInfo->numSampled; return pInfo->numSampled;
} }
bool getTailFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { bool getTailFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
#if 0 #if 0
SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0); SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
...@@ -6077,11 +6076,19 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { ...@@ -6077,11 +6076,19 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t row = 0; int32_t row = 0;
char st[256] = {0}; char st[256] = {0};
double totalRawSize = pData->totalRows * pData->rowSize; double averageSize = 0;
if (pData->numOfBlocks != 0) {
averageSize = ((double)pData->totalSize) / pData->numOfBlocks;
}
uint64_t totalRawSize = pData->totalRows * pData->rowSize;
double compRatio = 0;
if (totalRawSize != 0) {
compRatio = pData->totalSize * 100 / (double)totalRawSize;
}
int32_t len = sprintf(st + VARSTR_HEADER_SIZE, int32_t len = sprintf(st + VARSTR_HEADER_SIZE,
"Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c]", "Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c]",
pData->numOfBlocks, pData->totalSize / 1024.0, ((double)pData->totalSize) / pData->numOfBlocks, pData->numOfBlocks, pData->totalSize / 1024.0, averageSize, compRatio, '%');
pData->totalSize * 100 / totalRawSize, '%');
varDataSetLen(st, len); varDataSetLen(st, len);
colDataAppend(pColInfo, row++, st, false); colDataAppend(pColInfo, row++, st, false);
......
...@@ -321,7 +321,7 @@ ...@@ -321,7 +321,7 @@
,,y,script,./test.sh -f tsim/compress/compress.sim ,,y,script,./test.sh -f tsim/compress/compress.sim
,,y,script,./test.sh -f tsim/compress/uncompress.sim ,,y,script,./test.sh -f tsim/compress/uncompress.sim
,,y,script,./test.sh -f tsim/compute/avg.sim ,,y,script,./test.sh -f tsim/compute/avg.sim
,,,script,./test.sh -f tsim/compute/block_dist.sim ,,y,script,./test.sh -f tsim/compute/block_dist.sim
,,y,script,./test.sh -f tsim/compute/bottom.sim ,,y,script,./test.sh -f tsim/compute/bottom.sim
,,y,script,./test.sh -f tsim/compute/count.sim ,,y,script,./test.sh -f tsim/compute/count.sim
,,y,script,./test.sh -f tsim/compute/diff.sim ,,y,script,./test.sh -f tsim/compute/diff.sim
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册