executil.c 15.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "os.h"
H
Hongze Cheng 已提交
17
#include "tmsg.h"
18
#include "thash.h"
19

20 21
#include "executil.h"
#include "executorimpl.h"
H
Haojun Liao 已提交
22
#include "tcompression.h"
H
Haojun Liao 已提交
23 24 25 26 27 28 29
#include "tlosertree.h"

typedef struct SCompSupporter {
  STableQueryInfo **pTableQueryInfo;
  int32_t          *rowIndex;
  int32_t           order;
} SCompSupporter;
30

H
Haojun Liao 已提交
31
int32_t getOutputInterResultBufSize(STaskAttr* pQueryAttr) {
H
Haojun Liao 已提交
32 33
  int32_t size = 0;

H
Haojun Liao 已提交
34
  for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
35
//    size += pQueryAttr->pExpr1[i].base.interBytes;
H
Haojun Liao 已提交
36 37
  }

H
Haojun Liao 已提交
38
  assert(size >= 0);
H
Haojun Liao 已提交
39 40 41
  return size;
}

42
int32_t initResultRowInfo(SResultRowInfo *pResultRowInfo, int32_t size) {
43 44 45 46
  pResultRowInfo->size       = 0;
  pResultRowInfo->capacity   = size;
  pResultRowInfo->cur.pageId = -1;
  
wafwerar's avatar
wafwerar 已提交
47
  pResultRowInfo->pPosition = taosMemoryCalloc(pResultRowInfo->capacity, sizeof(SResultRowPosition));
H
Haojun Liao 已提交
48
  if (pResultRowInfo->pPosition == NULL) {
B
Bomin Zhang 已提交
49 50
    return TSDB_CODE_QRY_OUT_OF_MEMORY;
  }
51 52 53
  return TSDB_CODE_SUCCESS;
}

H
Haojun Liao 已提交
54
void cleanupResultRowInfo(SResultRowInfo *pResultRowInfo) {
H
Haojun Liao 已提交
55
  if (pResultRowInfo == NULL) {
56 57
    return;
  }
H
Haojun Liao 已提交
58

H
Haojun Liao 已提交
59
  if (pResultRowInfo->capacity == 0) {
H
Haojun Liao 已提交
60
//    assert(pResultRowInfo->pResult == NULL);
61 62
    return;
  }
63

D
dapan1121 已提交
64
  for(int32_t i = 0; i < pResultRowInfo->size; ++i) {
H
Haojun Liao 已提交
65 66 67
//    if (pResultRowInfo->pResult[i]) {
//      taosMemoryFreeClear(pResultRowInfo->pResult[i]->key);
//    }
68
  }
69
  
H
Haojun Liao 已提交
70
  taosMemoryFreeClear(pResultRowInfo->pPosition);
71 72
}

H
Haojun Liao 已提交
73
void resetResultRowInfo(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo) {
H
Haojun Liao 已提交
74
  if (pResultRowInfo == NULL || pResultRowInfo->capacity == 0) {
75 76
    return;
  }
H
Haojun Liao 已提交
77

H
Haojun Liao 已提交
78
  for (int32_t i = 0; i < pResultRowInfo->size; ++i) {
H
Haojun Liao 已提交
79 80
//    SResultRow *pWindowRes = pResultRowInfo->pResult[i];
//    clearResultRow(pRuntimeEnv, pWindowRes);
H
Haojun Liao 已提交
81 82 83 84 85 86

    int32_t groupIndex = 0;
    int64_t uid = 0;

    SET_RES_WINDOW_KEY(pRuntimeEnv->keyBuf, &groupIndex, sizeof(groupIndex), uid);
    taosHashRemove(pRuntimeEnv->pResultRowHashTable, (const char *)pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(sizeof(groupIndex)));
87
  }
88 89

  pResultRowInfo->size     = 0;
90 91
}

H
Haojun Liao 已提交
92
void closeAllResultRows(SResultRowInfo *pResultRowInfo) {
93
// do nothing
94 95
}

H
Haojun Liao 已提交
96 97
bool isResultRowClosed(SResultRow* pRow) {
  return (pRow->closed == true);
98 99
}

H
Haojun Liao 已提交
100 101
void closeResultRow(SResultRow* pResultRow) {
  pResultRow->closed = true;
102 103
}

H
Haojun Liao 已提交
104
// TODO refactor: use macro
105
SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, const int32_t* offset) {
H
Haojun Liao 已提交
106
  assert(index >= 0 && offset != NULL);
H
Haojun Liao 已提交
107
  return (SResultRowEntryInfo*)((char*) pRow->pEntryInfo + offset[index]);
H
Haojun Liao 已提交
108 109
}

110 111 112 113 114 115 116 117
size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
  int32_t rowSize = (numOfOutput * sizeof(SResultRowEntryInfo)) + sizeof(SResultRow);

  for(int32_t i = 0; i < numOfOutput; ++i) {
    rowSize += pCtx[i].resDataInfo.interBufSize;
  }

  return rowSize;
118 119
}

H
Haojun Liao 已提交
120 121 122 123 124 125 126 127
void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) {
  assert(pGroupResInfo != NULL);

  taosArrayDestroy(pGroupResInfo->pRows);
  pGroupResInfo->pRows     = NULL;
  pGroupResInfo->index     = 0;
}

128
static int32_t resultrowComparAsc(const void* p1, const void* p2) {
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  SResKeyPos* pp1 = *(SResKeyPos**) p1;
  SResKeyPos* pp2 = *(SResKeyPos**) p2;

  if (pp1->groupId == pp2->groupId) {
    int64_t pts1 = *(int64_t*) pp1->key;
    int64_t pts2 = *(int64_t*) pp2->key;

    if (pts1 == pts2) {
      return 0;
    } else {
      return pts1 < pts2? -1:1;
    }
  } else {
    return pp1->groupId < pp2->groupId? -1:1;
  }
}

146 147 148 149 150
static int32_t resultrowComparDesc(const void* p1, const void* p2) {
  return resultrowComparAsc(p2, p1);
}

void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, int32_t order) {
H
Haojun Liao 已提交
151 152 153 154
  if (pGroupResInfo->pRows != NULL) {
    taosArrayDestroy(pGroupResInfo->pRows);
  }

155 156 157 158 159 160 161 162 163 164 165 166
  // extract the result rows information from the hash map
  void* pData = NULL;
  pGroupResInfo->pRows = taosArrayInit(10, POINTER_BYTES);

  size_t keyLen = 0;
  while((pData = taosHashIterate(pHashmap, pData)) != NULL) {
    void* key = taosHashGetKey(pData, &keyLen);

    SResKeyPos* p = taosMemoryMalloc(keyLen + sizeof(SResultRowPosition));

    p->groupId = *(uint64_t*) key;
    p->pos = *(SResultRowPosition*) pData;
167
    memcpy(p->key, (char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t));
168 169 170 171

    taosArrayPush(pGroupResInfo->pRows, &p);
  }

172 173 174
  if (order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC) {
    __compar_fn_t fn = (order == TSDB_ORDER_ASC)? resultrowComparAsc:resultrowComparDesc;
    qsort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), POINTER_BYTES, fn);
175 176
  }

H
Haojun Liao 已提交
177
  pGroupResInfo->index = 0;
H
Haojun Liao 已提交
178 179 180
  assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
}

H
Haojun Liao 已提交
181 182
void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList) {
  if (pGroupResInfo->pRows != NULL) {
5
54liuyao 已提交
183
    taosArrayDestroyP(pGroupResInfo->pRows, taosMemoryFree);
H
Haojun Liao 已提交
184 185
  }

186
  pGroupResInfo->pRows = pArrayList;
H
Haojun Liao 已提交
187 188 189 190
  pGroupResInfo->index = 0;
  ASSERT(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
}

191
bool hashRemainDataInGroupInfo(SGroupResInfo* pGroupResInfo) {
H
Haojun Liao 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204
  if (pGroupResInfo->pRows == NULL) {
    return false;
  }

  return pGroupResInfo->index < taosArrayGetSize(pGroupResInfo->pRows);
}

int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) {
  assert(pGroupResInfo != NULL);
  if (pGroupResInfo->pRows == 0) {
    return 0;
  }

H
Haojun Liao 已提交
205
  return (int32_t) taosArrayGetSize(pGroupResInfo->pRows);
H
Haojun Liao 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
}

static int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *param) {
  int32_t left  = *(int32_t *)pLeft;
  int32_t right = *(int32_t *)pRight;

  SCompSupporter *  supporter = (SCompSupporter *)param;

  int32_t leftPos  = supporter->rowIndex[left];
  int32_t rightPos = supporter->rowIndex[right];

  /* left source is exhausted */
  if (leftPos == -1) {
    return 1;
  }

  /* right source is exhausted*/
  if (rightPos == -1) {
    return -1;
  }

H
Haojun Liao 已提交
227
  ASSERT(0);
H
Haojun Liao 已提交
228
  STableQueryInfo** pList = supporter->pTableQueryInfo;
H
Haojun Liao 已提交
229
//  SResultRow* pWindowRes1 = pList[left]->resInfo.pResult[leftPos];
H
Haojun Liao 已提交
230
//  SResultRow * pWindowRes1 = getResultRow(&(pList[left]->resInfo), leftPos);
H
Haojun Liao 已提交
231
//  TSKEY leftTimestamp = pWindowRes1->win.skey;
H
Haojun Liao 已提交
232

H
Haojun Liao 已提交
233 234
//  SResultRowInfo *pWindowResInfo2 = &(pList[right]->resInfo);
//  SResultRow * pWindowRes2 = getResultRow(pWindowResInfo2, rightPos);
H
Haojun Liao 已提交
235 236
//  SResultRow* pWindowRes2 = pList[right]->resInfo.pResult[rightPos];
//  TSKEY rightTimestamp = pWindowRes2->win.skey;
H
Haojun Liao 已提交
237

H
Haojun Liao 已提交
238
//  if (leftTimestamp == rightTimestamp) {
H
Haojun Liao 已提交
239
    return 0;
H
Haojun Liao 已提交
240
//  }
H
Haojun Liao 已提交
241

H
Haojun Liao 已提交
242 243 244 245 246
//  if (supporter->order == TSDB_ORDER_ASC) {
//    return (leftTimestamp > rightTimestamp)? 1:-1;
//  } else {
//    return (leftTimestamp < rightTimestamp)? 1:-1;
//  }
H
Haojun Liao 已提交
247 248
}

249 250 251 252 253
int32_t tsAscOrder(const void* p1, const void* p2) {
  SResultRowCell* pc1 = (SResultRowCell*) p1;
  SResultRowCell* pc2 = (SResultRowCell*) p2;

  if (pc1->groupId == pc2->groupId) {
H
Haojun Liao 已提交
254 255 256 257 258 259
    ASSERT(0);
//    if (pc1->pRow->win.skey == pc2->pRow->win.skey) {
//      return 0;
//    } else {
//      return (pc1->pRow->win.skey < pc2->pRow->win.skey)? -1:1;
//    }
260 261 262 263 264 265 266 267 268 269
  } else {
    return (pc1->groupId < pc2->groupId)? -1:1;
  }
}

int32_t tsDescOrder(const void* p1, const void* p2) {
  SResultRowCell* pc1 = (SResultRowCell*) p1;
  SResultRowCell* pc2 = (SResultRowCell*) p2;

  if (pc1->groupId == pc2->groupId) {
H
Haojun Liao 已提交
270 271 272 273 274 275
    ASSERT(0);
//    if (pc1->pRow->win.skey == pc2->pRow->win.skey) {
//      return 0;
//    } else {
//      return (pc1->pRow->win.skey < pc2->pRow->win.skey)? 1:-1;
//    }
276 277 278 279 280
  } else {
    return (pc1->groupId < pc2->groupId)? -1:1;
  }
}

H
Haojun Liao 已提交
281
void orderTheResultRows(STaskRuntimeEnv* pRuntimeEnv) {
282
  __compar_fn_t  fn = NULL;
283 284 285 286 287
//  if (pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_ASC) {
//    fn = tsAscOrder;
//  } else {
//    fn = tsDescOrder;
//  }
288 289 290 291

  taosArraySort(pRuntimeEnv->pResultRowArrayList, fn);
}

H
Haojun Liao 已提交
292
static int32_t mergeIntoGroupResultImplRv(STaskRuntimeEnv *pRuntimeEnv, SGroupResInfo* pGroupResInfo, uint64_t groupId, int32_t* rowCellInfoOffset) {
293 294 295 296 297 298 299 300 301 302 303
  if (pGroupResInfo->pRows == NULL) {
    pGroupResInfo->pRows = taosArrayInit(100, POINTER_BYTES);
  }

  size_t len = taosArrayGetSize(pRuntimeEnv->pResultRowArrayList);
  for(; pGroupResInfo->position < len; ++pGroupResInfo->position) {
    SResultRowCell* pResultRowCell = taosArrayGet(pRuntimeEnv->pResultRowArrayList, pGroupResInfo->position);
    if (pResultRowCell->groupId != groupId) {
      break;
    }

304

305
    int64_t num = 0;//getNumOfResultWindowRes(pRuntimeEnv, &pResultRowCell->pos, rowCellInfoOffset);
306 307 308 309
    if (num <= 0) {
      continue;
    }

H
Haojun Liao 已提交
310 311
    taosArrayPush(pGroupResInfo->pRows, &pResultRowCell->pos);
//    pResultRowCell->pRow->numOfRows = (uint32_t) num;
312 313 314 315 316
  }

  return TSDB_CODE_SUCCESS;
}

H
Haojun Liao 已提交
317
static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv, SGroupResInfo* pGroupResInfo, SArray *pTableList,
H
Haojun Liao 已提交
318
    int32_t* rowCellInfoOffset) {
319
  bool ascQuery = true;
320
#if 0
H
Haojun Liao 已提交
321 322 323
  int32_t code = TSDB_CODE_SUCCESS;

  int32_t *posList = NULL;
324
  SMultiwayMergeTreeInfo *pTree = NULL;
H
Haojun Liao 已提交
325 326 327 328 329 330 331
  STableQueryInfo **pTableQueryInfoList = NULL;

  size_t size = taosArrayGetSize(pTableList);
  if (pGroupResInfo->pRows == NULL) {
    pGroupResInfo->pRows = taosArrayInit(100, POINTER_BYTES);
  }

wafwerar's avatar
wafwerar 已提交
332 333
  posList = taosMemoryCalloc(size, sizeof(int32_t));
  pTableQueryInfoList = taosMemoryMalloc(POINTER_BYTES * size);
H
Haojun Liao 已提交
334 335

  if (pTableQueryInfoList == NULL || posList == NULL || pGroupResInfo->pRows == NULL || pGroupResInfo->pRows == NULL) {
336
//    qError("QInfo:%"PRIu64" failed alloc memory", GET_TASKID(pRuntimeEnv));
H
Haojun Liao 已提交
337 338 339 340 341 342 343
    code = TSDB_CODE_QRY_OUT_OF_MEMORY;
    goto _end;
  }

  int32_t numOfTables = 0;
  for (int32_t i = 0; i < size; ++i) {
    STableQueryInfo *item = taosArrayGetP(pTableList, i);
344 345 346
//    if (item->resInfo.size > 0) {
//      pTableQueryInfoList[numOfTables++] = item;
//    }
H
Haojun Liao 已提交
347 348 349 350
  }

  // there is no data in current group
  // no need to merge results since only one table in each group
351 352 353
//  if (numOfTables == 0) {
//    goto _end;
//  }
H
Haojun Liao 已提交
354

355 356
  int32_t order = TSDB_ORDER_ASC;
  SCompSupporter cs = {pTableQueryInfoList, posList, order};
H
Haojun Liao 已提交
357

358
  int32_t ret = tMergeTreeCreate(&pTree, numOfTables, &cs, tableResultComparFn);
H
Haojun Liao 已提交
359 360 361 362 363 364 365 366 367
  if (ret != TSDB_CODE_SUCCESS) {
    code = TSDB_CODE_QRY_OUT_OF_MEMORY;
    goto _end;
  }

  int64_t lastTimestamp = ascQuery? INT64_MIN:INT64_MAX;
  int64_t startt = taosGetTimestampMs();

  while (1) {
368
    int32_t tableIndex = tMergeTreeGetChosenIndex(pTree);
H
Haojun Liao 已提交
369 370

    SResultRowInfo *pWindowResInfo = &pTableQueryInfoList[tableIndex]->resInfo;
H
Haojun Liao 已提交
371 372
    ASSERT(0);
    SResultRow  *pWindowRes = NULL;//getResultRow(pBuf, pWindowResInfo, cs.rowIndex[tableIndex]);
H
Haojun Liao 已提交
373

H
Haojun Liao 已提交
374
    int64_t num = 0;//getNumOfResultWindowRes(pRuntimeEnv, pWindowRes, rowCellInfoOffset);
H
Haojun Liao 已提交
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
    if (num <= 0) {
      cs.rowIndex[tableIndex] += 1;

      if (cs.rowIndex[tableIndex] >= pWindowResInfo->size) {
        cs.rowIndex[tableIndex] = -1;
        if (--numOfTables == 0) { // all input sources are exhausted
          break;
        }
      }
    } else {
      assert((pWindowRes->win.skey >= lastTimestamp && ascQuery) || (pWindowRes->win.skey <= lastTimestamp && !ascQuery));

      if (pWindowRes->win.skey != lastTimestamp) {
        taosArrayPush(pGroupResInfo->pRows, &pWindowRes);
        pWindowRes->numOfRows = (uint32_t) num;
      }

      lastTimestamp = pWindowRes->win.skey;

      // move to the next row of current entry
      if ((++cs.rowIndex[tableIndex]) >= pWindowResInfo->size) {
        cs.rowIndex[tableIndex] = -1;

        // all input sources are exhausted
        if ((--numOfTables) == 0) {
          break;
        }
      }
    }

H
Haojun Liao 已提交
405
    tMergeTreeAdjust(pTree, tMergeTreeGetAdjustIndex(pTree));
H
Haojun Liao 已提交
406 407 408 409
  }

  int64_t endt = taosGetTimestampMs();

410
//  qDebug("QInfo:%"PRIx64" result merge completed for group:%d, elapsed time:%" PRId64 " ms", GET_TASKID(pRuntimeEnv),
411
//         pGroupResInfo->currentGroup, endt - startt);
H
Haojun Liao 已提交
412 413

  _end:
wafwerar's avatar
wafwerar 已提交
414 415 416
  taosMemoryFreeClear(pTableQueryInfoList);
  taosMemoryFreeClear(posList);
  taosMemoryFreeClear(pTree);
H
Haojun Liao 已提交
417 418 419 420

  return code;
}

H
Haojun Liao 已提交
421
int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRuntimeEnv, int32_t* offset) {
H
Haojun Liao 已提交
422 423 424
  int64_t st = taosGetTimestampUs();

  while (pGroupResInfo->currentGroup < pGroupResInfo->totalGroup) {
425
    mergeIntoGroupResultImplRv(pRuntimeEnv, pGroupResInfo, pGroupResInfo->currentGroup, offset);
H
Haojun Liao 已提交
426 427 428 429 430 431

    // this group generates at least one result, return results
    if (taosArrayGetSize(pGroupResInfo->pRows) > 0) {
      break;
    }

432
//    qDebug("QInfo:%"PRIu64" no result in group %d, continue", GET_TASKID(pRuntimeEnv), pGroupResInfo->currentGroup);
H
Haojun Liao 已提交
433 434 435 436
    cleanupGroupResInfo(pGroupResInfo);
    incNextGroup(pGroupResInfo);
  }

437
//  int64_t elapsedTime = taosGetTimestampUs() - st;
438
//  qDebug("QInfo:%"PRIu64" merge res data into group, index:%d, total group:%d, elapsed time:%" PRId64 "us", GET_TASKID(pRuntimeEnv),
439
//         pGroupResInfo->currentGroup, pGroupResInfo->totalGroup, elapsedTime);
440
#endif
H
Haojun Liao 已提交
441 442 443

  return TSDB_CODE_SUCCESS;
}
H
Haojun Liao 已提交
444

445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
//void blockDistInfoToBinary(STableBlockDist* pDist, struct SBufferWriter* bw) {
//  tbufWriteUint32(bw, pDist->numOfTables);
//  tbufWriteUint16(bw, pDist->numOfFiles);
//  tbufWriteUint64(bw, pDist->totalSize);
//  tbufWriteUint64(bw, pDist->totalRows);
//  tbufWriteInt32(bw, pDist->maxRows);
//  tbufWriteInt32(bw, pDist->minRows);
//  tbufWriteUint32(bw, pDist->numOfRowsInMemTable);
//  tbufWriteUint32(bw, pDist->numOfSmallBlocks);
//  tbufWriteUint64(bw, taosArrayGetSize(pDist->dataBlockInfos));
//
//  // compress the binary string
//  char* p = TARRAY_GET_START(pDist->dataBlockInfos);
//
//  // compress extra bytes
//  size_t x = taosArrayGetSize(pDist->dataBlockInfos) * pDist->dataBlockInfos->elemSize;
wafwerar's avatar
wafwerar 已提交
461
//  char* tmp = taosMemoryMalloc(x + 2);
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
//
//  bool comp = false;
//  int32_t len = tsCompressString(p, (int32_t)x, 1, tmp, (int32_t)x, ONE_STAGE_COMP, NULL, 0);
//  if (len == -1 || len >= x) { // compress failed, do not compress this binary data
//    comp = false;
//    len = (int32_t)x;
//  } else {
//    comp = true;
//  }
//
//  tbufWriteUint8(bw, comp);
//  tbufWriteUint32(bw, len);
//  if (comp) {
//    tbufWriteBinary(bw, tmp, len);
//  } else {
//    tbufWriteBinary(bw, p, len);
//  }
wafwerar's avatar
wafwerar 已提交
479
//  taosMemoryFreeClear(tmp);
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
//}

//void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDist* pDist) {
//  SBufferReader br = tbufInitReader(data, len, false);
//
//  pDist->numOfTables = tbufReadUint32(&br);
//  pDist->numOfFiles  = tbufReadUint16(&br);
//  pDist->totalSize   = tbufReadUint64(&br);
//  pDist->totalRows   = tbufReadUint64(&br);
//  pDist->maxRows     = tbufReadInt32(&br);
//  pDist->minRows     = tbufReadInt32(&br);
//  pDist->numOfRowsInMemTable = tbufReadUint32(&br);
//  pDist->numOfSmallBlocks = tbufReadUint32(&br);
//  int64_t numSteps = tbufReadUint64(&br);
//
//  bool comp = tbufReadUint8(&br);
//  uint32_t compLen = tbufReadUint32(&br);
//
//  size_t originalLen = (size_t) (numSteps *sizeof(SFileBlockInfo));
//
//  char* outputBuf = NULL;
//  if (comp) {
wafwerar's avatar
wafwerar 已提交
502
//    outputBuf = taosMemoryMalloc(originalLen);
503 504 505 506 507 508 509 510 511 512 513 514 515
//
//    size_t actualLen = compLen;
//    const char* compStr = tbufReadBinary(&br, &actualLen);
//
//    int32_t orignalLen = tsDecompressString(compStr, compLen, 1, outputBuf,
//                                            (int32_t)originalLen , ONE_STAGE_COMP, NULL, 0);
//    assert(orignalLen == numSteps *sizeof(SFileBlockInfo));
//  } else {
//    outputBuf = (char*) tbufReadBinary(&br, &originalLen);
//  }
//
//  pDist->dataBlockInfos = taosArrayFromList(outputBuf, (uint32_t)numSteps, sizeof(SFileBlockInfo));
//  if (comp) {
wafwerar's avatar
wafwerar 已提交
516
//    taosMemoryFreeClear(outputBuf);
517 518
//  }
//}
H
Haojun Liao 已提交
519