nodesCloneFuncs.c 30.2 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
  COPY_SCALAR_FIELD(tableId);
  COPY_SCALAR_FIELD(tableType);
  COPY_SCALAR_FIELD(colId);
113
  COPY_SCALAR_FIELD(projIdx);
114
  COPY_SCALAR_FIELD(colType);
X
Xiaoyu Wang 已提交
115
  COPY_SCALAR_FIELD(hasIndex);
116 117 118 119 120 121
  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);
122
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
123 124
}

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

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

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

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

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

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;
}

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

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

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

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

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

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

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

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

X
Xiaoyu Wang 已提交
300 301 302 303 304 305 306
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;
}

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

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

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

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

X
Xiaoyu Wang 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
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;
}

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

368
static int32_t logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
369 370
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pScanCols);
371
  CLONE_NODE_LIST_FIELD(pScanPseudoCols);
X
Xiaoyu Wang 已提交
372 373
  COPY_SCALAR_FIELD(tableType);
  COPY_SCALAR_FIELD(tableId);
X
Xiaoyu Wang 已提交
374
  COPY_SCALAR_FIELD(stableId);
375
  CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone);
376 377 378 379 380 381
  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);
382
  CLONE_NODE_LIST_FIELD(pDynamicScanFuncs);
383 384 385 386 387 388
  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 已提交
389
  CLONE_NODE_FIELD(pTagCond);
X
Xiaoyu Wang 已提交
390
  CLONE_NODE_FIELD(pTagIndexCond);
5
54liuyao 已提交
391 392
  COPY_SCALAR_FIELD(triggerType);
  COPY_SCALAR_FIELD(watermark);
393
  COPY_SCALAR_FIELD(deleteMark);
394
  COPY_SCALAR_FIELD(igExpired);
395
  COPY_SCALAR_FIELD(igCheckUpdate);
396
  CLONE_NODE_LIST_FIELD(pGroupTags);
397
  COPY_SCALAR_FIELD(groupSort);
398 399
  CLONE_NODE_LIST_FIELD(pTags);
  CLONE_NODE_FIELD(pSubtable);
X
Xiaoyu Wang 已提交
400
  COPY_SCALAR_FIELD(igLastNull);
401
  COPY_SCALAR_FIELD(groupOrderScan);
402
  return TSDB_CODE_SUCCESS;
403 404
}

405
static int32_t logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) {
406
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
407
  COPY_SCALAR_FIELD(joinType);
408
  CLONE_NODE_FIELD(pMergeCondition);
409
  CLONE_NODE_FIELD(pOnConditions);
S
slzhou 已提交
410
  CLONE_NODE_FIELD(pColEqualOnConditions);
X
Xiaoyu Wang 已提交
411
  COPY_SCALAR_FIELD(isSingleTableJoin);
412
  return TSDB_CODE_SUCCESS;
413 414
}

415
static int32_t logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) {
416 417 418
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pGroupKeys);
  CLONE_NODE_LIST_FIELD(pAggFuncs);
419
  COPY_SCALAR_FIELD(hasGroupKeyOptimized);
420
  return TSDB_CODE_SUCCESS;
421 422
}

423
static int32_t logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) {
424 425
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pProjections);
426
  COPY_CHAR_ARRAY_FIELD(stmtName);
427
  COPY_SCALAR_FIELD(ignoreGroupId);
428
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
429 430
}

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

449
static int32_t logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNode* pDst) {
X
Xiaoyu Wang 已提交
450
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
451 452
  COPY_SCALAR_FIELD(srcStartGroupId);
  COPY_SCALAR_FIELD(srcEndGroupId);
X
Xiaoyu Wang 已提交
453
  COPY_SCALAR_FIELD(seqRecvData);
454
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
455 456
}

457
static int32_t logicMergeCopy(const SMergeLogicNode* pSrc, SMergeLogicNode* pDst) {
X
Xiaoyu Wang 已提交
458 459
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
  CLONE_NODE_LIST_FIELD(pMergeKeys);
X
Xiaoyu Wang 已提交
460
  CLONE_NODE_LIST_FIELD(pInputs);
X
Xiaoyu Wang 已提交
461 462
  COPY_SCALAR_FIELD(numOfChannels);
  COPY_SCALAR_FIELD(srcGroupId);
463
  COPY_SCALAR_FIELD(groupSort);
D
dapan1121 已提交
464
  COPY_SCALAR_FIELD(ignoreGroupId);
465
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
466 467
}

468
static int32_t logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) {
X
Xiaoyu Wang 已提交
469
  COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
470
  COPY_SCALAR_FIELD(winType);
X
Xiaoyu Wang 已提交
471
  CLONE_NODE_LIST_FIELD(pFuncs);
472 473 474 475 476 477
  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 已提交
478
  CLONE_NODE_FIELD(pTspk);
5
54liuyao 已提交
479
  CLONE_NODE_FIELD(pTsEnd);
480
  CLONE_NODE_FIELD(pStateExpr);
X
Xiaoyu Wang 已提交
481 482
  CLONE_NODE_FIELD(pStartCond);
  CLONE_NODE_FIELD(pEndCond);
483 484
  COPY_SCALAR_FIELD(triggerType);
  COPY_SCALAR_FIELD(watermark);
485
  COPY_SCALAR_FIELD(deleteMark);
486
  COPY_SCALAR_FIELD(igExpired);
487
  COPY_SCALAR_FIELD(igCheckUpdate);
488
  COPY_SCALAR_FIELD(windowAlgo);
489
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
490 491
}

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

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

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

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

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

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

544
static int32_t physiNodeCopy(const SPhysiNode* pSrc, SPhysiNode* pDst) {
545
  CLONE_NODE_FIELD_EX(pOutputDataBlockDesc, SDataBlockDescNode*);
X
Xiaoyu Wang 已提交
546 547
  CLONE_NODE_FIELD(pConditions);
  CLONE_NODE_LIST_FIELD(pChildren);
548 549
  COPY_SCALAR_FIELD(inputTsOrder);
  COPY_SCALAR_FIELD(outputTsOrder);
550
  COPY_SCALAR_FIELD(forceCreateNonBlockingOptr);
551
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
552 553
}

554
static int32_t physiScanCopy(const SScanPhysiNode* pSrc, SScanPhysiNode* pDst) {
555 556 557 558 559 560 561
  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));
562
  COPY_SCALAR_FIELD(groupOrderScan);
563
  return TSDB_CODE_SUCCESS;
564 565
}

566
static int32_t physiTagScanCopy(const STagScanPhysiNode* pSrc, STagScanPhysiNode* pDst) {
567 568 569
  return physiScanCopy(pSrc, pDst);
}

570
static int32_t physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhysiNode* pDst) {
571 572 573 574 575 576
  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);
577
  CLONE_NODE_LIST_FIELD(pGroupTags);
578 579 580 581 582 583 584
  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);
585
  COPY_SCALAR_FIELD(igExpired);
586
  return TSDB_CODE_SUCCESS;
587 588
}

589
static int32_t physiSysTableScanCopy(const SSystemTableScanPhysiNode* pSrc, SSystemTableScanPhysiNode* pDst) {
590 591 592 593
  COPY_BASE_OBJECT_FIELD(scan, physiScanCopy);
  COPY_OBJECT_FIELD(mgmtEpSet, sizeof(SEpSet));
  COPY_SCALAR_FIELD(showRewrite);
  COPY_SCALAR_FIELD(accountId);
594
  COPY_SCALAR_FIELD(sysInfo);
595
  return TSDB_CODE_SUCCESS;
596 597
}

598
static int32_t physiWindowCopy(const SWindowPhysiNode* pSrc, SWindowPhysiNode* pDst) {
X
Xiaoyu Wang 已提交
599 600 601 602
  COPY_BASE_OBJECT_FIELD(node, physiNodeCopy);
  CLONE_NODE_LIST_FIELD(pExprs);
  CLONE_NODE_LIST_FIELD(pFuncs);
  CLONE_NODE_FIELD(pTspk);
5
54liuyao 已提交
603
  CLONE_NODE_FIELD(pTsEnd);
X
Xiaoyu Wang 已提交
604 605
  COPY_SCALAR_FIELD(triggerType);
  COPY_SCALAR_FIELD(watermark);
606
  COPY_SCALAR_FIELD(igExpired);
607
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
608 609
}

610
static int32_t physiIntervalCopy(const SIntervalPhysiNode* pSrc, SIntervalPhysiNode* pDst) {
X
Xiaoyu Wang 已提交
611 612 613 614 615 616
  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);
617
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
618 619
}

620
static int32_t physiSessionCopy(const SSessionWinodwPhysiNode* pSrc, SSessionWinodwPhysiNode* pDst) {
621 622
  COPY_BASE_OBJECT_FIELD(window, physiWindowCopy);
  COPY_SCALAR_FIELD(gap);
623
  return TSDB_CODE_SUCCESS;
624 625
}

626
static int32_t physiPartitionCopy(const SPartitionPhysiNode* pSrc, SPartitionPhysiNode* pDst) {
X
Xiaoyu Wang 已提交
627 628 629 630
  COPY_BASE_OBJECT_FIELD(node, physiNodeCopy);
  CLONE_NODE_LIST_FIELD(pExprs);
  CLONE_NODE_LIST_FIELD(pPartitionKeys);
  CLONE_NODE_LIST_FIELD(pTargets);
631
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
632 633
}

634
static int32_t dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) {
635
  COPY_SCALAR_FIELD(dataBlockId);
636
  CLONE_NODE_LIST_FIELD(pSlots);
637 638 639
  COPY_SCALAR_FIELD(totalRowSize);
  COPY_SCALAR_FIELD(outputRowSize);
  COPY_SCALAR_FIELD(precision);
640
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
641 642
}

643
static int32_t slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) {
644 645 646 647 648
  COPY_SCALAR_FIELD(slotId);
  COPY_OBJECT_FIELD(dataType, sizeof(SDataType));
  COPY_SCALAR_FIELD(reserve);
  COPY_SCALAR_FIELD(output);
  COPY_SCALAR_FIELD(tag);
649
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
650 651
}

652
static int32_t downstreamSourceCopy(const SDownstreamSourceNode* pSrc, SDownstreamSourceNode* pDst) {
653 654 655
  COPY_OBJECT_FIELD(addr, sizeof(SQueryNodeAddr));
  COPY_SCALAR_FIELD(taskId);
  COPY_SCALAR_FIELD(schedId);
D
dapan1121 已提交
656
  COPY_SCALAR_FIELD(execId);
D
dapan1121 已提交
657
  COPY_SCALAR_FIELD(fetchMsgType);
D
dapan1121 已提交
658
  COPY_SCALAR_FIELD(localExec);
659
  return TSDB_CODE_SUCCESS;
660 661
}

662
static int32_t selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) {
663
  COPY_SCALAR_FIELD(isDistinct);
664 665 666 667 668 669 670 671
  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);
672 673
  CLONE_NODE_FIELD_EX(pLimit, SLimitNode*);
  CLONE_NODE_FIELD_EX(pLimit, SLimitNode*);
674 675 676
  COPY_CHAR_ARRAY_FIELD(stmtName);
  COPY_SCALAR_FIELD(precision);
  COPY_SCALAR_FIELD(isEmptyResult);
677
  COPY_SCALAR_FIELD(timeLineResMode);
678 679
  COPY_SCALAR_FIELD(hasAggFuncs);
  COPY_SCALAR_FIELD(hasRepeatScanFuncs);
680
  return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
681 682
}

683
SNode* nodesCloneNode(const SNode* pNode) {
X
Xiaoyu Wang 已提交
684 685 686
  if (NULL == pNode) {
    return NULL;
  }
687

X
Xiaoyu Wang 已提交
688 689
  SNode* pDst = nodesMakeNode(nodeType(pNode));
  if (NULL == pDst) {
X
Xiaoyu Wang 已提交
690
    terrno = TSDB_CODE_OUT_OF_MEMORY;
X
Xiaoyu Wang 已提交
691 692
    return NULL;
  }
693 694

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

  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 已提交
850 851 852
}

SNodeList* nodesCloneList(const SNodeList* pList) {
X
Xiaoyu Wang 已提交
853 854 855 856
  if (NULL == pList) {
    return NULL;
  }

857 858
  SNodeList* pDst = NULL;
  SNode*     pNode;
X
Xiaoyu Wang 已提交
859
  FOREACH(pNode, pList) {
860 861 862
    int32_t code = nodesListMakeStrictAppend(&pDst, nodesCloneNode(pNode));
    if (TSDB_CODE_SUCCESS != code) {
      terrno = TSDB_CODE_OUT_OF_MEMORY;
X
Xiaoyu Wang 已提交
863 864 865 866 867
      nodesDestroyList(pDst);
      return NULL;
    }
  }
  return pDst;
868
}