From 583bbf26c580d68b10317971c5b9c0f5a2c2e354 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 17 Mar 2021 12:02:01 +0800 Subject: [PATCH] [td-3338]: query data before 1970-1-1 00:00:00 caused taosd crash. --- src/tsdb/src/tsdbRead.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 0bf533d027..7b7c244ba8 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1021,6 +1021,14 @@ static int32_t doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SBlock* pBloc pBlock->numOfRows = pCols->numOfRows; + // Convert from TKEY to TSKEY for primary timestamp column if current block has timestamp before 1970-01-01T00:00:00Z + if(pBlock->keyFirst < 0 && colIds[0] == PRIMARYKEY_TIMESTAMP_COL_INDEX) { + int64_t* src = pCols->cols[0].pData; + for(int32_t i = 0; i < pBlock->numOfRows; ++i) { + src[i] = tdGetKey(src[i]); + } + } + int64_t elapsedTime = (taosGetTimestampUs() - st); pQueryHandle->cost.blockLoadTime += elapsedTime; @@ -1277,13 +1285,7 @@ int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t capacity } if (pColInfo->info.colId == src->colId) { - - if (pColInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP) { - for (int32_t n = 0; n < num; n++) { - TKEY tkey = *(TKEY *)((char*)src->pData + bytes * start + n * sizeof(TKEY)); - *(TSKEY *)(pData + n * sizeof(TSKEY)) = tdGetKey(tkey); - } - } else if (pColInfo->info.type != TSDB_DATA_TYPE_BINARY && pColInfo->info.type != TSDB_DATA_TYPE_NCHAR) { + if (pColInfo->info.type != TSDB_DATA_TYPE_BINARY && pColInfo->info.type != TSDB_DATA_TYPE_NCHAR) { memmove(pData, (char*)src->pData + bytes * start, bytes * num); } else { // handle the var-string char* dst = pData; -- GitLab