From 64184611d7e35c1aa84e59a91640e6b380e6b811 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 30 Mar 2022 14:03:54 +0800 Subject: [PATCH] [TD-14241]: ltrim/rtrim function adoption --- source/libs/scalar/src/sclfunc.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index e6eb3c43b4..9f481c8fb2 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -533,18 +533,32 @@ int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; + //allocate output buf + if (pOutputData->pData == NULL) { + int32_t outputLen = pInputData->varmeta.length; + setVarTypeOutputBuf(pOutputData, outputLen, GET_PARAM_TYPE(pInput)); + } + + char *input = pInputData->pData; + char *output = pOutputData->pData; + + int32_t offset = 0; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_f(pInputData->nullbitmap, i)) { colDataSetNull_f(pOutputData->nullbitmap, i); continue; } - char *in = pInputData->pData + i * GET_PARAM_BYTES(pInput); - char *out = pOutputData->pData + i * GET_PARAM_BYTES(pInput); - - int32_t len = varDataLen(in); + int32_t len = varDataLen(input); int32_t charLen = (type == TSDB_DATA_TYPE_VARCHAR) ? len : len / TSDB_NCHAR_SIZE; - trimFn(in, out, type, charLen); + trimFn(input, output, type, charLen); + + varDataSetLen(output, len); + input += varDataTLen(input); + output += varDataTLen(output); + + pOutputData->varmeta.offset[i] = offset; + offset += len + VARSTR_HEADER_SIZE; } pOutput->numOfRows = pInput->numOfRows; -- GitLab