diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 0bf533d027db284a12ae155dc494fd8f9f35a5f1..7b7c244ba8eb93730adc27714cb55b0ee75b6e35 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;