From 1710eb5b112541887d9932616c07bb9f27ea835b Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Mon, 29 Nov 2021 09:38:45 +0800 Subject: [PATCH] implement concat_ws that follow mysql --- src/common/src/texpr.c | 31 +++++++++---------- .../general/parser/scalar_expression.sim | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 941ce1ddcc..0fe99ac540 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -1180,28 +1180,27 @@ void vectorConcatWs(int16_t functionId, tExprOperandInfo* pInputs, int32_t numIn outputData = pOutput->data + i * pOutput->bytes; - bool hasNullInputs = false; - for (int j = 0; j < numInputs; ++j) { - if (isNull(inputData[j], pInputs[j].type)) { - hasNullInputs = true; - setNull(outputData, pOutput->type, pOutput->bytes); - } + if (isNull(inputData[0], pInputs[0].type)) { + setNull(outputData, pOutput->type, pOutput->bytes); + continue; } - if (!hasNullInputs) { - int16_t dataLen = 0; - for (int j = 1; j < numInputs; ++j) { - memcpy(((char*)varDataVal(outputData))+dataLen, varDataVal(inputData[j]), varDataLen(inputData[j])); - dataLen += varDataLen(inputData[j]); - if (j < numInputs - 1) { - memcpy(((char*)varDataVal(outputData))+dataLen, varDataVal(inputData[0]), varDataLen(inputData[0])); - dataLen += varDataLen(inputData[0]); - } + int16_t dataLen = 0; + for (int j = 1; j < numInputs; ++j) { + if (isNull(inputData[j], pInputs[j].type)) { + continue; + } + memcpy(((char*)varDataVal(outputData))+dataLen, varDataVal(inputData[j]), varDataLen(inputData[j])); + dataLen += varDataLen(inputData[j]); + if (j < numInputs - 1) { + memcpy(((char*)varDataVal(outputData))+dataLen, varDataVal(inputData[0]), varDataLen(inputData[0])); + dataLen += varDataLen(inputData[0]); } - varDataSetLen(outputData, dataLen); } + varDataSetLen(outputData, dataLen); } + free(inputData); } diff --git a/tests/script/general/parser/scalar_expression.sim b/tests/script/general/parser/scalar_expression.sim index 73847d9845..cc266d4489 100644 --- a/tests/script/general/parser/scalar_expression.sim +++ b/tests/script/general/parser/scalar_expression.sim @@ -230,6 +230,7 @@ sql_error select cos(c1) from $stb state_window(f1) sql_error select pow(c2,2) from $stb interval(1s) sliding(500a) sql_error select pow(c2,2) from $stb state_window(f1) sql_error select tan(f1) from $stb from d.st slimit 1 +sql_error select f1+2, tbname from $stb group by tbname print =============== clear sql drop database $db sql show databases -- GitLab