fix(query): set proper ltrim/rtrim result schema bytes
TD-18431
This commit is contained in:
parent
c0bd39cdc7
commit
4c654f8a17
|
@ -192,6 +192,24 @@ static bool validateTimezoneFormat(const SValueNode* pVal) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t countTrailingSpaces(const SValueNode* pVal, bool isLtrim) {
|
||||||
|
int32_t numOfSpaces = 0;
|
||||||
|
int32_t len = varDataLen(pVal->datum.p);
|
||||||
|
char* str = varDataVal(pVal->datum.p);
|
||||||
|
|
||||||
|
int32_t startPos = isLtrim ? 0 : len - 1;
|
||||||
|
int32_t step = isLtrim ? 1 : -1;
|
||||||
|
for (int32_t i = startPos; i < len || i >= 0; i + step) {
|
||||||
|
if (!isspace(str[i])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
numOfSpaces++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return numOfSpaces;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void static addTimezoneParam(SNodeList* pList) {
|
void static addTimezoneParam(SNodeList* pList) {
|
||||||
char buf[6] = {0};
|
char buf[6] = {0};
|
||||||
time_t t = taosTime(NULL);
|
time_t t = taosTime(NULL);
|
||||||
|
@ -293,6 +311,37 @@ static int32_t translateInOutStr(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t translateTrimStr(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isLtrim) {
|
||||||
|
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
|
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
|
if (!IS_VAR_DATA_TYPE(pPara1->resType.type)) {
|
||||||
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t numOfSpaces = 0;
|
||||||
|
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
|
if (nodeType(pParamNode1) != QUERY_NODE_VALUE) {
|
||||||
|
SValueNode* pValue = (SValueNode*)pParamNode1;
|
||||||
|
numOfSpaces = countTrailingSpaces(pValue, isLtrim);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t resBytes = pPara1->resType.bytes - numOfSpaces;
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = resBytes, .type = pPara1->resType.type};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateLtrim(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
return translateTrimStr(pFunc, pErrBuf, len, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateRtrim(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
return translateTrimStr(pFunc, pErrBuf, len, false);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateLogarithm(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
static int32_t translateLogarithm(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||||
if (1 != numOfParams && 2 != numOfParams) {
|
if (1 != numOfParams && 2 != numOfParams) {
|
||||||
|
|
Loading…
Reference in New Issue