nodesCodeFuncs.c 172.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 "cmdnodes.h"
X
Xiaoyu Wang 已提交
17
#include "nodesUtil.h"
X
Xiaoyu Wang 已提交
18 19
#include "plannodes.h"
#include "query.h"
X
Xiaoyu Wang 已提交
20
#include "querynodes.h"
X
Xiaoyu Wang 已提交
21
#include "taoserror.h"
wmmhello's avatar
wmmhello 已提交
22
#include "tdatablock.h"
23
#include "tjson.h"
24

X
Xiaoyu Wang 已提交
25
static int32_t nodeToJson(const void* pObj, SJson* pJson);
X
Xiaoyu Wang 已提交
26 27 28
static int32_t jsonToNode(const SJson* pJson, void* pObj);
static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** pNode);
static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode);
X
Xiaoyu Wang 已提交
29

30
const char* nodesNodeName(ENodeType type) {
X
Xiaoyu Wang 已提交
31
  switch (type) {
32
    case QUERY_NODE_COLUMN:
X
Xiaoyu Wang 已提交
33
      return "Column";
34
    case QUERY_NODE_VALUE:
X
Xiaoyu Wang 已提交
35
      return "Value";
36
    case QUERY_NODE_OPERATOR:
X
Xiaoyu Wang 已提交
37
      return "Operator";
38
    case QUERY_NODE_LOGIC_CONDITION:
X
Xiaoyu Wang 已提交
39
      return "LogicCondition";
40
    case QUERY_NODE_FUNCTION:
X
Xiaoyu Wang 已提交
41
      return "Function";
42
    case QUERY_NODE_REAL_TABLE:
X
Xiaoyu Wang 已提交
43
      return "RealTable";
44
    case QUERY_NODE_TEMP_TABLE:
X
Xiaoyu Wang 已提交
45
      return "TempTable";
46
    case QUERY_NODE_JOIN_TABLE:
X
Xiaoyu Wang 已提交
47
      return "JoinTable";
48
    case QUERY_NODE_GROUPING_SET:
X
Xiaoyu Wang 已提交
49
      return "GroupingSet";
50
    case QUERY_NODE_ORDER_BY_EXPR:
X
Xiaoyu Wang 已提交
51
      return "OrderByExpr";
52
    case QUERY_NODE_LIMIT:
X
Xiaoyu Wang 已提交
53
      return "Limit";
54
    case QUERY_NODE_STATE_WINDOW:
X
Xiaoyu Wang 已提交
55
      return "StateWindow";
56
    case QUERY_NODE_SESSION_WINDOW:
X
Xiaoyu Wang 已提交
57
      return "SessionWinow";
58
    case QUERY_NODE_INTERVAL_WINDOW:
X
Xiaoyu Wang 已提交
59
      return "IntervalWindow";
X
Xiaoyu Wang 已提交
60
    case QUERY_NODE_NODE_LIST:
X
Xiaoyu Wang 已提交
61
      return "NodeList";
X
Xiaoyu Wang 已提交
62
    case QUERY_NODE_FILL:
X
Xiaoyu Wang 已提交
63
      return "Fill";
X
Xiaoyu Wang 已提交
64
    case QUERY_NODE_RAW_EXPR:
X
Xiaoyu Wang 已提交
65
      return "RawExpr";
66 67
    case QUERY_NODE_TARGET:
      return "Target";
X
Xiaoyu Wang 已提交
68
    case QUERY_NODE_DATABLOCK_DESC:
69
      return "DataBlockDesc";
X
Xiaoyu Wang 已提交
70 71
    case QUERY_NODE_SLOT_DESC:
      return "SlotDesc";
72 73
    case QUERY_NODE_COLUMN_DEF:
      return "ColumnDef";
X
Xiaoyu Wang 已提交
74 75 76 77 78 79 80 81
    case QUERY_NODE_DOWNSTREAM_SOURCE:
      return "DownstreamSource";
    case QUERY_NODE_DATABASE_OPTIONS:
      return "DatabaseOptions";
    case QUERY_NODE_TABLE_OPTIONS:
      return "TableOptions";
    case QUERY_NODE_INDEX_OPTIONS:
      return "IndexOptions";
82 83
    case QUERY_NODE_LEFT_VALUE:
      return "LeftValue";
84
    case QUERY_NODE_SET_OPERATOR:
X
Xiaoyu Wang 已提交
85
      return "SetOperator";
86
    case QUERY_NODE_SELECT_STMT:
X
Xiaoyu Wang 已提交
87
      return "SelectStmt";
88 89 90 91
    case QUERY_NODE_VNODE_MODIF_STMT:
      return "VnodeModifStmt";
    case QUERY_NODE_CREATE_DATABASE_STMT:
      return "CreateDatabaseStmt";
X
Xiaoyu Wang 已提交
92 93 94 95
    case QUERY_NODE_DROP_DATABASE_STMT:
      return "DropDatabaseStmt";
    case QUERY_NODE_ALTER_DATABASE_STMT:
      return "AlterDatabaseStmt";
96 97
    case QUERY_NODE_CREATE_TABLE_STMT:
      return "CreateTableStmt";
X
Xiaoyu Wang 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
      return "CreateSubtableClause";
    case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
      return "CreateMultiTableStmt";
    case QUERY_NODE_DROP_TABLE_CLAUSE:
      return "DropTableClause";
    case QUERY_NODE_DROP_TABLE_STMT:
      return "DropTableStmt";
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
      return "DropSuperTableStmt";
    case QUERY_NODE_ALTER_TABLE_STMT:
      return "AlterTableStmt";
    case QUERY_NODE_CREATE_USER_STMT:
      return "CreateUserStmt";
    case QUERY_NODE_ALTER_USER_STMT:
      return "AlterUserStmt";
    case QUERY_NODE_DROP_USER_STMT:
      return "DropUserStmt";
116 117
    case QUERY_NODE_USE_DATABASE_STMT:
      return "UseDatabaseStmt";
X
Xiaoyu Wang 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    case QUERY_NODE_CREATE_DNODE_STMT:
      return "CreateDnodeStmt";
    case QUERY_NODE_DROP_DNODE_STMT:
      return "DropDnodeStmt";
    case QUERY_NODE_ALTER_DNODE_STMT:
      return "AlterDnodeStmt";
    case QUERY_NODE_CREATE_INDEX_STMT:
      return "CreateIndexStmt";
    case QUERY_NODE_DROP_INDEX_STMT:
      return "DropIndexStmt";
    case QUERY_NODE_CREATE_QNODE_STMT:
      return "CreateQnodeStmt";
    case QUERY_NODE_DROP_QNODE_STMT:
      return "DropQnodeStmt";
    case QUERY_NODE_CREATE_TOPIC_STMT:
      return "CreateTopicStmt";
    case QUERY_NODE_DROP_TOPIC_STMT:
      return "DropTopicStmt";
    case QUERY_NODE_ALTER_LOCAL_STMT:
      return "AlterLocalStmt";
    case QUERY_NODE_SHOW_DNODES_STMT:
      return "ShowDnodesStmt";
    case QUERY_NODE_SHOW_MNODES_STMT:
      return "ShowMnodesStmt";
    case QUERY_NODE_SHOW_MODULES_STMT:
      return "ShowModulesStmt";
    case QUERY_NODE_SHOW_QNODES_STMT:
      return "ShowQnodesStmt";
146 147 148 149 150 151
    case QUERY_NODE_SHOW_SNODES_STMT:
      return "ShowSnodesStmt";
    case QUERY_NODE_SHOW_BNODES_STMT:
      return "ShowBnodesStmt";
    case QUERY_NODE_SHOW_DATABASES_STMT:
      return "ShowDatabaseStmt";
X
Xiaoyu Wang 已提交
152 153 154 155
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
      return "ShowFunctionsStmt";
    case QUERY_NODE_SHOW_INDEXES_STMT:
      return "ShowIndexesStmt";
156 157
    case QUERY_NODE_SHOW_STABLES_STMT:
      return "ShowStablesStmt";
X
Xiaoyu Wang 已提交
158 159
    case QUERY_NODE_SHOW_STREAMS_STMT:
      return "ShowStreamsStmt";
160 161
    case QUERY_NODE_SHOW_TABLES_STMT:
      return "ShowTablesStmt";
162 163
    case QUERY_NODE_SHOW_TAGS_STMT:
      return "ShowTagsStmt";
164 165
    case QUERY_NODE_SHOW_USERS_STMT:
      return "ShowUsersStmt";
X
Xiaoyu Wang 已提交
166
    case QUERY_NODE_SHOW_LICENCES_STMT:
167 168 169 170 171 172 173 174 175 176 177
      return "ShowGrantsStmt";
    case QUERY_NODE_SHOW_VGROUPS_STMT:
      return "ShowVgroupsStmt";
    case QUERY_NODE_SHOW_TOPICS_STMT:
      return "ShowTopicsStmt";
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
      return "ShowConsumersStmt";
    case QUERY_NODE_SHOW_QUERIES_STMT:
      return "ShowQueriesStmt";
    case QUERY_NODE_SHOW_VNODES_STMT:
      return "ShowVnodeStmt";
X
Xiaoyu Wang 已提交
178 179
    case QUERY_NODE_DELETE_STMT:
      return "DeleteStmt";
180 181
    case QUERY_NODE_INSERT_STMT:
      return "InsertStmt";
X
Xiaoyu Wang 已提交
182 183 184 185 186 187 188 189
    case QUERY_NODE_LOGIC_PLAN_SCAN:
      return "LogicScan";
    case QUERY_NODE_LOGIC_PLAN_JOIN:
      return "LogicJoin";
    case QUERY_NODE_LOGIC_PLAN_AGG:
      return "LogicAgg";
    case QUERY_NODE_LOGIC_PLAN_PROJECT:
      return "LogicProject";
X
Xiaoyu Wang 已提交
190 191
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
      return "LogicVnodeModify";
X
Xiaoyu Wang 已提交
192 193
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
      return "LogicExchange";
X
Xiaoyu Wang 已提交
194 195
    case QUERY_NODE_LOGIC_PLAN_MERGE:
      return "LogicMerge";
X
Xiaoyu Wang 已提交
196 197
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
      return "LogicWindow";
X
Xiaoyu Wang 已提交
198 199
    case QUERY_NODE_LOGIC_PLAN_FILL:
      return "LogicFill";
200 201 202 203
    case QUERY_NODE_LOGIC_PLAN_SORT:
      return "LogicSort";
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
      return "LogicPartition";
204 205
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
      return "LogicIndefRowsFunc";
X
Xiaoyu Wang 已提交
206 207
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
      return "LogicInterpFunc";
208 209 210 211
    case QUERY_NODE_LOGIC_SUBPLAN:
      return "LogicSubplan";
    case QUERY_NODE_LOGIC_PLAN:
      return "LogicPlan";
X
Xiaoyu Wang 已提交
212 213 214 215
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
      return "PhysiTagScan";
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
      return "PhysiTableScan";
216 217 218 219
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
      return "PhysiTableSeqScan";
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
      return "PhysiSreamScan";
X
Xiaoyu Wang 已提交
220 221
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
      return "PhysiSystemTableScan";
222 223
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
      return "PhysiBlockDistScan";
X
Xiaoyu Wang 已提交
224 225
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
      return "PhysiLastRowScan";
226 227
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
      return "PhysiTableMergeScan";
X
Xiaoyu Wang 已提交
228 229
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
      return "PhysiProject";
230
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
X
Xiaoyu Wang 已提交
231
      return "PhysiJoin";
232
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
X
Xiaoyu Wang 已提交
233
      return "PhysiAgg";
234 235
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
      return "PhysiExchange";
X
Xiaoyu Wang 已提交
236 237
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
      return "PhysiMerge";
238 239
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
      return "PhysiSort";
240 241
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT:
      return "PhysiGroupSort";
X
Xiaoyu Wang 已提交
242 243
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
      return "PhysiHashInterval";
244 245
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
      return "PhysiMergeAlignedInterval";
X
Xiaoyu Wang 已提交
246 247
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
      return "PhysiStreamInterval";
248 249 250 251
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
      return "PhysiStreamFinalInterval";
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
      return "PhysiStreamSemiInterval";
X
Xiaoyu Wang 已提交
252 253
    case QUERY_NODE_PHYSICAL_PLAN_FILL:
      return "PhysiFill";
254
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
255
      return "PhysiSessionWindow";
256
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
5
54liuyao 已提交
257
      return "PhysiStreamSessionWindow";
258 259 260 261
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
      return "PhysiStreamSemiSessionWindow";
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
      return "PhysiStreamFinalSessionWindow";
262
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
263
      return "PhysiStateWindow";
264
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE:
5
54liuyao 已提交
265
      return "PhysiStreamStateWindow";
266 267
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
      return "PhysiPartition";
268 269
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
      return "PhysiIndefRowsFunc";
X
Xiaoyu Wang 已提交
270 271
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
      return "PhysiInterpFunc";
272 273 274 275
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
      return "PhysiDispatch";
    case QUERY_NODE_PHYSICAL_PLAN_INSERT:
      return "PhysiInsert";
276 277
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return "PhysiQueryInsert";
X
Xiaoyu Wang 已提交
278 279
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return "PhysiDelete";
X
Xiaoyu Wang 已提交
280 281 282 283
    case QUERY_NODE_PHYSICAL_SUBPLAN:
      return "PhysiSubplan";
    case QUERY_NODE_PHYSICAL_PLAN:
      return "PhysiPlan";
284 285 286
    default:
      break;
  }
287 288
  nodesWarn("nodesNodeName unknown node = %d", type);
  return "UnknownNode";
289 290
}

X
Xiaoyu Wang 已提交
291
static int32_t nodeListToJson(SJson* pJson, const char* pName, const SNodeList* pList) {
X
Xiaoyu Wang 已提交
292 293 294 295 296 297 298
  if (LIST_LENGTH(pList) > 0) {
    SJson* jList = tjsonAddArrayToObject(pJson, pName);
    if (NULL == jList) {
      return TSDB_CODE_OUT_OF_MEMORY;
    }
    SNode* pNode;
    FOREACH(pNode, pList) {
X
Xiaoyu Wang 已提交
299
      int32_t code = tjsonAddItem(jList, nodeToJson, pNode);
X
Xiaoyu Wang 已提交
300 301 302 303 304 305 306 307
      if (TSDB_CODE_SUCCESS != code) {
        return code;
      }
    }
  }
  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
308
static int32_t jsonToNodeListImpl(const SJson* pJsonArray, SNodeList** pList) {
X
Xiaoyu Wang 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
  int32_t size = (NULL == pJsonArray ? 0 : tjsonGetArraySize(pJsonArray));
  if (size > 0) {
    *pList = nodesMakeList();
    if (NULL == *pList) {
      return TSDB_CODE_OUT_OF_MEMORY;
    }
  }

  int32_t code = TSDB_CODE_SUCCESS;
  for (int32_t i = 0; i < size; ++i) {
    SJson* pJsonItem = tjsonGetArrayItem(pJsonArray, i);
    SNode* pNode = NULL;
    code = makeNodeByJson(pJsonItem, &pNode);
    if (TSDB_CODE_SUCCESS == code) {
      code = nodesListAppend(*pList, pNode);
    }
    if (TSDB_CODE_SUCCESS != code) {
      break;
    }
  }
  return code;
}

X
Xiaoyu Wang 已提交
332 333 334 335
static int32_t jsonToNodeList(const SJson* pJson, const char* pName, SNodeList** pList) {
  return jsonToNodeListImpl(tjsonGetObjectItem(pJson, pName), pList);
}

X
Xiaoyu Wang 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
static const char* jkTableComInfoNumOfTags = "NumOfTags";
static const char* jkTableComInfoPrecision = "Precision";
static const char* jkTableComInfoNumOfColumns = "NumOfColumns";
static const char* jkTableComInfoRowSize = "RowSize";

static int32_t tableComInfoToJson(const void* pObj, SJson* pJson) {
  const STableComInfo* pNode = (const STableComInfo*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkTableComInfoNumOfTags, pNode->numOfTags);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableComInfoPrecision, pNode->precision);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableComInfoNumOfColumns, pNode->numOfColumns);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableComInfoRowSize, pNode->rowSize);
  }
X
Xiaoyu Wang 已提交
354

X
Xiaoyu Wang 已提交
355 356 357 358 359 360
  return code;
}

static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) {
  STableComInfo* pNode = (STableComInfo*)pObj;

361
  int32_t code;
362 363
  tjsonGetNumberValue(pJson, jkTableComInfoNumOfTags, pNode->numOfTags, code);
  ;
X
Xiaoyu Wang 已提交
364
  if (TSDB_CODE_SUCCESS == code) {
365 366
    tjsonGetNumberValue(pJson, jkTableComInfoPrecision, pNode->precision, code);
    ;
X
Xiaoyu Wang 已提交
367 368
  }
  if (TSDB_CODE_SUCCESS == code) {
369 370
    tjsonGetNumberValue(pJson, jkTableComInfoNumOfColumns, pNode->numOfColumns, code);
    ;
X
Xiaoyu Wang 已提交
371 372
  }
  if (TSDB_CODE_SUCCESS == code) {
373 374
    tjsonGetNumberValue(pJson, jkTableComInfoRowSize, pNode->rowSize, code);
    ;
X
Xiaoyu Wang 已提交
375
  }
X
Xiaoyu Wang 已提交
376

X
Xiaoyu Wang 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
  return code;
}

static const char* jkSchemaType = "Type";
static const char* jkSchemaColId = "ColId";
static const char* jkSchemaBytes = "bytes";
static const char* jkSchemaName = "Name";

static int32_t schemaToJson(const void* pObj, SJson* pJson) {
  const SSchema* pNode = (const SSchema*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkSchemaType, pNode->type);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSchemaColId, pNode->colId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSchemaBytes, pNode->bytes);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSchemaName, pNode->name);
  }
X
Xiaoyu Wang 已提交
398

X
Xiaoyu Wang 已提交
399 400 401 402 403 404
  return code;
}

static int32_t jsonToSchema(const SJson* pJson, void* pObj) {
  SSchema* pNode = (SSchema*)pObj;

405
  int32_t code;
406 407
  tjsonGetNumberValue(pJson, jkSchemaType, pNode->type, code);
  ;
X
Xiaoyu Wang 已提交
408
  if (TSDB_CODE_SUCCESS == code) {
409 410
    tjsonGetNumberValue(pJson, jkSchemaColId, pNode->colId, code);
    ;
X
Xiaoyu Wang 已提交
411 412
  }
  if (TSDB_CODE_SUCCESS == code) {
413 414
    tjsonGetNumberValue(pJson, jkSchemaBytes, pNode->bytes, code);
    ;
X
Xiaoyu Wang 已提交
415 416 417 418
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSchemaName, pNode->name);
  }
X
Xiaoyu Wang 已提交
419

X
Xiaoyu Wang 已提交
420 421 422 423 424 425 426 427 428 429 430
  return code;
}

static const char* jkTableMetaVgId = "VgId";
static const char* jkTableMetaTableType = "TableType";
static const char* jkTableMetaUid = "Uid";
static const char* jkTableMetaSuid = "Suid";
static const char* jkTableMetaSversion = "Sversion";
static const char* jkTableMetaTversion = "Tversion";
static const char* jkTableMetaComInfo = "ComInfo";
static const char* jkTableMetaColSchemas = "ColSchemas";
X
Xiaoyu Wang 已提交
431 432 433 434

static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
  const STableMeta* pNode = (const STableMeta*)pObj;

X
Xiaoyu Wang 已提交
435 436 437 438 439 440 441
  int32_t code = tjsonAddIntegerToObject(pJson, jkTableMetaVgId, pNode->vgId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableMetaTableType, pNode->tableType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableMetaUid, pNode->uid);
  }
X
Xiaoyu Wang 已提交
442 443 444
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableMetaSuid, pNode->suid);
  }
X
Xiaoyu Wang 已提交
445 446 447 448 449 450 451 452 453 454
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableMetaSversion, pNode->sversion);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableMetaTversion, pNode->tversion);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkTableMetaComInfo, tableComInfoToJson, &pNode->tableInfo);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
455 456
    code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema),
                         TABLE_TOTAL_COL_NUM(pNode));
X
Xiaoyu Wang 已提交
457
  }
X
Xiaoyu Wang 已提交
458 459 460 461

  return code;
}

X
Xiaoyu Wang 已提交
462 463 464
static int32_t jsonToTableMeta(const SJson* pJson, void* pObj) {
  STableMeta* pNode = (STableMeta*)pObj;

465
  int32_t code;
466 467
  tjsonGetNumberValue(pJson, jkTableMetaVgId, pNode->vgId, code);
  ;
X
Xiaoyu Wang 已提交
468
  if (TSDB_CODE_SUCCESS == code) {
469 470
    tjsonGetNumberValue(pJson, jkTableMetaTableType, pNode->tableType, code);
    ;
X
Xiaoyu Wang 已提交
471 472
  }
  if (TSDB_CODE_SUCCESS == code) {
473 474
    tjsonGetNumberValue(pJson, jkTableMetaUid, pNode->uid, code);
    ;
X
Xiaoyu Wang 已提交
475 476
  }
  if (TSDB_CODE_SUCCESS == code) {
477 478
    tjsonGetNumberValue(pJson, jkTableMetaSuid, pNode->suid, code);
    ;
X
Xiaoyu Wang 已提交
479 480
  }
  if (TSDB_CODE_SUCCESS == code) {
481 482
    tjsonGetNumberValue(pJson, jkTableMetaSversion, pNode->sversion, code);
    ;
X
Xiaoyu Wang 已提交
483 484
  }
  if (TSDB_CODE_SUCCESS == code) {
485 486
    tjsonGetNumberValue(pJson, jkTableMetaTversion, pNode->tversion, code);
    ;
X
Xiaoyu Wang 已提交
487 488 489 490 491 492
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkTableMetaComInfo, jsonToTableComInfo, &pNode->tableInfo);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToArray(pJson, jkTableMetaColSchemas, jsonToSchema, pNode->schema, sizeof(SSchema));
X
Xiaoyu Wang 已提交
493
  }
X
Xiaoyu Wang 已提交
494 495 496 497 498 499 500

  return code;
}

static const char* jkLogicPlanTargets = "Targets";
static const char* jkLogicPlanConditions = "Conditions";
static const char* jkLogicPlanChildren = "Children";
501 502
static const char* jkLogicPlanLimit = "Limit";
static const char* jkLogicPlanSlimit = "SLimit";
503 504 505
static const char* jkLogicPlanRequireDataOrder = "RequireDataOrder";
static const char* jkLogicPlanResultDataOrder = "ResultDataOrder";
static const char* jkLogicPlanGroupAction = "GroupAction";
X
Xiaoyu Wang 已提交
506 507 508 509

static int32_t logicPlanNodeToJson(const void* pObj, SJson* pJson) {
  const SLogicNode* pNode = (const SLogicNode*)pObj;

X
Xiaoyu Wang 已提交
510
  int32_t code = nodeListToJson(pJson, jkLogicPlanTargets, pNode->pTargets);
X
Xiaoyu Wang 已提交
511 512 513 514
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicPlanConditions, nodeToJson, pNode->pConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
515
    code = nodeListToJson(pJson, jkLogicPlanChildren, pNode->pChildren);
X
Xiaoyu Wang 已提交
516
  }
517 518 519 520 521 522
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicPlanLimit, nodeToJson, pNode->pLimit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicPlanSlimit, nodeToJson, pNode->pSlimit);
  }
523 524 525 526 527 528 529 530 531
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicPlanRequireDataOrder, pNode->requireDataOrder);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicPlanResultDataOrder, pNode->resultDataOrder);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicPlanGroupAction, pNode->groupAction);
  }
X
Xiaoyu Wang 已提交
532 533 534 535

  return code;
}

X
Xiaoyu Wang 已提交
536 537 538 539 540 541 542 543 544 545
static int32_t jsonToLogicPlanNode(const SJson* pJson, void* pObj) {
  SLogicNode* pNode = (SLogicNode*)pObj;

  int32_t code = jsonToNodeList(pJson, jkLogicPlanTargets, &pNode->pTargets);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkLogicPlanConditions, &pNode->pConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkLogicPlanChildren, &pNode->pChildren);
  }
546 547 548 549 550 551
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkLogicPlanLimit, &pNode->pLimit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkLogicPlanSlimit, &pNode->pSlimit);
  }
552 553 554 555 556 557 558 559 560
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkLogicPlanRequireDataOrder, pNode->requireDataOrder, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkLogicPlanResultDataOrder, pNode->resultDataOrder, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkLogicPlanGroupAction, pNode->groupAction, code);
  }
X
Xiaoyu Wang 已提交
561 562 563 564

  return code;
}

X
Xiaoyu Wang 已提交
565
static const char* jkScanLogicPlanScanCols = "ScanCols";
566
static const char* jkScanLogicPlanScanPseudoCols = "ScanPseudoCols";
X
Xiaoyu Wang 已提交
567
static const char* jkScanLogicPlanTableType = "TableType";
568 569
static const char* jkScanLogicPlanTableId = "TableId";
static const char* jkScanLogicPlanStableId = "StableId";
570
static const char* jkScanLogicPlanScanType = "ScanType";
571 572
static const char* jkScanLogicPlanScanCount = "ScanCount";
static const char* jkScanLogicPlanReverseScanCount = "ReverseScanCount";
X
Xiaoyu Wang 已提交
573
static const char* jkScanLogicPlanTagCond = "TagCond";
574
static const char* jkScanLogicPlanGroupTags = "GroupTags";
X
Xiaoyu Wang 已提交
575

X
Xiaoyu Wang 已提交
576
static int32_t logicScanNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
577 578 579 580
  const SScanLogicNode* pNode = (const SScanLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
581
    code = nodeListToJson(pJson, jkScanLogicPlanScanCols, pNode->pScanCols);
X
Xiaoyu Wang 已提交
582
  }
583 584 585
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkScanLogicPlanScanPseudoCols, pNode->pScanPseudoCols);
  }
586 587 588
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableType, pNode->tableType);
  }
X
Xiaoyu Wang 已提交
589
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
590
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableId, pNode->tableId);
X
Xiaoyu Wang 已提交
591
  }
X
Xiaoyu Wang 已提交
592
  if (TSDB_CODE_SUCCESS == code) {
593 594
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanStableId, pNode->stableId);
  }
595 596 597
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanScanType, pNode->scanType);
  }
598 599 600 601 602
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanScanCount, pNode->scanSeq[0]);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanReverseScanCount, pNode->scanSeq[1]);
X
Xiaoyu Wang 已提交
603
  }
X
Xiaoyu Wang 已提交
604 605 606
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkScanLogicPlanTagCond, nodeToJson, pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
607
  if (TSDB_CODE_SUCCESS == code) {
608
    code = nodeListToJson(pJson, jkScanLogicPlanGroupTags, pNode->pGroupTags);
X
Xiaoyu Wang 已提交
609
  }
X
Xiaoyu Wang 已提交
610 611 612 613

  return code;
}

X
Xiaoyu Wang 已提交
614 615 616 617 618 619 620 621
static int32_t jsonToLogicScanNode(const SJson* pJson, void* pObj) {
  SScanLogicNode* pNode = (SScanLogicNode*)pObj;

  int32_t objSize = 0;
  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkScanLogicPlanScanCols, &pNode->pScanCols);
  }
622 623 624
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkScanLogicPlanScanPseudoCols, &pNode->pScanPseudoCols);
  }
625 626 627
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkScanLogicPlanTableType, &pNode->tableType);
  }
X
Xiaoyu Wang 已提交
628
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
629
    code = tjsonGetUBigIntValue(pJson, jkScanLogicPlanTableId, &pNode->tableId);
X
Xiaoyu Wang 已提交
630 631
  }
  if (TSDB_CODE_SUCCESS == code) {
632 633
    code = tjsonGetUBigIntValue(pJson, jkScanLogicPlanStableId, &pNode->stableId);
  }
634 635 636
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkScanLogicPlanScanType, pNode->scanType, code);
  }
637 638 639 640 641
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkScanLogicPlanScanCount, &pNode->scanSeq[0]);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkScanLogicPlanReverseScanCount, &pNode->scanSeq[1]);
X
Xiaoyu Wang 已提交
642
  }
X
Xiaoyu Wang 已提交
643 644 645
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkScanLogicPlanTagCond, &pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
646
  if (TSDB_CODE_SUCCESS == code) {
647
    code = jsonToNodeList(pJson, jkScanLogicPlanGroupTags, &pNode->pGroupTags);
X
Xiaoyu Wang 已提交
648
  }
X
Xiaoyu Wang 已提交
649 650 651 652

  return code;
}

X
Xiaoyu Wang 已提交
653
static const char* jkProjectLogicPlanProjections = "Projections";
654
static const char* jkProjectLogicPlanIgnoreGroupId = "IgnoreGroupId";
X
Xiaoyu Wang 已提交
655

X
Xiaoyu Wang 已提交
656
static int32_t logicProjectNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
657 658 659 660
  const SProjectLogicNode* pNode = (const SProjectLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
661
    code = nodeListToJson(pJson, jkProjectLogicPlanProjections, pNode->pProjections);
X
Xiaoyu Wang 已提交
662
  }
663 664 665
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanIgnoreGroupId, pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
666 667 668 669

  return code;
}

X
Xiaoyu Wang 已提交
670 671 672 673 674 675 676
static int32_t jsonToLogicProjectNode(const SJson* pJson, void* pObj) {
  SProjectLogicNode* pNode = (SProjectLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkProjectLogicPlanProjections, &pNode->pProjections);
  }
677 678 679
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkProjectLogicPlanIgnoreGroupId, &pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
680 681 682 683 684 685

  return code;
}

static const char* jkVnodeModifyLogicPlanModifyType = "ModifyType";
static const char* jkVnodeModifyLogicPlanMsgType = "MsgType";
X
Xiaoyu Wang 已提交
686
static const char* jkVnodeModifyLogicPlanAffectedRows = "AffectedRows";
X
Xiaoyu Wang 已提交
687 688 689 690 691 692 693 694 695 696 697 698

static int32_t logicVnodeModifyNodeToJson(const void* pObj, SJson* pJson) {
  const SVnodeModifyLogicNode* pNode = (const SVnodeModifyLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkVnodeModifyLogicPlanModifyType, pNode->modifyType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkVnodeModifyLogicPlanMsgType, pNode->msgType);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
699
    code = tjsonAddObject(pJson, jkVnodeModifyLogicPlanAffectedRows, nodeToJson, pNode->pAffectedRows);
X
Xiaoyu Wang 已提交
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
  }

  return code;
}

static int32_t jsonToLogicVnodeModifyNode(const SJson* pJson, void* pObj) {
  SVnodeModifyLogicNode* pNode = (SVnodeModifyLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkVnodeModifyLogicPlanModifyType, pNode->modifyType, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkVnodeModifyLogicPlanMsgType, &pNode->msgType);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
716
    code = jsonToNodeObject(pJson, jkVnodeModifyLogicPlanAffectedRows, &pNode->pAffectedRows);
717
  }
X
Xiaoyu Wang 已提交
718 719 720 721

  return code;
}

X
Xiaoyu Wang 已提交
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
static const char* jkExchangeLogicPlanSrcGroupId = "SrcGroupId";

static int32_t logicExchangeNodeToJson(const void* pObj, SJson* pJson) {
  const SExchangeLogicNode* pNode = (const SExchangeLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkExchangeLogicPlanSrcGroupId, pNode->srcGroupId);
  }

  return code;
}

static int32_t jsonToLogicExchangeNode(const SJson* pJson, void* pObj) {
  SExchangeLogicNode* pNode = (SExchangeLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkExchangeLogicPlanSrcGroupId, &pNode->srcGroupId);
  }
X
Xiaoyu Wang 已提交
742 743 744 745 746

  return code;
}

static const char* jkMergeLogicPlanMergeKeys = "MergeKeys";
747
static const char* jkMergeLogicPlanInputs = "Inputs";
X
Xiaoyu Wang 已提交
748 749 750 751 752 753 754 755 756 757
static const char* jkMergeLogicPlanNumOfChannels = "NumOfChannels";
static const char* jkMergeLogicPlanSrcGroupId = "SrcGroupId";

static int32_t logicMergeNodeToJson(const void* pObj, SJson* pJson) {
  const SMergeLogicNode* pNode = (const SMergeLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkMergeLogicPlanMergeKeys, pNode->pMergeKeys);
  }
758 759 760
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkMergeLogicPlanInputs, pNode->pInputs);
  }
X
Xiaoyu Wang 已提交
761
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
    code = tjsonAddIntegerToObject(pJson, jkMergeLogicPlanNumOfChannels, pNode->numOfChannels);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkMergeLogicPlanSrcGroupId, pNode->srcGroupId);
  }

  return code;
}

static int32_t jsonToLogicMergeNode(const SJson* pJson, void* pObj) {
  SMergeLogicNode* pNode = (SMergeLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkMergeLogicPlanMergeKeys, &pNode->pMergeKeys);
  }
778 779 780
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkMergeLogicPlanInputs, &pNode->pInputs);
  }
X
Xiaoyu Wang 已提交
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 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 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkMergeLogicPlanNumOfChannels, &pNode->numOfChannels);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkMergeLogicPlanSrcGroupId, &pNode->srcGroupId);
  }

  return code;
}

static const char* jkWindowLogicPlanWinType = "WinType";
static const char* jkWindowLogicPlanFuncs = "Funcs";
static const char* jkWindowLogicPlanInterval = "Interval";
static const char* jkWindowLogicPlanOffset = "Offset";
static const char* jkWindowLogicPlanSliding = "Sliding";
static const char* jkWindowLogicPlanIntervalUnit = "IntervalUnit";
static const char* jkWindowLogicPlanSlidingUnit = "SlidingUnit";
static const char* jkWindowLogicPlanSessionGap = "SessionGap";
static const char* jkWindowLogicPlanTspk = "Tspk";
static const char* jkWindowLogicPlanStateExpr = "StateExpr";
static const char* jkWindowLogicPlanTriggerType = "TriggerType";
static const char* jkWindowLogicPlanWatermark = "Watermark";

static int32_t logicWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SWindowLogicNode* pNode = (const SWindowLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanWinType, pNode->winType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkWindowLogicPlanFuncs, pNode->pFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanInterval, pNode->interval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanOffset, pNode->offset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanSliding, pNode->sliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanIntervalUnit, pNode->intervalUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanSlidingUnit, pNode->slidingUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanSessionGap, pNode->sessionGap);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWindowLogicPlanTspk, nodeToJson, pNode->pTspk);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWindowLogicPlanStateExpr, nodeToJson, pNode->pStateExpr);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanTriggerType, pNode->triggerType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanWatermark, pNode->watermark);
  }

  return code;
}

static int32_t jsonToLogicWindowNode(const SJson* pJson, void* pObj) {
  SWindowLogicNode* pNode = (SWindowLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkWindowLogicPlanWinType, pNode->winType, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkWindowLogicPlanFuncs, &pNode->pFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkWindowLogicPlanInterval, &pNode->interval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkWindowLogicPlanOffset, &pNode->offset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkWindowLogicPlanSliding, &pNode->sliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkWindowLogicPlanIntervalUnit, &pNode->intervalUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkWindowLogicPlanSlidingUnit, &pNode->slidingUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkWindowLogicPlanSessionGap, &pNode->sessionGap);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWindowLogicPlanTspk, &pNode->pTspk);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWindowLogicPlanStateExpr, &pNode->pStateExpr);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkWindowLogicPlanTriggerType, &pNode->triggerType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkWindowLogicPlanWatermark, &pNode->watermark);
X
Xiaoyu Wang 已提交
887 888 889 890 891
  }

  return code;
}

X
Xiaoyu Wang 已提交
892 893 894
static const char* jkFillLogicPlanMode = "Mode";
static const char* jkFillLogicPlanWStartTs = "WStartTs";
static const char* jkFillLogicPlanValues = "Values";
X
Xiaoyu Wang 已提交
895 896
static const char* jkFillLogicPlanStartTime = "StartTime";
static const char* jkFillLogicPlanEndTime = "EndTime";
X
Xiaoyu Wang 已提交
897 898 899 900 901 902 903 904 905 906 907 908 909 910

static int32_t logicFillNodeToJson(const void* pObj, SJson* pJson) {
  const SFillLogicNode* pNode = (const SFillLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillLogicPlanMode, pNode->mode);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkFillLogicPlanWStartTs, nodeToJson, pNode->pWStartTs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkFillLogicPlanValues, nodeToJson, pNode->pValues);
  }
X
Xiaoyu Wang 已提交
911 912 913 914 915 916
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillLogicPlanStartTime, pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillLogicPlanEndTime, pNode->timeRange.ekey);
  }
X
Xiaoyu Wang 已提交
917 918 919 920 921 922 923 924 925

  return code;
}

static int32_t jsonToLogicFillNode(const SJson* pJson, void* pObj) {
  SFillLogicNode* pNode = (SFillLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
926 927
    tjsonGetNumberValue(pJson, jkFillLogicPlanMode, pNode->mode, code);
    ;
X
Xiaoyu Wang 已提交
928 929 930 931 932 933 934
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillLogicPlanWStartTs, &pNode->pWStartTs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillLogicPlanValues, &pNode->pValues);
  }
X
Xiaoyu Wang 已提交
935 936 937 938 939 940
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkFillLogicPlanStartTime, &pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkFillLogicPlanEndTime, &pNode->timeRange.ekey);
  }
X
Xiaoyu Wang 已提交
941 942 943 944

  return code;
}

945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
static const char* jkSortLogicPlanSortKeys = "SortKeys";

static int32_t logicSortNodeToJson(const void* pObj, SJson* pJson) {
  const SSortLogicNode* pNode = (const SSortLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSortLogicPlanSortKeys, pNode->pSortKeys);
  }

  return code;
}

static int32_t jsonToLogicSortNode(const SJson* pJson, void* pObj) {
  SSortLogicNode* pNode = (SSortLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSortLogicPlanSortKeys, &pNode->pSortKeys);
  }

  return code;
}

969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
static const char* jkPartitionLogicPlanPartitionKeys = "PartitionKeys";

static int32_t logicPartitionNodeToJson(const void* pObj, SJson* pJson) {
  const SPartitionLogicNode* pNode = (const SPartitionLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkPartitionLogicPlanPartitionKeys, pNode->pPartitionKeys);
  }

  return code;
}

static int32_t jsonToLogicPartitionNode(const SJson* pJson, void* pObj) {
  SPartitionLogicNode* pNode = (SPartitionLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkPartitionLogicPlanPartitionKeys, &pNode->pPartitionKeys);
  }

  return code;
}

X
Xiaoyu Wang 已提交
993
static const char* jkIndefRowsFuncLogicPlanFuncs = "Funcs";
994 995 996 997 998 999

static int32_t logicIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
  const SIndefRowsFuncLogicNode* pNode = (const SIndefRowsFuncLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1000
    code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanFuncs, pNode->pFuncs);
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
  }

  return code;
}

static int32_t jsonToLogicIndefRowsFuncNode(const SJson* pJson, void* pObj) {
  SIndefRowsFuncLogicNode* pNode = (SIndefRowsFuncLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
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 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
    code = jsonToNodeList(pJson, jkIndefRowsFuncLogicPlanFuncs, &pNode->pFuncs);
  }

  return code;
}

static const char* jkInterpFuncLogicPlanFuncs = "Funcs";
static const char* jkInterpFuncLogicPlanStartTime = "StartTime";
static const char* jkInterpFuncLogicPlanEndTime = "EndTime";
static const char* jkInterpFuncLogicPlanInterval = "Interval";

static int32_t logicInterpFuncNodeToJson(const void* pObj, SJson* pJson) {
  const SInterpFuncLogicNode* pNode = (const SInterpFuncLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkInterpFuncLogicPlanFuncs, pNode->pFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanStartTime, pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanEndTime, pNode->timeRange.ekey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanInterval, pNode->interval);
  }

  return code;
}

static int32_t jsonToLogicInterpFuncNode(const SJson* pJson, void* pObj) {
  SInterpFuncLogicNode* pNode = (SInterpFuncLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkInterpFuncLogicPlanFuncs, &pNode->pFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanStartTime, &pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanEndTime, &pNode->timeRange.ekey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanInterval, &pNode->interval);
1057 1058 1059 1060 1061
  }

  return code;
}

1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 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 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
static const char* jkSubplanIdQueryId = "QueryId";
static const char* jkSubplanIdGroupId = "GroupId";
static const char* jkSubplanIdSubplanId = "SubplanId";

static int32_t subplanIdToJson(const void* pObj, SJson* pJson) {
  const SSubplanId* pNode = (const SSubplanId*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkSubplanIdQueryId, pNode->queryId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSubplanIdGroupId, pNode->groupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSubplanIdSubplanId, pNode->subplanId);
  }

  return code;
}

static int32_t jsonToSubplanId(const SJson* pJson, void* pObj) {
  SSubplanId* pNode = (SSubplanId*)pObj;

  int32_t code = tjsonGetUBigIntValue(pJson, jkSubplanIdQueryId, &pNode->queryId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkSubplanIdGroupId, &pNode->groupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkSubplanIdSubplanId, &pNode->subplanId);
  }

  return code;
}

static const char* jkEndPointFqdn = "Fqdn";
static const char* jkEndPointPort = "Port";

static int32_t epToJson(const void* pObj, SJson* pJson) {
  const SEp* pNode = (const SEp*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkEndPointFqdn, pNode->fqdn);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkEndPointPort, pNode->port);
  }

  return code;
}

static int32_t jsonToEp(const SJson* pJson, void* pObj) {
  SEp* pNode = (SEp*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkEndPointFqdn, pNode->fqdn);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetSmallIntValue(pJson, jkEndPointPort, &pNode->port);
  }

  return code;
}

static const char* jkEpSetInUse = "InUse";
static const char* jkEpSetNumOfEps = "NumOfEps";
static const char* jkEpSetEps = "Eps";

static int32_t epSetToJson(const void* pObj, SJson* pJson) {
  const SEpSet* pNode = (const SEpSet*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkEpSetInUse, pNode->inUse);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkEpSetNumOfEps, pNode->numOfEps);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddArray(pJson, jkEpSetEps, epToJson, pNode->eps, sizeof(SEp), pNode->numOfEps);
  }

  return code;
}

static int32_t jsonToEpSet(const SJson* pJson, void* pObj) {
  SEpSet* pNode = (SEpSet*)pObj;

  int32_t code = tjsonGetTinyIntValue(pJson, jkEpSetInUse, &pNode->inUse);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkEpSetNumOfEps, &pNode->numOfEps);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToArray(pJson, jkEpSetEps, jsonToEp, pNode->eps, sizeof(SEp));
  }

  return code;
}

static const char* jkVgroupInfoVgId = "VgId";
static const char* jkVgroupInfoHashBegin = "HashBegin";
static const char* jkVgroupInfoHashEnd = "HashEnd";
static const char* jkVgroupInfoEpSet = "EpSet";
static const char* jkVgroupInfoNumOfTable = "NumOfTable";

static int32_t vgroupInfoToJson(const void* pObj, SJson* pJson) {
  const SVgroupInfo* pNode = (const SVgroupInfo*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupInfoVgId, pNode->vgId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashBegin, pNode->hashBegin);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashEnd, pNode->hashEnd);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkVgroupInfoEpSet, epSetToJson, &pNode->epSet);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkVgroupInfoNumOfTable, pNode->numOfTable);
  }

  return code;
}

static int32_t jsonToVgroupInfo(const SJson* pJson, void* pObj) {
  SVgroupInfo* pNode = (SVgroupInfo*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkVgroupInfoVgId, &pNode->vgId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUIntValue(pJson, jkVgroupInfoHashBegin, &pNode->hashBegin);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUIntValue(pJson, jkVgroupInfoHashEnd, &pNode->hashEnd);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkVgroupInfoEpSet, jsonToEpSet, &pNode->epSet);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkVgroupInfoNumOfTable, &pNode->numOfTable);
  }

  return code;
}

static const char* jkVgroupsInfoNum = "Num";
static const char* jkVgroupsInfoVgroups = "Vgroups";

static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) {
  const SVgroupsInfo* pNode = (const SVgroupsInfo*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo),
                         pNode->numOfVgroups);
  }

  return code;
}

static int32_t jsonToVgroupsInfo(const SJson* pJson, void* pObj) {
  SVgroupsInfo* pNode = (SVgroupsInfo*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkVgroupsInfoNum, &pNode->numOfVgroups);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToArray(pJson, jkVgroupsInfoVgroups, jsonToVgroupInfo, pNode->vgroups, sizeof(SVgroupInfo));
  }

  return code;
}

static const char* jkLogicSubplanId = "Id";
static const char* jkLogicSubplanChildren = "Children";
static const char* jkLogicSubplanRootNode = "RootNode";
static const char* jkLogicSubplanType = "SubplanType";
static const char* jkLogicSubplanVgroupsSize = "VgroupsSize";
static const char* jkLogicSubplanVgroups = "Vgroups";
static const char* jkLogicSubplanLevel = "Level";
static const char* jkLogicSubplanSplitFlag = "SplitFlag";
1231
static const char* jkLogicSubplanNumOfComputeNodes = "NumOfComputeNodes";
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257

static int32_t logicSubplanToJson(const void* pObj, SJson* pJson) {
  const SLogicSubplan* pNode = (const SLogicSubplan*)pObj;

  int32_t code = tjsonAddObject(pJson, jkLogicSubplanId, subplanIdToJson, &pNode->id);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkLogicSubplanChildren, pNode->pChildren);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicSubplanRootNode, nodeToJson, pNode->pNode);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicSubplanType, pNode->subplanType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicSubplanVgroupsSize, VGROUPS_INFO_SIZE(pNode->pVgroupList));
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicSubplanVgroups, vgroupsInfoToJson, pNode->pVgroupList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicSubplanLevel, pNode->level);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicSubplanSplitFlag, pNode->splitFlag);
  }
1258 1259 1260
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicSubplanNumOfComputeNodes, pNode->numOfComputeNodes);
  }
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275

  return code;
}

static int32_t jsonToLogicSubplan(const SJson* pJson, void* pObj) {
  SLogicSubplan* pNode = (SLogicSubplan*)pObj;

  int32_t code = tjsonToObject(pJson, jkLogicSubplanId, jsonToSubplanId, &pNode->id);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkLogicSubplanChildren, &pNode->pChildren);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkLogicSubplanRootNode, (SNode**)&pNode->pNode);
  }
  if (TSDB_CODE_SUCCESS == code) {
1276
    tjsonGetNumberValue(pJson, jkLogicSubplanType, pNode->subplanType, code);
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
  }
  int32_t objSize = 0;
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkLogicSubplanVgroupsSize, &objSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonMakeObject(pJson, jkLogicSubplanVgroups, jsonToVgroupsInfo, (void**)&pNode->pVgroupList, objSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkLogicSubplanLevel, &pNode->level);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkLogicSubplanSplitFlag, &pNode->splitFlag);
  }
1291 1292 1293
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkLogicSubplanNumOfComputeNodes, &pNode->numOfComputeNodes);
  }
1294 1295 1296 1297

  return code;
}

1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
static const char* jkLogicPlanSubplans = "Subplans";

static int32_t logicPlanToJson(const void* pObj, SJson* pJson) {
  const SQueryLogicPlan* pNode = (const SQueryLogicPlan*)pObj;
  return tjsonAddObject(pJson, jkLogicPlanSubplans, nodeToJson, nodesListGetNode(pNode->pTopSubplans, 0));
}

static int32_t jsonToLogicPlan(const SJson* pJson, void* pObj) {
  SQueryLogicPlan* pNode = (SQueryLogicPlan*)pObj;
  SNode*           pChild = NULL;
  int32_t          code = jsonToNodeObject(pJson, jkLogicPlanSubplans, &pChild);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodesListMakeStrictAppend(&pNode->pTopSubplans, pChild);
  }
  return code;
}

X
Xiaoyu Wang 已提交
1315 1316
static const char* jkJoinLogicPlanJoinType = "JoinType";
static const char* jkJoinLogicPlanOnConditions = "OnConditions";
1317
static const char* jkJoinLogicPlanMergeCondition = "MergeConditions";
X
Xiaoyu Wang 已提交
1318

X
Xiaoyu Wang 已提交
1319
static int32_t logicJoinNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
1320 1321 1322 1323 1324 1325
  const SJoinLogicNode* pNode = (const SJoinLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkJoinLogicPlanJoinType, pNode->joinType);
  }
1326 1327 1328
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinLogicPlanMergeCondition, nodeToJson, pNode->pMergeCondition);
  }
X
Xiaoyu Wang 已提交
1329 1330 1331 1332 1333 1334 1335
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinLogicPlanOnConditions, nodeToJson, pNode->pOnConditions);
  }

  return code;
}

X
Xiaoyu Wang 已提交
1336
static const char* jkPhysiPlanOutputDataBlockDesc = "OutputDataBlockDesc";
X
Xiaoyu Wang 已提交
1337 1338
static const char* jkPhysiPlanConditions = "Conditions";
static const char* jkPhysiPlanChildren = "Children";
1339 1340
static const char* jkPhysiPlanLimit = "Limit";
static const char* jkPhysiPlanSlimit = "SLimit";
X
Xiaoyu Wang 已提交
1341 1342 1343 1344

static int32_t physicPlanNodeToJson(const void* pObj, SJson* pJson) {
  const SPhysiNode* pNode = (const SPhysiNode*)pObj;

X
Xiaoyu Wang 已提交
1345
  int32_t code = tjsonAddObject(pJson, jkPhysiPlanOutputDataBlockDesc, nodeToJson, pNode->pOutputDataBlockDesc);
X
Xiaoyu Wang 已提交
1346 1347 1348 1349
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkPhysiPlanConditions, nodeToJson, pNode->pConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1350 1351
    code = nodeListToJson(pJson, jkPhysiPlanChildren, pNode->pChildren);
  }
1352 1353 1354 1355 1356 1357
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkPhysiPlanLimit, nodeToJson, pNode->pLimit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkPhysiPlanSlimit, nodeToJson, pNode->pSlimit);
  }
X
Xiaoyu Wang 已提交
1358 1359 1360 1361 1362 1363 1364

  return code;
}

static int32_t jsonToPhysicPlanNode(const SJson* pJson, void* pObj) {
  SPhysiNode* pNode = (SPhysiNode*)pObj;

X
Xiaoyu Wang 已提交
1365
  int32_t code = jsonToNodeObject(pJson, jkPhysiPlanOutputDataBlockDesc, (SNode**)&pNode->pOutputDataBlockDesc);
X
Xiaoyu Wang 已提交
1366 1367 1368 1369 1370
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkPhysiPlanConditions, &pNode->pConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkPhysiPlanChildren, &pNode->pChildren);
X
Xiaoyu Wang 已提交
1371
  }
1372 1373 1374 1375 1376 1377
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkPhysiPlanLimit, &pNode->pLimit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkPhysiPlanSlimit, &pNode->pSlimit);
  }
X
Xiaoyu Wang 已提交
1378 1379 1380 1381

  return code;
}

X
Xiaoyu Wang 已提交
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
static const char* jkNameType = "NameType";
static const char* jkNameAcctId = "AcctId";
static const char* jkNameDbName = "DbName";
static const char* jkNameTableName = "TableName";

static int32_t nameToJson(const void* pObj, SJson* pJson) {
  const SName* pNode = (const SName*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkNameType, pNode->type);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkNameAcctId, pNode->acctId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkNameDbName, pNode->dbname);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkNameTableName, pNode->tname);
  }

  return code;
}

static int32_t jsonToName(const SJson* pJson, void* pObj) {
  SName* pNode = (SName*)pObj;

  int32_t code = tjsonGetUTinyIntValue(pJson, jkNameType, &pNode->type);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkNameAcctId, &pNode->acctId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkNameDbName, pNode->dbname);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkNameTableName, pNode->tname);
  }

  return code;
}

X
Xiaoyu Wang 已提交
1421
static const char* jkScanPhysiPlanScanCols = "ScanCols";
1422
static const char* jkScanPhysiPlanScanPseudoCols = "ScanPseudoCols";
X
Xiaoyu Wang 已提交
1423
static const char* jkScanPhysiPlanTableId = "TableId";
X
Xiaoyu Wang 已提交
1424
static const char* jkScanPhysiPlanSTableId = "STableId";
X
Xiaoyu Wang 已提交
1425
static const char* jkScanPhysiPlanTableType = "TableType";
X
Xiaoyu Wang 已提交
1426
static const char* jkScanPhysiPlanTableName = "TableName";
X
Xiaoyu Wang 已提交
1427 1428 1429 1430 1431 1432

static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) {
  const STagScanPhysiNode* pNode = (const STagScanPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1433
    code = nodeListToJson(pJson, jkScanPhysiPlanScanCols, pNode->pScanCols);
X
Xiaoyu Wang 已提交
1434
  }
1435 1436 1437
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkScanPhysiPlanScanPseudoCols, pNode->pScanPseudoCols);
  }
X
Xiaoyu Wang 已提交
1438 1439 1440
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableId, pNode->uid);
  }
X
Xiaoyu Wang 已提交
1441 1442 1443
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanSTableId, pNode->suid);
  }
X
Xiaoyu Wang 已提交
1444 1445 1446
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableType, pNode->tableType);
  }
X
Xiaoyu Wang 已提交
1447 1448 1449
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkScanPhysiPlanTableName, nameToJson, &pNode->tableName);
  }
X
Xiaoyu Wang 已提交
1450 1451 1452 1453

  return code;
}

X
Xiaoyu Wang 已提交
1454 1455 1456 1457 1458 1459 1460
static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
  STagScanPhysiNode* pNode = (STagScanPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkScanPhysiPlanScanCols, &pNode->pScanCols);
  }
1461 1462 1463
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkScanPhysiPlanScanPseudoCols, &pNode->pScanPseudoCols);
  }
X
Xiaoyu Wang 已提交
1464 1465 1466
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanTableId, &pNode->uid);
  }
X
Xiaoyu Wang 已提交
1467 1468 1469
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanSTableId, &pNode->suid);
  }
X
Xiaoyu Wang 已提交
1470 1471 1472
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkScanPhysiPlanTableType, &pNode->tableType);
  }
X
Xiaoyu Wang 已提交
1473 1474 1475
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkScanPhysiPlanTableName, jsonToName, &pNode->tableName);
  }
X
Xiaoyu Wang 已提交
1476 1477 1478 1479

  return code;
}

X
Xiaoyu Wang 已提交
1480 1481
static const char* jkLastRowScanPhysiPlanGroupTags = "GroupTags";
static const char* jkLastRowScanPhysiPlanGroupSort = "GroupSort";
X
Xiaoyu Wang 已提交
1482

X
Xiaoyu Wang 已提交
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
static int32_t physiLastRowScanNodeToJson(const void* pObj, SJson* pJson) {
  const SLastRowScanPhysiNode* pNode = (const SLastRowScanPhysiNode*)pObj;

  int32_t code = physiScanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkLastRowScanPhysiPlanGroupTags, pNode->pGroupTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkLastRowScanPhysiPlanGroupSort, pNode->groupSort);
  }

  return code;
}

static int32_t jsonToPhysiLastRowScanNode(const SJson* pJson, void* pObj) {
  SLastRowScanPhysiNode* pNode = (SLastRowScanPhysiNode*)pObj;

  int32_t code = jsonToPhysiScanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkLastRowScanPhysiPlanGroupTags, &pNode->pGroupTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkLastRowScanPhysiPlanGroupSort, &pNode->groupSort);
  }

  return code;
}
X
Xiaoyu Wang 已提交
1510

X
Xiaoyu Wang 已提交
1511 1512
static const char* jkTableScanPhysiPlanScanCount = "ScanCount";
static const char* jkTableScanPhysiPlanReverseScanCount = "ReverseScanCount";
X
Xiaoyu Wang 已提交
1513 1514
static const char* jkTableScanPhysiPlanStartKey = "StartKey";
static const char* jkTableScanPhysiPlanEndKey = "EndKey";
S
Shengliang Guan 已提交
1515 1516 1517
static const char* jkTableScanPhysiPlanRatio = "Ratio";
static const char* jkTableScanPhysiPlanDataRequired = "DataRequired";
static const char* jkTableScanPhysiPlanDynamicScanFuncs = "DynamicScanFuncs";
X
Xiaoyu Wang 已提交
1518 1519 1520
static const char* jkTableScanPhysiPlanInterval = "Interval";
static const char* jkTableScanPhysiPlanOffset = "Offset";
static const char* jkTableScanPhysiPlanSliding = "Sliding";
1521 1522 1523 1524 1525
static const char* jkTableScanPhysiPlanIntervalUnit = "IntervalUnit";
static const char* jkTableScanPhysiPlanSlidingUnit = "SlidingUnit";
static const char* jkTableScanPhysiPlanTriggerType = "TriggerType";
static const char* jkTableScanPhysiPlanWatermark = "Watermark";
static const char* jkTableScanPhysiPlanIgnoreExpired = "IgnoreExpired";
1526 1527
static const char* jkTableScanPhysiPlanGroupTags = "GroupTags";
static const char* jkTableScanPhysiPlanGroupSort = "GroupSort";
1528
static const char* jkTableScanPhysiPlanAssignBlockUid = "AssignBlockUid";
X
Xiaoyu Wang 已提交
1529 1530 1531 1532 1533 1534

static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) {
  const STableScanPhysiNode* pNode = (const STableScanPhysiNode*)pObj;

  int32_t code = physiScanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1535 1536 1537 1538
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanScanCount, pNode->scanSeq[0]);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanReverseScanCount, pNode->scanSeq[1]);
X
Xiaoyu Wang 已提交
1539 1540 1541 1542 1543 1544 1545
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanStartKey, pNode->scanRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanEndKey, pNode->scanRange.ekey);
  }
S
Shengliang Guan 已提交
1546 1547 1548 1549 1550 1551 1552 1553 1554
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddDoubleToObject(pJson, jkTableScanPhysiPlanRatio, pNode->ratio);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkTableScanPhysiPlanDynamicScanFuncs, pNode->pDynamicScanFuncs);
  }
X
Xiaoyu Wang 已提交
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanInterval, pNode->interval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanOffset, pNode->offset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanSliding, pNode->sliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanIntervalUnit, pNode->intervalUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanSlidingUnit, pNode->slidingUnit);
  }
5
54liuyao 已提交
1570 1571 1572 1573 1574 1575 1576
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanTriggerType, pNode->triggerType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanWatermark, pNode->watermark);
  }
  if (TSDB_CODE_SUCCESS == code) {
1577
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanIgnoreExpired, pNode->igExpired);
5
54liuyao 已提交
1578
  }
X
Xiaoyu Wang 已提交
1579
  if (TSDB_CODE_SUCCESS == code) {
1580 1581 1582 1583
    code = nodeListToJson(pJson, jkTableScanPhysiPlanGroupTags, pNode->pGroupTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkTableScanPhysiPlanGroupSort, pNode->groupSort);
X
Xiaoyu Wang 已提交
1584
  }
1585 1586 1587
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkTableScanPhysiPlanAssignBlockUid, pNode->assignBlockUid);
  }
X
Xiaoyu Wang 已提交
1588 1589 1590 1591

  return code;
}

X
Xiaoyu Wang 已提交
1592 1593 1594 1595 1596
static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
  STableScanPhysiNode* pNode = (STableScanPhysiNode*)pObj;

  int32_t code = jsonToPhysiScanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1597 1598 1599 1600
    code = tjsonGetUTinyIntValue(pJson, jkTableScanPhysiPlanScanCount, &pNode->scanSeq[0]);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkTableScanPhysiPlanReverseScanCount, &pNode->scanSeq[1]);
X
Xiaoyu Wang 已提交
1601 1602 1603 1604 1605 1606 1607
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanStartKey, &pNode->scanRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanEndKey, &pNode->scanRange.ekey);
  }
S
Shengliang Guan 已提交
1608 1609 1610 1611
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetDoubleValue(pJson, jkTableScanPhysiPlanRatio, &pNode->ratio);
  }
  if (TSDB_CODE_SUCCESS == code) {
1612
    code = tjsonGetIntValue(pJson, jkTableScanPhysiPlanDataRequired, &pNode->dataRequired);
S
Shengliang Guan 已提交
1613 1614 1615 1616
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableScanPhysiPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs);
  }
X
Xiaoyu Wang 已提交
1617
  if (TSDB_CODE_SUCCESS == code) {
1618
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanInterval, &pNode->interval);
X
Xiaoyu Wang 已提交
1619 1620
  }
  if (TSDB_CODE_SUCCESS == code) {
1621
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanOffset, &pNode->offset);
X
Xiaoyu Wang 已提交
1622 1623
  }
  if (TSDB_CODE_SUCCESS == code) {
1624
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanSliding, &pNode->sliding);
X
Xiaoyu Wang 已提交
1625 1626
  }
  if (TSDB_CODE_SUCCESS == code) {
1627
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanIntervalUnit, &pNode->intervalUnit);
X
Xiaoyu Wang 已提交
1628
  }
5
54liuyao 已提交
1629
  if (TSDB_CODE_SUCCESS == code) {
1630
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanSlidingUnit, &pNode->slidingUnit);
5
54liuyao 已提交
1631 1632
  }
  if (TSDB_CODE_SUCCESS == code) {
1633
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanTriggerType, &pNode->triggerType);
5
54liuyao 已提交
1634 1635
  }
  if (TSDB_CODE_SUCCESS == code) {
1636
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanWatermark, &pNode->watermark);
5
54liuyao 已提交
1637
  }
5
54liuyao 已提交
1638
  if (TSDB_CODE_SUCCESS == code) {
1639
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanIgnoreExpired, &pNode->igExpired);
5
54liuyao 已提交
1640
  }
X
Xiaoyu Wang 已提交
1641
  if (TSDB_CODE_SUCCESS == code) {
1642 1643 1644 1645
    code = jsonToNodeList(pJson, jkTableScanPhysiPlanGroupTags, &pNode->pGroupTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkTableScanPhysiPlanGroupSort, &pNode->groupSort);
X
Xiaoyu Wang 已提交
1646
  }
1647 1648 1649
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkTableScanPhysiPlanAssignBlockUid, &pNode->assignBlockUid);
  }
X
Xiaoyu Wang 已提交
1650

X
Xiaoyu Wang 已提交
1651 1652 1653
  return code;
}

X
Xiaoyu Wang 已提交
1654
static const char* jkSysTableScanPhysiPlanMnodeEpSet = "MnodeEpSet";
D
dapan1121 已提交
1655 1656
static const char* jkSysTableScanPhysiPlanShowRewrite = "ShowRewrite";
static const char* jkSysTableScanPhysiPlanAccountId = "AccountId";
X
Xiaoyu Wang 已提交
1657

X
Xiaoyu Wang 已提交
1658
static int32_t physiSysTableScanNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
1659 1660 1661 1662 1663 1664
  const SSystemTableScanPhysiNode* pNode = (const SSystemTableScanPhysiNode*)pObj;

  int32_t code = physiScanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSysTableScanPhysiPlanMnodeEpSet, epSetToJson, &pNode->mgmtEpSet);
  }
D
dapan1121 已提交
1665 1666 1667 1668 1669 1670
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkSysTableScanPhysiPlanShowRewrite, pNode->showRewrite);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId);
  }
X
Xiaoyu Wang 已提交
1671 1672

  return code;
X
Xiaoyu Wang 已提交
1673 1674 1675
}

static int32_t jsonToPhysiSysTableScanNode(const SJson* pJson, void* pObj) {
X
Xiaoyu Wang 已提交
1676 1677 1678 1679 1680 1681
  SSystemTableScanPhysiNode* pNode = (SSystemTableScanPhysiNode*)pObj;

  int32_t code = jsonToPhysiScanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkSysTableScanPhysiPlanMnodeEpSet, jsonToEpSet, &pNode->mgmtEpSet);
  }
D
dapan1121 已提交
1682 1683 1684 1685
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSysTableScanPhysiPlanShowRewrite, &pNode->showRewrite);
  }
  if (TSDB_CODE_SUCCESS == code) {
1686 1687
    tjsonGetNumberValue(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId, code);
    ;
D
dapan1121 已提交
1688
  }
X
Xiaoyu Wang 已提交
1689 1690

  return code;
X
Xiaoyu Wang 已提交
1691 1692
}

X
Xiaoyu Wang 已提交
1693
static const char* jkProjectPhysiPlanProjections = "Projections";
1694
static const char* jkProjectPhysiPlanMergeDataBlock = "MergeDataBlock";
1695
static const char* jkProjectPhysiPlanIgnoreGroupId = "IgnoreGroupId";
X
Xiaoyu Wang 已提交
1696 1697 1698 1699 1700 1701

static int32_t physiProjectNodeToJson(const void* pObj, SJson* pJson) {
  const SProjectPhysiNode* pNode = (const SProjectPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1702 1703
    code = nodeListToJson(pJson, jkProjectPhysiPlanProjections, pNode->pProjections);
  }
1704 1705 1706
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkProjectPhysiPlanMergeDataBlock, pNode->mergeDataBlock);
  }
1707 1708 1709
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkProjectPhysiPlanIgnoreGroupId, pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719

  return code;
}

static int32_t jsonToPhysiProjectNode(const SJson* pJson, void* pObj) {
  SProjectPhysiNode* pNode = (SProjectPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkProjectPhysiPlanProjections, &pNode->pProjections);
X
Xiaoyu Wang 已提交
1720
  }
1721 1722 1723
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkProjectPhysiPlanMergeDataBlock, &pNode->mergeDataBlock);
  }
1724 1725 1726
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkProjectPhysiPlanIgnoreGroupId, &pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
1727 1728

  return code;
X
Xiaoyu Wang 已提交
1729 1730
}

X
Xiaoyu Wang 已提交
1731
static const char* jkJoinPhysiPlanJoinType = "JoinType";
1732
static const char* jkJoinPhysiPlanInputTsOrder = "InputTsOrder";
1733
static const char* jkJoinPhysiPlanMergeCondition = "MergeCondition";
X
Xiaoyu Wang 已提交
1734 1735 1736 1737
static const char* jkJoinPhysiPlanOnConditions = "OnConditions";
static const char* jkJoinPhysiPlanTargets = "Targets";

static int32_t physiJoinNodeToJson(const void* pObj, SJson* pJson) {
1738
  const SSortMergeJoinPhysiNode* pNode = (const SSortMergeJoinPhysiNode*)pObj;
X
Xiaoyu Wang 已提交
1739 1740 1741 1742 1743

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanJoinType, pNode->joinType);
  }
1744 1745 1746
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanInputTsOrder, pNode->inputTsOrder);
  }
1747 1748 1749
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinPhysiPlanMergeCondition, nodeToJson, pNode->pMergeCondition);
  }
X
Xiaoyu Wang 已提交
1750 1751 1752 1753
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinPhysiPlanOnConditions, nodeToJson, pNode->pOnConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1754 1755 1756 1757 1758 1759 1760
    code = nodeListToJson(pJson, jkJoinPhysiPlanTargets, pNode->pTargets);
  }

  return code;
}

static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) {
1761
  SSortMergeJoinPhysiNode* pNode = (SSortMergeJoinPhysiNode*)pObj;
X
Xiaoyu Wang 已提交
1762 1763 1764

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
1765
    tjsonGetNumberValue(pJson, jkJoinPhysiPlanJoinType, pNode->joinType, code);
1766 1767 1768
  }
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkJoinPhysiPlanInputTsOrder, pNode->inputTsOrder, code);
X
Xiaoyu Wang 已提交
1769 1770 1771 1772
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions);
  }
1773 1774 1775
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinPhysiPlanMergeCondition, &pNode->pMergeCondition);
  }
X
Xiaoyu Wang 已提交
1776 1777
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkJoinPhysiPlanTargets, &pNode->pTargets);
X
Xiaoyu Wang 已提交
1778 1779 1780 1781 1782 1783 1784 1785
  }

  return code;
}

static const char* jkAggPhysiPlanExprs = "Exprs";
static const char* jkAggPhysiPlanGroupKeys = "GroupKeys";
static const char* jkAggPhysiPlanAggFuncs = "AggFuncs";
1786
static const char* jkAggPhysiPlanMergeDataBlock = "MergeDataBlock";
X
Xiaoyu Wang 已提交
1787 1788 1789 1790 1791 1792

static int32_t physiAggNodeToJson(const void* pObj, SJson* pJson) {
  const SAggPhysiNode* pNode = (const SAggPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1793
    code = nodeListToJson(pJson, jkAggPhysiPlanExprs, pNode->pExprs);
X
Xiaoyu Wang 已提交
1794 1795
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1796
    code = nodeListToJson(pJson, jkAggPhysiPlanGroupKeys, pNode->pGroupKeys);
X
Xiaoyu Wang 已提交
1797 1798
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1799 1800
    code = nodeListToJson(pJson, jkAggPhysiPlanAggFuncs, pNode->pAggFuncs);
  }
1801 1802 1803
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkAggPhysiPlanMergeDataBlock, pNode->mergeDataBlock);
  }
X
Xiaoyu Wang 已提交
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819

  return code;
}

static int32_t jsonToPhysiAggNode(const SJson* pJson, void* pObj) {
  SAggPhysiNode* pNode = (SAggPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkAggPhysiPlanExprs, &pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkAggPhysiPlanGroupKeys, &pNode->pGroupKeys);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkAggPhysiPlanAggFuncs, &pNode->pAggFuncs);
X
Xiaoyu Wang 已提交
1820
  }
1821 1822 1823
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkAggPhysiPlanMergeDataBlock, &pNode->mergeDataBlock);
  }
X
Xiaoyu Wang 已提交
1824 1825 1826 1827

  return code;
}

X
Xiaoyu Wang 已提交
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
static const char* jkExchangePhysiPlanSrcGroupId = "SrcGroupId";
static const char* jkExchangePhysiPlanSrcEndPoints = "SrcEndPoints";

static int32_t physiExchangeNodeToJson(const void* pObj, SJson* pJson) {
  const SExchangePhysiNode* pNode = (const SExchangePhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkExchangePhysiPlanSrcGroupId, pNode->srcGroupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkExchangePhysiPlanSrcEndPoints, pNode->pSrcEndPoints);
  }

  return code;
}

static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) {
  SExchangePhysiNode* pNode = (SExchangePhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkExchangePhysiPlanSrcGroupId, &pNode->srcGroupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkExchangePhysiPlanSrcEndPoints, &pNode->pSrcEndPoints);
  }

  return code;
}

X
Xiaoyu Wang 已提交
1859
static const char* jkMergePhysiPlanMergeKeys = "MergeKeys";
X
Xiaoyu Wang 已提交
1860
static const char* jkMergePhysiPlanTargets = "Targets";
X
Xiaoyu Wang 已提交
1861 1862
static const char* jkMergePhysiPlanNumOfChannels = "NumOfChannels";
static const char* jkMergePhysiPlanSrcGroupId = "SrcGroupId";
1863
static const char* jkMergePhysiPlanGroupSort = "GroupSort";
X
Xiaoyu Wang 已提交
1864 1865 1866 1867 1868 1869 1870 1871

static int32_t physiMergeNodeToJson(const void* pObj, SJson* pJson) {
  const SMergePhysiNode* pNode = (const SMergePhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkMergePhysiPlanMergeKeys, pNode->pMergeKeys);
  }
X
Xiaoyu Wang 已提交
1872 1873 1874
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkMergePhysiPlanTargets, pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
1875 1876 1877 1878 1879 1880
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkMergePhysiPlanNumOfChannels, pNode->numOfChannels);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkMergePhysiPlanSrcGroupId, pNode->srcGroupId);
  }
1881 1882 1883
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkMergePhysiPlanGroupSort, pNode->groupSort);
  }
X
Xiaoyu Wang 已提交
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894

  return code;
}

static int32_t jsonToPhysiMergeNode(const SJson* pJson, void* pObj) {
  SMergePhysiNode* pNode = (SMergePhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkMergePhysiPlanMergeKeys, &pNode->pMergeKeys);
  }
X
Xiaoyu Wang 已提交
1895 1896 1897
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkMergePhysiPlanTargets, &pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
1898 1899 1900 1901 1902 1903
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkMergePhysiPlanNumOfChannels, &pNode->numOfChannels);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkMergePhysiPlanSrcGroupId, &pNode->srcGroupId);
  }
1904 1905 1906
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkMergePhysiPlanGroupSort, &pNode->groupSort);
  }
X
Xiaoyu Wang 已提交
1907 1908 1909 1910

  return code;
}

X
Xiaoyu Wang 已提交
1911 1912
static const char* jkSortPhysiPlanExprs = "Exprs";
static const char* jkSortPhysiPlanSortKeys = "SortKeys";
X
Xiaoyu Wang 已提交
1913
static const char* jkSortPhysiPlanTargets = "Targets";
X
Xiaoyu Wang 已提交
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924

static int32_t physiSortNodeToJson(const void* pObj, SJson* pJson) {
  const SSortPhysiNode* pNode = (const SSortPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSortPhysiPlanExprs, pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSortPhysiPlanSortKeys, pNode->pSortKeys);
  }
X
Xiaoyu Wang 已提交
1925 1926 1927
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSortPhysiPlanTargets, pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941

  return code;
}

static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) {
  SSortPhysiNode* pNode = (SSortPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSortPhysiPlanExprs, &pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSortPhysiPlanSortKeys, &pNode->pSortKeys);
  }
X
Xiaoyu Wang 已提交
1942 1943 1944
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSortPhysiPlanTargets, &pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
1945 1946 1947 1948

  return code;
}

X
Xiaoyu Wang 已提交
1949 1950
static const char* jkWindowPhysiPlanExprs = "Exprs";
static const char* jkWindowPhysiPlanFuncs = "Funcs";
1951
static const char* jkWindowPhysiPlanTsPk = "TsPk";
5
54liuyao 已提交
1952
static const char* jkWindowPhysiPlanTsEnd = "TsEnd";
X
Xiaoyu Wang 已提交
1953 1954
static const char* jkWindowPhysiPlanTriggerType = "TriggerType";
static const char* jkWindowPhysiPlanWatermark = "Watermark";
1955
static const char* jkWindowPhysiPlanIgnoreExpired = "IgnoreExpired";
1956
static const char* jkWindowPhysiPlanInputTsOrder = "InputTsOrder";
X
Xiaoyu Wang 已提交
1957
static const char* jkWindowPhysiPlanOutputTsOrder = "outputTsOrder";
1958
static const char* jkWindowPhysiPlanMergeDataBlock = "MergeDataBlock";
X
Xiaoyu Wang 已提交
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969

static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SWinodwPhysiNode* pNode = (const SWinodwPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkWindowPhysiPlanExprs, pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkWindowPhysiPlanFuncs, pNode->pFuncs);
  }
1970 1971 1972
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk);
  }
5
54liuyao 已提交
1973 1974 1975
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWindowPhysiPlanTsEnd, nodeToJson, pNode->pTsEnd);
  }
X
Xiaoyu Wang 已提交
1976 1977 1978 1979 1980 1981
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanWatermark, pNode->watermark);
  }
5
54liuyao 已提交
1982
  if (TSDB_CODE_SUCCESS == code) {
1983
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanIgnoreExpired, pNode->igExpired);
5
54liuyao 已提交
1984
  }
X
Xiaoyu Wang 已提交
1985 1986 1987 1988 1989 1990
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanInputTsOrder, pNode->inputTsOrder);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanOutputTsOrder, pNode->outputTsOrder);
  }
1991 1992 1993
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkWindowPhysiPlanMergeDataBlock, pNode->mergeDataBlock);
  }
X
Xiaoyu Wang 已提交
1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007

  return code;
}

static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) {
  SWinodwPhysiNode* pNode = (SWinodwPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkWindowPhysiPlanExprs, &pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkWindowPhysiPlanFuncs, &pNode->pFuncs);
  }
2008 2009 2010
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk);
  }
5
54liuyao 已提交
2011 2012 2013
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsEnd, (SNode**)&pNode->pTsEnd);
  }
X
Xiaoyu Wang 已提交
2014
  if (TSDB_CODE_SUCCESS == code) {
2015
    code = tjsonGetTinyIntValue(pJson, jkWindowPhysiPlanTriggerType, &pNode->triggerType);
X
Xiaoyu Wang 已提交
2016 2017
  }
  if (TSDB_CODE_SUCCESS == code) {
2018
    code = tjsonGetBigIntValue(pJson, jkWindowPhysiPlanWatermark, &pNode->watermark);
X
Xiaoyu Wang 已提交
2019
  }
5
54liuyao 已提交
2020
  if (TSDB_CODE_SUCCESS == code) {
2021
    code = tjsonGetTinyIntValue(pJson, jkWindowPhysiPlanIgnoreExpired, &pNode->igExpired);
5
54liuyao 已提交
2022
  }
X
Xiaoyu Wang 已提交
2023 2024 2025 2026 2027 2028
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkWindowPhysiPlanInputTsOrder, pNode->inputTsOrder, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkWindowPhysiPlanOutputTsOrder, pNode->outputTsOrder, code);
  }
2029 2030 2031
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkWindowPhysiPlanMergeDataBlock, &pNode->mergeDataBlock);
  }
X
Xiaoyu Wang 已提交
2032 2033 2034 2035

  return code;
}

X
Xiaoyu Wang 已提交
2036 2037 2038
static const char* jkIntervalPhysiPlanInterval = "Interval";
static const char* jkIntervalPhysiPlanOffset = "Offset";
static const char* jkIntervalPhysiPlanSliding = "Sliding";
H
Haojun Liao 已提交
2039
static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit";
X
Xiaoyu Wang 已提交
2040
static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit";
X
Xiaoyu Wang 已提交
2041 2042 2043 2044

static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
  const SIntervalPhysiNode* pNode = (const SIntervalPhysiNode*)pObj;

X
Xiaoyu Wang 已提交
2045
  int32_t code = physiWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
2046 2047 2048 2049 2050 2051 2052 2053 2054
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanInterval, pNode->interval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanOffset, pNode->offset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanSliding, pNode->sliding);
  }
H
Haojun Liao 已提交
2055 2056 2057 2058 2059 2060
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanIntervalUnit, pNode->intervalUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanSlidingUnit, pNode->slidingUnit);
  }
X
Xiaoyu Wang 已提交
2061 2062 2063 2064 2065 2066 2067

  return code;
}

static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) {
  SIntervalPhysiNode* pNode = (SIntervalPhysiNode*)pObj;

X
Xiaoyu Wang 已提交
2068
  int32_t code = jsonToPhysiWindowNode(pJson, pObj);
X
Xiaoyu Wang 已提交
2069 2070 2071 2072 2073 2074 2075 2076 2077
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkIntervalPhysiPlanInterval, &pNode->interval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkIntervalPhysiPlanOffset, &pNode->offset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkIntervalPhysiPlanSliding, &pNode->sliding);
  }
H
Haojun Liao 已提交
2078 2079 2080 2081 2082 2083
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkIntervalPhysiPlanIntervalUnit, &pNode->intervalUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkIntervalPhysiPlanSlidingUnit, &pNode->slidingUnit);
  }
X
Xiaoyu Wang 已提交
2084 2085 2086 2087 2088

  return code;
}

static const char* jkFillPhysiPlanMode = "Mode";
2089 2090
static const char* jkFillPhysiPlanFillExprs = "FillExprs";
static const char* jkFillPhysiPlanNotFillExprs = "NotFillExprs";
X
Xiaoyu Wang 已提交
2091 2092
static const char* jkFillPhysiPlanWStartTs = "WStartTs";
static const char* jkFillPhysiPlanValues = "Values";
X
Xiaoyu Wang 已提交
2093 2094
static const char* jkFillPhysiPlanStartTime = "StartTime";
static const char* jkFillPhysiPlanEndTime = "EndTime";
X
Xiaoyu Wang 已提交
2095
static const char* jkFillPhysiPlanInputTsOrder = "inputTsOrder";
X
Xiaoyu Wang 已提交
2096 2097 2098 2099 2100 2101 2102 2103

static int32_t physiFillNodeToJson(const void* pObj, SJson* pJson) {
  const SFillPhysiNode* pNode = (const SFillPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillPhysiPlanMode, pNode->mode);
  }
X
Xiaoyu Wang 已提交
2104
  if (TSDB_CODE_SUCCESS == code) {
2105
    code = nodeListToJson(pJson, jkFillPhysiPlanFillExprs, pNode->pFillExprs);
X
Xiaoyu Wang 已提交
2106 2107
  }
  if (TSDB_CODE_SUCCESS == code) {
2108
    code = nodeListToJson(pJson, jkFillPhysiPlanNotFillExprs, pNode->pNotFillExprs);
X
Xiaoyu Wang 已提交
2109 2110
  }
  if (TSDB_CODE_SUCCESS == code) {
2111 2112 2113 2114
    code = tjsonAddObject(pJson, jkFillPhysiPlanWStartTs, nodeToJson, pNode->pWStartTs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkFillPhysiPlanValues, nodeToJson, pNode->pValues);
X
Xiaoyu Wang 已提交
2115
  }
X
Xiaoyu Wang 已提交
2116 2117 2118 2119 2120 2121
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillPhysiPlanStartTime, pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillPhysiPlanEndTime, pNode->timeRange.ekey);
  }
X
Xiaoyu Wang 已提交
2122 2123 2124
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillPhysiPlanInputTsOrder, pNode->inputTsOrder);
  }
X
Xiaoyu Wang 已提交
2125 2126 2127 2128 2129 2130 2131

  return code;
}

static int32_t jsonToPhysiFillNode(const SJson* pJson, void* pObj) {
  SFillPhysiNode* pNode = (SFillPhysiNode*)pObj;

2132
  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
2133
  if (TSDB_CODE_SUCCESS == code) {
2134
    tjsonGetNumberValue(pJson, jkFillPhysiPlanMode, pNode->mode, code);
X
Xiaoyu Wang 已提交
2135 2136
  }
  if (TSDB_CODE_SUCCESS == code) {
2137
    code = jsonToNodeList(pJson, jkFillPhysiPlanFillExprs, &pNode->pFillExprs);
X
Xiaoyu Wang 已提交
2138 2139
  }
  if (TSDB_CODE_SUCCESS == code) {
2140 2141 2142 2143
    code = jsonToNodeList(pJson, jkFillPhysiPlanNotFillExprs, &pNode->pNotFillExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillPhysiPlanWStartTs, &pNode->pWStartTs);
X
Xiaoyu Wang 已提交
2144
  }
X
Xiaoyu Wang 已提交
2145
  if (TSDB_CODE_SUCCESS == code) {
2146
    code = jsonToNodeObject(pJson, jkFillPhysiPlanValues, &pNode->pValues);
X
Xiaoyu Wang 已提交
2147
  }
X
Xiaoyu Wang 已提交
2148 2149 2150 2151 2152
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkFillPhysiPlanStartTime, &pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkFillPhysiPlanEndTime, &pNode->timeRange.ekey);
X
Xiaoyu Wang 已提交
2153
  }
X
Xiaoyu Wang 已提交
2154 2155 2156
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkFillPhysiPlanInputTsOrder, pNode->inputTsOrder, code);
  }
X
Xiaoyu Wang 已提交
2157 2158 2159 2160

  return code;
}

X
Xiaoyu Wang 已提交
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178
static const char* jkSessionWindowPhysiPlanGap = "Gap";

static int32_t physiSessionWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SSessionWinodwPhysiNode* pNode = (const SSessionWinodwPhysiNode*)pObj;

  int32_t code = physiWindowNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSessionWindowPhysiPlanGap, pNode->gap);
  }

  return code;
}

static int32_t jsonToPhysiSessionWindowNode(const SJson* pJson, void* pObj) {
  SSessionWinodwPhysiNode* pNode = (SSessionWinodwPhysiNode*)pObj;

  int32_t code = jsonToPhysiWindowNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
2179
    tjsonGetNumberValue(pJson, jkSessionWindowPhysiPlanGap, pNode->gap, code);
X
Xiaoyu Wang 已提交
2180 2181 2182 2183 2184
  }

  return code;
}

2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210
static const char* jkStateWindowPhysiPlanStateKey = "StateKey";

static int32_t physiStateWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SStateWinodwPhysiNode* pNode = (const SStateWinodwPhysiNode*)pObj;

  int32_t code = physiWindowNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkStateWindowPhysiPlanStateKey, nodeToJson, pNode->pStateKey);
  }

  return code;
}

static int32_t jsonToPhysiStateWindowNode(const SJson* pJson, void* pObj) {
  SStateWinodwPhysiNode* pNode = (SStateWinodwPhysiNode*)pObj;

  int32_t code = jsonToPhysiWindowNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkStateWindowPhysiPlanStateKey, &pNode->pStateKey);
  }

  return code;
}

static const char* jkPartitionPhysiPlanExprs = "Exprs";
static const char* jkPartitionPhysiPlanPartitionKeys = "PartitionKeys";
X
Xiaoyu Wang 已提交
2211
static const char* jkPartitionPhysiPlanTargets = "Targets";
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222

static int32_t physiPartitionNodeToJson(const void* pObj, SJson* pJson) {
  const SPartitionPhysiNode* pNode = (const SPartitionPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkPartitionPhysiPlanExprs, pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkPartitionPhysiPlanPartitionKeys, pNode->pPartitionKeys);
  }
X
Xiaoyu Wang 已提交
2223 2224 2225
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkPartitionPhysiPlanTargets, pNode->pTargets);
  }
2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239

  return code;
}

static int32_t jsonToPhysiPartitionNode(const SJson* pJson, void* pObj) {
  SPartitionPhysiNode* pNode = (SPartitionPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkPartitionPhysiPlanExprs, &pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkPartitionPhysiPlanPartitionKeys, &pNode->pPartitionKeys);
  }
X
Xiaoyu Wang 已提交
2240 2241 2242
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkPartitionPhysiPlanTargets, &pNode->pTargets);
  }
2243 2244 2245 2246

  return code;
}

2247
static const char* jkIndefRowsFuncPhysiPlanExprs = "Exprs";
X
Xiaoyu Wang 已提交
2248
static const char* jkIndefRowsFuncPhysiPlanFuncs = "Funcs";
2249 2250 2251 2252 2253 2254 2255 2256 2257

static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
  const SIndefRowsFuncPhysiNode* pNode = (const SIndefRowsFuncPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanExprs, pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2258
    code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanFuncs, pNode->pFuncs);
2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271
  }

  return code;
}

static int32_t jsonToPhysiIndefRowsFuncNode(const SJson* pJson, void* pObj) {
  SIndefRowsFuncPhysiNode* pNode = (SIndefRowsFuncPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanExprs, &pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282
    code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanFuncs, &pNode->pFuncs);
  }

  return code;
}

static const char* jkInterpFuncPhysiPlanExprs = "Exprs";
static const char* jkInterpFuncPhysiPlanFuncs = "Funcs";
static const char* jkInterpFuncPhysiPlanStartTime = "StartTime";
static const char* jkInterpFuncPhysiPlanEndTime = "EndTime";
static const char* jkInterpFuncPhysiPlanInterval = "Interval";
X
Xiaoyu Wang 已提交
2283 2284 2285
static const char* jkInterpFuncPhysiPlanFillMode = "FillMode";
static const char* jkInterpFuncPhysiPlanFillValues = "FillValues";
static const char* jkInterpFuncPhysiPlanTimeSeries = "TimeSeries";
X
Xiaoyu Wang 已提交
2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305

static int32_t physiInterpFuncNodeToJson(const void* pObj, SJson* pJson) {
  const SInterpFuncPhysiNode* pNode = (const SInterpFuncPhysiNode*)pObj;

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkInterpFuncPhysiPlanExprs, pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkInterpFuncPhysiPlanFuncs, pNode->pFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanStartTime, pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanEndTime, pNode->timeRange.ekey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanInterval, pNode->interval);
  }
X
Xiaoyu Wang 已提交
2306 2307 2308 2309 2310 2311 2312 2313 2314
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanFillMode, pNode->fillMode);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkInterpFuncPhysiPlanFillValues, nodeToJson, pNode->pFillValues);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkInterpFuncPhysiPlanTimeSeries, nodeToJson, pNode->pTimeSeries);
  }
X
Xiaoyu Wang 已提交
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336

  return code;
}

static int32_t jsonToPhysiInterpFuncNode(const SJson* pJson, void* pObj) {
  SInterpFuncPhysiNode* pNode = (SInterpFuncPhysiNode*)pObj;

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkInterpFuncPhysiPlanExprs, &pNode->pExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkInterpFuncPhysiPlanFuncs, &pNode->pFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanStartTime, &pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanEndTime, &pNode->timeRange.ekey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanInterval, &pNode->interval);
2337
  }
X
Xiaoyu Wang 已提交
2338 2339 2340 2341 2342 2343 2344 2345 2346
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkInterpFuncPhysiPlanFillMode, pNode->fillMode, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkInterpFuncPhysiPlanFillValues, &pNode->pFillValues);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkInterpFuncPhysiPlanTimeSeries, &pNode->pTimeSeries);
  }
2347 2348 2349 2350

  return code;
}

X
Xiaoyu Wang 已提交
2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
static const char* jkDataSinkInputDataBlockDesc = "InputDataBlockDesc";

static int32_t physicDataSinkNodeToJson(const void* pObj, SJson* pJson) {
  const SDataSinkNode* pNode = (const SDataSinkNode*)pObj;
  return tjsonAddObject(pJson, jkDataSinkInputDataBlockDesc, nodeToJson, pNode->pInputDataBlockDesc);
}

static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) {
  SDataSinkNode* pNode = (SDataSinkNode*)pObj;
  return jsonToNodeObject(pJson, jkDataSinkInputDataBlockDesc, (SNode**)&pNode->pInputDataBlockDesc);
}

X
Xiaoyu Wang 已提交
2363
static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return physicDataSinkNodeToJson(pObj, pJson); }
X
Xiaoyu Wang 已提交
2364

X
Xiaoyu Wang 已提交
2365
static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { return jsonToPhysicDataSinkNode(pJson, pObj); }
X
Xiaoyu Wang 已提交
2366

2367 2368
static const char* jkQueryInsertPhysiPlanInsertCols = "InsertCols";
static const char* jkQueryInsertPhysiPlanStableId = "StableId";
2369 2370 2371 2372 2373 2374 2375 2376 2377 2378
static const char* jkQueryInsertPhysiPlanTableId = "TableId";
static const char* jkQueryInsertPhysiPlanTableType = "TableType";
static const char* jkQueryInsertPhysiPlanTableFName = "TableFName";
static const char* jkQueryInsertPhysiPlanVgId = "VgId";
static const char* jkQueryInsertPhysiPlanEpSet = "EpSet";

static int32_t physiQueryInsertNodeToJson(const void* pObj, SJson* pJson) {
  const SQueryInserterNode* pNode = (const SQueryInserterNode*)pObj;

  int32_t code = physicDataSinkNodeToJson(pObj, pJson);
2379 2380 2381 2382 2383 2384
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkQueryInsertPhysiPlanInsertCols, pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanStableId, pNode->stableId);
  }
2385 2386 2387 2388 2389 2390 2391
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanTableId, pNode->tableId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanTableType, pNode->tableType);
  }
  if (TSDB_CODE_SUCCESS == code) {
2392
    code = tjsonAddStringToObject(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableName);
2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanVgId, pNode->vgId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkQueryInsertPhysiPlanEpSet, epSetToJson, &pNode->epSet);
  }

  return code;
}

static int32_t jsonToPhysiQueryInsertNode(const SJson* pJson, void* pObj) {
  SQueryInserterNode* pNode = (SQueryInserterNode*)pObj;

  int32_t code = jsonToPhysicDataSinkNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
2409 2410 2411 2412 2413 2414
    code = jsonToNodeList(pJson, jkQueryInsertPhysiPlanInsertCols, &pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkQueryInsertPhysiPlanStableId, &pNode->stableId);
  }
  if (TSDB_CODE_SUCCESS == code) {
2415 2416 2417 2418 2419 2420
    code = tjsonGetUBigIntValue(pJson, jkQueryInsertPhysiPlanTableId, &pNode->tableId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkQueryInsertPhysiPlanTableType, &pNode->tableType);
  }
  if (TSDB_CODE_SUCCESS == code) {
2421
    code = tjsonGetStringValue(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableName);
2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkQueryInsertPhysiPlanVgId, &pNode->vgId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkQueryInsertPhysiPlanEpSet, jsonToEpSet, &pNode->epSet);
  }

  return code;
}

X
Xiaoyu Wang 已提交
2433 2434 2435
static const char* jkDeletePhysiPlanTableId = "TableId";
static const char* jkDeletePhysiPlanTableType = "TableType";
static const char* jkDeletePhysiPlanTableFName = "TableFName";
2436
static const char* jkDeletePhysiPlanTsColName = "TsColName";
X
Xiaoyu Wang 已提交
2437 2438
static const char* jkDeletePhysiPlanDeleteTimeRangeStartKey = "DeleteTimeRangeStartKey";
static const char* jkDeletePhysiPlanDeleteTimeRangeEndKey = "DeleteTimeRangeEndKey";
X
Xiaoyu Wang 已提交
2439
static const char* jkDeletePhysiPlanAffectedRows = "AffectedRows";
X
Xiaoyu Wang 已提交
2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453

static int32_t physiDeleteNodeToJson(const void* pObj, SJson* pJson) {
  const SDataDeleterNode* pNode = (const SDataDeleterNode*)pObj;

  int32_t code = physicDataSinkNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDeletePhysiPlanTableId, pNode->tableId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDeletePhysiPlanTableType, pNode->tableType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDeletePhysiPlanTableFName, pNode->tableFName);
  }
2454 2455 2456
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDeletePhysiPlanTsColName, pNode->tsColName);
  }
X
Xiaoyu Wang 已提交
2457 2458 2459 2460 2461 2462
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDeletePhysiPlanDeleteTimeRangeStartKey, pNode->deleteTimeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDeletePhysiPlanDeleteTimeRangeEndKey, pNode->deleteTimeRange.ekey);
  }
X
Xiaoyu Wang 已提交
2463 2464 2465
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkDeletePhysiPlanAffectedRows, nodeToJson, pNode->pAffectedRows);
  }
X
Xiaoyu Wang 已提交
2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482

  return code;
}

static int32_t jsonToPhysiDeleteNode(const SJson* pJson, void* pObj) {
  SDataDeleterNode* pNode = (SDataDeleterNode*)pObj;

  int32_t code = jsonToPhysicDataSinkNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkDeletePhysiPlanTableId, &pNode->tableId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkDeletePhysiPlanTableType, &pNode->tableType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDeletePhysiPlanTableFName, pNode->tableFName);
  }
2483 2484 2485
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDeletePhysiPlanTsColName, pNode->tsColName);
  }
X
Xiaoyu Wang 已提交
2486 2487 2488 2489 2490 2491
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkDeletePhysiPlanDeleteTimeRangeStartKey, &pNode->deleteTimeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkDeletePhysiPlanDeleteTimeRangeEndKey, &pNode->deleteTimeRange.ekey);
  }
X
Xiaoyu Wang 已提交
2492 2493 2494
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkDeletePhysiPlanAffectedRows, &pNode->pAffectedRows);
  }
X
Xiaoyu Wang 已提交
2495 2496 2497 2498

  return code;
}

X
Xiaoyu Wang 已提交
2499 2500 2501 2502 2503 2504 2505 2506 2507 2508
static const char* jkQueryNodeAddrId = "Id";
static const char* jkQueryNodeAddrInUse = "InUse";
static const char* jkQueryNodeAddrNumOfEps = "NumOfEps";
static const char* jkQueryNodeAddrEps = "Eps";

static int32_t queryNodeAddrToJson(const void* pObj, SJson* pJson) {
  const SQueryNodeAddr* pNode = (const SQueryNodeAddr*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrId, pNode->nodeId);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2509
    code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrInUse, pNode->epSet.inUse);
X
Xiaoyu Wang 已提交
2510 2511
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2512
    code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrNumOfEps, pNode->epSet.numOfEps);
X
Xiaoyu Wang 已提交
2513 2514
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2515
    code = tjsonAddArray(pJson, jkQueryNodeAddrEps, epToJson, pNode->epSet.eps, sizeof(SEp), pNode->epSet.numOfEps);
X
Xiaoyu Wang 已提交
2516 2517 2518 2519 2520 2521 2522 2523 2524 2525
  }

  return code;
}

static int32_t jsonToQueryNodeAddr(const SJson* pJson, void* pObj) {
  SQueryNodeAddr* pNode = (SQueryNodeAddr*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkQueryNodeAddrId, &pNode->nodeId);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2526
    code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrInUse, &pNode->epSet.inUse);
X
Xiaoyu Wang 已提交
2527 2528
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2529
    code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrNumOfEps, &pNode->epSet.numOfEps);
X
Xiaoyu Wang 已提交
2530 2531
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2532
    code = tjsonToArray(pJson, jkQueryNodeAddrEps, jsonToEp, pNode->epSet.eps, sizeof(SEp));
X
Xiaoyu Wang 已提交
2533 2534 2535 2536 2537 2538 2539 2540 2541
  }

  return code;
}

static const char* jkSubplanId = "Id";
static const char* jkSubplanType = "SubplanType";
static const char* jkSubplanMsgType = "MsgType";
static const char* jkSubplanLevel = "Level";
2542
static const char* jkSubplanDbFName = "DbFName";
X
Xiaoyu Wang 已提交
2543
static const char* jkSubplanUser = "User";
X
Xiaoyu Wang 已提交
2544 2545 2546
static const char* jkSubplanNodeAddr = "NodeAddr";
static const char* jkSubplanRootNode = "RootNode";
static const char* jkSubplanDataSink = "DataSink";
X
Xiaoyu Wang 已提交
2547
static const char* jkSubplanTagCond = "TagCond";
X
Xiaoyu Wang 已提交
2548
static const char* jkSubplanTagIndexCond = "TagIndexCond";
X
Xiaoyu Wang 已提交
2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562

static int32_t subplanToJson(const void* pObj, SJson* pJson) {
  const SSubplan* pNode = (const SSubplan*)pObj;

  int32_t code = tjsonAddObject(pJson, jkSubplanId, subplanIdToJson, &pNode->id);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSubplanType, pNode->subplanType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSubplanMsgType, pNode->msgType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSubplanLevel, pNode->level);
  }
2563 2564 2565
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSubplanDbFName, pNode->dbFName);
  }
X
Xiaoyu Wang 已提交
2566 2567 2568
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSubplanUser, pNode->user);
  }
X
Xiaoyu Wang 已提交
2569 2570 2571 2572 2573 2574 2575 2576 2577
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSubplanNodeAddr, queryNodeAddrToJson, &pNode->execNode);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSubplanRootNode, nodeToJson, pNode->pNode);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSubplanDataSink, nodeToJson, pNode->pDataSink);
  }
X
Xiaoyu Wang 已提交
2578 2579 2580
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSubplanTagCond, nodeToJson, pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
2581 2582 2583
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSubplanTagIndexCond, nodeToJson, pNode->pTagIndexCond);
  }
X
Xiaoyu Wang 已提交
2584 2585 2586 2587 2588 2589 2590 2591 2592

  return code;
}

static int32_t jsonToSubplan(const SJson* pJson, void* pObj) {
  SSubplan* pNode = (SSubplan*)pObj;

  int32_t code = tjsonToObject(pJson, jkSubplanId, jsonToSubplanId, &pNode->id);
  if (TSDB_CODE_SUCCESS == code) {
2593
    tjsonGetNumberValue(pJson, jkSubplanType, pNode->subplanType, code);
X
Xiaoyu Wang 已提交
2594 2595 2596 2597 2598 2599 2600
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkSubplanMsgType, &pNode->msgType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkSubplanLevel, &pNode->level);
  }
2601 2602 2603
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSubplanDbFName, pNode->dbFName);
  }
X
Xiaoyu Wang 已提交
2604 2605 2606
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSubplanUser, pNode->user);
  }
X
Xiaoyu Wang 已提交
2607 2608 2609 2610 2611 2612 2613 2614 2615
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkSubplanNodeAddr, jsonToQueryNodeAddr, &pNode->execNode);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSubplanRootNode, (SNode**)&pNode->pNode);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSubplanDataSink, (SNode**)&pNode->pDataSink);
  }
X
Xiaoyu Wang 已提交
2616 2617 2618
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSubplanTagCond, (SNode**)&pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
2619 2620 2621
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSubplanTagIndexCond, (SNode**)&pNode->pTagIndexCond);
  }
X
Xiaoyu Wang 已提交
2622 2623 2624 2625

  return code;
}

X
Xiaoyu Wang 已提交
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657
static const char* jkPlanQueryId = "QueryId";
static const char* jkPlanNumOfSubplans = "NumOfSubplans";
static const char* jkPlanSubplans = "Subplans";

static int32_t planToJson(const void* pObj, SJson* pJson) {
  const SQueryPlan* pNode = (const SQueryPlan*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkPlanQueryId, pNode->queryId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkPlanNumOfSubplans, pNode->numOfSubplans);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkPlanSubplans, pNode->pSubplans);
  }

  return code;
}

static int32_t jsonToPlan(const SJson* pJson, void* pObj) {
  SQueryPlan* pNode = (SQueryPlan*)pObj;

  int32_t code = tjsonGetUBigIntValue(pJson, jkPlanQueryId, &pNode->queryId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkPlanNumOfSubplans, &pNode->numOfSubplans);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkPlanSubplans, &pNode->pSubplans);
  }

  return code;
}

X
Xiaoyu Wang 已提交
2658 2659 2660
static const char* jkAggLogicPlanGroupKeys = "GroupKeys";
static const char* jkAggLogicPlanAggFuncs = "AggFuncs";

X
Xiaoyu Wang 已提交
2661
static int32_t logicAggNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
2662
  const SAggLogicNode* pNode = (const SAggLogicNode*)pObj;
2663

X
Xiaoyu Wang 已提交
2664 2665
  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2666
    code = nodeListToJson(pJson, jkAggLogicPlanGroupKeys, pNode->pGroupKeys);
X
Xiaoyu Wang 已提交
2667 2668
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2669
    code = nodeListToJson(pJson, jkAggLogicPlanAggFuncs, pNode->pAggFuncs);
X
Xiaoyu Wang 已提交
2670 2671 2672 2673 2674
  }

  return code;
}

X
Xiaoyu Wang 已提交
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696
static const char* jkDataTypeType = "Type";
static const char* jkDataTypePrecision = "Precision";
static const char* jkDataTypeScale = "Scale";
static const char* jkDataTypeDataBytes = "Bytes";

static int32_t dataTypeToJson(const void* pObj, SJson* pJson) {
  const SDataType* pNode = (const SDataType*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkDataTypeType, pNode->type);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDataTypePrecision, pNode->precision);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDataTypeScale, pNode->scale);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDataTypeDataBytes, pNode->bytes);
  }

  return code;
}

X
Xiaoyu Wang 已提交
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713
static int32_t jsonToDataType(const SJson* pJson, void* pObj) {
  SDataType* pNode = (SDataType*)pObj;

  int32_t code = tjsonGetUTinyIntValue(pJson, jkDataTypeType, &pNode->type);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkDataTypePrecision, &pNode->precision);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkDataTypeScale, &pNode->scale);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDataTypeDataBytes, &pNode->bytes);
  }

  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
2714 2715
static const char* jkExprDataType = "DataType";
static const char* jkExprAliasName = "AliasName";
X
Xiaoyu Wang 已提交
2716
static const char* jkExprUserAlias = "UserAlias";
X
Xiaoyu Wang 已提交
2717 2718 2719 2720 2721 2722 2723 2724

static int32_t exprNodeToJson(const void* pObj, SJson* pJson) {
  const SExprNode* pNode = (const SExprNode*)pObj;

  int32_t code = tjsonAddObject(pJson, jkExprDataType, dataTypeToJson, &pNode->resType);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkExprAliasName, pNode->aliasName);
  }
X
Xiaoyu Wang 已提交
2725 2726 2727
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkExprUserAlias, pNode->userAlias);
  }
X
Xiaoyu Wang 已提交
2728 2729 2730 2731

  return code;
}

X
Xiaoyu Wang 已提交
2732 2733 2734 2735 2736 2737 2738
static int32_t jsonToExprNode(const SJson* pJson, void* pObj) {
  SExprNode* pNode = (SExprNode*)pObj;

  int32_t code = tjsonToObject(pJson, jkExprDataType, jsonToDataType, &pNode->resType);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkExprAliasName, pNode->aliasName);
  }
X
Xiaoyu Wang 已提交
2739 2740 2741
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkExprUserAlias, pNode->userAlias);
  }
X
Xiaoyu Wang 已提交
2742 2743 2744 2745

  return code;
}

X
Xiaoyu Wang 已提交
2746
static const char* jkColumnTableId = "TableId";
L
Liu Jicong 已提交
2747
static const char* jkColumnTableType = "TableType";
X
Xiaoyu Wang 已提交
2748 2749 2750 2751 2752 2753
static const char* jkColumnColId = "ColId";
static const char* jkColumnColType = "ColType";
static const char* jkColumnDbName = "DbName";
static const char* jkColumnTableName = "TableName";
static const char* jkColumnTableAlias = "TableAlias";
static const char* jkColumnColName = "ColName";
X
Xiaoyu Wang 已提交
2754 2755
static const char* jkColumnDataBlockId = "DataBlockId";
static const char* jkColumnSlotId = "SlotId";
X
Xiaoyu Wang 已提交
2756 2757 2758 2759 2760 2761 2762 2763

static int32_t columnNodeToJson(const void* pObj, SJson* pJson) {
  const SColumnNode* pNode = (const SColumnNode*)pObj;

  int32_t code = exprNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkColumnTableId, pNode->tableId);
  }
L
Liu Jicong 已提交
2764 2765 2766
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkColumnTableType, pNode->tableType);
  }
X
Xiaoyu Wang 已提交
2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkColumnColId, pNode->colId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkColumnColType, pNode->colType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkColumnDbName, pNode->dbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkColumnTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkColumnTableAlias, pNode->tableAlias);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkColumnColName, pNode->colName);
  }
X
Xiaoyu Wang 已提交
2785 2786 2787 2788 2789 2790
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkColumnDataBlockId, pNode->dataBlockId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkColumnSlotId, pNode->slotId);
  }
X
Xiaoyu Wang 已提交
2791 2792 2793 2794

  return code;
}

X
Xiaoyu Wang 已提交
2795 2796 2797 2798 2799 2800 2801
static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
  SColumnNode* pNode = (SColumnNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkColumnTableId, &pNode->tableId);
  }
L
Liu Jicong 已提交
2802 2803 2804
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkColumnTableType, &pNode->tableType);
  }
X
Xiaoyu Wang 已提交
2805 2806 2807 2808
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetSmallIntValue(pJson, jkColumnColId, &pNode->colId);
  }
  if (TSDB_CODE_SUCCESS == code) {
2809 2810
    tjsonGetNumberValue(pJson, jkColumnColType, pNode->colType, code);
    ;
X
Xiaoyu Wang 已提交
2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkColumnDbName, pNode->dbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkColumnTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkColumnTableAlias, pNode->tableAlias);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkColumnColName, pNode->colName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetSmallIntValue(pJson, jkColumnDataBlockId, &pNode->dataBlockId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetSmallIntValue(pJson, jkColumnSlotId, &pNode->slotId);
  }

  return code;
}

2834
static const char* jkValueLiteralSize = "LiteralSize";
X
Xiaoyu Wang 已提交
2835 2836
static const char* jkValueLiteral = "Literal";
static const char* jkValueDuration = "Duration";
2837
static const char* jkValueTranslate = "Translate";
5
54liuyao 已提交
2838
static const char* jkValueNotReserved = "NotReserved";
2839
static const char* jkValueIsNull = "IsNull";
X
Xiaoyu Wang 已提交
2840 2841
static const char* jkValueDatum = "Datum";

2842
static int32_t datumToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
2843 2844
  const SValueNode* pNode = (const SValueNode*)pObj;

2845
  int32_t code = TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
2846 2847 2848 2849
  switch (pNode->node.resType.type) {
    case TSDB_DATA_TYPE_NULL:
      break;
    case TSDB_DATA_TYPE_BOOL:
X
Xiaoyu Wang 已提交
2850
      code = tjsonAddBoolToObject(pJson, jkValueDatum, pNode->datum.b);
X
Xiaoyu Wang 已提交
2851 2852 2853 2854 2855 2856
      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:
2857
      code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.i);
X
Xiaoyu Wang 已提交
2858 2859 2860 2861 2862
      break;
    case TSDB_DATA_TYPE_UTINYINT:
    case TSDB_DATA_TYPE_USMALLINT:
    case TSDB_DATA_TYPE_UINT:
    case TSDB_DATA_TYPE_UBIGINT:
2863
      code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.u);
X
Xiaoyu Wang 已提交
2864 2865 2866
      break;
    case TSDB_DATA_TYPE_FLOAT:
    case TSDB_DATA_TYPE_DOUBLE:
2867
      code = tjsonAddDoubleToObject(pJson, jkValueDatum, pNode->datum.d);
X
Xiaoyu Wang 已提交
2868
      break;
2869
    case TSDB_DATA_TYPE_NCHAR: {
2870 2871
      // cJSON only support utf-8 encoding. Convert memory content to hex string.
      char* buf = taosMemoryCalloc(varDataLen(pNode->datum.p) * 2 + 1, sizeof(char));
2872
      code = taosHexEncode(varDataVal(pNode->datum.p), buf, varDataLen(pNode->datum.p));
2873
      if (code != TSDB_CODE_SUCCESS) {
2874 2875 2876 2877 2878 2879 2880
        taosMemoryFree(buf);
        return TSDB_CODE_TSC_INVALID_VALUE;
      }
      code = tjsonAddStringToObject(pJson, jkValueDatum, buf);
      taosMemoryFree(buf);
      break;
    }
X
Xiaoyu Wang 已提交
2881 2882
    case TSDB_DATA_TYPE_VARCHAR:
    case TSDB_DATA_TYPE_VARBINARY:
X
Xiaoyu Wang 已提交
2883
      code = tjsonAddStringToObject(pJson, jkValueDatum, varDataVal(pNode->datum.p));
X
Xiaoyu Wang 已提交
2884
      break;
2885
    case TSDB_DATA_TYPE_JSON: {
wmmhello's avatar
wmmhello 已提交
2886
      int32_t len = getJsonValueLen(pNode->datum.p);
2887
      char*   buf = taosMemoryCalloc(len * 2 + 1, sizeof(char));
wmmhello's avatar
wmmhello 已提交
2888 2889 2890 2891 2892 2893 2894 2895 2896
      code = taosHexEncode(pNode->datum.p, buf, len);
      if (code != TSDB_CODE_SUCCESS) {
        taosMemoryFree(buf);
        return TSDB_CODE_TSC_INVALID_VALUE;
      }
      code = tjsonAddStringToObject(pJson, jkValueDatum, buf);
      taosMemoryFree(buf);
      break;
    }
X
Xiaoyu Wang 已提交
2897 2898 2899 2900 2901 2902 2903
    case TSDB_DATA_TYPE_DECIMAL:
    case TSDB_DATA_TYPE_BLOB:
      // todo
    default:
      break;
  }

X
Xiaoyu Wang 已提交
2904
  return code;
X
Xiaoyu Wang 已提交
2905 2906 2907 2908
}

static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
  const SValueNode* pNode = (const SValueNode*)pObj;
X
Xiaoyu Wang 已提交
2909

X
Xiaoyu Wang 已提交
2910
  int32_t code = exprNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
2911
  if (TSDB_CODE_SUCCESS == code) {
2912
    code = tjsonAddIntegerToObject(pJson, jkValueLiteralSize, NULL != pNode->literal ? strlen(pNode->literal) : 0);
X
Xiaoyu Wang 已提交
2913
  }
2914
  if (TSDB_CODE_SUCCESS == code && NULL != pNode->literal) {
X
Xiaoyu Wang 已提交
2915
    code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->literal);
X
Xiaoyu Wang 已提交
2916 2917 2918 2919
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkValueDuration, pNode->isDuration);
  }
X
Xiaoyu Wang 已提交
2920
  if (TSDB_CODE_SUCCESS == code) {
2921 2922
    code = tjsonAddBoolToObject(pJson, jkValueTranslate, pNode->translate);
  }
5
54liuyao 已提交
2923 2924 2925
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkValueNotReserved, pNode->notReserved);
  }
2926 2927 2928
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkValueIsNull, pNode->isNull);
  }
2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939
  if (TSDB_CODE_SUCCESS == code && pNode->translate) {
    code = datumToJson(pNode, pJson);
  }

  return code;
}

static int32_t jsonToDatum(const SJson* pJson, void* pObj) {
  SValueNode* pNode = (SValueNode*)pObj;

  int32_t code = TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
2940 2941 2942 2943
  switch (pNode->node.resType.type) {
    case TSDB_DATA_TYPE_NULL:
      break;
    case TSDB_DATA_TYPE_BOOL:
2944
      code = tjsonGetBoolValue(pJson, jkValueDatum, &pNode->datum.b);
D
dapan1121 已提交
2945
      *(bool*)&pNode->typeData = pNode->datum.b;
X
Xiaoyu Wang 已提交
2946 2947
      break;
    case TSDB_DATA_TYPE_TINYINT:
D
dapan1121 已提交
2948 2949 2950
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int8_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
2951
    case TSDB_DATA_TYPE_SMALLINT:
D
dapan1121 已提交
2952 2953 2954
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int16_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
2955
    case TSDB_DATA_TYPE_INT:
D
dapan1121 已提交
2956 2957 2958
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int32_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
2959
    case TSDB_DATA_TYPE_BIGINT:
D
dapan1121 已提交
2960 2961 2962
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int64_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
2963
    case TSDB_DATA_TYPE_TIMESTAMP:
2964
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
D
dapan1121 已提交
2965
      *(int64_t*)&pNode->typeData = pNode->datum.i;
X
Xiaoyu Wang 已提交
2966 2967
      break;
    case TSDB_DATA_TYPE_UTINYINT:
D
dapan1121 已提交
2968 2969 2970
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
      *(uint8_t*)&pNode->typeData = pNode->datum.u;
      break;
X
Xiaoyu Wang 已提交
2971
    case TSDB_DATA_TYPE_USMALLINT:
D
dapan1121 已提交
2972 2973 2974
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
      *(uint16_t*)&pNode->typeData = pNode->datum.u;
      break;
X
Xiaoyu Wang 已提交
2975
    case TSDB_DATA_TYPE_UINT:
D
dapan1121 已提交
2976 2977 2978
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
      *(uint32_t*)&pNode->typeData = pNode->datum.u;
      break;
X
Xiaoyu Wang 已提交
2979
    case TSDB_DATA_TYPE_UBIGINT:
2980
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
D
dapan1121 已提交
2981
      *(uint64_t*)&pNode->typeData = pNode->datum.u;
X
Xiaoyu Wang 已提交
2982 2983
      break;
    case TSDB_DATA_TYPE_FLOAT:
D
dapan1121 已提交
2984 2985 2986
      code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d);
      *(float*)&pNode->typeData = pNode->datum.d;
      break;
X
Xiaoyu Wang 已提交
2987
    case TSDB_DATA_TYPE_DOUBLE:
2988
      code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d);
D
dapan1121 已提交
2989
      *(double*)&pNode->typeData = pNode->datum.d;
X
Xiaoyu Wang 已提交
2990 2991 2992
      break;
    case TSDB_DATA_TYPE_NCHAR:
    case TSDB_DATA_TYPE_VARCHAR:
X
Xiaoyu Wang 已提交
2993
    case TSDB_DATA_TYPE_VARBINARY: {
wafwerar's avatar
wafwerar 已提交
2994
      pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
X
Xiaoyu Wang 已提交
2995 2996 2997 2998
      if (NULL == pNode->datum.p) {
        code = TSDB_CODE_OUT_OF_MEMORY;
        break;
      }
D
dapan1121 已提交
2999
      varDataSetLen(pNode->datum.p, pNode->node.resType.bytes - VARSTR_HEADER_SIZE);
3000
      if (TSDB_DATA_TYPE_NCHAR == pNode->node.resType.type) {
3001
        char* buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + VARSTR_HEADER_SIZE + 1);
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019
        if (NULL == buf) {
          code = TSDB_CODE_OUT_OF_MEMORY;
          break;
        }
        code = tjsonGetStringValue(pJson, jkValueDatum, buf);
        if (code != TSDB_CODE_SUCCESS) {
          taosMemoryFree(buf);
          break;
        }
        code = taosHexDecode(buf, varDataVal(pNode->datum.p), pNode->node.resType.bytes - VARSTR_HEADER_SIZE);
        if (code != TSDB_CODE_SUCCESS) {
          taosMemoryFree(buf);
          break;
        }
        taosMemoryFree(buf);
      } else {
        code = tjsonGetStringValue(pJson, jkValueDatum, varDataVal(pNode->datum.p));
      }
X
Xiaoyu Wang 已提交
3020
      break;
X
Xiaoyu Wang 已提交
3021
    }
3022
    case TSDB_DATA_TYPE_JSON: {
wmmhello's avatar
wmmhello 已提交
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045
      pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes);
      if (NULL == pNode->datum.p) {
        code = TSDB_CODE_OUT_OF_MEMORY;
        break;
      }
      char* buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + 1);
      if (NULL == buf) {
        code = TSDB_CODE_OUT_OF_MEMORY;
        break;
      }
      code = tjsonGetStringValue(pJson, jkValueDatum, buf);
      if (code != TSDB_CODE_SUCCESS) {
        taosMemoryFree(buf);
        break;
      }
      code = taosHexDecode(buf, pNode->datum.p, pNode->node.resType.bytes);
      if (code != TSDB_CODE_SUCCESS) {
        taosMemoryFree(buf);
        break;
      }
      taosMemoryFree(buf);
      break;
    }
X
Xiaoyu Wang 已提交
3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059
    case TSDB_DATA_TYPE_DECIMAL:
    case TSDB_DATA_TYPE_BLOB:
      // todo
    default:
      break;
  }

  return code;
}

static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
  SValueNode* pNode = (SValueNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
3060
  int32_t literalSize = 0;
X
Xiaoyu Wang 已提交
3061
  if (TSDB_CODE_SUCCESS == code) {
3062
    code = tjsonGetIntValue(pJson, jkValueLiteralSize, &literalSize);
X
Xiaoyu Wang 已提交
3063
  }
3064
  if (TSDB_CODE_SUCCESS == code && literalSize > 0) {
X
Xiaoyu Wang 已提交
3065 3066 3067 3068 3069
    code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->literal);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkValueDuration, &pNode->isDuration);
  }
X
Xiaoyu Wang 已提交
3070
  if (TSDB_CODE_SUCCESS == code) {
3071 3072
    code = tjsonGetBoolValue(pJson, jkValueTranslate, &pNode->translate);
  }
5
54liuyao 已提交
3073 3074 3075
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkValueNotReserved, &pNode->notReserved);
  }
3076 3077 3078
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkValueIsNull, &pNode->isNull);
  }
3079 3080
  if (TSDB_CODE_SUCCESS == code && pNode->translate) {
    code = jsonToDatum(pJson, pNode);
X
Xiaoyu Wang 已提交
3081 3082 3083 3084 3085
  }

  return code;
}

X
Xiaoyu Wang 已提交
3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106
static const char* jkOperatorType = "OpType";
static const char* jkOperatorLeft = "Left";
static const char* jkOperatorRight = "Right";

static int32_t operatorNodeToJson(const void* pObj, SJson* pJson) {
  const SOperatorNode* pNode = (const SOperatorNode*)pObj;

  int32_t code = exprNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkOperatorType, pNode->opType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkOperatorLeft, nodeToJson, pNode->pLeft);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkOperatorRight, nodeToJson, pNode->pRight);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3107 3108 3109 3110 3111
static int32_t jsonToOperatorNode(const SJson* pJson, void* pObj) {
  SOperatorNode* pNode = (SOperatorNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
3112 3113
    tjsonGetNumberValue(pJson, jkOperatorType, pNode->opType, code);
    ;
X
Xiaoyu Wang 已提交
3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkOperatorLeft, &pNode->pLeft);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkOperatorRight, &pNode->pRight);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135
static const char* jkLogicCondType = "CondType";
static const char* jkLogicCondParameters = "Parameters";

static int32_t logicConditionNodeToJson(const void* pObj, SJson* pJson) {
  const SLogicConditionNode* pNode = (const SLogicConditionNode*)pObj;

  int32_t code = exprNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicCondType, pNode->condType);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146
    code = nodeListToJson(pJson, jkLogicCondParameters, pNode->pParameterList);
  }

  return code;
}

static int32_t jsonToLogicConditionNode(const SJson* pJson, void* pObj) {
  SLogicConditionNode* pNode = (SLogicConditionNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
3147 3148
    tjsonGetNumberValue(pJson, jkLogicCondType, pNode->condType, code);
    ;
X
Xiaoyu Wang 已提交
3149 3150 3151
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkLogicCondParameters, &pNode->pParameterList);
X
Xiaoyu Wang 已提交
3152 3153 3154 3155 3156 3157 3158 3159 3160
  }

  return code;
}

static const char* jkFunctionName = "Name";
static const char* jkFunctionId = "Id";
static const char* jkFunctionType = "Type";
static const char* jkFunctionParameter = "Parameters";
S
slzhou 已提交
3161
static const char* jkFunctionUdfBufSize = "UdfBufSize";
X
Xiaoyu Wang 已提交
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176

static int32_t functionNodeToJson(const void* pObj, SJson* pJson) {
  const SFunctionNode* pNode = (const SFunctionNode*)pObj;

  int32_t code = exprNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkFunctionName, pNode->functionName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFunctionId, pNode->funcId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFunctionType, pNode->funcType);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
3177 3178
    code = nodeListToJson(pJson, jkFunctionParameter, pNode->pParameterList);
  }
S
slzhou 已提交
3179 3180 3181
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFunctionUdfBufSize, pNode->udfBufSize);
  }
X
Xiaoyu Wang 已提交
3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200

  return code;
}

static int32_t jsonToFunctionNode(const SJson* pJson, void* pObj) {
  SFunctionNode* pNode = (SFunctionNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkFunctionName, pNode->functionName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkFunctionId, &pNode->funcId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkFunctionType, &pNode->funcType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkFunctionParameter, &pNode->pParameterList);
X
Xiaoyu Wang 已提交
3201
  }
S
slzhou 已提交
3202 3203 3204
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkFunctionUdfBufSize, &pNode->udfBufSize);
  }
X
Xiaoyu Wang 已提交
3205 3206 3207 3208

  return code;
}

X
Xiaoyu Wang 已提交
3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246
static const char* jkTableDbName = "DbName";
static const char* jkTableTableName = "tableName";
static const char* jkTableTableAlias = "tableAlias";

static int32_t tableNodeToJson(const void* pObj, SJson* pJson) {
  const STableNode* pNode = (const STableNode*)pObj;

  int32_t code = exprNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkTableDbName, pNode->dbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkTableTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkTableTableAlias, pNode->tableAlias);
  }

  return code;
}

static int32_t jsonToTableNode(const SJson* pJson, void* pObj) {
  STableNode* pNode = (STableNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkTableDbName, pNode->dbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkTableTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkTableTableAlias, pNode->tableAlias);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320
static const char* jkTableIndexInfoIntervalUnit = "IntervalUnit";
static const char* jkTableIndexInfoSlidingUnit = "SlidingUnit";
static const char* jkTableIndexInfoInterval = "Interval";
static const char* jkTableIndexInfoOffset = "Offset";
static const char* jkTableIndexInfoSliding = "Sliding";
static const char* jkTableIndexInfoDstTbUid = "DstTbUid";
static const char* jkTableIndexInfoDstVgId = "DstVgId";
static const char* jkTableIndexInfoEpSet = "EpSet";
static const char* jkTableIndexInfoExpr = "Expr";

static int32_t tableIndexInfoToJson(const void* pObj, SJson* pJson) {
  const STableIndexInfo* pNode = (const STableIndexInfo*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkTableIndexInfoIntervalUnit, pNode->intervalUnit);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableIndexInfoSlidingUnit, pNode->slidingUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableIndexInfoInterval, pNode->interval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableIndexInfoOffset, pNode->offset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableIndexInfoSliding, pNode->sliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableIndexInfoDstTbUid, pNode->dstTbUid);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableIndexInfoDstVgId, pNode->dstVgId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkTableIndexInfoEpSet, epSetToJson, &pNode->epSet);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkTableIndexInfoExpr, pNode->expr);
  }

  return code;
}

static int32_t jsonToTableIndexInfo(const SJson* pJson, void* pObj) {
  STableIndexInfo* pNode = (STableIndexInfo*)pObj;

  int32_t code = tjsonGetTinyIntValue(pJson, jkTableIndexInfoIntervalUnit, &pNode->intervalUnit);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkTableIndexInfoSlidingUnit, &pNode->slidingUnit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkTableIndexInfoInterval, &pNode->interval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkTableIndexInfoOffset, &pNode->offset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkTableIndexInfoSliding, &pNode->sliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkTableIndexInfoDstTbUid, &pNode->dstTbUid);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkTableIndexInfoDstVgId, &pNode->dstVgId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkTableIndexInfoEpSet, jsonToEpSet, &pNode->epSet);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonDupStringValue(pJson, jkTableIndexInfoExpr, &pNode->expr);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3321 3322 3323 3324
static const char* jkRealTableMetaSize = "MetaSize";
static const char* jkRealTableMeta = "Meta";
static const char* jkRealTableVgroupsInfoSize = "VgroupsInfoSize";
static const char* jkRealTableVgroupsInfo = "VgroupsInfo";
X
Xiaoyu Wang 已提交
3325
static const char* jkRealTableSmaIndexes = "SmaIndexes";
X
Xiaoyu Wang 已提交
3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342

static int32_t realTableNodeToJson(const void* pObj, SJson* pJson) {
  const SRealTableNode* pNode = (const SRealTableNode*)pObj;

  int32_t code = tableNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkRealTableMetaSize, TABLE_META_SIZE(pNode->pMeta));
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkRealTableMeta, tableMetaToJson, pNode->pMeta);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkRealTableVgroupsInfoSize, VGROUPS_INFO_SIZE(pNode->pVgroupList));
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkRealTableVgroupsInfo, vgroupsInfoToJson, pNode->pVgroupList);
  }
X
Xiaoyu Wang 已提交
3343 3344 3345
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddTArray(pJson, jkRealTableSmaIndexes, tableIndexInfoToJson, pNode->pSmaIndexes);
  }
X
Xiaoyu Wang 已提交
3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366

  return code;
}

static int32_t jsonToRealTableNode(const SJson* pJson, void* pObj) {
  SRealTableNode* pNode = (SRealTableNode*)pObj;

  int32_t objSize = 0;
  int32_t code = jsonToTableNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkRealTableMetaSize, &objSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonMakeObject(pJson, jkRealTableMeta, jsonToTableMeta, (void**)&pNode->pMeta, objSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkRealTableVgroupsInfoSize, &objSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonMakeObject(pJson, jkRealTableVgroupsInfo, jsonToVgroupsInfo, (void**)&pNode->pVgroupList, objSize);
  }
X
Xiaoyu Wang 已提交
3367 3368 3369 3370
  if (TSDB_CODE_SUCCESS == code) {
    code =
        tjsonToTArray(pJson, jkRealTableSmaIndexes, jsonToTableIndexInfo, &pNode->pSmaIndexes, sizeof(STableIndexInfo));
  }
X
Xiaoyu Wang 已提交
3371 3372 3373 3374

  return code;
}

3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398
static const char* jkTempTableSubquery = "Subquery";

static int32_t tempTableNodeToJson(const void* pObj, SJson* pJson) {
  const STempTableNode* pNode = (const STempTableNode*)pObj;

  int32_t code = tableNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkTempTableSubquery, nodeToJson, pNode->pSubquery);
  }

  return code;
}

static int32_t jsonToTempTableNode(const SJson* pJson, void* pObj) {
  STempTableNode* pNode = (STempTableNode*)pObj;

  int32_t code = jsonToTableNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkTempTableSubquery, &pNode->pSubquery);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3399 3400 3401 3402 3403 3404 3405 3406
static const char* jkGroupingSetType = "GroupingSetType";
static const char* jkGroupingSetParameter = "Parameters";

static int32_t groupingSetNodeToJson(const void* pObj, SJson* pJson) {
  const SGroupingSetNode* pNode = (const SGroupingSetNode*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkGroupingSetType, pNode->groupingSetType);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
3407
    code = nodeListToJson(pJson, jkGroupingSetParameter, pNode->pParameterList);
X
Xiaoyu Wang 已提交
3408 3409 3410 3411 3412
  }

  return code;
}

X
Xiaoyu Wang 已提交
3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435
static const char* jkOrderByExprExpr = "Expr";
static const char* jkOrderByExprOrder = "Order";
static const char* jkOrderByExprNullOrder = "NullOrder";

static int32_t orderByExprNodeToJson(const void* pObj, SJson* pJson) {
  const SOrderByExprNode* pNode = (const SOrderByExprNode*)pObj;

  int32_t code = tjsonAddObject(pJson, jkOrderByExprExpr, nodeToJson, pNode->pExpr);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkOrderByExprOrder, pNode->order);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkOrderByExprNullOrder, pNode->nullOrder);
  }

  return code;
}

static int32_t jsonToOrderByExprNode(const SJson* pJson, void* pObj) {
  SOrderByExprNode* pNode = (SOrderByExprNode*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkOrderByExprExpr, &pNode->pExpr);
  if (TSDB_CODE_SUCCESS == code) {
3436 3437
    tjsonGetNumberValue(pJson, jkOrderByExprOrder, pNode->order, code);
    ;
X
Xiaoyu Wang 已提交
3438 3439
  }
  if (TSDB_CODE_SUCCESS == code) {
3440 3441
    tjsonGetNumberValue(pJson, jkOrderByExprNullOrder, pNode->nullOrder, code);
    ;
X
Xiaoyu Wang 已提交
3442 3443 3444 3445 3446
  }

  return code;
}

3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471
static const char* jkLimitLimit = "Limit";
static const char* jkLimitOffset = "Offset";

static int32_t limitNodeToJson(const void* pObj, SJson* pJson) {
  const SLimitNode* pNode = (const SLimitNode*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkLimitLimit, pNode->limit);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLimitOffset, pNode->offset);
  }

  return code;
}

static int32_t jsonToLimitNode(const SJson* pJson, void* pObj) {
  SLimitNode* pNode = (SLimitNode*)pObj;

  int32_t code = tjsonGetBigIntValue(pJson, jkLimitLimit, &pNode->limit);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkLimitOffset, &pNode->offset);
  }

  return code;
}

5
54liuyao 已提交
3472 3473 3474 3475 3476
static const char* jkStateWindowCol = "StateWindowCol";
static const char* jkStateWindowExpr = "StateWindowExpr";

static int32_t stateWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SStateWindowNode* pNode = (const SStateWindowNode*)pObj;
X
Xiaoyu Wang 已提交
3477
  int32_t                 code = tjsonAddObject(pJson, jkStateWindowCol, nodeToJson, pNode->pCol);
5
54liuyao 已提交
3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkStateWindowExpr, nodeToJson, pNode->pExpr);
  }
  return code;
}

static int32_t jsonToStateWindowNode(const SJson* pJson, void* pObj) {
  SStateWindowNode* pNode = (SStateWindowNode*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkStateWindowCol, (SNode**)&pNode->pCol);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkStateWindowExpr, (SNode**)&pNode->pExpr);
  }
  return code;
}

5
54liuyao 已提交
3494 3495 3496 3497
static const char* jkSessionWindowTsPrimaryKey = "TsPrimaryKey";
static const char* jkSessionWindowGap = "Gap";

static int32_t sessionWindowNodeToJson(const void* pObj, SJson* pJson) {
3498
  const SSessionWindowNode* pNode = (const SSessionWindowNode*)pObj;
5
54liuyao 已提交
3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509

  int32_t code = tjsonAddObject(pJson, jkSessionWindowTsPrimaryKey, nodeToJson, pNode->pCol);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSessionWindowGap, nodeToJson, pNode->pGap);
  }
  return code;
}

static int32_t jsonToSessionWindowNode(const SJson* pJson, void* pObj) {
  SSessionWindowNode* pNode = (SSessionWindowNode*)pObj;

3510
  int32_t code = jsonToNodeObject(pJson, jkSessionWindowTsPrimaryKey, (SNode**)&pNode->pCol);
5
54liuyao 已提交
3511
  if (TSDB_CODE_SUCCESS == code) {
3512
    code = jsonToNodeObject(pJson, jkSessionWindowGap, (SNode**)&pNode->pGap);
5
54liuyao 已提交
3513 3514 3515 3516
  }
  return code;
}

X
bugfix  
Xiaoyu Wang 已提交
3517 3518 3519 3520
static const char* jkIntervalWindowInterval = "Interval";
static const char* jkIntervalWindowOffset = "Offset";
static const char* jkIntervalWindowSliding = "Sliding";
static const char* jkIntervalWindowFill = "Fill";
X
bugfix  
Xiaoyu Wang 已提交
3521
static const char* jkIntervalWindowTsPk = "TsPk";
X
bugfix  
Xiaoyu Wang 已提交
3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535

static int32_t intervalWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SIntervalWindowNode* pNode = (const SIntervalWindowNode*)pObj;

  int32_t code = tjsonAddObject(pJson, jkIntervalWindowInterval, nodeToJson, pNode->pInterval);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIntervalWindowOffset, nodeToJson, pNode->pOffset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIntervalWindowSliding, nodeToJson, pNode->pSliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIntervalWindowFill, nodeToJson, pNode->pFill);
  }
X
bugfix  
Xiaoyu Wang 已提交
3536 3537 3538
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIntervalWindowTsPk, nodeToJson, pNode->pCol);
  }
X
bugfix  
Xiaoyu Wang 已提交
3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555

  return code;
}

static int32_t jsonToIntervalWindowNode(const SJson* pJson, void* pObj) {
  SIntervalWindowNode* pNode = (SIntervalWindowNode*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkIntervalWindowInterval, &pNode->pInterval);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIntervalWindowOffset, &pNode->pOffset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIntervalWindowSliding, &pNode->pSliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIntervalWindowFill, &pNode->pFill);
  }
X
bugfix  
Xiaoyu Wang 已提交
3556 3557 3558
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIntervalWindowTsPk, &pNode->pCol);
  }
X
bugfix  
Xiaoyu Wang 已提交
3559 3560 3561 3562

  return code;
}

X
Xiaoyu Wang 已提交
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587
static const char* jkNodeListDataType = "DataType";
static const char* jkNodeListNodeList = "NodeList";

static int32_t nodeListNodeToJson(const void* pObj, SJson* pJson) {
  const SNodeListNode* pNode = (const SNodeListNode*)pObj;

  int32_t code = tjsonAddObject(pJson, jkNodeListDataType, dataTypeToJson, &pNode->dataType);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkNodeListNodeList, pNode->pNodeList);
  }

  return code;
}

static int32_t jsonToNodeListNode(const SJson* pJson, void* pObj) {
  SNodeListNode* pNode = (SNodeListNode*)pObj;

  int32_t code = tjsonToObject(pJson, jkNodeListDataType, jsonToDataType, &pNode->dataType);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkNodeListNodeList, &pNode->pNodeList);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3588 3589
static const char* jkFillMode = "Mode";
static const char* jkFillValues = "Values";
X
Xiaoyu Wang 已提交
3590
static const char* jkFillWStartTs = "WStartTs";
X
Xiaoyu Wang 已提交
3591 3592
static const char* jkFillStartTime = "StartTime";
static const char* jkFillEndTime = "EndTime";
X
Xiaoyu Wang 已提交
3593 3594 3595 3596 3597 3598 3599 3600

static int32_t fillNodeToJson(const void* pObj, SJson* pJson) {
  const SFillNode* pNode = (const SFillNode*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkFillMode, pNode->mode);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkFillValues, nodeToJson, pNode->pValues);
  }
X
Xiaoyu Wang 已提交
3601 3602 3603
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkFillWStartTs, nodeToJson, pNode->pWStartTs);
  }
X
Xiaoyu Wang 已提交
3604 3605 3606 3607 3608 3609
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillStartTime, pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillEndTime, pNode->timeRange.ekey);
  }
X
Xiaoyu Wang 已提交
3610 3611 3612 3613 3614 3615 3616

  return code;
}

static int32_t jsonToFillNode(const SJson* pJson, void* pObj) {
  SFillNode* pNode = (SFillNode*)pObj;

3617
  int32_t code;
3618 3619
  tjsonGetNumberValue(pJson, jkFillMode, pNode->mode, code);
  ;
X
Xiaoyu Wang 已提交
3620 3621 3622
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillValues, &pNode->pValues);
  }
X
Xiaoyu Wang 已提交
3623 3624 3625
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillWStartTs, &pNode->pWStartTs);
  }
X
Xiaoyu Wang 已提交
3626 3627 3628 3629 3630 3631
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkFillStartTime, &pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkFillEndTime, &pNode->timeRange.ekey);
  }
X
Xiaoyu Wang 已提交
3632 3633 3634 3635

  return code;
}

X
Xiaoyu Wang 已提交
3636
static const char* jkTargetDataBlockId = "DataBlockId";
X
Xiaoyu Wang 已提交
3637 3638 3639 3640 3641 3642
static const char* jkTargetSlotId = "SlotId";
static const char* jkTargetExpr = "Expr";

static int32_t targetNodeToJson(const void* pObj, SJson* pJson) {
  const STargetNode* pNode = (const STargetNode*)pObj;

X
Xiaoyu Wang 已提交
3643
  int32_t code = tjsonAddIntegerToObject(pJson, jkTargetDataBlockId, pNode->dataBlockId);
X
Xiaoyu Wang 已提交
3644 3645 3646 3647 3648 3649 3650 3651 3652 3653
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTargetSlotId, pNode->slotId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkTargetExpr, nodeToJson, pNode->pExpr);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667
static int32_t jsonToTargetNode(const SJson* pJson, void* pObj) {
  STargetNode* pNode = (STargetNode*)pObj;

  int32_t code = tjsonGetSmallIntValue(pJson, jkTargetDataBlockId, &pNode->dataBlockId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetSmallIntValue(pJson, jkTargetSlotId, &pNode->slotId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkTargetExpr, &pNode->pExpr);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3668 3669
static const char* jkSlotDescSlotId = "SlotId";
static const char* jkSlotDescDataType = "DataType";
X
Xiaoyu Wang 已提交
3670 3671
static const char* jkSlotDescReserve = "Reserve";
static const char* jkSlotDescOutput = "Output";
3672
static const char* jkSlotDescName = "Name";
X
Xiaoyu Wang 已提交
3673 3674 3675 3676 3677 3678 3679 3680

static int32_t slotDescNodeToJson(const void* pObj, SJson* pJson) {
  const SSlotDescNode* pNode = (const SSlotDescNode*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkSlotDescSlotId, pNode->slotId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSlotDescDataType, dataTypeToJson, &pNode->dataType);
  }
X
Xiaoyu Wang 已提交
3681
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
3682
    code = tjsonAddBoolToObject(pJson, jkSlotDescReserve, pNode->reserve);
X
Xiaoyu Wang 已提交
3683 3684
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
3685 3686
    code = tjsonAddBoolToObject(pJson, jkSlotDescOutput, pNode->output);
  }
3687 3688 3689
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSlotDescName, pNode->name);
  }
X
Xiaoyu Wang 已提交
3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705

  return code;
}

static int32_t jsonToSlotDescNode(const SJson* pJson, void* pObj) {
  SSlotDescNode* pNode = (SSlotDescNode*)pObj;

  int32_t code = tjsonGetSmallIntValue(pJson, jkSlotDescSlotId, &pNode->slotId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkSlotDescDataType, jsonToDataType, &pNode->dataType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSlotDescReserve, &pNode->reserve);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSlotDescOutput, &pNode->output);
X
Xiaoyu Wang 已提交
3706
  }
3707 3708 3709
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSlotDescName, pNode->name);
  }
X
Xiaoyu Wang 已提交
3710 3711 3712 3713

  return code;
}

X
Xiaoyu Wang 已提交
3714 3715 3716
static const char* jkDownstreamSourceAddr = "Addr";
static const char* jkDownstreamSourceTaskId = "TaskId";
static const char* jkDownstreamSourceSchedId = "SchedId";
D
dapan1121 已提交
3717
static const char* jkDownstreamSourceExecId = "ExecId";
D
dapan1121 已提交
3718
static const char* jkDownstreamSourceFetchMsgType = "FetchMsgType";
X
Xiaoyu Wang 已提交
3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729

static int32_t downstreamSourceNodeToJson(const void* pObj, SJson* pJson) {
  const SDownstreamSourceNode* pNode = (const SDownstreamSourceNode*)pObj;

  int32_t code = tjsonAddObject(pJson, jkDownstreamSourceAddr, queryNodeAddrToJson, &pNode->addr);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceTaskId, pNode->taskId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceSchedId, pNode->schedId);
  }
D
dapan1121 已提交
3730
  if (TSDB_CODE_SUCCESS == code) {
D
dapan1121 已提交
3731
    code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceExecId, pNode->execId);
D
dapan1121 已提交
3732
  }
D
dapan1121 已提交
3733 3734 3735
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceFetchMsgType, pNode->fetchMsgType);
  }
X
Xiaoyu Wang 已提交
3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749

  return code;
}

static int32_t jsonToDownstreamSourceNode(const SJson* pJson, void* pObj) {
  SDownstreamSourceNode* pNode = (SDownstreamSourceNode*)pObj;

  int32_t code = tjsonToObject(pJson, jkDownstreamSourceAddr, jsonToQueryNodeAddr, &pNode->addr);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceTaskId, &pNode->taskId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceSchedId, &pNode->schedId);
  }
D
dapan1121 已提交
3750
  if (TSDB_CODE_SUCCESS == code) {
D
dapan1121 已提交
3751
    code = tjsonGetIntValue(pJson, jkDownstreamSourceExecId, &pNode->execId);
D
dapan1121 已提交
3752
  }
D
dapan1121 已提交
3753 3754 3755
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDownstreamSourceFetchMsgType, &pNode->fetchMsgType);
  }
X
Xiaoyu Wang 已提交
3756 3757 3758 3759

  return code;
}

3760
static const char* jkDatabaseOptionsBuffer = "Buffer";
3761
static const char* jkDatabaseOptionsCacheModel = "CacheModel";
3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784
static const char* jkDatabaseOptionsCompressionLevel = "CompressionLevel";
static const char* jkDatabaseOptionsDaysPerFileNode = "DaysPerFileNode";
static const char* jkDatabaseOptionsDaysPerFile = "DaysPerFile";
static const char* jkDatabaseOptionsFsyncPeriod = "FsyncPeriod";
static const char* jkDatabaseOptionsMaxRowsPerBlock = "MaxRowsPerBlock";
static const char* jkDatabaseOptionsMinRowsPerBlock = "MinRowsPerBlock";
static const char* jkDatabaseOptionsKeep = "Keep";
static const char* jkDatabaseOptionsPages = "Pages";
static const char* jkDatabaseOptionsPagesize = "Pagesize";
static const char* jkDatabaseOptionsPrecision = "Precision";
static const char* jkDatabaseOptionsReplica = "Replica";
static const char* jkDatabaseOptionsStrict = "Strict";
static const char* jkDatabaseOptionsWalLevel = "WalLevel";
static const char* jkDatabaseOptionsNumOfVgroups = "NumOfVgroups";
static const char* jkDatabaseOptionsSingleStable = "SingleStable";
static const char* jkDatabaseOptionsRetentions = "Retentions";
static const char* jkDatabaseOptionsSchemaless = "Schemaless";

static int32_t databaseOptionsToJson(const void* pObj, SJson* pJson) {
  const SDatabaseOptions* pNode = (const SDatabaseOptions*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsBuffer, pNode->buffer);
  if (TSDB_CODE_SUCCESS == code) {
3785
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsCacheModel, pNode->cacheModel);
3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsCompressionLevel, pNode->compressionLevel);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkDatabaseOptionsDaysPerFileNode, nodeToJson, pNode->pDaysPerFile);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsDaysPerFile, pNode->daysPerFile);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsFsyncPeriod, pNode->fsyncPeriod);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsMaxRowsPerBlock, pNode->maxRowsPerBlock);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsMinRowsPerBlock, pNode->minRowsPerBlock);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkDatabaseOptionsKeep, pNode->pKeep);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsPages, pNode->pages);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsPagesize, pNode->pagesize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDatabaseOptionsPrecision, pNode->precisionStr);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsReplica, pNode->replica);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsStrict, pNode->strict);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsWalLevel, pNode->walLevel);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsNumOfVgroups, pNode->numOfVgroups);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsSingleStable, pNode->singleStable);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkDatabaseOptionsRetentions, pNode->pRetentions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsSchemaless, pNode->schemaless);
  }

  return code;
}

static int32_t jsonToDatabaseOptions(const SJson* pJson, void* pObj) {
  SDatabaseOptions* pNode = (SDatabaseOptions*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkDatabaseOptionsBuffer, &pNode->buffer);
  if (TSDB_CODE_SUCCESS == code) {
3847
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsCacheModel, &pNode->cacheModel);
3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsCompressionLevel, &pNode->compressionLevel);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkDatabaseOptionsDaysPerFileNode, (SNode**)&pNode->pDaysPerFile);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDatabaseOptionsDaysPerFile, &pNode->daysPerFile);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDatabaseOptionsFsyncPeriod, &pNode->fsyncPeriod);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDatabaseOptionsMaxRowsPerBlock, &pNode->maxRowsPerBlock);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDatabaseOptionsMinRowsPerBlock, &pNode->minRowsPerBlock);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkDatabaseOptionsKeep, &pNode->pKeep);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDatabaseOptionsPages, &pNode->pages);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDatabaseOptionsPagesize, &pNode->pagesize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDatabaseOptionsPrecision, pNode->precisionStr);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsReplica, &pNode->replica);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsStrict, &pNode->strict);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsWalLevel, &pNode->walLevel);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDatabaseOptionsNumOfVgroups, &pNode->numOfVgroups);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsSingleStable, &pNode->singleStable);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkDatabaseOptionsRetentions, &pNode->pRetentions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsSchemaless, &pNode->schemaless);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3904 3905
static const char* jkDataBlockDescDataBlockId = "DataBlockId";
static const char* jkDataBlockDescSlots = "Slots";
3906 3907 3908
static const char* jkDataBlockTotalRowSize = "TotalRowSize";
static const char* jkDataBlockOutputRowSize = "OutputRowSize";
static const char* jkDataBlockPrecision = "Precision";
X
Xiaoyu Wang 已提交
3909

X
Xiaoyu Wang 已提交
3910 3911
static int32_t dataBlockDescNodeToJson(const void* pObj, SJson* pJson) {
  const SDataBlockDescNode* pNode = (const SDataBlockDescNode*)pObj;
X
Xiaoyu Wang 已提交
3912

X
Xiaoyu Wang 已提交
3913
  int32_t code = tjsonAddIntegerToObject(pJson, jkDataBlockDescDataBlockId, pNode->dataBlockId);
3914
  if (TSDB_CODE_SUCCESS == code) {
3915 3916 3917 3918
    code = tjsonAddIntegerToObject(pJson, jkDataBlockTotalRowSize, pNode->totalRowSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDataBlockOutputRowSize, pNode->outputRowSize);
3919
  }
X
Xiaoyu Wang 已提交
3920
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
3921 3922
    code = nodeListToJson(pJson, jkDataBlockDescSlots, pNode->pSlots);
  }
3923 3924 3925
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDataBlockPrecision, pNode->precision);
  }
X
Xiaoyu Wang 已提交
3926 3927 3928 3929 3930 3931 3932 3933

  return code;
}

static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) {
  SDataBlockDescNode* pNode = (SDataBlockDescNode*)pObj;

  int32_t code = tjsonGetSmallIntValue(pJson, jkDataBlockDescDataBlockId, &pNode->dataBlockId);
3934
  if (TSDB_CODE_SUCCESS == code) {
3935 3936 3937 3938
    code = tjsonGetIntValue(pJson, jkDataBlockTotalRowSize, &pNode->totalRowSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDataBlockOutputRowSize, &pNode->outputRowSize);
3939
  }
X
Xiaoyu Wang 已提交
3940 3941
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkDataBlockDescSlots, &pNode->pSlots);
X
Xiaoyu Wang 已提交
3942
  }
3943
  if (TSDB_CODE_SUCCESS == code) {
3944
    code = tjsonGetUTinyIntValue(pJson, jkDataBlockPrecision, &pNode->precision);
3945
  }
X
Xiaoyu Wang 已提交
3946 3947 3948 3949

  return code;
}

3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982
static const char* jkSetOperatorOpType = "OpType";
static const char* jkSetOperatorProjections = "Projections";
static const char* jkSetOperatorLeft = "Left";
static const char* jkSetOperatorRight = "Right";
static const char* jkSetOperatorOrderByList = "OrderByList";
static const char* jkSetOperatorLimit = "Limit";

static int32_t setOperatorToJson(const void* pObj, SJson* pJson) {
  const SSetOperator* pNode = (const SSetOperator*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkSetOperatorOpType, pNode->opType);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSetOperatorProjections, pNode->pProjectionList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSetOperatorLeft, nodeToJson, pNode->pLeft);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSetOperatorRight, nodeToJson, pNode->pRight);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSetOperatorOrderByList, pNode->pOrderByList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSetOperatorLimit, nodeToJson, pNode->pLimit);
  }

  return code;
}

static int32_t jsonToSetOperator(const SJson* pJson, void* pObj) {
  SSetOperator* pNode = (SSetOperator*)pObj;

3983 3984
  int32_t code = TSDB_CODE_SUCCESS;
  tjsonGetNumberValue(pJson, jkSetOperatorOpType, pNode->opType, code);
3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSetOperatorProjections, &pNode->pProjectionList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSetOperatorLeft, &pNode->pLeft);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSetOperatorRight, &pNode->pRight);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSetOperatorOrderByList, &pNode->pOrderByList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSetOperatorLimit, &pNode->pLimit);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014
static const char* jkSelectStmtDistinct = "Distinct";
static const char* jkSelectStmtProjections = "Projections";
static const char* jkSelectStmtFrom = "From";
static const char* jkSelectStmtWhere = "Where";
static const char* jkSelectStmtPartitionBy = "PartitionBy";
static const char* jkSelectStmtWindow = "Window";
static const char* jkSelectStmtGroupBy = "GroupBy";
static const char* jkSelectStmtHaving = "Having";
static const char* jkSelectStmtOrderBy = "OrderBy";
static const char* jkSelectStmtLimit = "Limit";
static const char* jkSelectStmtSlimit = "Slimit";
X
bugfix  
Xiaoyu Wang 已提交
4015
static const char* jkSelectStmtStmtName = "StmtName";
X
Xiaoyu Wang 已提交
4016
static const char* jkSelectStmtHasAggFuncs = "HasAggFuncs";
X
Xiaoyu Wang 已提交
4017

4018
static int32_t selectStmtToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
4019 4020
  const SSelectStmt* pNode = (const SSelectStmt*)pObj;

X
Xiaoyu Wang 已提交
4021
  int32_t code = tjsonAddBoolToObject(pJson, jkSelectStmtDistinct, pNode->isDistinct);
X
Xiaoyu Wang 已提交
4022
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4023
    code = nodeListToJson(pJson, jkSelectStmtProjections, pNode->pProjectionList);
X
Xiaoyu Wang 已提交
4024 4025 4026 4027 4028 4029 4030 4031
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtFrom, nodeToJson, pNode->pFromTable);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtWhere, nodeToJson, pNode->pWhere);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4032
    code = nodeListToJson(pJson, jkSelectStmtPartitionBy, pNode->pPartitionByList);
X
Xiaoyu Wang 已提交
4033 4034 4035 4036 4037
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtWindow, nodeToJson, pNode->pWindow);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4038
    code = nodeListToJson(pJson, jkSelectStmtGroupBy, pNode->pGroupByList);
X
Xiaoyu Wang 已提交
4039 4040 4041 4042 4043
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtHaving, nodeToJson, pNode->pHaving);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4044
    code = nodeListToJson(pJson, jkSelectStmtOrderBy, pNode->pOrderByList);
X
Xiaoyu Wang 已提交
4045 4046 4047 4048 4049 4050 4051
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtLimit, nodeToJson, pNode->pLimit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtSlimit, nodeToJson, pNode->pSlimit);
  }
X
bugfix  
Xiaoyu Wang 已提交
4052 4053 4054
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName);
  }
X
Xiaoyu Wang 已提交
4055 4056 4057
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkSelectStmtHasAggFuncs, pNode->hasAggFuncs);
  }
X
Xiaoyu Wang 已提交
4058 4059 4060 4061

  return code;
}

X
Xiaoyu Wang 已提交
4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090
static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) {
  SSelectStmt* pNode = (SSelectStmt*)pObj;

  int32_t code = tjsonGetBoolValue(pJson, jkSelectStmtDistinct, &pNode->isDistinct);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSelectStmtProjections, &pNode->pProjectionList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSelectStmtFrom, &pNode->pFromTable);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSelectStmtWhere, &pNode->pWhere);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSelectStmtPartitionBy, &pNode->pPartitionByList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSelectStmtWindow, &pNode->pWindow);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSelectStmtGroupBy, &pNode->pGroupByList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSelectStmtHaving, &pNode->pHaving);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSelectStmtOrderBy, &pNode->pOrderByList);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4091
    code = jsonToNodeObject(pJson, jkSelectStmtLimit, (SNode**)&pNode->pLimit);
X
Xiaoyu Wang 已提交
4092 4093
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4094
    code = jsonToNodeObject(pJson, jkSelectStmtSlimit, (SNode**)&pNode->pSlimit);
X
Xiaoyu Wang 已提交
4095
  }
X
bugfix  
Xiaoyu Wang 已提交
4096 4097 4098
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName);
  }
X
Xiaoyu Wang 已提交
4099 4100 4101
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSelectStmtHasAggFuncs, &pNode->hasAggFuncs);
  }
X
Xiaoyu Wang 已提交
4102 4103 4104 4105

  return code;
}

4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229
static const char* jkAlterDatabaseStmtDbName = "DbName";
static const char* jkAlterDatabaseStmtOptions = "Options";

static int32_t alterDatabaseStmtToJson(const void* pObj, SJson* pJson) {
  const SAlterDatabaseStmt* pNode = (const SAlterDatabaseStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkAlterDatabaseStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkAlterDatabaseStmtOptions, nodeToJson, pNode->pOptions);
  }

  return code;
}

static int32_t jsonToAlterDatabaseStmt(const SJson* pJson, void* pObj) {
  SAlterDatabaseStmt* pNode = (SAlterDatabaseStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkAlterDatabaseStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkAlterDatabaseStmtOptions, (SNode**)&pNode->pOptions);
  }

  return code;
}

static const char* jkAlterTableStmtDbName = "DbName";
static const char* jkAlterTableStmtTableName = "TableName";
static const char* jkAlterTableStmtAlterType = "AlterType";
static const char* jkAlterTableStmtColName = "ColName";
static const char* jkAlterTableStmtNewColName = "NewColName";
static const char* jkAlterTableStmtOptions = "Options";
static const char* jkAlterTableStmtNewDataType = "NewDataType";
static const char* jkAlterTableStmtNewTagVal = "NewTagVal";

static int32_t alterTableStmtToJson(const void* pObj, SJson* pJson) {
  const SAlterTableStmt* pNode = (const SAlterTableStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkAlterTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkAlterTableStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkAlterTableStmtAlterType, pNode->alterType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkAlterTableStmtColName, pNode->colName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkAlterTableStmtNewColName, pNode->newColName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkAlterTableStmtOptions, nodeToJson, pNode->pOptions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkAlterTableStmtNewDataType, dataTypeToJson, &pNode->dataType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkAlterTableStmtOptions, nodeToJson, pNode->pVal);
  }

  return code;
}

static int32_t jsonToAlterTableStmt(const SJson* pJson, void* pObj) {
  SAlterTableStmt* pNode = (SAlterTableStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkAlterTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkAlterTableStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkAlterTableStmtAlterType, &pNode->alterType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkAlterTableStmtColName, pNode->colName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkAlterTableStmtNewColName, pNode->newColName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkAlterTableStmtOptions, (SNode**)&pNode->pOptions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkAlterTableStmtNewDataType, jsonToDataType, &pNode->dataType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkAlterTableStmtOptions, (SNode**)&pNode->pVal);
  }

  return code;
}

static const char* jkAlterDnodeStmtDnodeId = "DnodeId";
static const char* jkAlterDnodeStmtConfig = "Config";
static const char* jkAlterDnodeStmtValue = "Value";

static int32_t alterDnodeStmtToJson(const void* pObj, SJson* pJson) {
  const SAlterDnodeStmt* pNode = (const SAlterDnodeStmt*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkAlterDnodeStmtDnodeId, pNode->dnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkAlterDnodeStmtConfig, pNode->config);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkAlterDnodeStmtValue, pNode->value);
  }

  return code;
}

static int32_t jsonToAlterDnodeStmt(const SJson* pJson, void* pObj) {
  SAlterDnodeStmt* pNode = (SAlterDnodeStmt*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkAlterDnodeStmtDnodeId, &pNode->dnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkAlterDnodeStmtConfig, pNode->config);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkAlterDnodeStmtValue, pNode->value);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4230 4231 4232 4233 4234 4235 4236 4237 4238 4239
static const char* jkCreateTopicStmtTopicName = "TopicName";
static const char* jkCreateTopicStmtSubscribeDbName = "SubscribeDbName";
static const char* jkCreateTopicStmtIgnoreExists = "IgnoreExists";
static const char* jkCreateTopicStmtQuery = "Query";

static int32_t createTopicStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateTopicStmt* pNode = (const SCreateTopicStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkCreateTopicStmtTopicName, pNode->topicName);
  if (TSDB_CODE_SUCCESS == code) {
4240
    code = tjsonAddStringToObject(pJson, jkCreateTopicStmtSubscribeDbName, pNode->subDbName);
X
Xiaoyu Wang 已提交
4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkCreateTopicStmtIgnoreExists, pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateTopicStmtQuery, nodeToJson, pNode->pQuery);
  }

  return code;
}

static int32_t jsonToCreateTopicStmt(const SJson* pJson, void* pObj) {
  SCreateTopicStmt* pNode = (SCreateTopicStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkCreateTopicStmtTopicName, pNode->topicName);
  if (TSDB_CODE_SUCCESS == code) {
4257
    code = tjsonGetStringValue(pJson, jkCreateTopicStmtSubscribeDbName, pNode->subDbName);
X
Xiaoyu Wang 已提交
4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkCreateTopicStmtIgnoreExists, &pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateTopicStmtQuery, &pNode->pQuery);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288
static const char* jkDeleteStmtFromTable = "FromTable";
static const char* jkDeleteStmtWhere = "Where";
static const char* jkDeleteStmtCountFunc = "CountFunc";
static const char* jkDeleteStmtTagIndexCond = "TagIndexCond";
static const char* jkDeleteStmtTimeRangeStartKey = "TimeRangeStartKey";
static const char* jkDeleteStmtTimeRangeEndKey = "TimeRangeEndKey";
static const char* jkDeleteStmtPrecision = "Precision";
static const char* jkDeleteStmtDeleteZeroRows = "DeleteZeroRows";

static int32_t deleteStmtToJson(const void* pObj, SJson* pJson) {
  const SDeleteStmt* pNode = (const SDeleteStmt*)pObj;

  int32_t code = tjsonAddObject(pJson, jkDeleteStmtFromTable, nodeToJson, pNode->pFromTable);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkDeleteStmtWhere, nodeToJson, pNode->pWhere);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkDeleteStmtCountFunc, nodeToJson, pNode->pCountFunc);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4289
    code = tjsonAddObject(pJson, jkDeleteStmtTagIndexCond, nodeToJson, pNode->pTagCond);
X
Xiaoyu Wang 已提交
4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDeleteStmtTimeRangeStartKey, pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDeleteStmtTimeRangeEndKey, pNode->timeRange.ekey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDeleteStmtPrecision, pNode->precision);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDeleteStmtDeleteZeroRows, pNode->deleteZeroRows);
  }

  return code;
}

static int32_t jsonToDeleteStmt(const SJson* pJson, void* pObj) {
  SDeleteStmt* pNode = (SDeleteStmt*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkDeleteStmtFromTable, &pNode->pFromTable);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkDeleteStmtWhere, &pNode->pWhere);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkDeleteStmtCountFunc, &pNode->pCountFunc);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4318
    code = jsonToNodeObject(pJson, jkDeleteStmtTagIndexCond, &pNode->pTagCond);
X
Xiaoyu Wang 已提交
4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkDeleteStmtTimeRangeStartKey, &pNode->timeRange.skey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkDeleteStmtTimeRangeEndKey, &pNode->timeRange.ekey);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkDeleteStmtPrecision, &pNode->precision);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDeleteStmtDeleteZeroRows, &pNode->deleteZeroRows);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4336 4337 4338
static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
  switch (nodeType(pObj)) {
    case QUERY_NODE_COLUMN:
X
Xiaoyu Wang 已提交
4339
      return columnNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4340
    case QUERY_NODE_VALUE:
X
Xiaoyu Wang 已提交
4341
      return valueNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4342
    case QUERY_NODE_OPERATOR:
X
Xiaoyu Wang 已提交
4343
      return operatorNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4344
    case QUERY_NODE_LOGIC_CONDITION:
X
Xiaoyu Wang 已提交
4345
      return logicConditionNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4346
    case QUERY_NODE_FUNCTION:
X
Xiaoyu Wang 已提交
4347
      return functionNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4348
    case QUERY_NODE_REAL_TABLE:
X
Xiaoyu Wang 已提交
4349
      return realTableNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4350
    case QUERY_NODE_TEMP_TABLE:
4351
      return tempTableNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4352
    case QUERY_NODE_JOIN_TABLE:
X
Xiaoyu Wang 已提交
4353
      break;
X
Xiaoyu Wang 已提交
4354
    case QUERY_NODE_GROUPING_SET:
X
Xiaoyu Wang 已提交
4355
      return groupingSetNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4356
    case QUERY_NODE_ORDER_BY_EXPR:
X
Xiaoyu Wang 已提交
4357
      return orderByExprNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4358
    case QUERY_NODE_LIMIT:
4359
      return limitNodeToJson(pObj, pJson);
5
54liuyao 已提交
4360 4361
    case QUERY_NODE_STATE_WINDOW:
      return stateWindowNodeToJson(pObj, pJson);
5
54liuyao 已提交
4362 4363
    case QUERY_NODE_SESSION_WINDOW:
      return sessionWindowNodeToJson(pObj, pJson);
X
bugfix  
Xiaoyu Wang 已提交
4364 4365
    case QUERY_NODE_INTERVAL_WINDOW:
      return intervalWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4366
    case QUERY_NODE_NODE_LIST:
X
Xiaoyu Wang 已提交
4367
      return nodeListNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4368
    case QUERY_NODE_FILL:
X
Xiaoyu Wang 已提交
4369
      return fillNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4370
    case QUERY_NODE_RAW_EXPR:
X
Xiaoyu Wang 已提交
4371
      break;
X
Xiaoyu Wang 已提交
4372
    case QUERY_NODE_TARGET:
X
Xiaoyu Wang 已提交
4373
      return targetNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4374 4375
    case QUERY_NODE_DATABLOCK_DESC:
      return dataBlockDescNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4376 4377
    case QUERY_NODE_SLOT_DESC:
      return slotDescNodeToJson(pObj, pJson);
4378
    case QUERY_NODE_COLUMN_DEF:
X
Xiaoyu Wang 已提交
4379 4380 4381
      break;
    case QUERY_NODE_DOWNSTREAM_SOURCE:
      return downstreamSourceNodeToJson(pObj, pJson);
4382 4383
    case QUERY_NODE_DATABASE_OPTIONS:
      return databaseOptionsToJson(pObj, pJson);
4384 4385
    case QUERY_NODE_LEFT_VALUE:
      return TSDB_CODE_SUCCESS;  // SLeftValueNode has no fields to serialize.
X
Xiaoyu Wang 已提交
4386
    case QUERY_NODE_SET_OPERATOR:
4387
      return setOperatorToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4388
    case QUERY_NODE_SELECT_STMT:
4389
      return selectStmtToJson(pObj, pJson);
4390 4391
    case QUERY_NODE_VNODE_MODIF_STMT:
    case QUERY_NODE_CREATE_DATABASE_STMT:
4392 4393 4394
      break;
    case QUERY_NODE_ALTER_DATABASE_STMT:
      return alterDatabaseStmtToJson(pObj, pJson);
4395
    case QUERY_NODE_CREATE_TABLE_STMT:
4396 4397 4398
      break;
    case QUERY_NODE_ALTER_TABLE_STMT:
      return alterTableStmtToJson(pObj, pJson);
4399
    case QUERY_NODE_USE_DATABASE_STMT:
4400 4401 4402
      break;
    case QUERY_NODE_ALTER_DNODE_STMT:
      return alterDnodeStmtToJson(pObj, pJson);
4403 4404
    case QUERY_NODE_SHOW_DATABASES_STMT:
    case QUERY_NODE_SHOW_TABLES_STMT:
4405
    case QUERY_NODE_SHOW_TAGS_STMT:
X
Xiaoyu Wang 已提交
4406
      break;
X
Xiaoyu Wang 已提交
4407 4408
    case QUERY_NODE_CREATE_TOPIC_STMT:
      return createTopicStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4409 4410
    case QUERY_NODE_DELETE_STMT:
      return deleteStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4411
    case QUERY_NODE_LOGIC_PLAN_SCAN:
X
Xiaoyu Wang 已提交
4412
      return logicScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4413
    case QUERY_NODE_LOGIC_PLAN_JOIN:
X
Xiaoyu Wang 已提交
4414
      return logicJoinNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4415
    case QUERY_NODE_LOGIC_PLAN_AGG:
X
Xiaoyu Wang 已提交
4416
      return logicAggNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4417
    case QUERY_NODE_LOGIC_PLAN_PROJECT:
X
Xiaoyu Wang 已提交
4418
      return logicProjectNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4419 4420
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
      return logicVnodeModifyNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4421 4422
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
      return logicExchangeNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4423 4424 4425 4426
    case QUERY_NODE_LOGIC_PLAN_MERGE:
      return logicMergeNodeToJson(pObj, pJson);
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
      return logicWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4427 4428
    case QUERY_NODE_LOGIC_PLAN_FILL:
      return logicFillNodeToJson(pObj, pJson);
4429 4430
    case QUERY_NODE_LOGIC_PLAN_SORT:
      return logicSortNodeToJson(pObj, pJson);
4431 4432
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
      return logicPartitionNodeToJson(pObj, pJson);
4433 4434
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
      return logicIndefRowsFuncNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4435 4436
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
      return logicInterpFuncNodeToJson(pObj, pJson);
4437
    case QUERY_NODE_LOGIC_SUBPLAN:
4438
      return logicSubplanToJson(pObj, pJson);
4439
    case QUERY_NODE_LOGIC_PLAN:
4440
      return logicPlanToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4441
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
4442
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
X
Xiaoyu Wang 已提交
4443
      return physiScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4444
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
X
Xiaoyu Wang 已提交
4445
      return physiLastRowScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4446
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
X
Xiaoyu Wang 已提交
4447
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
4448
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
X
Xiaoyu Wang 已提交
4449
      return physiTableScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4450 4451
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
      return physiSysTableScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4452 4453
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
      return physiProjectNodeToJson(pObj, pJson);
4454
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
X
Xiaoyu Wang 已提交
4455
      return physiJoinNodeToJson(pObj, pJson);
4456
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
X
Xiaoyu Wang 已提交
4457
      return physiAggNodeToJson(pObj, pJson);
4458
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
X
Xiaoyu Wang 已提交
4459
      return physiExchangeNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4460 4461
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
      return physiMergeNodeToJson(pObj, pJson);
4462
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
4463
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT:
X
Xiaoyu Wang 已提交
4464
      return physiSortNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4465
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
4466
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
X
Xiaoyu Wang 已提交
4467
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
4468 4469
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
X
Xiaoyu Wang 已提交
4470
      return physiIntervalNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4471 4472
    case QUERY_NODE_PHYSICAL_PLAN_FILL:
      return physiFillNodeToJson(pObj, pJson);
4473 4474
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
4475 4476
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
X
Xiaoyu Wang 已提交
4477
      return physiSessionWindowNodeToJson(pObj, pJson);
4478 4479
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE:
4480 4481 4482
      return physiStateWindowNodeToJson(pObj, pJson);
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
      return physiPartitionNodeToJson(pObj, pJson);
4483 4484
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
      return physiIndefRowsFuncNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4485 4486
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
      return physiInterpFuncNodeToJson(pObj, pJson);
4487
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
X
Xiaoyu Wang 已提交
4488
      return physiDispatchNodeToJson(pObj, pJson);
4489 4490
    case QUERY_NODE_PHYSICAL_PLAN_INSERT:
      break;
4491 4492
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return physiQueryInsertNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4493 4494
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return physiDeleteNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4495 4496
    case QUERY_NODE_PHYSICAL_SUBPLAN:
      return subplanToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4497 4498
    case QUERY_NODE_PHYSICAL_PLAN:
      return planToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
4499 4500 4501
    default:
      break;
  }
4502
  nodesWarn("specificNodeToJson unknown node = %s", nodesNodeName(nodeType(pObj)));
X
Xiaoyu Wang 已提交
4503 4504 4505
  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517
static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
  switch (nodeType(pObj)) {
    case QUERY_NODE_COLUMN:
      return jsonToColumnNode(pJson, pObj);
    case QUERY_NODE_VALUE:
      return jsonToValueNode(pJson, pObj);
    case QUERY_NODE_OPERATOR:
      return jsonToOperatorNode(pJson, pObj);
    case QUERY_NODE_LOGIC_CONDITION:
      return jsonToLogicConditionNode(pJson, pObj);
    case QUERY_NODE_FUNCTION:
      return jsonToFunctionNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4518 4519
    case QUERY_NODE_REAL_TABLE:
      return jsonToRealTableNode(pJson, pObj);
4520 4521
    case QUERY_NODE_TEMP_TABLE:
      return jsonToTempTableNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4522 4523
    case QUERY_NODE_ORDER_BY_EXPR:
      return jsonToOrderByExprNode(pJson, pObj);
4524 4525
    case QUERY_NODE_LIMIT:
      return jsonToLimitNode(pJson, pObj);
5
54liuyao 已提交
4526 4527
    case QUERY_NODE_STATE_WINDOW:
      return jsonToStateWindowNode(pJson, pObj);
5
54liuyao 已提交
4528 4529
    case QUERY_NODE_SESSION_WINDOW:
      return jsonToSessionWindowNode(pJson, pObj);
X
bugfix  
Xiaoyu Wang 已提交
4530 4531
    case QUERY_NODE_INTERVAL_WINDOW:
      return jsonToIntervalWindowNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4532 4533
    case QUERY_NODE_NODE_LIST:
      return jsonToNodeListNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4534 4535
    case QUERY_NODE_FILL:
      return jsonToFillNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4536 4537 4538 4539 4540 4541
    case QUERY_NODE_TARGET:
      return jsonToTargetNode(pJson, pObj);
    case QUERY_NODE_DATABLOCK_DESC:
      return jsonToDataBlockDescNode(pJson, pObj);
    case QUERY_NODE_SLOT_DESC:
      return jsonToSlotDescNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4542 4543
    case QUERY_NODE_DOWNSTREAM_SOURCE:
      return jsonToDownstreamSourceNode(pJson, pObj);
4544 4545
    case QUERY_NODE_DATABASE_OPTIONS:
      return jsonToDatabaseOptions(pJson, pObj);
4546 4547
    case QUERY_NODE_LEFT_VALUE:
      return TSDB_CODE_SUCCESS;  // SLeftValueNode has no fields to deserialize.
4548 4549
    case QUERY_NODE_SET_OPERATOR:
      return jsonToSetOperator(pJson, pObj);
X
Xiaoyu Wang 已提交
4550 4551
    case QUERY_NODE_SELECT_STMT:
      return jsonToSelectStmt(pJson, pObj);
4552 4553 4554 4555 4556 4557
    case QUERY_NODE_ALTER_DATABASE_STMT:
      return jsonToAlterDatabaseStmt(pJson, pObj);
    case QUERY_NODE_ALTER_TABLE_STMT:
      return jsonToAlterTableStmt(pJson, pObj);
    case QUERY_NODE_ALTER_DNODE_STMT:
      return jsonToAlterDnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
4558 4559
    case QUERY_NODE_CREATE_TOPIC_STMT:
      return jsonToCreateTopicStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
4560 4561
    case QUERY_NODE_DELETE_STMT:
      return jsonToDeleteStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
4562 4563 4564 4565
    case QUERY_NODE_LOGIC_PLAN_SCAN:
      return jsonToLogicScanNode(pJson, pObj);
    case QUERY_NODE_LOGIC_PLAN_PROJECT:
      return jsonToLogicProjectNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4566 4567
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
      return jsonToLogicVnodeModifyNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4568 4569
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
      return jsonToLogicExchangeNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4570 4571 4572 4573
    case QUERY_NODE_LOGIC_PLAN_MERGE:
      return jsonToLogicMergeNode(pJson, pObj);
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
      return jsonToLogicWindowNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4574 4575
    case QUERY_NODE_LOGIC_PLAN_FILL:
      return jsonToLogicFillNode(pJson, pObj);
4576 4577
    case QUERY_NODE_LOGIC_PLAN_SORT:
      return jsonToLogicSortNode(pJson, pObj);
4578 4579
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
      return jsonToLogicPartitionNode(pJson, pObj);
4580 4581
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
      return jsonToLogicIndefRowsFuncNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4582 4583
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
      return jsonToLogicInterpFuncNode(pJson, pObj);
4584 4585
    case QUERY_NODE_LOGIC_SUBPLAN:
      return jsonToLogicSubplan(pJson, pObj);
4586 4587
    case QUERY_NODE_LOGIC_PLAN:
      return jsonToLogicPlan(pJson, pObj);
X
Xiaoyu Wang 已提交
4588
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
4589
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
X
Xiaoyu Wang 已提交
4590
      return jsonToPhysiScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4591
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
X
Xiaoyu Wang 已提交
4592
      return jsonToPhysiLastRowScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4593
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
X
Xiaoyu Wang 已提交
4594
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
X
Xiaoyu Wang 已提交
4595
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
X
Xiaoyu Wang 已提交
4596
      return jsonToPhysiTableScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4597
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
X
Xiaoyu Wang 已提交
4598
      return jsonToPhysiSysTableScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4599 4600
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
      return jsonToPhysiProjectNode(pJson, pObj);
4601
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
X
Xiaoyu Wang 已提交
4602
      return jsonToPhysiJoinNode(pJson, pObj);
4603
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
X
Xiaoyu Wang 已提交
4604
      return jsonToPhysiAggNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4605 4606
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
      return jsonToPhysiExchangeNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4607 4608
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
      return jsonToPhysiMergeNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4609
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
4610
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT:
X
Xiaoyu Wang 已提交
4611
      return jsonToPhysiSortNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4612
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
4613
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
X
Xiaoyu Wang 已提交
4614
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
4615 4616
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
X
Xiaoyu Wang 已提交
4617
      return jsonToPhysiIntervalNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4618 4619
    case QUERY_NODE_PHYSICAL_PLAN_FILL:
      return jsonToPhysiFillNode(pJson, pObj);
4620 4621
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
4622 4623
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
X
Xiaoyu Wang 已提交
4624
      return jsonToPhysiSessionWindowNode(pJson, pObj);
4625 4626
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE:
4627 4628 4629
      return jsonToPhysiStateWindowNode(pJson, pObj);
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
      return jsonToPhysiPartitionNode(pJson, pObj);
4630 4631
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
      return jsonToPhysiIndefRowsFuncNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4632 4633
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
      return jsonToPhysiInterpFuncNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4634 4635
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
      return jsonToPhysiDispatchNode(pJson, pObj);
4636 4637
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return jsonToPhysiQueryInsertNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4638 4639
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return jsonToPhysiDeleteNode(pJson, pObj);
X
Xiaoyu Wang 已提交
4640 4641
    case QUERY_NODE_PHYSICAL_SUBPLAN:
      return jsonToSubplan(pJson, pObj);
X
Xiaoyu Wang 已提交
4642 4643
    case QUERY_NODE_PHYSICAL_PLAN:
      return jsonToPlan(pJson, pObj);
X
Xiaoyu Wang 已提交
4644 4645 4646
    default:
      break;
  }
4647
  nodesWarn("jsonToSpecificNode unknown node = %s", nodesNodeName(nodeType(pObj)));
X
Xiaoyu Wang 已提交
4648 4649 4650
  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
4651
static const char* jkNodeType = "NodeType";
X
Xiaoyu Wang 已提交
4652 4653
static const char* jkNodeName = "Name";

X
Xiaoyu Wang 已提交
4654 4655 4656
static int32_t nodeToJson(const void* pObj, SJson* pJson) {
  const SNode* pNode = (const SNode*)pObj;

X
Xiaoyu Wang 已提交
4657 4658
  int32_t code = tjsonAddIntegerToObject(pJson, jkNodeType, pNode->type);
  if (TSDB_CODE_SUCCESS == code) {
4659
    code = tjsonAddStringToObject(pJson, jkNodeName, nodesNodeName(pNode->type));
X
Xiaoyu Wang 已提交
4660
  }
X
Xiaoyu Wang 已提交
4661
  if (TSDB_CODE_SUCCESS == code) {
4662
    code = tjsonAddObject(pJson, nodesNodeName(pNode->type), specificNodeToJson, pNode);
4663 4664 4665
    if (TSDB_CODE_SUCCESS != code) {
      nodesError("%s ToJson error", nodesNodeName(pNode->type));
    }
X
Xiaoyu Wang 已提交
4666 4667 4668 4669 4670
  }

  return code;
}

X
Xiaoyu Wang 已提交
4671 4672 4673
static int32_t jsonToNode(const SJson* pJson, void* pObj) {
  SNode* pNode = (SNode*)pObj;

4674
  int32_t code;
4675
  tjsonGetNumberValue(pJson, jkNodeType, pNode->type, code);
X
Xiaoyu Wang 已提交
4676
  if (TSDB_CODE_SUCCESS == code) {
4677
    code = tjsonToObject(pJson, nodesNodeName(pNode->type), jsonToSpecificNode, pNode);
X
Xiaoyu Wang 已提交
4678
    if (TSDB_CODE_SUCCESS != code) {
4679
      nodesError("%s toNode error", nodesNodeName(pNode->type));
X
Xiaoyu Wang 已提交
4680
    }
X
Xiaoyu Wang 已提交
4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702
  }

  return code;
}

static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode) {
  int32_t val = 0;
  int32_t code = tjsonGetIntValue(pJson, jkNodeType, &val);
  if (TSDB_CODE_SUCCESS == code) {
    *pNode = nodesMakeNode(val);
    if (NULL == *pNode) {
      return TSDB_CODE_FAILED;
    }
    code = jsonToNode(pJson, *pNode);
  }

  return code;
}

static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** pNode) {
  SJson* pJsonNode = tjsonGetObjectItem(pJson, pName);
  if (NULL == pJsonNode) {
X
Xiaoyu Wang 已提交
4703
    return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
4704 4705 4706 4707
  }
  return makeNodeByJson(pJsonNode, pNode);
}

4708
int32_t nodesNodeToString(const SNode* pNode, bool format, char** pStr, int32_t* pLen) {
4709
  if (NULL == pNode || NULL == pStr) {
4710 4711
    terrno = TSDB_CODE_FAILED;
    return TSDB_CODE_FAILED;
X
Xiaoyu Wang 已提交
4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725
  }

  SJson* pJson = tjsonCreateObject();
  if (NULL == pJson) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return TSDB_CODE_OUT_OF_MEMORY;
  }

  int32_t code = nodeToJson(pNode, pJson);
  if (TSDB_CODE_SUCCESS != code) {
    terrno = code;
    return code;
  }

X
Xiaoyu Wang 已提交
4726
  *pStr = format ? tjsonToString(pJson) : tjsonToUnformattedString(pJson);
X
Xiaoyu Wang 已提交
4727 4728
  tjsonDelete(pJson);

4729 4730 4731 4732
  if (NULL != pLen) {
    *pLen = strlen(*pStr) + 1;
  }

X
Xiaoyu Wang 已提交
4733 4734 4735 4736
  return TSDB_CODE_SUCCESS;
}

int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
X
Xiaoyu Wang 已提交
4737 4738 4739 4740 4741 4742 4743 4744
  if (NULL == pStr || NULL == pNode) {
    return TSDB_CODE_SUCCESS;
  }
  SJson* pJson = tjsonParse(pStr);
  if (NULL == pJson) {
    return TSDB_CODE_FAILED;
  }
  int32_t code = makeNodeByJson(pJson, pNode);
X
Xiaoyu Wang 已提交
4745
  tjsonDelete(pJson);
X
Xiaoyu Wang 已提交
4746 4747
  if (TSDB_CODE_SUCCESS != code) {
    nodesDestroyNode(*pNode);
X
Xiaoyu Wang 已提交
4748
    *pNode = NULL;
X
Xiaoyu Wang 已提交
4749 4750 4751
    terrno = code;
    return code;
  }
X
Xiaoyu Wang 已提交
4752
  return TSDB_CODE_SUCCESS;
4753
}
X
Xiaoyu Wang 已提交
4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795

int32_t nodesListToString(const SNodeList* pList, bool format, char** pStr, int32_t* pLen) {
  if (NULL == pList || NULL == pStr || NULL == pLen) {
    terrno = TSDB_CODE_FAILED;
    return TSDB_CODE_FAILED;
  }

  if (0 == LIST_LENGTH(pList)) {
    return TSDB_CODE_SUCCESS;
  }

  SJson* pJson = tjsonCreateArray();
  if (NULL == pJson) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return TSDB_CODE_OUT_OF_MEMORY;
  }

  SNode* pNode;
  FOREACH(pNode, pList) {
    int32_t code = tjsonAddItem(pJson, nodeToJson, pNode);
    if (TSDB_CODE_SUCCESS != code) {
      terrno = code;
      return code;
    }
  }

  *pStr = format ? tjsonToString(pJson) : tjsonToUnformattedString(pJson);
  tjsonDelete(pJson);

  *pLen = strlen(*pStr) + 1;
  return TSDB_CODE_SUCCESS;
}

int32_t nodesStringToList(const char* pStr, SNodeList** pList) {
  if (NULL == pStr || NULL == pList) {
    return TSDB_CODE_SUCCESS;
  }
  SJson* pJson = tjsonParse(pStr);
  if (NULL == pJson) {
    return TSDB_CODE_FAILED;
  }
  int32_t code = jsonToNodeListImpl(pJson, pList);
S
Shengliang Guan 已提交
4796
  tjsonDelete(pJson);
X
Xiaoyu Wang 已提交
4797 4798
  if (TSDB_CODE_SUCCESS != code) {
    nodesDestroyList(*pList);
X
Xiaoyu Wang 已提交
4799
    *pList = NULL;
X
Xiaoyu Wang 已提交
4800 4801 4802
    terrno = code;
    return code;
  }
X
Xiaoyu Wang 已提交
4803
  return TSDB_CODE_SUCCESS;
4804
}