Merge pull request #14358 from taosdata/refactor/db_precision
refactor(query): function adoption to us/ns db precision
This commit is contained in:
commit
26e6d7ccf7
|
@ -1379,6 +1379,20 @@ static bool validateTimezoneFormat(const SValueNode* pVal) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void static addDbPrecisonParam(SNodeList* pList, uint8_t precision) {
|
||||||
|
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
|
pVal->literal = NULL;
|
||||||
|
pVal->isDuration = false;
|
||||||
|
pVal->translate = true;
|
||||||
|
pVal->node.resType.type = TSDB_DATA_TYPE_TINYINT;
|
||||||
|
pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TINYINT].bytes;
|
||||||
|
pVal->node.resType.precision = precision;
|
||||||
|
pVal->datum.i = (int64_t)precision;
|
||||||
|
pVal->typeData = (int64_t)precision;
|
||||||
|
|
||||||
|
nodesListAppend(pList, (SNode*)pVal);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -1462,6 +1476,9 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||||
|
addDbPrecisonParam(pFunc->pParameterList, dbPrec);
|
||||||
|
|
||||||
pFunc->node.resType =
|
pFunc->node.resType =
|
||||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -1192,10 +1192,10 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
||||||
|
|
||||||
int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
int32_t type = GET_PARAM_TYPE(&pInput[0]);
|
int32_t type = GET_PARAM_TYPE(&pInput[0]);
|
||||||
int32_t timePrec = GET_PARAM_PRECISON(&pInput[0]);
|
|
||||||
|
|
||||||
int64_t timeUnit, timeVal = 0;
|
int64_t timeUnit, timePrec, timeVal = 0;
|
||||||
GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData);
|
GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData);
|
||||||
|
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
||||||
|
|
||||||
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||||
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||||
|
|
Loading…
Reference in New Issue