executorTests.cpp 58.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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 <gtest/gtest.h>
#include <iostream>

S
Shengliang Guan 已提交
19 20
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
21 22 23 24 25
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h"

26 27 28
#include "tglobal.h"
#include "executorimpl.h"
#include "function.h"
29 30 31
#include "taos.h"
#include "tdef.h"
#include "tvariant.h"
H
Haojun Liao 已提交
32
#include "tdatablock.h"
33 34 35
#include "trpc.h"
#include "stub.h"
#include "executor.h"
D
dapan1121 已提交
36 37
#include "tmsg.h"
#include "tname.h"
38

H
Haojun Liao 已提交
39 40
namespace {

H
Haojun Liao 已提交
41 42 43 44 45 46
enum {
  data_rand = 0x1,
  data_asc  = 0x2,
  data_desc = 0x3,
};

H
Haojun Liao 已提交
47
typedef struct SDummyInputInfo {
48 49 50 51 52
  int32_t      totalPages;     // numOfPages
  int32_t      current;
  int32_t      startVal;
  int32_t      type;
  int32_t      numOfRowsPerPage;
H
Haojun Liao 已提交
53 54
  int32_t      numOfCols;      // number of columns
  int64_t      tsStart;
H
Haojun Liao 已提交
55 56 57 58 59 60
  SSDataBlock* pBlock;
} SDummyInputInfo;

SSDataBlock* getDummyBlock(void* param, bool* newgroup) {
  SOperatorInfo* pOperator = static_cast<SOperatorInfo*>(param);
  SDummyInputInfo* pInfo = static_cast<SDummyInputInfo*>(pOperator->info);
61
  if (pInfo->current >= pInfo->totalPages) {
H
Haojun Liao 已提交
62 63 64 65 66 67 68 69 70 71 72 73
    return NULL;
  }

  if (pInfo->pBlock == NULL) {
    pInfo->pBlock = static_cast<SSDataBlock*>(calloc(1, sizeof(SSDataBlock)));

    pInfo->pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData));

    SColumnInfoData colInfo = {0};
    colInfo.info.type = TSDB_DATA_TYPE_INT;
    colInfo.info.bytes = sizeof(int32_t);
    colInfo.info.colId = 1;
74 75
    colInfo.pData = static_cast<char*>(calloc(pInfo->numOfRowsPerPage, sizeof(int32_t)));
    colInfo.nullbitmap = static_cast<char*>(calloc(1, (pInfo->numOfRowsPerPage + 7) / 8));
H
Haojun Liao 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo);

//    SColumnInfoData colInfo1 = {0};
//    colInfo1.info.type = TSDB_DATA_TYPE_BINARY;
//    colInfo1.info.bytes = 40;
//    colInfo1.info.colId = 2;
//
//    colInfo1.varmeta.allocLen = 0;//numOfRows * sizeof(int32_t);
//    colInfo1.varmeta.length = 0;
//    colInfo1.varmeta.offset = static_cast<int32_t*>(calloc(1, numOfRows * sizeof(int32_t)));
//
//    taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1);
  } else {
    blockDataClearup(pInfo->pBlock, true);
  }

  SSDataBlock* pBlock = pInfo->pBlock;

  char buf[128] = {0};
  char b1[128] = {0};
H
Haojun Liao 已提交
97
  int32_t v = 0;
98
  for(int32_t i = 0; i < pInfo->numOfRowsPerPage; ++i) {
H
Haojun Liao 已提交
99 100
    SColumnInfoData* pColInfo = static_cast<SColumnInfoData*>(TARRAY_GET_ELEM(pBlock->pDataBlock, 0));

H
Haojun Liao 已提交
101 102 103 104 105 106 107 108
    if (pInfo->type == data_desc) {
      v = (--pInfo->startVal);
    } else if (pInfo->type == data_asc) {
      v = ++pInfo->startVal;
    } else if (pInfo->type == data_rand) {
      v = random();
    }

H
Haojun Liao 已提交
109 110 111 112 113 114 115 116 117
    colDataAppend(pColInfo, i, reinterpret_cast<const char*>(&v), false);

//    sprintf(buf, "this is %d row", i);
//    STR_TO_VARSTR(b1, buf);
//
//    SColumnInfoData* pColInfo2 = static_cast<SColumnInfoData*>(TARRAY_GET_ELEM(pBlock->pDataBlock, 1));
//    colDataAppend(pColInfo2, i, b1, false);
  }

118
  pBlock->info.rows = pInfo->numOfRowsPerPage;
H
Haojun Liao 已提交
119 120 121 122
  pBlock->info.numOfCols = 1;

  pInfo->current += 1;
  return pBlock;
123 124
}

H
Haojun Liao 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
SSDataBlock* get2ColsDummyBlock(void* param, bool* newgroup) {
  SOperatorInfo* pOperator = static_cast<SOperatorInfo*>(param);
  SDummyInputInfo* pInfo = static_cast<SDummyInputInfo*>(pOperator->info);
  if (pInfo->current >= pInfo->totalPages) {
    return NULL;
  }

  if (pInfo->pBlock == NULL) {
    pInfo->pBlock = static_cast<SSDataBlock*>(calloc(1, sizeof(SSDataBlock)));

    pInfo->pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData));

    SColumnInfoData colInfo = {0};
    colInfo.info.type = TSDB_DATA_TYPE_TIMESTAMP;
    colInfo.info.bytes = sizeof(int64_t);
    colInfo.info.colId = 1;
    colInfo.pData = static_cast<char*>(calloc(pInfo->numOfRowsPerPage, sizeof(int64_t)));
//    colInfo.nullbitmap = static_cast<char*>(calloc(1, (pInfo->numOfRowsPerPage + 7) / 8));

    taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo);

    SColumnInfoData colInfo1 = {0};
    colInfo1.info.type = TSDB_DATA_TYPE_INT;
    colInfo1.info.bytes = 4;
    colInfo1.info.colId = 2;

    colInfo1.pData = static_cast<char*>(calloc(pInfo->numOfRowsPerPage, sizeof(int32_t)));
    colInfo1.nullbitmap = static_cast<char*>(calloc(1, (pInfo->numOfRowsPerPage + 7) / 8));

    taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1);
  } else {
    blockDataClearup(pInfo->pBlock, false);
  }

  SSDataBlock* pBlock = pInfo->pBlock;

  char buf[128] = {0};
  char b1[128] = {0};
  int64_t ts = 0;
  int32_t v  = 0;
  for(int32_t i = 0; i < pInfo->numOfRowsPerPage; ++i) {
    SColumnInfoData* pColInfo = static_cast<SColumnInfoData*>(TARRAY_GET_ELEM(pBlock->pDataBlock, 0));

    ts = (++pInfo->tsStart);
    colDataAppend(pColInfo, i, reinterpret_cast<const char*>(&ts), false);

    SColumnInfoData* pColInfo1 = static_cast<SColumnInfoData*>(TARRAY_GET_ELEM(pBlock->pDataBlock, 1));
    if (pInfo->type == data_desc) {
      v = (--pInfo->startVal);
    } else if (pInfo->type == data_asc) {
      v = ++pInfo->startVal;
    } else if (pInfo->type == data_rand) {
      v = random();
    }

    colDataAppend(pColInfo1, i, reinterpret_cast<const char*>(&v), false);

//    sprintf(buf, "this is %d row", i);
//    STR_TO_VARSTR(b1, buf);
//
//    SColumnInfoData* pColInfo2 = static_cast<SColumnInfoData*>(TARRAY_GET_ELEM(pBlock->pDataBlock, 1));
//    colDataAppend(pColInfo2, i, b1, false);
  }

  pBlock->info.rows = pInfo->numOfRowsPerPage;
  pBlock->info.numOfCols = 1;

  pInfo->current += 1;

  blockDataUpdateTsWindow(pBlock);
  return pBlock;

}

SOperatorInfo* createDummyOperator(int32_t startVal, int32_t numOfBlocks, int32_t rowsPerPage, int32_t type, int32_t numOfCols) {
H
Haojun Liao 已提交
200 201
  SOperatorInfo* pOperator = static_cast<SOperatorInfo*>(calloc(1, sizeof(SOperatorInfo)));
  pOperator->name = "dummyInputOpertor4Test";
H
Haojun Liao 已提交
202 203

  if (numOfCols == 1) {
H
Haojun Liao 已提交
204
    pOperator->nextDataFn = getDummyBlock;
H
Haojun Liao 已提交
205
  } else {
H
Haojun Liao 已提交
206
    pOperator->nextDataFn = get2ColsDummyBlock;
H
Haojun Liao 已提交
207
  }
H
Haojun Liao 已提交
208 209

  SDummyInputInfo *pInfo = (SDummyInputInfo*) calloc(1, sizeof(SDummyInputInfo));
210 211 212 213
  pInfo->totalPages = numOfBlocks;
  pInfo->startVal   = startVal;
  pInfo->numOfRowsPerPage = rowsPerPage;
  pInfo->type       = type;
H
Haojun Liao 已提交
214
  pInfo->tsStart    = 1620000000000;
H
Haojun Liao 已提交
215 216 217 218 219

  pOperator->info = pInfo;
  return pOperator;
}
}
220 221 222 223 224 225 226
int main(int argc, char** argv) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

TEST(testCase, build_executor_tree_Test) {
  const char* msg = "{\n"
H
Haojun Liao 已提交
227
      "    \"NodeType\": \"48\",\n"
H
Haojun Liao 已提交
228 229 230 231 232 233 234 235
      "    \"Name\": \"PhysiSubplan\",\n"
      "    \"PhysiSubplan\": {\n"
      "        \"Id\": {\n"
      "            \"QueryId\": \"0\",\n"
      "            \"TemplateId\": \"0\",\n"
      "            \"SubplanId\": \"0\"\n"
      "        },\n"
      "        \"SubplanType\": \"0\",\n"
H
Haojun Liao 已提交
236
      "        \"MsgType\": \"515\",\n"
H
Haojun Liao 已提交
237 238
      "        \"Level\": \"0\",\n"
      "        \"NodeAddr\": {\n"
H
Haojun Liao 已提交
239
      "            \"Id\": \"1\",\n"
H
Haojun Liao 已提交
240
      "            \"InUse\": \"0\",\n"
H
Haojun Liao 已提交
241 242 243 244 245 246 247
      "            \"NumOfEps\": \"1\",\n"
      "            \"Eps\": [\n"
      "                {\n"
      "                    \"Fqdn\": \"node1\",\n"
      "                    \"Port\": \"6030\"\n"
      "                }\n"
      "            ]\n"
H
Haojun Liao 已提交
248 249
      "        },\n"
      "        \"RootNode\": {\n"
H
Haojun Liao 已提交
250
      "            \"NodeType\": \"41\",\n"
H
Haojun Liao 已提交
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
      "            \"Name\": \"PhysiProject\",\n"
      "            \"PhysiProject\": {\n"
      "                \"OutputDataBlockDesc\": {\n"
      "                    \"NodeType\": \"19\",\n"
      "                    \"Name\": \"TupleDesc\",\n"
      "                    \"TupleDesc\": {\n"
      "                        \"DataBlockId\": \"1\",\n"
      "                        \"Slots\": [\n"
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"0\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"9\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
273
      "                            },\n"
H
Haojun Liao 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"1\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"4\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"4\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
288
      "                            },\n"
H
Haojun Liao 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301 302
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"2\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"8\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"20\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
303
      "                            },\n"
H
Haojun Liao 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316 317
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"3\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"5\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
318
      "                            },\n"
H
Haojun Liao 已提交
319 320 321 322 323 324 325 326 327 328 329 330 331 332
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"4\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"7\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
333
      "                            },\n"
H
Haojun Liao 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"5\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"7\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
      "                            }\n"
      "                        ]\n"
      "                    }\n"
      "                },\n"
      "                \"Children\": [\n"
H
Haojun Liao 已提交
353
      "                    {\n"
H
Haojun Liao 已提交
354
      "                        \"NodeType\": \"38\",\n"
H
Haojun Liao 已提交
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
      "                        \"Name\": \"PhysiTableScan\",\n"
      "                        \"PhysiTableScan\": {\n"
      "                            \"OutputDataBlockDesc\": {\n"
      "                                \"NodeType\": \"19\",\n"
      "                                \"Name\": \"TupleDesc\",\n"
      "                                \"TupleDesc\": {\n"
      "                                    \"DataBlockId\": \"0\",\n"
      "                                    \"Slots\": [\n"
      "                                        {\n"
      "                                            \"NodeType\": \"20\",\n"
      "                                            \"Name\": \"SlotDesc\",\n"
      "                                            \"SlotDesc\": {\n"
      "                                                \"SlotId\": \"0\",\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"9\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"Reserve\": false,\n"
      "                                                \"Output\": true\n"
      "                                            }\n"
      "                                        },\n"
      "                                        {\n"
      "                                            \"NodeType\": \"20\",\n"
      "                                            \"Name\": \"SlotDesc\",\n"
      "                                            \"SlotDesc\": {\n"
      "                                                \"SlotId\": \"1\",\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"4\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"4\"\n"
      "                                                },\n"
      "                                                \"Reserve\": false,\n"
      "                                                \"Output\": true\n"
      "                                            }\n"
      "                                        },\n"
      "                                        {\n"
      "                                            \"NodeType\": \"20\",\n"
      "                                            \"Name\": \"SlotDesc\",\n"
      "                                            \"SlotDesc\": {\n"
      "                                                \"SlotId\": \"2\",\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"8\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"20\"\n"
      "                                                },\n"
      "                                                \"Reserve\": false,\n"
      "                                                \"Output\": true\n"
      "                                            }\n"
      "                                        },\n"
      "                                        {\n"
      "                                            \"NodeType\": \"20\",\n"
      "                                            \"Name\": \"SlotDesc\",\n"
      "                                            \"SlotDesc\": {\n"
      "                                                \"SlotId\": \"3\",\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"5\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"Reserve\": false,\n"
      "                                                \"Output\": true\n"
      "                                            }\n"
      "                                        },\n"
      "                                        {\n"
      "                                            \"NodeType\": \"20\",\n"
      "                                            \"Name\": \"SlotDesc\",\n"
      "                                            \"SlotDesc\": {\n"
      "                                                \"SlotId\": \"4\",\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"7\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"Reserve\": false,\n"
      "                                                \"Output\": true\n"
      "                                            }\n"
      "                                        },\n"
      "                                        {\n"
      "                                            \"NodeType\": \"20\",\n"
      "                                            \"Name\": \"SlotDesc\",\n"
      "                                            \"SlotDesc\": {\n"
      "                                                \"SlotId\": \"5\",\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"7\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"Reserve\": false,\n"
      "                                                \"Output\": true\n"
      "                                            }\n"
      "                                        }\n"
      "                                    ]\n"
      "                                }\n"
H
Haojun Liao 已提交
455
      "                            },\n"
H
Haojun Liao 已提交
456
      "                            \"ScanCols\": [\n"
H
Haojun Liao 已提交
457
      "                                {\n"
H
Haojun Liao 已提交
458 459 460 461
      "                                    \"NodeType\": \"18\",\n"
      "                                    \"Name\": \"Target\",\n"
      "                                    \"Target\": {\n"
      "                                        \"DataBlockId\": \"0\",\n"
H
Haojun Liao 已提交
462
      "                                        \"SlotId\": \"0\",\n"
H
Haojun Liao 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
      "                                        \"Expr\": {\n"
      "                                            \"NodeType\": \"1\",\n"
      "                                            \"Name\": \"Column\",\n"
      "                                            \"Column\": {\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"9\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"AliasName\": \"ts\",\n"
      "                                                \"TableId\": \"0\",\n"
      "                                                \"ColId\": \"1\",\n"
      "                                                \"ColType\": \"1\",\n"
      "                                                \"DbName\": \"test\",\n"
      "                                                \"TableName\": \"t1\",\n"
      "                                                \"TableAlias\": \"t1\",\n"
      "                                                \"ColName\": \"ts\",\n"
      "                                                \"DataBlockId\": \"0\",\n"
      "                                                \"SlotId\": \"0\"\n"
      "                                            }\n"
      "                                        }\n"
H
Haojun Liao 已提交
485 486 487
      "                                    }\n"
      "                                },\n"
      "                                {\n"
H
Haojun Liao 已提交
488 489 490 491
      "                                    \"NodeType\": \"18\",\n"
      "                                    \"Name\": \"Target\",\n"
      "                                    \"Target\": {\n"
      "                                        \"DataBlockId\": \"0\",\n"
H
Haojun Liao 已提交
492
      "                                        \"SlotId\": \"1\",\n"
H
Haojun Liao 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
      "                                        \"Expr\": {\n"
      "                                            \"NodeType\": \"1\",\n"
      "                                            \"Name\": \"Column\",\n"
      "                                            \"Column\": {\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"4\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"4\"\n"
      "                                                },\n"
      "                                                \"AliasName\": \"c1\",\n"
      "                                                \"TableId\": \"0\",\n"
      "                                                \"ColId\": \"2\",\n"
      "                                                \"ColType\": \"1\",\n"
      "                                                \"DbName\": \"test\",\n"
      "                                                \"TableName\": \"t1\",\n"
      "                                                \"TableAlias\": \"t1\",\n"
      "                                                \"ColName\": \"c1\",\n"
      "                                                \"DataBlockId\": \"0\",\n"
      "                                                \"SlotId\": \"0\"\n"
      "                                            }\n"
      "                                        }\n"
H
Haojun Liao 已提交
515 516 517
      "                                    }\n"
      "                                },\n"
      "                                {\n"
H
Haojun Liao 已提交
518 519 520 521
      "                                    \"NodeType\": \"18\",\n"
      "                                    \"Name\": \"Target\",\n"
      "                                    \"Target\": {\n"
      "                                        \"DataBlockId\": \"0\",\n"
H
Haojun Liao 已提交
522
      "                                        \"SlotId\": \"2\",\n"
H
Haojun Liao 已提交
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
      "                                        \"Expr\": {\n"
      "                                            \"NodeType\": \"1\",\n"
      "                                            \"Name\": \"Column\",\n"
      "                                            \"Column\": {\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"8\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"20\"\n"
      "                                                },\n"
      "                                                \"AliasName\": \"c2\",\n"
      "                                                \"TableId\": \"0\",\n"
      "                                                \"ColId\": \"3\",\n"
      "                                                \"ColType\": \"1\",\n"
      "                                                \"DbName\": \"test\",\n"
      "                                                \"TableName\": \"t1\",\n"
      "                                                \"TableAlias\": \"t1\",\n"
      "                                                \"ColName\": \"c2\",\n"
      "                                                \"DataBlockId\": \"0\",\n"
      "                                                \"SlotId\": \"0\"\n"
      "                                            }\n"
      "                                        }\n"
H
Haojun Liao 已提交
545 546 547
      "                                    }\n"
      "                                },\n"
      "                                {\n"
H
Haojun Liao 已提交
548 549 550 551
      "                                    \"NodeType\": \"18\",\n"
      "                                    \"Name\": \"Target\",\n"
      "                                    \"Target\": {\n"
      "                                        \"DataBlockId\": \"0\",\n"
H
Haojun Liao 已提交
552
      "                                        \"SlotId\": \"3\",\n"
H
Haojun Liao 已提交
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
      "                                        \"Expr\": {\n"
      "                                            \"NodeType\": \"1\",\n"
      "                                            \"Name\": \"Column\",\n"
      "                                            \"Column\": {\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"5\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"AliasName\": \"c3\",\n"
      "                                                \"TableId\": \"0\",\n"
      "                                                \"ColId\": \"4\",\n"
      "                                                \"ColType\": \"1\",\n"
      "                                                \"DbName\": \"test\",\n"
      "                                                \"TableName\": \"t1\",\n"
      "                                                \"TableAlias\": \"t1\",\n"
      "                                                \"ColName\": \"c3\",\n"
      "                                                \"DataBlockId\": \"0\",\n"
      "                                                \"SlotId\": \"0\"\n"
      "                                            }\n"
      "                                        }\n"
H
Haojun Liao 已提交
575 576 577
      "                                    }\n"
      "                                },\n"
      "                                {\n"
H
Haojun Liao 已提交
578 579 580 581
      "                                    \"NodeType\": \"18\",\n"
      "                                    \"Name\": \"Target\",\n"
      "                                    \"Target\": {\n"
      "                                        \"DataBlockId\": \"0\",\n"
H
Haojun Liao 已提交
582
      "                                        \"SlotId\": \"4\",\n"
H
Haojun Liao 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
      "                                        \"Expr\": {\n"
      "                                            \"NodeType\": \"1\",\n"
      "                                            \"Name\": \"Column\",\n"
      "                                            \"Column\": {\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"7\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"AliasName\": \"c4\",\n"
      "                                                \"TableId\": \"0\",\n"
      "                                                \"ColId\": \"5\",\n"
      "                                                \"ColType\": \"1\",\n"
      "                                                \"DbName\": \"test\",\n"
      "                                                \"TableName\": \"t1\",\n"
      "                                                \"TableAlias\": \"t1\",\n"
      "                                                \"ColName\": \"c4\",\n"
      "                                                \"DataBlockId\": \"0\",\n"
      "                                                \"SlotId\": \"0\"\n"
      "                                            }\n"
      "                                        }\n"
H
Haojun Liao 已提交
605 606 607
      "                                    }\n"
      "                                },\n"
      "                                {\n"
H
Haojun Liao 已提交
608 609 610 611
      "                                    \"NodeType\": \"18\",\n"
      "                                    \"Name\": \"Target\",\n"
      "                                    \"Target\": {\n"
      "                                        \"DataBlockId\": \"0\",\n"
H
Haojun Liao 已提交
612
      "                                        \"SlotId\": \"5\",\n"
H
Haojun Liao 已提交
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
      "                                        \"Expr\": {\n"
      "                                            \"NodeType\": \"1\",\n"
      "                                            \"Name\": \"Column\",\n"
      "                                            \"Column\": {\n"
      "                                                \"DataType\": {\n"
      "                                                    \"Type\": \"7\",\n"
      "                                                    \"Precision\": \"0\",\n"
      "                                                    \"Scale\": \"0\",\n"
      "                                                    \"Bytes\": \"8\"\n"
      "                                                },\n"
      "                                                \"AliasName\": \"c5\",\n"
      "                                                \"TableId\": \"0\",\n"
      "                                                \"ColId\": \"6\",\n"
      "                                                \"ColType\": \"1\",\n"
      "                                                \"DbName\": \"test\",\n"
      "                                                \"TableName\": \"t1\",\n"
      "                                                \"TableAlias\": \"t1\",\n"
      "                                                \"ColName\": \"c5\",\n"
      "                                                \"DataBlockId\": \"0\",\n"
      "                                                \"SlotId\": \"0\"\n"
      "                                            }\n"
      "                                        }\n"
H
Haojun Liao 已提交
635 636
      "                                    }\n"
      "                                }\n"
H
Haojun Liao 已提交
637 638 639 640 641 642 643 644 645
      "                            ],\n"
      "                            \"TableId\": \"1\",\n"
      "                            \"TableType\": \"3\",\n"
      "                            \"ScanOrder\": \"1\",\n"
      "                            \"ScanCount\": \"1\",\n"
      "                            \"ReverseScanCount\": \"0\",\n"
      "                            \"ScanFlag\": \"0\",\n"
      "                            \"StartKey\": \"-9223372036854775808\",\n"
      "                            \"EndKey\": \"9223372036854775807\"\n"
H
Haojun Liao 已提交
646
      "                        }\n"
H
Haojun Liao 已提交
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
      "                    }\n"
      "                ],\n"
      "                \"Projections\": [\n"
      "                    {\n"
      "                        \"NodeType\": \"18\",\n"
      "                        \"Name\": \"Target\",\n"
      "                        \"Target\": {\n"
      "                            \"DataBlockId\": \"1\",\n"
      "                            \"SlotId\": \"0\",\n"
      "                            \"Expr\": {\n"
      "                                \"NodeType\": \"1\",\n"
      "                                \"Name\": \"Column\",\n"
      "                                \"Column\": {\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"9\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"AliasName\": \"ts\",\n"
      "                                    \"TableId\": \"0\",\n"
      "                                    \"ColId\": \"1\",\n"
      "                                    \"ColType\": \"1\",\n"
      "                                    \"DbName\": \"test\",\n"
      "                                    \"TableName\": \"t1\",\n"
      "                                    \"TableAlias\": \"t1\",\n"
      "                                    \"ColName\": \"ts\",\n"
      "                                    \"DataBlockId\": \"0\",\n"
      "                                    \"SlotId\": \"0\"\n"
H
Haojun Liao 已提交
676 677
      "                                }\n"
      "                            }\n"
H
Haojun Liao 已提交
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
      "                        }\n"
      "                    },\n"
      "                    {\n"
      "                        \"NodeType\": \"18\",\n"
      "                        \"Name\": \"Target\",\n"
      "                        \"Target\": {\n"
      "                            \"DataBlockId\": \"1\",\n"
      "                            \"SlotId\": \"1\",\n"
      "                            \"Expr\": {\n"
      "                                \"NodeType\": \"1\",\n"
      "                                \"Name\": \"Column\",\n"
      "                                \"Column\": {\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"4\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"4\"\n"
      "                                    },\n"
      "                                    \"AliasName\": \"c1\",\n"
      "                                    \"TableId\": \"0\",\n"
      "                                    \"ColId\": \"2\",\n"
      "                                    \"ColType\": \"1\",\n"
      "                                    \"DbName\": \"test\",\n"
      "                                    \"TableName\": \"t1\",\n"
      "                                    \"TableAlias\": \"t1\",\n"
      "                                    \"ColName\": \"c1\",\n"
      "                                    \"DataBlockId\": \"0\",\n"
      "                                    \"SlotId\": \"1\"\n"
H
Haojun Liao 已提交
706 707
      "                                }\n"
      "                            }\n"
H
Haojun Liao 已提交
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
      "                        }\n"
      "                    },\n"
      "                    {\n"
      "                        \"NodeType\": \"18\",\n"
      "                        \"Name\": \"Target\",\n"
      "                        \"Target\": {\n"
      "                            \"DataBlockId\": \"1\",\n"
      "                            \"SlotId\": \"2\",\n"
      "                            \"Expr\": {\n"
      "                                \"NodeType\": \"1\",\n"
      "                                \"Name\": \"Column\",\n"
      "                                \"Column\": {\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"8\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"20\"\n"
      "                                    },\n"
      "                                    \"AliasName\": \"c2\",\n"
      "                                    \"TableId\": \"0\",\n"
      "                                    \"ColId\": \"3\",\n"
      "                                    \"ColType\": \"1\",\n"
      "                                    \"DbName\": \"test\",\n"
      "                                    \"TableName\": \"t1\",\n"
      "                                    \"TableAlias\": \"t1\",\n"
      "                                    \"ColName\": \"c2\",\n"
      "                                    \"DataBlockId\": \"0\",\n"
      "                                    \"SlotId\": \"2\"\n"
H
Haojun Liao 已提交
736 737
      "                                }\n"
      "                            }\n"
H
Haojun Liao 已提交
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
      "                        }\n"
      "                    },\n"
      "                    {\n"
      "                        \"NodeType\": \"18\",\n"
      "                        \"Name\": \"Target\",\n"
      "                        \"Target\": {\n"
      "                            \"DataBlockId\": \"1\",\n"
      "                            \"SlotId\": \"3\",\n"
      "                            \"Expr\": {\n"
      "                                \"NodeType\": \"1\",\n"
      "                                \"Name\": \"Column\",\n"
      "                                \"Column\": {\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"5\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"AliasName\": \"c3\",\n"
      "                                    \"TableId\": \"0\",\n"
      "                                    \"ColId\": \"4\",\n"
      "                                    \"ColType\": \"1\",\n"
      "                                    \"DbName\": \"test\",\n"
      "                                    \"TableName\": \"t1\",\n"
      "                                    \"TableAlias\": \"t1\",\n"
      "                                    \"ColName\": \"c3\",\n"
      "                                    \"DataBlockId\": \"0\",\n"
      "                                    \"SlotId\": \"3\"\n"
H
Haojun Liao 已提交
766 767
      "                                }\n"
      "                            }\n"
H
Haojun Liao 已提交
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
      "                        }\n"
      "                    },\n"
      "                    {\n"
      "                        \"NodeType\": \"18\",\n"
      "                        \"Name\": \"Target\",\n"
      "                        \"Target\": {\n"
      "                            \"DataBlockId\": \"1\",\n"
      "                            \"SlotId\": \"4\",\n"
      "                            \"Expr\": {\n"
      "                                \"NodeType\": \"1\",\n"
      "                                \"Name\": \"Column\",\n"
      "                                \"Column\": {\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"7\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"AliasName\": \"c4\",\n"
      "                                    \"TableId\": \"0\",\n"
      "                                    \"ColId\": \"5\",\n"
      "                                    \"ColType\": \"1\",\n"
      "                                    \"DbName\": \"test\",\n"
      "                                    \"TableName\": \"t1\",\n"
      "                                    \"TableAlias\": \"t1\",\n"
      "                                    \"ColName\": \"c4\",\n"
      "                                    \"DataBlockId\": \"0\",\n"
      "                                    \"SlotId\": \"4\"\n"
H
Haojun Liao 已提交
796 797
      "                                }\n"
      "                            }\n"
H
Haojun Liao 已提交
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
      "                        }\n"
      "                    },\n"
      "                    {\n"
      "                        \"NodeType\": \"18\",\n"
      "                        \"Name\": \"Target\",\n"
      "                        \"Target\": {\n"
      "                            \"DataBlockId\": \"1\",\n"
      "                            \"SlotId\": \"5\",\n"
      "                            \"Expr\": {\n"
      "                                \"NodeType\": \"1\",\n"
      "                                \"Name\": \"Column\",\n"
      "                                \"Column\": {\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"7\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"AliasName\": \"c5\",\n"
      "                                    \"TableId\": \"0\",\n"
      "                                    \"ColId\": \"6\",\n"
      "                                    \"ColType\": \"1\",\n"
      "                                    \"DbName\": \"test\",\n"
      "                                    \"TableName\": \"t1\",\n"
      "                                    \"TableAlias\": \"t1\",\n"
      "                                    \"ColName\": \"c5\",\n"
      "                                    \"DataBlockId\": \"0\",\n"
      "                                    \"SlotId\": \"5\"\n"
H
Haojun Liao 已提交
826 827 828 829
      "                                }\n"
      "                            }\n"
      "                        }\n"
      "                    }\n"
H
Haojun Liao 已提交
830 831 832 833
      "                ]\n"
      "            }\n"
      "        },\n"
      "        \"DataSink\": {\n"
H
Haojun Liao 已提交
834
      "            \"NodeType\": \"46\",\n"
H
Haojun Liao 已提交
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
      "            \"Name\": \"PhysiDispatch\",\n"
      "            \"PhysiDispatch\": {\n"
      "                \"InputDataBlockDesc\": {\n"
      "                    \"NodeType\": \"19\",\n"
      "                    \"Name\": \"TupleDesc\",\n"
      "                    \"TupleDesc\": {\n"
      "                        \"DataBlockId\": \"1\",\n"
      "                        \"Slots\": [\n"
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"0\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"9\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
857
      "                            },\n"
H
Haojun Liao 已提交
858 859 860 861 862 863 864 865 866 867 868 869 870 871
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"1\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"4\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"4\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
872
      "                            },\n"
H
Haojun Liao 已提交
873 874 875 876 877 878 879 880 881 882 883 884 885 886
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"2\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"8\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"20\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
887
      "                            },\n"
H
Haojun Liao 已提交
888 889 890 891 892 893 894 895 896 897 898 899 900 901
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"3\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"5\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
902
      "                            },\n"
H
Haojun Liao 已提交
903 904 905 906 907 908 909 910 911 912 913 914 915 916
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"4\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"7\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
H
Haojun Liao 已提交
917
      "                            },\n"
H
Haojun Liao 已提交
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
      "                            {\n"
      "                                \"NodeType\": \"20\",\n"
      "                                \"Name\": \"SlotDesc\",\n"
      "                                \"SlotDesc\": {\n"
      "                                    \"SlotId\": \"5\",\n"
      "                                    \"DataType\": {\n"
      "                                        \"Type\": \"7\",\n"
      "                                        \"Precision\": \"0\",\n"
      "                                        \"Scale\": \"0\",\n"
      "                                        \"Bytes\": \"8\"\n"
      "                                    },\n"
      "                                    \"Reserve\": false,\n"
      "                                    \"Output\": false\n"
      "                                }\n"
      "                            }\n"
      "                        ]\n"
H
Haojun Liao 已提交
934 935 936
      "                    }\n"
      "                }\n"
      "            }\n"
H
Haojun Liao 已提交
937
      "        }\n"
H
Haojun Liao 已提交
938 939
      "    }\n"
      "}";
940 941

  SExecTaskInfo* pTaskInfo = nullptr;
D
dapan1121 已提交
942
  DataSinkHandle sinkHandle = nullptr;
H
Haojun Liao 已提交
943 944
  SReadHandle handle = {.reader = reinterpret_cast<void*>(0x1), .meta = reinterpret_cast<void*>(0x1)};

H
Haojun Liao 已提交
945 946 947 948 949 950
  struct SSubplan *plan = NULL;
  int32_t code = qStringToSubplan(msg, &plan);
  ASSERT_EQ(code, 0);

  code = qCreateExecTask(&handle, 2, 1, plan, (void**) &pTaskInfo, &sinkHandle);
  ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
951 952
}

H
Haojun Liao 已提交
953
#if 0
X
Xiaoyu Wang 已提交
954

H
Haojun Liao 已提交
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
TEST(testCase, inMem_sort_Test) {
  SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
  SOrder o = {.order = TSDB_ORDER_ASC};
  o.col.info.colId = 1;
  o.col.info.type = TSDB_DATA_TYPE_INT;
  taosArrayPush(pOrderVal, &o);

  SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo));
  SExprInfo *exp = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
  exp->base.resSchema = createSchema(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1, "res");
  taosArrayPush(pExprInfo, &exp);

  SExprInfo *exp1 = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
  exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1");
  taosArrayPush(pExprInfo, &exp1);

H
Haojun Liao 已提交
971
  SOperatorInfo* pOperator = createOrderOperatorInfo(createDummyOperator(10000, 5, 1000, data_asc, 1), pExprInfo, pOrderVal, NULL);
H
Haojun Liao 已提交
972 973

  bool newgroup = false;
H
Haojun Liao 已提交
974
  SSDataBlock* pRes = pOperator->nextDataFn(pOperator, &newgroup);
H
Haojun Liao 已提交
975 976 977 978

  SColumnInfoData* pCol1 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 0));
  SColumnInfoData* pCol2 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 1));
  for(int32_t i = 0; i < pRes->info.rows; ++i) {
979
    char* p = colDataGetData(pCol2, i);
H
Haojun Liao 已提交
980 981 982 983 984
    printf("%d: %d, %s\n", i, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p));
  }
}

#endif
H
Haojun Liao 已提交
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003

typedef struct su {
  int32_t v;
  char   *c;
} su;

int32_t cmp(const void* p1, const void* p2) {
  su* v1 = (su*) p1;
  su* v2 = (su*) p2;

  int32_t x1 = *(int32_t*) v1->c;
  int32_t x2 = *(int32_t*) v2->c;
  if (x1 == x2) {
    return 0;
  } else {
    return x1 < x2? -1:1;
  }
}

X
Xiaoyu Wang 已提交
1004
#if 0
H
Haojun Liao 已提交
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
TEST(testCase, external_sort_Test) {
#if 0
  su* v = static_cast<su*>(calloc(1000000, sizeof(su)));
  for(int32_t i = 0; i < 1000000; ++i) {
    v[i].v = rand();
    v[i].c = static_cast<char*>(malloc(4));
    *(int32_t*) v[i].c = i;
  }

  qsort(v, 1000000, sizeof(su), cmp);
//  for(int32_t i = 0; i < 1000; ++i) {
//    printf("%d ", v[i]);
//  }
//  printf("\n");
  return;
#endif

  srand(time(NULL));

  SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
  SOrder o = {0};
  o.order = TSDB_ORDER_ASC;
  o.col.info.colId = 1;
  o.col.info.type = TSDB_DATA_TYPE_INT;
  taosArrayPush(pOrderVal, &o);

  SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo));
  SExprInfo *exp = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
  exp->base.resSchema = createSchema(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1, "res");
  taosArrayPush(pExprInfo, &exp);

  SExprInfo *exp1 = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
  exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1");
//  taosArrayPush(pExprInfo, &exp1);

H
Haojun Liao 已提交
1040
  SOperatorInfo* pOperator = createOrderOperatorInfo(createDummyOperator(10000, 1500, 1000, data_desc, 1), pExprInfo, pOrderVal, NULL);
H
Haojun Liao 已提交
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051

  bool newgroup = false;
  SSDataBlock* pRes = NULL;

  int32_t total = 1;

  int64_t s1 = taosGetTimestampUs();
  int32_t t = 1;

  while(1) {
    int64_t s = taosGetTimestampUs();
H
Haojun Liao 已提交
1052
    pRes = pOperator->nextDataFn(pOperator, &newgroup);
H
Haojun Liao 已提交
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062

    int64_t e = taosGetTimestampUs();
    if (t++ == 1) {
      printf("---------------elapsed:%ld\n", e - s);
    }

    if (pRes == NULL) {
      break;
    }

H
Haojun Liao 已提交
1063
    SColumnInfoData* pCol1 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 0));
H
Haojun Liao 已提交
1064
//    SColumnInfoData* pCol2 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 1));
H
Haojun Liao 已提交
1065
    for (int32_t i = 0; i < pRes->info.rows; ++i) {
1066
//      char* p = colDataGetData(pCol2, i);
H
Haojun Liao 已提交
1067
      printf("%d: %d\n", total++, ((int32_t*)pCol1->pData)[i]);
H
Haojun Liao 已提交
1068
//      printf("%d: %d, %s\n", total++, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p));
H
Haojun Liao 已提交
1069
    }
H
Haojun Liao 已提交
1070 1071 1072 1073 1074
  }

  int64_t s2 = taosGetTimestampUs();
  printf("total:%ld\n", s2 - s1);

H
Haojun Liao 已提交
1075
  pOperator->closeFn(pOperator->info, 2);
H
Haojun Liao 已提交
1076 1077 1078 1079 1080
  tfree(exp);
  tfree(exp1);
  taosArrayDestroy(pExprInfo);
  taosArrayDestroy(pOrderVal);
}
H
Haojun Liao 已提交
1081

H
Haojun Liao 已提交
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
TEST(testCase, sorted_merge_Test) {
  srand(time(NULL));

  SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
  SOrder o = {0};
  o.order = TSDB_ORDER_ASC;
  o.col.info.colId = 1;
  o.col.info.type = TSDB_DATA_TYPE_INT;
  taosArrayPush(pOrderVal, &o);

  SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo));
  SExprInfo *exp = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
1094 1095 1096 1097 1098 1099
  exp->base.resSchema = createSchema(TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 1, "count_result");
  exp->base.pColumns = static_cast<SColumn*>(calloc(1, sizeof(SColumn)));
  exp->base.pColumns->flag = TSDB_COL_NORMAL;
  exp->base.pColumns->info = (SColumnInfo) {.colId = 1, .type = TSDB_DATA_TYPE_INT, .bytes = 4};
  exp->base.numOfCols = 1;

H
Haojun Liao 已提交
1100 1101 1102 1103 1104 1105
  taosArrayPush(pExprInfo, &exp);

  SExprInfo *exp1 = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
  exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BINARY, 40, 2, "res1");
//  taosArrayPush(pExprInfo, &exp1);

H
Haojun Liao 已提交
1106 1107 1108
  int32_t numOfSources = 10;
  SOperatorInfo** plist = (SOperatorInfo**) calloc(numOfSources, sizeof(void*));
  for(int32_t i = 0; i < numOfSources; ++i) {
H
Haojun Liao 已提交
1109
    plist[i] = createDummyOperator(1, 1, 1, data_asc, 1);
H
Haojun Liao 已提交
1110 1111
  }

1112
  SOperatorInfo* pOperator = createSortedMergeOperatorInfo(plist, numOfSources, pExprInfo, pOrderVal, NULL, NULL);
H
Haojun Liao 已提交
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123

  bool newgroup = false;
  SSDataBlock* pRes = NULL;

  int32_t total = 1;

  int64_t s1 = taosGetTimestampUs();
  int32_t t = 1;

  while(1) {
    int64_t s = taosGetTimestampUs();
H
Haojun Liao 已提交
1124
    pRes = pOperator->nextDataFn(pOperator, &newgroup);
H
Haojun Liao 已提交
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137

    int64_t e = taosGetTimestampUs();
    if (t++ == 1) {
      printf("---------------elapsed:%ld\n", e - s);
    }

    if (pRes == NULL) {
      break;
    }

    SColumnInfoData* pCol1 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 0));
//    SColumnInfoData* pCol2 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 1));
    for (int32_t i = 0; i < pRes->info.rows; ++i) {
1138 1139
//      char* p = colDataGetData(pCol2, i);
      printf("%d: %ld\n", total++, ((int64_t*)pCol1->pData)[i]);
H
Haojun Liao 已提交
1140 1141 1142 1143 1144 1145 1146
//      printf("%d: %d, %s\n", total++, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p));
    }
  }

  int64_t s2 = taosGetTimestampUs();
  printf("total:%ld\n", s2 - s1);

H
Haojun Liao 已提交
1147
  pOperator->closeFn(pOperator->info, 2);
H
Haojun Liao 已提交
1148 1149 1150 1151 1152
  tfree(exp);
  tfree(exp1);
  taosArrayDestroy(pExprInfo);
  taosArrayDestroy(pOrderVal);
}
H
Haojun Liao 已提交
1153

H
Haojun Liao 已提交
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
TEST(testCase, time_interval_Operator_Test) {
  srand(time(NULL));

  SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
  SOrder o = {0};
  o.order = TSDB_ORDER_ASC;
  o.col.info.colId = 1;
  o.col.info.type = TSDB_DATA_TYPE_INT;
  taosArrayPush(pOrderVal, &o);

  SArray* pExprInfo = taosArrayInit(4, sizeof(SExprInfo));
  SExprInfo *exp = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
  exp->base.resSchema = createSchema(TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 1, "ts");
  exp->base.pColumns = static_cast<SColumn*>(calloc(1, sizeof(SColumn)));
  exp->base.pColumns->flag = TSDB_COL_NORMAL;
  exp->base.pColumns->info = (SColumnInfo) {.colId = 1, .type = TSDB_DATA_TYPE_TIMESTAMP, .bytes = 8};
  exp->base.numOfCols = 1;

  taosArrayPush(pExprInfo, &exp);

  SExprInfo *exp1 = static_cast<SExprInfo*>(calloc(1, sizeof(SExprInfo)));
  exp1->base.resSchema = createSchema(TSDB_DATA_TYPE_BIGINT, 8, 2, "res1");
  exp1->base.pColumns = static_cast<SColumn*>(calloc(1, sizeof(SColumn)));
  exp1->base.pColumns->flag = TSDB_COL_NORMAL;
  exp1->base.pColumns->info = (SColumnInfo) {.colId = 1, .type = TSDB_DATA_TYPE_INT, .bytes = 4};
  exp1->base.numOfCols = 1;

  taosArrayPush(pExprInfo, &exp1);

  SOperatorInfo* p = createDummyOperator(1, 1, 2000, data_asc, 2);

  SExecTaskInfo ti = {0};
1186 1187 1188 1189 1190
  SInterval interval = {0};
  interval.sliding = interval.interval = 1000;
  interval.slidingUnit = interval.intervalUnit = 'a';

  SOperatorInfo* pOperator = createIntervalOperatorInfo(p, pExprInfo, &interval, &ti);
H
Haojun Liao 已提交
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201

  bool newgroup = false;
  SSDataBlock* pRes = NULL;

  int32_t total = 1;

  int64_t s1 = taosGetTimestampUs();
  int32_t t = 1;

  while(1) {
    int64_t s = taosGetTimestampUs();
H
Haojun Liao 已提交
1202
    pRes = pOperator->nextDataFn(pOperator, &newgroup);
H
Haojun Liao 已提交
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220

    int64_t e = taosGetTimestampUs();
    if (t++ == 1) {
      printf("---------------elapsed:%ld\n", e - s);
    }

    if (pRes == NULL) {
      break;
    }

    SColumnInfoData* pCol1 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 0));
//    SColumnInfoData* pCol2 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 1));
    for (int32_t i = 0; i < pRes->info.rows; ++i) {
//      char* p = colDataGetData(pCol2, i);
      printf("%d: %ld\n", total++, ((int64_t*)pCol1->pData)[i]);
//      printf("%d: %d, %s\n", total++, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p));
    }
  }
H
Haojun Liao 已提交
1221 1222 1223 1224

  int64_t s2 = taosGetTimestampUs();
  printf("total:%ld\n", s2 - s1);

H
Haojun Liao 已提交
1225
  pOperator->closeFn(pOperator->info, 2);
H
Haojun Liao 已提交
1226 1227 1228 1229 1230
  tfree(exp);
  tfree(exp1);
  taosArrayDestroy(pExprInfo);
  taosArrayDestroy(pOrderVal);
}
X
Xiaoyu Wang 已提交
1231
#endif
H
Haojun Liao 已提交
1232

L
Liu Jicong 已提交
1233
#pragma GCC diagnostic pop