nodesCloneFuncs.c 30.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

X
Xiaoyu Wang 已提交
16
#include "nodesUtil.h"
17
#include "plannodes.h"
X
Xiaoyu Wang 已提交
18 19
#include "querynodes.h"
#include "taos.h"
X
Xiaoyu Wang 已提交
20
#include "taoserror.h"
wmmhello's avatar
wmmhello 已提交
21
#include "tdatablock.h"
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#define COPY_SCALAR_FIELD(fldname)     \
  do {                                 \
    (pDst)->fldname = (pSrc)->fldname; \
  } while (0)

#define COPY_CHAR_ARRAY_FIELD(fldname)        \
  do {                                        \
    strcpy((pDst)->fldname, (pSrc)->fldname); \
  } while (0)

#define COPY_OBJECT_FIELD(fldname, size)                  \
  do {                                                    \
    memcpy(&((pDst)->fldname), &((pSrc)->fldname), size); \
  } while (0)

38 39 40 41 42
#define COPY_CHAR_POINT_FIELD(fldname)             \
  do {                                             \
    if (NULL == (pSrc)->fldname) {                 \
      break;                                       \
    }                                              \
43
    (pDst)->fldname = taosStrdup((pSrc)->fldname); \
44 45 46
    if (NULL == (pDst)->fldname) {                 \
      return TSDB_CODE_OUT_OF_MEMORY;              \
    }                                              \
X
Xiaoyu Wang 已提交
47
  } while (0)
X
Xiaoyu Wang 已提交
48

X
Xiaoyu Wang 已提交
49 50 51 52 53
#define CLONE_NODE_FIELD(fldname)                      \
  do {                                                 \
    if (NULL == (pSrc)->fldname) {                     \
      break;                                           \
    }                                                  \
X
Xiaoyu Wang 已提交
54
    (pDst)->fldname = nodesCloneNode((pSrc)->fldname); \
X
Xiaoyu Wang 已提交
55
    if (NULL == (pDst)->fldname) {                     \
56
      return TSDB_CODE_OUT_OF_MEMORY;                  \
X
Xiaoyu Wang 已提交
57 58 59
    }                                                  \
  } while (0)

60 61 62 63 64 65 66
#define CLONE_NODE_FIELD_EX(fldname, nodePtrType)                           \
  do {                                                                      \
    if (NULL == (pSrc)->fldname) {                                          \
      break;                                                                \
    }                                                                       \
    (pDst)->fldname = (nodePtrType)nodesCloneNode((SNode*)(pSrc)->fldname); \
    if (NULL == (pDst)->fldname) {                                          \
67
      return TSDB_CODE_OUT_OF_MEMORY;                                       \
68 69 70
    }                                                                       \
  } while (0)

X
Xiaoyu Wang 已提交
71 72 73 74 75
#define CLONE_NODE_LIST_FIELD(fldname)                 \
  do {                                                 \
    if (NULL == (pSrc)->fldname) {                     \
      break;                                           \
    }                                                  \
X
Xiaoyu Wang 已提交
76
    (pDst)->fldname = nodesCloneList((pSrc)->fldname); \
X
Xiaoyu Wang 已提交
77
    if (NULL == (pDst)->fldname) {                     \
78
      return TSDB_CODE_OUT_OF_MEMORY;                  \
X
Xiaoyu Wang 已提交
79 80 81 82 83 84 85 86
    }                                                  \
  } while (0)

#define CLONE_OBJECT_FIELD(fldname, cloneFunc)    \
  do {                                            \
    if (NULL == (pSrc)->fldname) {                \
      break;                                      \
    }                                             \
87
    (pDst)->fldname = cloneFunc((pSrc)->fldname); \
X
Xiaoyu Wang 已提交
88
    if (NULL == (pDst)->fldname) {                \
89
      return TSDB_CODE_OUT_OF_MEMORY;             \
X
Xiaoyu Wang 已提交
90 91 92
    }                                             \
  } while (0)

93 94 95 96 97
#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc)                                \
  do {                                                                           \
    if (TSDB_CODE_SUCCESS != copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \
      return TSDB_CODE_OUT_OF_MEMORY;                                            \
    }                                                                            \
X
Xiaoyu Wang 已提交
98
  } while (0)
99

100
static int32_t exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) {
101 102 103
  COPY_OBJECT_FIELD(resType, sizeof(SDataType));
  COPY_CHAR_ARRAY_FIELD(aliasName);
  COPY_CHAR_ARRAY_FIELD(userAlias);
104
  COPY_SCALAR_FIELD(orderAlias);
105
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
106 107
}

108
static int32_t columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
109
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
110 111 112 113
  COPY_SCALAR_FIELD(tableId);
  COPY_SCALAR_FIELD(tableType);
  COPY_SCALAR_FIELD(colId);
  COPY_SCALAR_FIELD(colType);
X
Xiaoyu Wang 已提交
114
  COPY_SCALAR_FIELD(hasIndex);
115 116 117 118 119 120
  COPY_CHAR_ARRAY_FIELD(dbName);
  COPY_CHAR_ARRAY_FIELD(tableName);
  COPY_CHAR_ARRAY_FIELD(tableAlias);
  COPY_CHAR_ARRAY_FIELD(colName);
  COPY_SCALAR_FIELD(dataBlockId);
  COPY_SCALAR_FIELD(slotId);
121
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
122 123
}

124
static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
125
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
X
Xiaoyu Wang 已提交
126
  COPY_CHAR_POINT_FIELD(literal);
127 128
  COPY_SCALAR_FIELD(isDuration);
  COPY_SCALAR_FIELD(translate);
129
  COPY_SCALAR_FIELD(notReserved);
130
  COPY_SCALAR_FIELD(isNull);
131 132 133
  COPY_SCALAR_FIELD(placeholderNo);
  COPY_SCALAR_FIELD(typeData);
  COPY_SCALAR_FIELD(unit);
D
dapan1121 已提交
134
  if (!pSrc->translate || pSrc->isNull) {
135
    return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
136
  }
X
Xiaoyu Wang 已提交
137
  switch (pSrc->node.resType.type) {
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    case TSDB_DATA_TYPE_BOOL:
      COPY_SCALAR_FIELD(datum.b);
      break;
    case TSDB_DATA_TYPE_TINYINT:
    case TSDB_DATA_TYPE_SMALLINT:
    case TSDB_DATA_TYPE_INT:
    case TSDB_DATA_TYPE_BIGINT:
    case TSDB_DATA_TYPE_TIMESTAMP:
      COPY_SCALAR_FIELD(datum.i);
      break;
    case TSDB_DATA_TYPE_FLOAT:
    case TSDB_DATA_TYPE_DOUBLE:
      COPY_SCALAR_FIELD(datum.d);
      break;
    case TSDB_DATA_TYPE_UTINYINT:
    case TSDB_DATA_TYPE_USMALLINT:
    case TSDB_DATA_TYPE_UINT:
    case TSDB_DATA_TYPE_UBIGINT:
      COPY_SCALAR_FIELD(datum.u);
      break;
X
Xiaoyu Wang 已提交
158 159
    case TSDB_DATA_TYPE_NCHAR:
    case TSDB_DATA_TYPE_VARCHAR:
160
    case TSDB_DATA_TYPE_VARBINARY: {
161
      int32_t len = pSrc->node.resType.bytes + 1;
162
      pDst->datum.p = taosMemoryCalloc(1, len);
X
Xiaoyu Wang 已提交
163
      if (NULL == pDst->datum.p) {
164
        return TSDB_CODE_OUT_OF_MEMORY;
X
Xiaoyu Wang 已提交
165
      }
166
      memcpy(pDst->datum.p, pSrc->datum.p, len);
X
Xiaoyu Wang 已提交
167
      break;
168
    }
169
    case TSDB_DATA_TYPE_JSON: {
wmmhello's avatar
wmmhello 已提交
170 171 172 173 174 175 176 177
      int32_t len = getJsonValueLen(pSrc->datum.p);
      pDst->datum.p = taosMemoryCalloc(1, len);
      if (NULL == pDst->datum.p) {
        return TSDB_CODE_OUT_OF_MEMORY;
      }
      memcpy(pDst->datum.p, pSrc->datum.p, len);
      break;
    }
X
Xiaoyu Wang 已提交
178 179
    case TSDB_DATA_TYPE_DECIMAL:
    case TSDB_DATA_TYPE_BLOB:
180
    case TSDB_DATA_TYPE_MEDIUMBLOB:
X
Xiaoyu Wang 已提交
181 182 183
    default:
      break;
  }
184
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
185 186
}

187
static int32_t operatorNodeCopy(const SOperatorNode* pSrc, SOperatorNode* pDst) {
188
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
189
  COPY_SCALAR_FIELD(opType);
190 191
  CLONE_NODE_FIELD(pLeft);
  CLONE_NODE_FIELD(pRight);
192
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
193 194
}

195
static int32_t logicConditionNodeCopy(const SLogicConditionNode* pSrc, SLogicConditionNode* pDst) {
196
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
197
  COPY_SCALAR_FIELD(condType);
198
  CLONE_NODE_LIST_FIELD(pParameterList);
199
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
200 201
}

202
static int32_t functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) {
203
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
204 205 206
  COPY_CHAR_ARRAY_FIELD(functionName);
  COPY_SCALAR_FIELD(funcId);
  COPY_SCALAR_FIELD(funcType);
207
  CLONE_NODE_LIST_FIELD(pParameterList);
208
  COPY_SCALAR_FIELD(udfBufSize);
209
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
210 211
}

212
static int32_t tableNodeCopy(const STableNode* pSrc, STableNode* pDst) {
213
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
214 215 216 217
  COPY_CHAR_ARRAY_FIELD(dbName);
  COPY_CHAR_ARRAY_FIELD(tableName);
  COPY_CHAR_ARRAY_FIELD(tableAlias);
  COPY_SCALAR_FIELD(precision);
X
Xiaoyu Wang 已提交
218
  COPY_SCALAR_FIELD(singleTable);
219
  return TSDB_CODE_SUCCESS;
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
}

static STableMeta* tableMetaClone(const STableMeta* pSrc) {
  int32_t     len = TABLE_META_SIZE(pSrc);
  STableMeta* pDst = taosMemoryMalloc(len);
  if (NULL == pDst) {
    return NULL;
  }
  memcpy(pDst, pSrc, len);
  return pDst;
}

static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) {
  int32_t       len = VGROUPS_INFO_SIZE(pSrc);
  SVgroupsInfo* pDst = taosMemoryMalloc(len);
  if (NULL == pDst) {
    return NULL;
  }
  memcpy(pDst, pSrc, len);
  return pDst;
}

242
static int32_t realTableNodeCopy(const SRealTableNode* pSrc, SRealTableNode* pDst) {
243 244 245
  COPY_BASE_OBJECT_FIELD(table, tableNodeCopy);
  CLONE_OBJECT_FIELD(pMeta, tableMetaClone);
  CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone);
246 247
  COPY_CHAR_ARRAY_FIELD(qualDbName);
  COPY_SCALAR_FIELD(ratio);
248
  return TSDB_CODE_SUCCESS;
249 250
}

251
static int32_t tempTableNodeCopy(const STempTableNode* pSrc, STempTableNode* pDst) {
252 253
  COPY_BASE_OBJECT_FIELD(table, tableNodeCopy);
  CLONE_NODE_FIELD(pSubquery);
254
  return TSDB_CODE_SUCCESS;
255 256
}

257
static int32_t joinTableNodeCopy(const SJoinTableNode* pSrc, SJoinTableNode* pDst) {
258
  COPY_BASE_OBJECT_FIELD(table, tableNodeCopy);
259
  COPY_SCALAR_FIELD(joinType);
260 261 262
  CLONE_NODE_FIELD(pLeft);
  CLONE_NODE_FIELD(pRight);
  CLONE_NODE_FIELD(pOnCond);
263
  return TSDB_CODE_SUCCESS;
264 265
}

266
static int32_t targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) {
267 268
  COPY_SCALAR_FIELD(dataBlockId);
  COPY_SCALAR_FIELD(slotId);
269
  CLONE_NODE_FIELD(pExpr);
270
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
271 272
}

273
static int32_t groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode* pDst) {
274
  COPY_SCALAR_FIELD(groupingSetType);
275
  CLONE_NODE_LIST_FIELD(pParameterList);
276
  return TSDB_CODE_SUCCESS;
277 278
}

279
static int32_t orderByExprNodeCopy(const SOrderByExprNode* pSrc, SOrderByExprNode* pDst) {
X
Xiaoyu Wang 已提交
280
  CLONE_NODE_FIELD(pExpr);
281 282
  COPY_SCALAR_FIELD(order);
  COPY_SCALAR_FIELD(nullOrder);
283
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
284 285
}

286
static int32_t limitNodeCopy(const SLimitNode* pSrc, SLimitNode* pDst) {
287 288
  COPY_SCALAR_FIELD(limit);
  COPY_SCALAR_FIELD(offset);
289
  return TSDB_CODE_SUCCESS;
290
}
291

292
static int32_t stateWindowNodeCopy(const SStateWindowNode* pSrc, SStateWindowNode* pDst) {
293 294
  CLONE_NODE_FIELD(pCol);
  CLONE_NODE_FIELD(pExpr);
295
  return TSDB_CODE_SUCCESS;
296 297
}

X
Xiaoyu Wang 已提交
298 299 300 301 302 303 304
static int32_t eventWindowNodeCopy(const SEventWindowNode* pSrc, SEventWindowNode* pDst) {
  CLONE_NODE_FIELD(pCol);
  CLONE_NODE_FIELD(pStartCond);
  CLONE_NODE_FIELD(pEndCond);
  return TSDB_CODE_SUCCESS;
}

305
static int32_t sessionWindowNodeCopy(const SSessionWindowNode* pSrc, SSessionWindowNode* pDst) {
306 307
  CLONE_NODE_FIELD_EX(pCol, SColumnNode*);
  CLONE_NODE_FIELD_EX(pGap, SValueNode*);
308
  return TSDB_CODE_SUCCESS;
309 310
}

311
static int32_t intervalWindowNodeCopy(const SIntervalWindowNode* pSrc, SIntervalWindowNode* pDst) {
312 313 314 315 316
  CLONE_NODE_FIELD(pCol);
  CLONE_NODE_FIELD(pInterval);
  CLONE_NODE_FIELD(pOffset);
  CLONE_NODE_FIELD(pSliding);
  CLONE_NODE_FIELD(pFill);
317
  return TSDB_CODE_SUCCESS;
318 319
}

320
static int32_t nodeListNodeCopy(const SNodeListNode* pSrc, SNodeListNode* pDst) {
321
  COPY_OBJECT_FIELD(node.resType, sizeof(SDataType));
X
Xiaoyu Wang 已提交
322
  CLONE_NODE_LIST_FIELD(pNodeList);
323
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
324 325
}

326
static int32_t fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) {
327
  COPY_SCALAR_FIELD(mode);
X
Xiaoyu Wang 已提交
328
  CLONE_NODE_FIELD(pValues);
X
Xiaoyu Wang 已提交
329
  CLONE_NODE_FIELD(pWStartTs);
330
  COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow));
331
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
332 333
}

X
Xiaoyu Wang 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
static int32_t whenThenNodeCopy(const SWhenThenNode* pSrc, SWhenThenNode* pDst) {
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
  CLONE_NODE_FIELD(pWhen);
  CLONE_NODE_FIELD(pThen);
  return TSDB_CODE_SUCCESS;
}

static int32_t caseWhenNodeCopy(const SCaseWhenNode* pSrc, SCaseWhenNode* pDst) {
  COPY_BASE_OBJECT_FIELD(node, exprNodeCopy);
  CLONE_NODE_FIELD(pCase);
  CLONE_NODE_FIELD(pElse);
  CLONE_NODE_LIST_FIELD(pWhenThenList);
  return TSDB_CODE_SUCCESS;
}

349
static int32_t logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
350 351 352
  CLONE_NODE_LIST_FIELD(pTargets);
  CLONE_NODE_FIELD(pConditions);
  CLONE_NODE_LIST_FIELD(pChildren);
353
  COPY_SCALAR_FIELD(optimizedFlag);
354
  COPY_SCALAR_FIELD(precision);
355 356
  CLONE_NODE_FIELD(pLimit);
  CLONE_NODE_FIELD(pSlimit);
357 358 359
  COPY_SCALAR_FIELD(requireDataOrder);
  COPY_SCALAR_FIELD(resultDataOrder);
  COPY_SCALAR_FIELD(groupAction);
360
  return TSDB_CODE_SUCCESS;
361 362
}

363
static int32_t logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
364 365
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pScanCols);
366
  CLONE_NODE_LIST_FIELD(pScanPseudoCols);
X
Xiaoyu Wang 已提交
367 368
  COPY_SCALAR_FIELD(tableType);
  COPY_SCALAR_FIELD(tableId);
X
Xiaoyu Wang 已提交
369
  COPY_SCALAR_FIELD(stableId);
370
  CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone);
371 372 373 374 375 376
  COPY_SCALAR_FIELD(scanType);
  COPY_OBJECT_FIELD(scanSeq[0], sizeof(uint8_t) * 2);
  COPY_OBJECT_FIELD(scanRange, sizeof(STimeWindow));
  COPY_OBJECT_FIELD(tableName, sizeof(SName));
  COPY_SCALAR_FIELD(showRewrite);
  COPY_SCALAR_FIELD(ratio);
377
  CLONE_NODE_LIST_FIELD(pDynamicScanFuncs);
378 379 380 381 382 383
  COPY_SCALAR_FIELD(dataRequired);
  COPY_SCALAR_FIELD(interval);
  COPY_SCALAR_FIELD(offset);
  COPY_SCALAR_FIELD(sliding);
  COPY_SCALAR_FIELD(intervalUnit);
  COPY_SCALAR_FIELD(slidingUnit);
X
Xiaoyu Wang 已提交
384
  CLONE_NODE_FIELD(pTagCond);
X
Xiaoyu Wang 已提交
385
  CLONE_NODE_FIELD(pTagIndexCond);
5
54liuyao 已提交
386 387
  COPY_SCALAR_FIELD(triggerType);
  COPY_SCALAR_FIELD(watermark);
388
  COPY_SCALAR_FIELD(deleteMark);
389
  COPY_SCALAR_FIELD(igExpired);
390
  COPY_SCALAR_FIELD(igCheckUpdate);
391
  CLONE_NODE_LIST_FIELD(pGroupTags);
392
  COPY_SCALAR_FIELD(groupSort);
393 394
  CLONE_NODE_LIST_FIELD(pTags);
  CLONE_NODE_FIELD(pSubtable);
X
Xiaoyu Wang 已提交
395
  COPY_SCALAR_FIELD(igLastNull);
396
  return TSDB_CODE_SUCCESS;
397 398
}

399
static int32_t logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) {
400
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
401
  COPY_SCALAR_FIELD(joinType);
402
  CLONE_NODE_FIELD(pMergeCondition);
403
  CLONE_NODE_FIELD(pOnConditions);
X
Xiaoyu Wang 已提交
404
  COPY_SCALAR_FIELD(isSingleTableJoin);
405
  COPY_SCALAR_FIELD(inputTsOrder);
406
  return TSDB_CODE_SUCCESS;
407 408
}

409
static int32_t logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) {
410 411 412
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pGroupKeys);
  CLONE_NODE_LIST_FIELD(pAggFuncs);
413
  COPY_SCALAR_FIELD(hasGroupKeyOptimized);
414
  return TSDB_CODE_SUCCESS;
415 416
}

417
static int32_t logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) {
418 419
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pProjections);
420
  COPY_CHAR_ARRAY_FIELD(stmtName);
421
  COPY_SCALAR_FIELD(ignoreGroupId);
422
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
423 424
}

425
static int32_t logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModifyLogicNode* pDst) {
X
Xiaoyu Wang 已提交
426
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
X
Xiaoyu Wang 已提交
427
  COPY_SCALAR_FIELD(modifyType);
428
  COPY_SCALAR_FIELD(msgType);
X
Xiaoyu Wang 已提交
429
  CLONE_NODE_FIELD(pAffectedRows);
430 431
  CLONE_NODE_FIELD(pStartTs);
  CLONE_NODE_FIELD(pEndTs);
X
Xiaoyu Wang 已提交
432
  COPY_SCALAR_FIELD(tableId);
433
  COPY_SCALAR_FIELD(stableId);
X
Xiaoyu Wang 已提交
434
  COPY_SCALAR_FIELD(tableType);
435
  COPY_CHAR_ARRAY_FIELD(tableName);
436
  COPY_CHAR_ARRAY_FIELD(tsColName);
X
Xiaoyu Wang 已提交
437
  COPY_OBJECT_FIELD(deleteTimeRange, sizeof(STimeWindow));
438
  CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone);
439
  CLONE_NODE_LIST_FIELD(pInsertCols);
440
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
441 442
}

443
static int32_t logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNode* pDst) {
X
Xiaoyu Wang 已提交
444
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
445 446
  COPY_SCALAR_FIELD(srcStartGroupId);
  COPY_SCALAR_FIELD(srcEndGroupId);
X
Xiaoyu Wang 已提交
447
  COPY_SCALAR_FIELD(seqRecvData);
448
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
449 450
}

451
static int32_t logicMergeCopy(const SMergeLogicNode* pSrc, SMergeLogicNode* pDst) {
X
Xiaoyu Wang 已提交
452 453
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pMergeKeys);
X
Xiaoyu Wang 已提交
454
  CLONE_NODE_LIST_FIELD(pInputs);
X
Xiaoyu Wang 已提交
455 456
  COPY_SCALAR_FIELD(numOfChannels);
  COPY_SCALAR_FIELD(srcGroupId);
457
  COPY_SCALAR_FIELD(groupSort);
D
dapan1121 已提交
458
  COPY_SCALAR_FIELD(ignoreGroupId);
459
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
460 461
}

462
static int32_t logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) {
X
Xiaoyu Wang 已提交
463
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
464
  COPY_SCALAR_FIELD(winType);
X
Xiaoyu Wang 已提交
465
  CLONE_NODE_LIST_FIELD(pFuncs);
466 467 468 469 470 471
  COPY_SCALAR_FIELD(interval);
  COPY_SCALAR_FIELD(offset);
  COPY_SCALAR_FIELD(sliding);
  COPY_SCALAR_FIELD(intervalUnit);
  COPY_SCALAR_FIELD(slidingUnit);
  COPY_SCALAR_FIELD(sessionGap);
X
bugfix  
Xiaoyu Wang 已提交
472
  CLONE_NODE_FIELD(pTspk);
5
54liuyao 已提交
473
  CLONE_NODE_FIELD(pTsEnd);
474
  CLONE_NODE_FIELD(pStateExpr);
X
Xiaoyu Wang 已提交
475 476
  CLONE_NODE_FIELD(pStartCond);
  CLONE_NODE_FIELD(pEndCond);
477 478
  COPY_SCALAR_FIELD(triggerType);
  COPY_SCALAR_FIELD(watermark);
479
  COPY_SCALAR_FIELD(deleteMark);
480
  COPY_SCALAR_FIELD(igExpired);
481
  COPY_SCALAR_FIELD(igCheckUpdate);
482
  COPY_SCALAR_FIELD(windowAlgo);
483
  COPY_SCALAR_FIELD(inputTsOrder);
X
Xiaoyu Wang 已提交
484
  COPY_SCALAR_FIELD(outputTsOrder);
485
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
486 487
}

488
static int32_t logicFillCopy(const SFillLogicNode* pSrc, SFillLogicNode* pDst) {
X
Xiaoyu Wang 已提交
489
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
490
  COPY_SCALAR_FIELD(mode);
491 492
  CLONE_NODE_LIST_FIELD(pFillExprs);
  CLONE_NODE_LIST_FIELD(pNotFillExprs);
X
Xiaoyu Wang 已提交
493 494
  CLONE_NODE_FIELD(pWStartTs);
  CLONE_NODE_FIELD(pValues);
495
  COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow));
X
Xiaoyu Wang 已提交
496
  COPY_SCALAR_FIELD(inputTsOrder);
497
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
498 499
}

500
static int32_t logicSortCopy(const SSortLogicNode* pSrc, SSortLogicNode* pDst) {
X
Xiaoyu Wang 已提交
501 502
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pSortKeys);
503
  COPY_SCALAR_FIELD(groupSort);
504
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
505 506
}

507
static int32_t logicPartitionCopy(const SPartitionLogicNode* pSrc, SPartitionLogicNode* pDst) {
508 509
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pPartitionKeys);
510 511
  CLONE_NODE_LIST_FIELD(pTags);
  CLONE_NODE_FIELD(pSubtable);
512
  return TSDB_CODE_SUCCESS;
513 514
}

515
static int32_t logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) {
516
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
X
Xiaoyu Wang 已提交
517
  CLONE_NODE_LIST_FIELD(pFuncs);
518
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
519 520
}

521
static int32_t logicInterpFuncCopy(const SInterpFuncLogicNode* pSrc, SInterpFuncLogicNode* pDst) {
X
Xiaoyu Wang 已提交
522 523 524 525
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pFuncs);
  COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow));
  COPY_SCALAR_FIELD(interval);
X
Xiaoyu Wang 已提交
526 527 528
  COPY_SCALAR_FIELD(fillMode);
  CLONE_NODE_FIELD(pFillValues);
  CLONE_NODE_FIELD(pTimeSeries);
529
  return TSDB_CODE_SUCCESS;
530 531
}

532
static int32_t logicSubplanCopy(const SLogicSubplan* pSrc, SLogicSubplan* pDst) {
533
  COPY_OBJECT_FIELD(id, sizeof(SSubplanId));
534
  CLONE_NODE_FIELD_EX(pNode, SLogicNode*);
535 536 537
  COPY_SCALAR_FIELD(subplanType);
  COPY_SCALAR_FIELD(level);
  COPY_SCALAR_FIELD(splitFlag);
538
  return TSDB_CODE_SUCCESS;
539 540
}

541
static int32_t physiNodeCopy(const SPhysiNode* pSrc, SPhysiNode* pDst) {
542
  CLONE_NODE_FIELD_EX(pOutputDataBlockDesc, SDataBlockDescNode*);
X
Xiaoyu Wang 已提交
543 544
  CLONE_NODE_FIELD(pConditions);
  CLONE_NODE_LIST_FIELD(pChildren);
545
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
546 547
}

548
static int32_t physiScanCopy(const SScanPhysiNode* pSrc, SScanPhysiNode* pDst) {
549 550 551 552 553 554 555
  COPY_BASE_OBJECT_FIELD(node, physiNodeCopy);
  CLONE_NODE_LIST_FIELD(pScanCols);
  CLONE_NODE_LIST_FIELD(pScanPseudoCols);
  COPY_SCALAR_FIELD(uid);
  COPY_SCALAR_FIELD(suid);
  COPY_SCALAR_FIELD(tableType);
  COPY_OBJECT_FIELD(tableName, sizeof(SName));
556
  return TSDB_CODE_SUCCESS;
557 558
}

559
static int32_t physiTagScanCopy(const STagScanPhysiNode* pSrc, STagScanPhysiNode* pDst) {
560 561 562
  return physiScanCopy(pSrc, pDst);
}

563
static int32_t physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhysiNode* pDst) {
564 565 566 567 568 569
  COPY_BASE_OBJECT_FIELD(scan, physiScanCopy);
  COPY_OBJECT_FIELD(scanSeq[0], sizeof(uint8_t) * 2);
  COPY_OBJECT_FIELD(scanRange, sizeof(STimeWindow));
  COPY_SCALAR_FIELD(ratio);
  COPY_SCALAR_FIELD(dataRequired);
  CLONE_NODE_LIST_FIELD(pDynamicScanFuncs);
570
  CLONE_NODE_LIST_FIELD(pGroupTags);
571 572 573 574 575 576 577
  COPY_SCALAR_FIELD(interval);
  COPY_SCALAR_FIELD(offset);
  COPY_SCALAR_FIELD(sliding);
  COPY_SCALAR_FIELD(intervalUnit);
  COPY_SCALAR_FIELD(slidingUnit);
  COPY_SCALAR_FIELD(triggerType);
  COPY_SCALAR_FIELD(watermark);
578
  COPY_SCALAR_FIELD(igExpired);
579
  return TSDB_CODE_SUCCESS;
580 581
}

582
static int32_t physiSysTableScanCopy(const SSystemTableScanPhysiNode* pSrc, SSystemTableScanPhysiNode* pDst) {
583 584 585 586
  COPY_BASE_OBJECT_FIELD(scan, physiScanCopy);
  COPY_OBJECT_FIELD(mgmtEpSet, sizeof(SEpSet));
  COPY_SCALAR_FIELD(showRewrite);
  COPY_SCALAR_FIELD(accountId);
587
  COPY_SCALAR_FIELD(sysInfo);
588
  return TSDB_CODE_SUCCESS;
589 590
}

591
static int32_t physiWindowCopy(const SWinodwPhysiNode* pSrc, SWinodwPhysiNode* pDst) {
X
Xiaoyu Wang 已提交
592 593 594 595
  COPY_BASE_OBJECT_FIELD(node, physiNodeCopy);
  CLONE_NODE_LIST_FIELD(pExprs);
  CLONE_NODE_LIST_FIELD(pFuncs);
  CLONE_NODE_FIELD(pTspk);
5
54liuyao 已提交
596
  CLONE_NODE_FIELD(pTsEnd);
X
Xiaoyu Wang 已提交
597 598
  COPY_SCALAR_FIELD(triggerType);
  COPY_SCALAR_FIELD(watermark);
599
  COPY_SCALAR_FIELD(igExpired);
600
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
601 602
}

603
static int32_t physiIntervalCopy(const SIntervalPhysiNode* pSrc, SIntervalPhysiNode* pDst) {
X
Xiaoyu Wang 已提交
604 605 606 607 608 609
  COPY_BASE_OBJECT_FIELD(window, physiWindowCopy);
  COPY_SCALAR_FIELD(interval);
  COPY_SCALAR_FIELD(offset);
  COPY_SCALAR_FIELD(sliding);
  COPY_SCALAR_FIELD(intervalUnit);
  COPY_SCALAR_FIELD(slidingUnit);
610
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
611 612
}

613
static int32_t physiSessionCopy(const SSessionWinodwPhysiNode* pSrc, SSessionWinodwPhysiNode* pDst) {
614 615
  COPY_BASE_OBJECT_FIELD(window, physiWindowCopy);
  COPY_SCALAR_FIELD(gap);
616
  return TSDB_CODE_SUCCESS;
617 618
}

619
static int32_t physiPartitionCopy(const SPartitionPhysiNode* pSrc, SPartitionPhysiNode* pDst) {
X
Xiaoyu Wang 已提交
620 621 622 623
  COPY_BASE_OBJECT_FIELD(node, physiNodeCopy);
  CLONE_NODE_LIST_FIELD(pExprs);
  CLONE_NODE_LIST_FIELD(pPartitionKeys);
  CLONE_NODE_LIST_FIELD(pTargets);
624
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
625 626
}

627
static int32_t dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) {
628
  COPY_SCALAR_FIELD(dataBlockId);
629
  CLONE_NODE_LIST_FIELD(pSlots);
630 631 632
  COPY_SCALAR_FIELD(totalRowSize);
  COPY_SCALAR_FIELD(outputRowSize);
  COPY_SCALAR_FIELD(precision);
633
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
634 635
}

636
static int32_t slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) {
637 638 639 640 641
  COPY_SCALAR_FIELD(slotId);
  COPY_OBJECT_FIELD(dataType, sizeof(SDataType));
  COPY_SCALAR_FIELD(reserve);
  COPY_SCALAR_FIELD(output);
  COPY_SCALAR_FIELD(tag);
642
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
643 644
}

645
static int32_t downstreamSourceCopy(const SDownstreamSourceNode* pSrc, SDownstreamSourceNode* pDst) {
646 647 648
  COPY_OBJECT_FIELD(addr, sizeof(SQueryNodeAddr));
  COPY_SCALAR_FIELD(taskId);
  COPY_SCALAR_FIELD(schedId);
D
dapan1121 已提交
649
  COPY_SCALAR_FIELD(execId);
D
dapan1121 已提交
650
  COPY_SCALAR_FIELD(fetchMsgType);
D
dapan1121 已提交
651
  COPY_SCALAR_FIELD(localExec);
652
  return TSDB_CODE_SUCCESS;
653 654
}

655
static int32_t selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) {
656
  COPY_SCALAR_FIELD(isDistinct);
657 658 659 660 661 662 663 664
  CLONE_NODE_LIST_FIELD(pProjectionList);
  CLONE_NODE_FIELD(pFromTable);
  CLONE_NODE_FIELD(pWhere);
  CLONE_NODE_LIST_FIELD(pPartitionByList);
  CLONE_NODE_FIELD(pWindow);
  CLONE_NODE_LIST_FIELD(pGroupByList);
  CLONE_NODE_FIELD(pHaving);
  CLONE_NODE_LIST_FIELD(pOrderByList);
665 666
  CLONE_NODE_FIELD_EX(pLimit, SLimitNode*);
  CLONE_NODE_FIELD_EX(pLimit, SLimitNode*);
667 668 669
  COPY_CHAR_ARRAY_FIELD(stmtName);
  COPY_SCALAR_FIELD(precision);
  COPY_SCALAR_FIELD(isEmptyResult);
670
  COPY_SCALAR_FIELD(isTimeLineResult);
671 672
  COPY_SCALAR_FIELD(hasAggFuncs);
  COPY_SCALAR_FIELD(hasRepeatScanFuncs);
673
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
674 675
}

676
SNode* nodesCloneNode(const SNode* pNode) {
X
Xiaoyu Wang 已提交
677 678 679
  if (NULL == pNode) {
    return NULL;
  }
680

X
Xiaoyu Wang 已提交
681 682
  SNode* pDst = nodesMakeNode(nodeType(pNode));
  if (NULL == pDst) {
X
Xiaoyu Wang 已提交
683
    terrno = TSDB_CODE_OUT_OF_MEMORY;
X
Xiaoyu Wang 已提交
684 685
    return NULL;
  }
686 687

  int32_t code = TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
688 689
  switch (nodeType(pNode)) {
    case QUERY_NODE_COLUMN:
690
      code = columnNodeCopy((const SColumnNode*)pNode, (SColumnNode*)pDst);
691
      break;
X
Xiaoyu Wang 已提交
692
    case QUERY_NODE_VALUE:
693
      code = valueNodeCopy((const SValueNode*)pNode, (SValueNode*)pDst);
694
      break;
X
Xiaoyu Wang 已提交
695
    case QUERY_NODE_OPERATOR:
696
      code = operatorNodeCopy((const SOperatorNode*)pNode, (SOperatorNode*)pDst);
697
      break;
X
Xiaoyu Wang 已提交
698
    case QUERY_NODE_LOGIC_CONDITION:
699
      code = logicConditionNodeCopy((const SLogicConditionNode*)pNode, (SLogicConditionNode*)pDst);
700
      break;
X
Xiaoyu Wang 已提交
701
    case QUERY_NODE_FUNCTION:
702
      code = functionNodeCopy((const SFunctionNode*)pNode, (SFunctionNode*)pDst);
703
      break;
X
Xiaoyu Wang 已提交
704
    case QUERY_NODE_REAL_TABLE:
705
      code = realTableNodeCopy((const SRealTableNode*)pNode, (SRealTableNode*)pDst);
706
      break;
X
Xiaoyu Wang 已提交
707
    case QUERY_NODE_TEMP_TABLE:
708
      code = tempTableNodeCopy((const STempTableNode*)pNode, (STempTableNode*)pDst);
709
      break;
X
Xiaoyu Wang 已提交
710
    case QUERY_NODE_JOIN_TABLE:
711
      code = joinTableNodeCopy((const SJoinTableNode*)pNode, (SJoinTableNode*)pDst);
712
      break;
X
Xiaoyu Wang 已提交
713
    case QUERY_NODE_GROUPING_SET:
714
      code = groupingSetNodeCopy((const SGroupingSetNode*)pNode, (SGroupingSetNode*)pDst);
715
      break;
X
Xiaoyu Wang 已提交
716
    case QUERY_NODE_ORDER_BY_EXPR:
717
      code = orderByExprNodeCopy((const SOrderByExprNode*)pNode, (SOrderByExprNode*)pDst);
718
      break;
X
Xiaoyu Wang 已提交
719
    case QUERY_NODE_LIMIT:
720
      code = limitNodeCopy((const SLimitNode*)pNode, (SLimitNode*)pDst);
721
      break;
722
    case QUERY_NODE_STATE_WINDOW:
723
      code = stateWindowNodeCopy((const SStateWindowNode*)pNode, (SStateWindowNode*)pDst);
724
      break;
X
Xiaoyu Wang 已提交
725 726 727
    case QUERY_NODE_EVENT_WINDOW:
      code = eventWindowNodeCopy((const SEventWindowNode*)pNode, (SEventWindowNode*)pDst);
      break;
728
    case QUERY_NODE_SESSION_WINDOW:
729
      code = sessionWindowNodeCopy((const SSessionWindowNode*)pNode, (SSessionWindowNode*)pDst);
730
      break;
731
    case QUERY_NODE_INTERVAL_WINDOW:
732
      code = intervalWindowNodeCopy((const SIntervalWindowNode*)pNode, (SIntervalWindowNode*)pDst);
733
      break;
X
Xiaoyu Wang 已提交
734
    case QUERY_NODE_NODE_LIST:
735
      code = nodeListNodeCopy((const SNodeListNode*)pNode, (SNodeListNode*)pDst);
736
      break;
X
Xiaoyu Wang 已提交
737
    case QUERY_NODE_FILL:
738
      code = fillNodeCopy((const SFillNode*)pNode, (SFillNode*)pDst);
739
      break;
740
    case QUERY_NODE_TARGET:
741
      code = targetNodeCopy((const STargetNode*)pNode, (STargetNode*)pDst);
742
      break;
X
Xiaoyu Wang 已提交
743
    case QUERY_NODE_DATABLOCK_DESC:
744
      code = dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst);
745
      break;
X
Xiaoyu Wang 已提交
746
    case QUERY_NODE_SLOT_DESC:
747
      code = slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst);
748
      break;
X
Xiaoyu Wang 已提交
749
    case QUERY_NODE_DOWNSTREAM_SOURCE:
750
      code = downstreamSourceCopy((const SDownstreamSourceNode*)pNode, (SDownstreamSourceNode*)pDst);
751
      break;
752
    case QUERY_NODE_LEFT_VALUE:
753
      code = TSDB_CODE_SUCCESS;
754
      break;
X
Xiaoyu Wang 已提交
755 756 757 758 759 760
    case QUERY_NODE_WHEN_THEN:
      code = whenThenNodeCopy((const SWhenThenNode*)pNode, (SWhenThenNode*)pDst);
      break;
    case QUERY_NODE_CASE_WHEN:
      code = caseWhenNodeCopy((const SCaseWhenNode*)pNode, (SCaseWhenNode*)pDst);
      break;
761
    case QUERY_NODE_SELECT_STMT:
762
      code = selectStmtCopy((const SSelectStmt*)pNode, (SSelectStmt*)pDst);
763
      break;
764
    case QUERY_NODE_LOGIC_PLAN_SCAN:
765
      code = logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst);
766
      break;
767
    case QUERY_NODE_LOGIC_PLAN_JOIN:
768
      code = logicJoinCopy((const SJoinLogicNode*)pNode, (SJoinLogicNode*)pDst);
769
      break;
770
    case QUERY_NODE_LOGIC_PLAN_AGG:
771
      code = logicAggCopy((const SAggLogicNode*)pNode, (SAggLogicNode*)pDst);
772
      break;
773
    case QUERY_NODE_LOGIC_PLAN_PROJECT:
774
      code = logicProjectCopy((const SProjectLogicNode*)pNode, (SProjectLogicNode*)pDst);
775
      break;
X
Xiaoyu Wang 已提交
776
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
777
      code = logicVnodeModifCopy((const SVnodeModifyLogicNode*)pNode, (SVnodeModifyLogicNode*)pDst);
778
      break;
X
Xiaoyu Wang 已提交
779
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
780
      code = logicExchangeCopy((const SExchangeLogicNode*)pNode, (SExchangeLogicNode*)pDst);
781
      break;
X
Xiaoyu Wang 已提交
782
    case QUERY_NODE_LOGIC_PLAN_MERGE:
783
      code = logicMergeCopy((const SMergeLogicNode*)pNode, (SMergeLogicNode*)pDst);
784
      break;
X
Xiaoyu Wang 已提交
785
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
786
      code = logicWindowCopy((const SWindowLogicNode*)pNode, (SWindowLogicNode*)pDst);
787
      break;
X
Xiaoyu Wang 已提交
788
    case QUERY_NODE_LOGIC_PLAN_FILL:
789
      code = logicFillCopy((const SFillLogicNode*)pNode, (SFillLogicNode*)pDst);
790
      break;
X
Xiaoyu Wang 已提交
791
    case QUERY_NODE_LOGIC_PLAN_SORT:
792
      code = logicSortCopy((const SSortLogicNode*)pNode, (SSortLogicNode*)pDst);
793
      break;
794
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
795
      code = logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst);
796
      break;
797
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
798
      code = logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst);
799
      break;
X
Xiaoyu Wang 已提交
800
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
801
      code = logicInterpFuncCopy((const SInterpFuncLogicNode*)pNode, (SInterpFuncLogicNode*)pDst);
802
      break;
803
    case QUERY_NODE_LOGIC_SUBPLAN:
804
      code = logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst);
805
      break;
806
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
807
      code = physiTagScanCopy((const STagScanPhysiNode*)pNode, (STagScanPhysiNode*)pDst);
808
      break;
809 810 811
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
812
      code = physiTableScanCopy((const STableScanPhysiNode*)pNode, (STableScanPhysiNode*)pDst);
813
      break;
814
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
815
      code = physiSysTableScanCopy((const SSystemTableScanPhysiNode*)pNode, (SSystemTableScanPhysiNode*)pDst);
816
      break;
X
Xiaoyu Wang 已提交
817
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
818
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
X
Xiaoyu Wang 已提交
819 820 821
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
822
      code = physiIntervalCopy((const SIntervalPhysiNode*)pNode, (SIntervalPhysiNode*)pDst);
823
      break;
824 825
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
826
      code = physiSessionCopy((const SSessionWinodwPhysiNode*)pNode, (SSessionWinodwPhysiNode*)pDst);
827
      break;
X
Xiaoyu Wang 已提交
828
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
829
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION:
830
      code = physiPartitionCopy((const SPartitionPhysiNode*)pNode, (SPartitionPhysiNode*)pDst);
831
      break;
X
Xiaoyu Wang 已提交
832 833 834
    default:
      break;
  }
835 836 837 838 839 840 841 842

  if (TSDB_CODE_SUCCESS != code) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    nodesDestroyNode(pDst);
    nodesError("nodesCloneNode failed node = %s", nodesNodeName(nodeType(pNode)));
    return NULL;
  }
  return pDst;
X
Xiaoyu Wang 已提交
843 844 845
}

SNodeList* nodesCloneList(const SNodeList* pList) {
X
Xiaoyu Wang 已提交
846 847 848 849
  if (NULL == pList) {
    return NULL;
  }

850 851
  SNodeList* pDst = NULL;
  SNode*     pNode;
X
Xiaoyu Wang 已提交
852
  FOREACH(pNode, pList) {
853 854 855
    int32_t code = nodesListMakeStrictAppend(&pDst, nodesCloneNode(pNode));
    if (TSDB_CODE_SUCCESS != code) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
X
Xiaoyu Wang 已提交
856 857 858 859 860
      nodesDestroyList(pDst);
      return NULL;
    }
  }
  return pDst;
861
}