Merge pull request #11993 from taosdata/fix/TD-15172
fix(query): fix bug in multi-input math functions
This commit is contained in:
commit
5587eb375c
|
@ -15,7 +15,15 @@ typedef int16_t (*_len_fn)(char *, int32_t);
|
||||||
|
|
||||||
/** Math functions **/
|
/** Math functions **/
|
||||||
static double tlog(double v, double base) {
|
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) {
|
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 *out = (double *)pOutputData->pData;
|
||||||
|
double result;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
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) ||
|
if (colDataIsNull_s(pInputData[0], i) ||
|
||||||
colDataIsNull_s(pInputData[1], 0)) {
|
colDataIsNull_s(pInputData[1], i)) {
|
||||||
colDataAppendNULL(pOutputData, i);
|
colDataAppendNULL(pOutputData, i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
double result = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, 0));
|
result = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, i));
|
||||||
if (isinf(result) || isnan(result)) {
|
if (isinf(result) || isnan(result)) {
|
||||||
colDataAppendNULL(pOutputData, i);
|
colDataAppendNULL(pOutputData, i);
|
||||||
} else {
|
} else {
|
||||||
out[i] = result;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
pOutput->numOfRows = pInput->numOfRows;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (pInput[1].numOfRows == 1) {
|
||||||
|
if (colDataIsNull_s(pInputData[1], 0)) {
|
||||||
|
colDataAppendNNULL(pOutputData, 0, pInput[0].numOfRows);
|
||||||
|
} else {
|
||||||
|
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 = numOfRows;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue