提交 148b9034 编写于 作者: D dapan1121

[TD-10932]fix double to int64 issue

上级 6265dd45
......@@ -50,6 +50,47 @@ typedef struct {
#define TSDB_DATA_TYPE_POINTER_ARRAY (1000)
#define TSDB_DATA_TYPE_VALUE_ARRAY (1001)
#define COPY_DATA(dst, src) *((int64_t *)(dst)) = *((int64_t *)(src))
#define COPY_TYPED_DATA(_v, _type, _data) \
do { \
switch (_type) { \
case TSDB_DATA_TYPE_BOOL: \
case TSDB_DATA_TYPE_TINYINT: \
(*(int8_t *)_v) = GET_INT8_VAL(_data); \
break; \
case TSDB_DATA_TYPE_UTINYINT: \
(*(uint8_t *)_v) = GET_UINT8_VAL(_data); \
break; \
case TSDB_DATA_TYPE_SMALLINT: \
(*(int16_t *)_v) = GET_INT16_VAL(_data); \
break; \
case TSDB_DATA_TYPE_USMALLINT: \
(*(uint16_t *)_v) = GET_UINT16_VAL(_data); \
break; \
case TSDB_DATA_TYPE_TIMESTAMP: \
case TSDB_DATA_TYPE_BIGINT: \
(*(int64_t *)_v) = (GET_INT64_VAL(_data)); \
break; \
case TSDB_DATA_TYPE_UBIGINT: \
(*(uint64_t *)_v) = (GET_UINT64_VAL(_data)); \
break; \
case TSDB_DATA_TYPE_FLOAT: \
(*(float *)_v) = GET_FLOAT_VAL(_data); \
break; \
case TSDB_DATA_TYPE_DOUBLE: \
(*(double *)_v) = GET_DOUBLE_VAL(_data); \
break; \
case TSDB_DATA_TYPE_UINT: \
(*(uint32_t *)_v) = GET_UINT32_VAL(_data); \
break; \
default: \
(*(int32_t *)_v) = GET_INT32_VAL(_data); \
break; \
} \
} while (0)
#define GET_TYPED_DATA(_v, _finalType, _type, _data) \
do { \
switch (_type) { \
......
......@@ -3913,11 +3913,11 @@ static void interp_function(SQLFunctionCtx *pCtx) {
if (pCtx->start.key == pCtx->startTs) {
assert(pCtx->start.key != INT64_MIN);
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->start.val);
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val);
goto interp_success_exit;
} else if (pCtx->end.key == pCtx->startTs && pCtx->end.key != INT64_MIN && fillType == TSDB_FILL_NEXT) {
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->end.val);
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val);
goto interp_success_exit;
}
......@@ -3936,6 +3936,9 @@ static void interp_function(SQLFunctionCtx *pCtx) {
|| pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) {
goto interp_exit;
}
GET_TYPED_DATA(pCtx->start.val, double, pCtx->inputType, &pCtx->start.val);
GET_TYPED_DATA(pCtx->end.val, double, pCtx->inputType, &pCtx->end.val);
SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val};
SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val};
......@@ -3954,7 +3957,7 @@ static void interp_function(SQLFunctionCtx *pCtx) {
goto interp_exit;
}
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->start.val);
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val);
break;
case TSDB_FILL_NEXT:
......@@ -3962,7 +3965,7 @@ static void interp_function(SQLFunctionCtx *pCtx) {
goto interp_exit;
}
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->end.val);
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val);
break;
case TSDB_FILL_NONE:
......
......@@ -1260,13 +1260,12 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
if (functionId == TSDB_FUNC_INTERP) {
if (type == RESULT_ROW_START_INTERP) {
if (prevRowIndex == -1) {
GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pRuntimeEnv->prevRow[index]);
COPY_DATA(&pCtx[k].start.val, (char *)pRuntimeEnv->prevRow[index]);
} else {
GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes);
COPY_DATA(&pCtx[k].start.val, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes);
}
pCtx[k].start.key = prevTs;
pCtx[k].start.val = v1;
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
if (prevRowIndex == -1) {
......@@ -1278,13 +1277,12 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
} else {
if (curRowIndex == -1) {
GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pRuntimeEnv->prevRow[index]);
COPY_DATA(&pCtx[k].end.val, pRuntimeEnv->prevRow[index]);
} else {
GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes);
COPY_DATA(&pCtx[k].end.val, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes);
}
pCtx[k].end.key = curTs;
pCtx[k].end.val = v2;
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
pCtx[k].end.ptr = (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册