未验证 提交 5587eb37 编写于 作者: G Ganlin Zhao 提交者: GitHub

Merge pull request #11993 from taosdata/fix/TD-15172

fix(query): fix bug in multi-input math functions
......@@ -15,7 +15,15 @@ typedef int16_t (*_len_fn)(char *, int32_t);
/** Math functions **/
static double tlog(double v, double base) {
return log(v) / log(base);
double a = log(v);
double b = log(base);
if (isnan(a) || isinf(a)) {
return a;
} else if (isnan(b) || isinf(b)) {
return b;
} else {
return a / b;
}
}
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
......@@ -160,22 +168,64 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S
}
double *out = (double *)pOutputData->pData;
double result;
int32_t numOfRows = MAX(pInput[0].numOfRows, pInput[1].numOfRows);
if (pInput[0].numOfRows == pInput[1].numOfRows) {
for (int32_t i = 0; i < numOfRows; ++i) {
if (colDataIsNull_s(pInputData[0], i) ||
colDataIsNull_s(pInputData[1], i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
result = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, i));
if (isinf(result) || isnan(result)) {
colDataAppendNULL(pOutputData, i);
} else {
out[i] = result;
}
}
} else if (pInput[0].numOfRows == 1) { //left operand is constant
if (colDataIsNull_s(pInputData[0], 0)) {
colDataAppendNNULL(pOutputData, 0, pInput[1].numOfRows);
} else {
for (int32_t i = 0; i < numOfRows; ++i) {
if (colDataIsNull_s(pInputData[1], i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData[0], i) ||
colDataIsNull_s(pInputData[1], 0)) {
colDataAppendNULL(pOutputData, i);
continue;
result = valFn(getValueFn[0](pInputData[0]->pData, 0), getValueFn[1](pInputData[1]->pData, i));
if (isinf(result) || isnan(result)) {
colDataAppendNULL(pOutputData, i);
continue;
}
out[i] = result;
}
}
double result = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, 0));
if (isinf(result) || isnan(result)) {
colDataAppendNULL(pOutputData, i);
} else if (pInput[1].numOfRows == 1) {
if (colDataIsNull_s(pInputData[1], 0)) {
colDataAppendNNULL(pOutputData, 0, pInput[0].numOfRows);
} else {
out[i] = result;
for (int32_t i = 0; i < numOfRows; ++i) {
if (colDataIsNull_s(pInputData[0], i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
result = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, 0));
if (isinf(result) || isnan(result)) {
colDataAppendNULL(pOutputData, i);
continue;
}
out[i] = result;
}
}
}
pOutput->numOfRows = pInput->numOfRows;
pOutput->numOfRows = numOfRows;
return TSDB_CODE_SUCCESS;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册