nodesCodeFuncs.c 262.8 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";
X
Xiaoyu Wang 已提交
82 83
    case QUERY_NODE_EXPLAIN_OPTIONS:
      return "ExplainOptions";
X
Xiaoyu Wang 已提交
84 85
    case QUERY_NODE_STREAM_OPTIONS:
      return "StreamOptions";
86 87
    case QUERY_NODE_LEFT_VALUE:
      return "LeftValue";
X
Xiaoyu Wang 已提交
88 89 90 91
    case QUERY_NODE_WHEN_THEN:
      return "WhenThen";
    case QUERY_NODE_CASE_WHEN:
      return "CaseWhen";
X
Xiaoyu Wang 已提交
92 93
    case QUERY_NODE_EVENT_WINDOW:
      return "EventWindow";
94
    case QUERY_NODE_SET_OPERATOR:
X
Xiaoyu Wang 已提交
95
      return "SetOperator";
96
    case QUERY_NODE_SELECT_STMT:
X
Xiaoyu Wang 已提交
97
      return "SelectStmt";
X
Xiaoyu Wang 已提交
98
    case QUERY_NODE_VNODE_MODIFY_STMT:
99 100 101
      return "VnodeModifStmt";
    case QUERY_NODE_CREATE_DATABASE_STMT:
      return "CreateDatabaseStmt";
X
Xiaoyu Wang 已提交
102 103 104 105
    case QUERY_NODE_DROP_DATABASE_STMT:
      return "DropDatabaseStmt";
    case QUERY_NODE_ALTER_DATABASE_STMT:
      return "AlterDatabaseStmt";
X
Xiaoyu Wang 已提交
106 107 108 109
    case QUERY_NODE_FLUSH_DATABASE_STMT:
      return "FlushDatabaseStmt";
    case QUERY_NODE_TRIM_DATABASE_STMT:
      return "TrimDatabaseStmt";
110 111
    case QUERY_NODE_CREATE_TABLE_STMT:
      return "CreateTableStmt";
X
Xiaoyu Wang 已提交
112 113
    case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
      return "CreateSubtableClause";
X
Xiaoyu Wang 已提交
114
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
X
Xiaoyu Wang 已提交
115 116 117 118 119 120 121 122 123
      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";
124 125
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
      return "AlterSuperTableStmt";
X
Xiaoyu Wang 已提交
126 127 128 129 130 131
    case QUERY_NODE_CREATE_USER_STMT:
      return "CreateUserStmt";
    case QUERY_NODE_ALTER_USER_STMT:
      return "AlterUserStmt";
    case QUERY_NODE_DROP_USER_STMT:
      return "DropUserStmt";
132 133
    case QUERY_NODE_USE_DATABASE_STMT:
      return "UseDatabaseStmt";
X
Xiaoyu Wang 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147
    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";
X
Xiaoyu Wang 已提交
148 149
    case QUERY_NODE_CREATE_SNODE_STMT:
      return "CreateSnodeStmt";
X
Xiaoyu Wang 已提交
150 151
    case QUERY_NODE_DROP_SNODE_STMT:
      return "DropSnodeStmt";
X
Xiaoyu Wang 已提交
152 153
    case QUERY_NODE_CREATE_MNODE_STMT:
      return "CreateMnodeStmt";
X
Xiaoyu Wang 已提交
154 155
    case QUERY_NODE_DROP_MNODE_STMT:
      return "DropMnodeStmt";
X
Xiaoyu Wang 已提交
156 157 158 159
    case QUERY_NODE_CREATE_TOPIC_STMT:
      return "CreateTopicStmt";
    case QUERY_NODE_DROP_TOPIC_STMT:
      return "DropTopicStmt";
X
Xiaoyu Wang 已提交
160 161
    case QUERY_NODE_DROP_CGROUP_STMT:
      return "DropConsumerGroupStmt";
X
Xiaoyu Wang 已提交
162 163
    case QUERY_NODE_ALTER_LOCAL_STMT:
      return "AlterLocalStmt";
X
Xiaoyu Wang 已提交
164 165
    case QUERY_NODE_EXPLAIN_STMT:
      return "ExplainStmt";
X
Xiaoyu Wang 已提交
166 167
    case QUERY_NODE_DESCRIBE_STMT:
      return "DescribeStmt";
X
Xiaoyu Wang 已提交
168 169
    case QUERY_NODE_COMPACT_DATABASE_STMT:
      return "CompactDatabaseStmt";
X
Xiaoyu Wang 已提交
170 171
    case QUERY_NODE_CREATE_STREAM_STMT:
      return "CreateStreamStmt";
X
Xiaoyu Wang 已提交
172 173
    case QUERY_NODE_DROP_STREAM_STMT:
      return "DropStreamStmt";
174 175 176 177
    case QUERY_NODE_PAUSE_STREAM_STMT:
      return "PauseStreamStmt";
    case QUERY_NODE_RESUME_STREAM_STMT:
      return "ResumeStreamStmt";
X
Xiaoyu Wang 已提交
178 179
    case QUERY_NODE_BALANCE_VGROUP_STMT:
      return "BalanceVgroupStmt";
C
cadem 已提交
180 181
    case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT:
      return "BalanceVgroupLeaderStmt";
X
Xiaoyu Wang 已提交
182 183
    case QUERY_NODE_MERGE_VGROUP_STMT:
      return "MergeVgroupStmt";
184 185 186
    case QUERY_NODE_SHOW_DB_ALIVE_STMT:
      return "ShowDbAliveStmt";
    case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
X
Xiaoyu Wang 已提交
187
      return "ShowClusterAliveStmt";
X
Xiaoyu Wang 已提交
188 189
    case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
      return "RedistributeVgroupStmt";
X
Xiaoyu Wang 已提交
190 191
    case QUERY_NODE_SPLIT_VGROUP_STMT:
      return "SplitVgroupStmt";
X
Xiaoyu Wang 已提交
192 193 194 195
    case QUERY_NODE_GRANT_STMT:
      return "GrantStmt";
    case QUERY_NODE_REVOKE_STMT:
      return "RevokeStmt";
X
Xiaoyu Wang 已提交
196 197 198 199 200 201 202 203
    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";
204 205 206 207
    case QUERY_NODE_SHOW_SNODES_STMT:
      return "ShowSnodesStmt";
    case QUERY_NODE_SHOW_BNODES_STMT:
      return "ShowBnodesStmt";
X
Xiaoyu Wang 已提交
208 209
    case QUERY_NODE_SHOW_CLUSTER_STMT:
      return "ShowClusterStmt";
210 211
    case QUERY_NODE_SHOW_DATABASES_STMT:
      return "ShowDatabaseStmt";
X
Xiaoyu Wang 已提交
212 213 214 215
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
      return "ShowFunctionsStmt";
    case QUERY_NODE_SHOW_INDEXES_STMT:
      return "ShowIndexesStmt";
216 217
    case QUERY_NODE_SHOW_STABLES_STMT:
      return "ShowStablesStmt";
X
Xiaoyu Wang 已提交
218 219
    case QUERY_NODE_SHOW_STREAMS_STMT:
      return "ShowStreamsStmt";
220 221
    case QUERY_NODE_SHOW_TABLES_STMT:
      return "ShowTablesStmt";
222 223
    case QUERY_NODE_SHOW_TAGS_STMT:
      return "ShowTagsStmt";
224 225
    case QUERY_NODE_SHOW_USERS_STMT:
      return "ShowUsersStmt";
X
Xiaoyu Wang 已提交
226
    case QUERY_NODE_SHOW_LICENCES_STMT:
227 228 229 230 231 232 233 234 235
      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";
X
Xiaoyu Wang 已提交
236 237
    case QUERY_NODE_SHOW_VARIABLES_STMT:
      return "ShowVariablesStmt";
X
Xiaoyu Wang 已提交
238 239 240 241 242 243
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
      return "ShowDnodeVariablesStmt";
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
      return "ShowTransactionsStmt";
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
      return "ShowSubscriptionsStmt";
244 245
    case QUERY_NODE_SHOW_VNODES_STMT:
      return "ShowVnodeStmt";
X
Xiaoyu Wang 已提交
246 247
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
      return "ShowUserPrivilegesStmt";
X
Xiaoyu Wang 已提交
248 249 250 251 252 253 254 255 256 257
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
      return "ShowCreateDatabasesStmt";
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
      return "ShowCreateTablesStmt";
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
      return "ShowCreateStablesStmt";
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
      return "ShowTableDistributedStmt";
    case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
      return "ShowLocalVariablesStmt";
X
Xiaoyu Wang 已提交
258 259
    case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
      return "ShowTableTagsStmt";
X
Xiaoyu Wang 已提交
260 261
    case QUERY_NODE_DELETE_STMT:
      return "DeleteStmt";
262 263
    case QUERY_NODE_INSERT_STMT:
      return "InsertStmt";
D
dapan1121 已提交
264 265 266 267 268 269 270 271
    case QUERY_NODE_RESTORE_DNODE_STMT:
      return "RestoreDnodeStmt";
    case QUERY_NODE_RESTORE_QNODE_STMT:
      return "RestoreQnodeStmt";
    case QUERY_NODE_RESTORE_MNODE_STMT:
      return "RestoreMnodeStmt";
    case QUERY_NODE_RESTORE_VNODE_STMT:
      return "RestoreVnodeStmt";
X
Xiaoyu Wang 已提交
272 273 274 275 276 277 278 279
    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 已提交
280 281
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
      return "LogicVnodeModify";
X
Xiaoyu Wang 已提交
282 283
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
      return "LogicExchange";
X
Xiaoyu Wang 已提交
284 285
    case QUERY_NODE_LOGIC_PLAN_MERGE:
      return "LogicMerge";
X
Xiaoyu Wang 已提交
286 287
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
      return "LogicWindow";
X
Xiaoyu Wang 已提交
288 289
    case QUERY_NODE_LOGIC_PLAN_FILL:
      return "LogicFill";
290 291 292 293
    case QUERY_NODE_LOGIC_PLAN_SORT:
      return "LogicSort";
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
      return "LogicPartition";
294 295
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
      return "LogicIndefRowsFunc";
X
Xiaoyu Wang 已提交
296 297
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
      return "LogicInterpFunc";
298 299 300 301
    case QUERY_NODE_LOGIC_SUBPLAN:
      return "LogicSubplan";
    case QUERY_NODE_LOGIC_PLAN:
      return "LogicPlan";
X
Xiaoyu Wang 已提交
302 303 304 305
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
      return "PhysiTagScan";
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
      return "PhysiTableScan";
306 307
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
      return "PhysiTableSeqScan";
308 309
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
      return "PhysiTableMergeScan";
310 311
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
      return "PhysiSreamScan";
X
Xiaoyu Wang 已提交
312 313
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
      return "PhysiSystemTableScan";
314 315
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
      return "PhysiBlockDistScan";
X
Xiaoyu Wang 已提交
316 317
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
      return "PhysiLastRowScan";
318 319
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN:
      return "PhysiTableCountScan";
X
Xiaoyu Wang 已提交
320 321 322 323
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT:
      return "PhysiMergeEventWindow";
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT:
      return "PhysiStreamEventWindow";
X
Xiaoyu Wang 已提交
324 325
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
      return "PhysiProject";
326
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
X
Xiaoyu Wang 已提交
327
      return "PhysiJoin";
328
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
X
Xiaoyu Wang 已提交
329
      return "PhysiAgg";
330 331
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
      return "PhysiExchange";
X
Xiaoyu Wang 已提交
332 333
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
      return "PhysiMerge";
334 335
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
      return "PhysiSort";
336 337
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT:
      return "PhysiGroupSort";
X
Xiaoyu Wang 已提交
338 339
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
      return "PhysiHashInterval";
340 341
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
      return "PhysiMergeAlignedInterval";
X
Xiaoyu Wang 已提交
342 343
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
      return "PhysiStreamInterval";
344 345 346 347
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
      return "PhysiStreamFinalInterval";
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
      return "PhysiStreamSemiInterval";
X
Xiaoyu Wang 已提交
348
    case QUERY_NODE_PHYSICAL_PLAN_FILL:
5
54liuyao 已提交
349
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL:
X
Xiaoyu Wang 已提交
350
      return "PhysiFill";
351
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
352
      return "PhysiSessionWindow";
353
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
5
54liuyao 已提交
354
      return "PhysiStreamSessionWindow";
355 356 357 358
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
      return "PhysiStreamSemiSessionWindow";
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
      return "PhysiStreamFinalSessionWindow";
359
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
360
      return "PhysiStateWindow";
361
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE:
5
54liuyao 已提交
362
      return "PhysiStreamStateWindow";
363 364
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
      return "PhysiPartition";
365 366
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION:
      return "PhysiStreamPartition";
367 368
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
      return "PhysiIndefRowsFunc";
X
Xiaoyu Wang 已提交
369 370
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
      return "PhysiInterpFunc";
371 372 373 374
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
      return "PhysiDispatch";
    case QUERY_NODE_PHYSICAL_PLAN_INSERT:
      return "PhysiInsert";
375 376
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return "PhysiQueryInsert";
X
Xiaoyu Wang 已提交
377 378
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return "PhysiDelete";
X
Xiaoyu Wang 已提交
379 380 381 382
    case QUERY_NODE_PHYSICAL_SUBPLAN:
      return "PhysiSubplan";
    case QUERY_NODE_PHYSICAL_PLAN:
      return "PhysiPlan";
383 384 385
    default:
      break;
  }
386 387
  nodesWarn("nodesNodeName unknown node = %d", type);
  return "UnknownNode";
388 389
}

X
Xiaoyu Wang 已提交
390
static int32_t nodeListToJson(SJson* pJson, const char* pName, const SNodeList* pList) {
X
Xiaoyu Wang 已提交
391 392 393 394 395 396 397
  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 已提交
398
      int32_t code = tjsonAddItem(jList, nodeToJson, pNode);
X
Xiaoyu Wang 已提交
399 400 401 402 403 404 405 406
      if (TSDB_CODE_SUCCESS != code) {
        return code;
      }
    }
  }
  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
407
static int32_t jsonToNodeListImpl(const SJson* pJsonArray, SNodeList** pList) {
X
Xiaoyu Wang 已提交
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
  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 已提交
431 432 433 434
static int32_t jsonToNodeList(const SJson* pJson, const char* pName, SNodeList** pList) {
  return jsonToNodeListImpl(tjsonGetObjectItem(pJson, pName), pList);
}

X
Xiaoyu Wang 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
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 已提交
453

X
Xiaoyu Wang 已提交
454 455 456 457 458 459
  return code;
}

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

460
  int32_t code;
461
  tjsonGetNumberValue(pJson, jkTableComInfoNumOfTags, pNode->numOfTags, code);
X
Xiaoyu Wang 已提交
462
  if (TSDB_CODE_SUCCESS == code) {
463
    tjsonGetNumberValue(pJson, jkTableComInfoPrecision, pNode->precision, code);
X
Xiaoyu Wang 已提交
464 465
  }
  if (TSDB_CODE_SUCCESS == code) {
466
    tjsonGetNumberValue(pJson, jkTableComInfoNumOfColumns, pNode->numOfColumns, code);
X
Xiaoyu Wang 已提交
467 468
  }
  if (TSDB_CODE_SUCCESS == code) {
469
    tjsonGetNumberValue(pJson, jkTableComInfoRowSize, pNode->rowSize, code);
X
Xiaoyu Wang 已提交
470
  }
X
Xiaoyu Wang 已提交
471

X
Xiaoyu Wang 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
  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 已提交
493

X
Xiaoyu Wang 已提交
494 495 496 497 498 499
  return code;
}

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

500
  int32_t code;
501
  tjsonGetNumberValue(pJson, jkSchemaType, pNode->type, code);
X
Xiaoyu Wang 已提交
502
  if (TSDB_CODE_SUCCESS == code) {
503
    tjsonGetNumberValue(pJson, jkSchemaColId, pNode->colId, code);
X
Xiaoyu Wang 已提交
504 505
  }
  if (TSDB_CODE_SUCCESS == code) {
506
    tjsonGetNumberValue(pJson, jkSchemaBytes, pNode->bytes, code);
X
Xiaoyu Wang 已提交
507 508 509 510
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSchemaName, pNode->name);
  }
X
Xiaoyu Wang 已提交
511

X
Xiaoyu Wang 已提交
512 513 514 515 516 517 518 519 520 521 522
  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 已提交
523 524 525 526

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

X
Xiaoyu Wang 已提交
527 528 529 530 531 532 533
  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 已提交
534 535 536
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableMetaSuid, pNode->suid);
  }
X
Xiaoyu Wang 已提交
537 538 539 540 541 542 543 544 545 546
  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 已提交
547 548
    code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema),
                         TABLE_TOTAL_COL_NUM(pNode));
X
Xiaoyu Wang 已提交
549
  }
X
Xiaoyu Wang 已提交
550 551 552 553

  return code;
}

X
Xiaoyu Wang 已提交
554 555 556
static int32_t jsonToTableMeta(const SJson* pJson, void* pObj) {
  STableMeta* pNode = (STableMeta*)pObj;

557
  int32_t code;
558
  tjsonGetNumberValue(pJson, jkTableMetaVgId, pNode->vgId, code);
X
Xiaoyu Wang 已提交
559
  if (TSDB_CODE_SUCCESS == code) {
560
    tjsonGetNumberValue(pJson, jkTableMetaTableType, pNode->tableType, code);
X
Xiaoyu Wang 已提交
561 562
  }
  if (TSDB_CODE_SUCCESS == code) {
563
    tjsonGetNumberValue(pJson, jkTableMetaUid, pNode->uid, code);
X
Xiaoyu Wang 已提交
564 565
  }
  if (TSDB_CODE_SUCCESS == code) {
566
    tjsonGetNumberValue(pJson, jkTableMetaSuid, pNode->suid, code);
X
Xiaoyu Wang 已提交
567 568
  }
  if (TSDB_CODE_SUCCESS == code) {
569
    tjsonGetNumberValue(pJson, jkTableMetaSversion, pNode->sversion, code);
X
Xiaoyu Wang 已提交
570 571
  }
  if (TSDB_CODE_SUCCESS == code) {
572
    tjsonGetNumberValue(pJson, jkTableMetaTversion, pNode->tversion, code);
X
Xiaoyu Wang 已提交
573 574 575 576 577 578
  }
  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 已提交
579
  }
X
Xiaoyu Wang 已提交
580 581 582 583 584 585 586

  return code;
}

static const char* jkLogicPlanTargets = "Targets";
static const char* jkLogicPlanConditions = "Conditions";
static const char* jkLogicPlanChildren = "Children";
587 588
static const char* jkLogicPlanLimit = "Limit";
static const char* jkLogicPlanSlimit = "SLimit";
589 590 591
static const char* jkLogicPlanRequireDataOrder = "RequireDataOrder";
static const char* jkLogicPlanResultDataOrder = "ResultDataOrder";
static const char* jkLogicPlanGroupAction = "GroupAction";
X
Xiaoyu Wang 已提交
592 593 594 595

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

X
Xiaoyu Wang 已提交
596
  int32_t code = nodeListToJson(pJson, jkLogicPlanTargets, pNode->pTargets);
X
Xiaoyu Wang 已提交
597 598 599 600
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicPlanConditions, nodeToJson, pNode->pConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
601
    code = nodeListToJson(pJson, jkLogicPlanChildren, pNode->pChildren);
X
Xiaoyu Wang 已提交
602
  }
603 604 605 606 607 608
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicPlanLimit, nodeToJson, pNode->pLimit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkLogicPlanSlimit, nodeToJson, pNode->pSlimit);
  }
609 610 611 612 613 614 615 616 617
  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 已提交
618 619 620 621

  return code;
}

X
Xiaoyu Wang 已提交
622 623 624 625 626 627 628 629 630 631
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);
  }
632 633 634 635 636 637
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkLogicPlanLimit, &pNode->pLimit);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkLogicPlanSlimit, &pNode->pSlimit);
  }
638 639 640 641 642 643 644 645 646
  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 已提交
647 648 649 650

  return code;
}

X
Xiaoyu Wang 已提交
651
static const char* jkScanLogicPlanScanCols = "ScanCols";
652
static const char* jkScanLogicPlanScanPseudoCols = "ScanPseudoCols";
X
Xiaoyu Wang 已提交
653
static const char* jkScanLogicPlanTableType = "TableType";
654 655
static const char* jkScanLogicPlanTableId = "TableId";
static const char* jkScanLogicPlanStableId = "StableId";
656
static const char* jkScanLogicPlanScanType = "ScanType";
657 658
static const char* jkScanLogicPlanScanCount = "ScanCount";
static const char* jkScanLogicPlanReverseScanCount = "ReverseScanCount";
659 660
static const char* jkScanLogicPlanDynamicScanFuncs = "DynamicScanFuncs";
static const char* jkScanLogicPlanDataRequired = "DataRequired";
X
Xiaoyu Wang 已提交
661
static const char* jkScanLogicPlanTagCond = "TagCond";
662
static const char* jkScanLogicPlanGroupTags = "GroupTags";
X
Xiaoyu Wang 已提交
663

X
Xiaoyu Wang 已提交
664
static int32_t logicScanNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
665 666 667 668
  const SScanLogicNode* pNode = (const SScanLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
669
    code = nodeListToJson(pJson, jkScanLogicPlanScanCols, pNode->pScanCols);
X
Xiaoyu Wang 已提交
670
  }
671 672 673
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkScanLogicPlanScanPseudoCols, pNode->pScanPseudoCols);
  }
674 675 676
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableType, pNode->tableType);
  }
X
Xiaoyu Wang 已提交
677
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
678
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableId, pNode->tableId);
X
Xiaoyu Wang 已提交
679
  }
X
Xiaoyu Wang 已提交
680
  if (TSDB_CODE_SUCCESS == code) {
681 682
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanStableId, pNode->stableId);
  }
683 684 685
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanScanType, pNode->scanType);
  }
686 687 688 689 690
  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 已提交
691
  }
692 693 694 695 696 697
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkScanLogicPlanDynamicScanFuncs, nodeToJson, pNode->pDynamicScanFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanDataRequired, pNode->dataRequired);
  }
X
Xiaoyu Wang 已提交
698 699 700
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkScanLogicPlanTagCond, nodeToJson, pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
701
  if (TSDB_CODE_SUCCESS == code) {
702
    code = nodeListToJson(pJson, jkScanLogicPlanGroupTags, pNode->pGroupTags);
X
Xiaoyu Wang 已提交
703
  }
X
Xiaoyu Wang 已提交
704 705 706 707

  return code;
}

X
Xiaoyu Wang 已提交
708 709 710 711 712 713 714 715
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);
  }
716 717 718
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkScanLogicPlanScanPseudoCols, &pNode->pScanPseudoCols);
  }
719 720 721
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkScanLogicPlanTableType, &pNode->tableType);
  }
X
Xiaoyu Wang 已提交
722
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
723
    code = tjsonGetUBigIntValue(pJson, jkScanLogicPlanTableId, &pNode->tableId);
X
Xiaoyu Wang 已提交
724 725
  }
  if (TSDB_CODE_SUCCESS == code) {
726 727
    code = tjsonGetUBigIntValue(pJson, jkScanLogicPlanStableId, &pNode->stableId);
  }
728 729 730
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkScanLogicPlanScanType, pNode->scanType, code);
  }
731 732 733 734 735
  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 已提交
736
  }
X
Xiaoyu Wang 已提交
737
  if (TSDB_CODE_SUCCESS == code) {
738 739 740 741 742 743
    code = jsonToNodeList(pJson, jkScanLogicPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkScanLogicPlanDataRequired, &pNode->dataRequired);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
744 745
    code = jsonToNodeObject(pJson, jkScanLogicPlanTagCond, &pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
746
  if (TSDB_CODE_SUCCESS == code) {
747
    code = jsonToNodeList(pJson, jkScanLogicPlanGroupTags, &pNode->pGroupTags);
X
Xiaoyu Wang 已提交
748
  }
X
Xiaoyu Wang 已提交
749 750 751 752

  return code;
}

X
Xiaoyu Wang 已提交
753
static const char* jkProjectLogicPlanProjections = "Projections";
754
static const char* jkProjectLogicPlanIgnoreGroupId = "IgnoreGroupId";
X
Xiaoyu Wang 已提交
755

X
Xiaoyu Wang 已提交
756
static int32_t logicProjectNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
757 758 759 760
  const SProjectLogicNode* pNode = (const SProjectLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
761
    code = nodeListToJson(pJson, jkProjectLogicPlanProjections, pNode->pProjections);
X
Xiaoyu Wang 已提交
762
  }
763
  if (TSDB_CODE_SUCCESS == code) {
764
    code = tjsonAddBoolToObject(pJson, jkProjectLogicPlanIgnoreGroupId, pNode->ignoreGroupId);
765
  }
X
Xiaoyu Wang 已提交
766 767 768 769

  return code;
}

X
Xiaoyu Wang 已提交
770 771 772 773 774 775 776
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);
  }
777 778 779
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkProjectLogicPlanIgnoreGroupId, &pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
780 781 782 783 784 785

  return code;
}

static const char* jkVnodeModifyLogicPlanModifyType = "ModifyType";
static const char* jkVnodeModifyLogicPlanMsgType = "MsgType";
X
Xiaoyu Wang 已提交
786
static const char* jkVnodeModifyLogicPlanAffectedRows = "AffectedRows";
X
Xiaoyu Wang 已提交
787 788 789 790 791 792 793 794 795 796 797 798

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 已提交
799
    code = tjsonAddObject(pJson, jkVnodeModifyLogicPlanAffectedRows, nodeToJson, pNode->pAffectedRows);
X
Xiaoyu Wang 已提交
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
  }

  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 已提交
816
    code = jsonToNodeObject(pJson, jkVnodeModifyLogicPlanAffectedRows, &pNode->pAffectedRows);
817
  }
X
Xiaoyu Wang 已提交
818 819 820 821

  return code;
}

822 823
static const char* jkExchangeLogicPlanSrcStartGroupId = "SrcStartGroupId";
static const char* jkExchangeLogicPlanSrcEndGroupId = "SrcEndGroupId";
X
Xiaoyu Wang 已提交
824 825 826 827 828 829

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) {
830 831 832 833
    code = tjsonAddIntegerToObject(pJson, jkExchangeLogicPlanSrcStartGroupId, pNode->srcStartGroupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkExchangeLogicPlanSrcEndGroupId, pNode->srcEndGroupId);
X
Xiaoyu Wang 已提交
834 835 836 837 838 839 840 841 842 843
  }

  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) {
844 845 846 847
    code = tjsonGetIntValue(pJson, jkExchangeLogicPlanSrcStartGroupId, &pNode->srcStartGroupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkExchangeLogicPlanSrcEndGroupId, &pNode->srcEndGroupId);
X
Xiaoyu Wang 已提交
848
  }
X
Xiaoyu Wang 已提交
849 850 851 852 853

  return code;
}

static const char* jkMergeLogicPlanMergeKeys = "MergeKeys";
854
static const char* jkMergeLogicPlanInputs = "Inputs";
X
Xiaoyu Wang 已提交
855 856 857 858 859 860 861 862 863 864
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);
  }
865 866 867
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkMergeLogicPlanInputs, pNode->pInputs);
  }
X
Xiaoyu Wang 已提交
868
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
    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);
  }
885 886 887
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkMergeLogicPlanInputs, &pNode->pInputs);
  }
X
Xiaoyu Wang 已提交
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
  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";
910
static const char* jkWindowLogicPlanDeleteMark = "DeleteMark";
X
Xiaoyu Wang 已提交
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951

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);
  }
952 953 954
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowLogicPlanDeleteMark, pNode->deleteMark);
  }
X
Xiaoyu Wang 已提交
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997

  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 已提交
998
  }
999 1000 1001
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkWindowLogicPlanDeleteMark, &pNode->deleteMark);
  }
X
Xiaoyu Wang 已提交
1002 1003 1004 1005

  return code;
}

X
Xiaoyu Wang 已提交
1006 1007 1008
static const char* jkFillLogicPlanMode = "Mode";
static const char* jkFillLogicPlanWStartTs = "WStartTs";
static const char* jkFillLogicPlanValues = "Values";
X
Xiaoyu Wang 已提交
1009 1010
static const char* jkFillLogicPlanStartTime = "StartTime";
static const char* jkFillLogicPlanEndTime = "EndTime";
X
Xiaoyu Wang 已提交
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024

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 已提交
1025 1026 1027 1028 1029 1030
  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 已提交
1031 1032 1033 1034 1035 1036 1037 1038 1039

  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) {
1040
    tjsonGetNumberValue(pJson, jkFillLogicPlanMode, pNode->mode, code);
X
Xiaoyu Wang 已提交
1041 1042 1043 1044 1045 1046 1047
  }
  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 已提交
1048 1049 1050 1051 1052 1053
  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 已提交
1054 1055 1056 1057

  return code;
}

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
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;
}

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
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 已提交
1106
static const char* jkIndefRowsFuncLogicPlanFuncs = "Funcs";
1107 1108 1109 1110 1111 1112

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 已提交
1113
    code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanFuncs, pNode->pFuncs);
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
  }

  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 已提交
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
    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);
1170 1171 1172 1173 1174
  }

  return code;
}

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 1231 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 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
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";
1344
static const char* jkLogicSubplanNumOfComputeNodes = "NumOfComputeNodes";
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370

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);
  }
1371 1372 1373
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkLogicSubplanNumOfComputeNodes, pNode->numOfComputeNodes);
  }
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388

  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) {
1389
    tjsonGetNumberValue(pJson, jkLogicSubplanType, pNode->subplanType, code);
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
  }
  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);
  }
1404 1405 1406
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkLogicSubplanNumOfComputeNodes, &pNode->numOfComputeNodes);
  }
1407 1408 1409 1410

  return code;
}

1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
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 已提交
1428 1429
static const char* jkJoinLogicPlanJoinType = "JoinType";
static const char* jkJoinLogicPlanOnConditions = "OnConditions";
1430
static const char* jkJoinLogicPlanMergeCondition = "MergeConditions";
S
slzhou 已提交
1431
static const char* jkJoinLogicPlanColEqualOnConditions = "ColumnEqualOnConditions";
X
Xiaoyu Wang 已提交
1432

X
Xiaoyu Wang 已提交
1433
static int32_t logicJoinNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
1434 1435 1436 1437 1438 1439
  const SJoinLogicNode* pNode = (const SJoinLogicNode*)pObj;

  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkJoinLogicPlanJoinType, pNode->joinType);
  }
1440 1441 1442
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinLogicPlanMergeCondition, nodeToJson, pNode->pMergeCondition);
  }
X
Xiaoyu Wang 已提交
1443 1444 1445
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinLogicPlanOnConditions, nodeToJson, pNode->pOnConditions);
  }
1446
  if (TSDB_CODE_SUCCESS == code) {
S
slzhou 已提交
1447
    code = tjsonAddObject(pJson, jkJoinLogicPlanColEqualOnConditions, nodeToJson, pNode->pColEqualOnConditions);
1448
  }
X
Xiaoyu Wang 已提交
1449 1450 1451
  return code;
}

X
Xiaoyu Wang 已提交
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
static int32_t jsonToLogicJoinNode(const SJson* pJson, void* pObj) {
  SJoinLogicNode* pNode = (SJoinLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkJoinLogicPlanJoinType, pNode->joinType, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinLogicPlanMergeCondition, &pNode->pMergeCondition);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinLogicPlanOnConditions, &pNode->pOnConditions);
  }
1465
  if (TSDB_CODE_SUCCESS == code) {
S
slzhou 已提交
1466
    code = jsonToNodeObject(pJson, jkJoinLogicPlanColEqualOnConditions, &pNode->pColEqualOnConditions);
1467
  }
X
Xiaoyu Wang 已提交
1468 1469 1470
  return code;
}

X
Xiaoyu Wang 已提交
1471
static const char* jkPhysiPlanOutputDataBlockDesc = "OutputDataBlockDesc";
X
Xiaoyu Wang 已提交
1472 1473
static const char* jkPhysiPlanConditions = "Conditions";
static const char* jkPhysiPlanChildren = "Children";
1474 1475
static const char* jkPhysiPlanLimit = "Limit";
static const char* jkPhysiPlanSlimit = "SLimit";
X
Xiaoyu Wang 已提交
1476 1477 1478 1479

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

X
Xiaoyu Wang 已提交
1480
  int32_t code = tjsonAddObject(pJson, jkPhysiPlanOutputDataBlockDesc, nodeToJson, pNode->pOutputDataBlockDesc);
X
Xiaoyu Wang 已提交
1481 1482 1483 1484
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkPhysiPlanConditions, nodeToJson, pNode->pConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1485 1486
    code = nodeListToJson(pJson, jkPhysiPlanChildren, pNode->pChildren);
  }
1487 1488 1489 1490 1491 1492
  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 已提交
1493 1494 1495 1496 1497 1498 1499

  return code;
}

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

X
Xiaoyu Wang 已提交
1500
  int32_t code = jsonToNodeObject(pJson, jkPhysiPlanOutputDataBlockDesc, (SNode**)&pNode->pOutputDataBlockDesc);
X
Xiaoyu Wang 已提交
1501 1502 1503 1504 1505
  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 已提交
1506
  }
1507 1508 1509 1510 1511 1512
  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 已提交
1513 1514 1515 1516

  return code;
}

X
Xiaoyu Wang 已提交
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
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 已提交
1556
static const char* jkScanPhysiPlanScanCols = "ScanCols";
1557
static const char* jkScanPhysiPlanScanPseudoCols = "ScanPseudoCols";
X
Xiaoyu Wang 已提交
1558
static const char* jkScanPhysiPlanTableId = "TableId";
X
Xiaoyu Wang 已提交
1559
static const char* jkScanPhysiPlanSTableId = "STableId";
X
Xiaoyu Wang 已提交
1560
static const char* jkScanPhysiPlanTableType = "TableType";
X
Xiaoyu Wang 已提交
1561
static const char* jkScanPhysiPlanTableName = "TableName";
X
Xiaoyu Wang 已提交
1562 1563 1564 1565 1566 1567

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 已提交
1568
    code = nodeListToJson(pJson, jkScanPhysiPlanScanCols, pNode->pScanCols);
X
Xiaoyu Wang 已提交
1569
  }
1570 1571 1572
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkScanPhysiPlanScanPseudoCols, pNode->pScanPseudoCols);
  }
X
Xiaoyu Wang 已提交
1573 1574 1575
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableId, pNode->uid);
  }
X
Xiaoyu Wang 已提交
1576 1577 1578
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanSTableId, pNode->suid);
  }
X
Xiaoyu Wang 已提交
1579 1580 1581
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableType, pNode->tableType);
  }
X
Xiaoyu Wang 已提交
1582 1583 1584
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkScanPhysiPlanTableName, nameToJson, &pNode->tableName);
  }
X
Xiaoyu Wang 已提交
1585 1586 1587 1588

  return code;
}

X
Xiaoyu Wang 已提交
1589 1590 1591 1592 1593 1594 1595
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);
  }
1596 1597 1598
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkScanPhysiPlanScanPseudoCols, &pNode->pScanPseudoCols);
  }
X
Xiaoyu Wang 已提交
1599 1600 1601
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanTableId, &pNode->uid);
  }
X
Xiaoyu Wang 已提交
1602 1603 1604
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanSTableId, &pNode->suid);
  }
X
Xiaoyu Wang 已提交
1605 1606 1607
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkScanPhysiPlanTableType, &pNode->tableType);
  }
X
Xiaoyu Wang 已提交
1608 1609 1610
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkScanPhysiPlanTableName, jsonToName, &pNode->tableName);
  }
X
Xiaoyu Wang 已提交
1611 1612 1613 1614

  return code;
}

X
Xiaoyu Wang 已提交
1615 1616
static const char* jkLastRowScanPhysiPlanGroupTags = "GroupTags";
static const char* jkLastRowScanPhysiPlanGroupSort = "GroupSort";
X
Xiaoyu Wang 已提交
1617

X
Xiaoyu Wang 已提交
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644
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 已提交
1645

X
Xiaoyu Wang 已提交
1646 1647
static const char* jkTableScanPhysiPlanScanCount = "ScanCount";
static const char* jkTableScanPhysiPlanReverseScanCount = "ReverseScanCount";
X
Xiaoyu Wang 已提交
1648 1649
static const char* jkTableScanPhysiPlanStartKey = "StartKey";
static const char* jkTableScanPhysiPlanEndKey = "EndKey";
S
Shengliang Guan 已提交
1650 1651 1652
static const char* jkTableScanPhysiPlanRatio = "Ratio";
static const char* jkTableScanPhysiPlanDataRequired = "DataRequired";
static const char* jkTableScanPhysiPlanDynamicScanFuncs = "DynamicScanFuncs";
X
Xiaoyu Wang 已提交
1653 1654 1655
static const char* jkTableScanPhysiPlanInterval = "Interval";
static const char* jkTableScanPhysiPlanOffset = "Offset";
static const char* jkTableScanPhysiPlanSliding = "Sliding";
1656 1657 1658 1659 1660
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";
1661 1662
static const char* jkTableScanPhysiPlanGroupTags = "GroupTags";
static const char* jkTableScanPhysiPlanGroupSort = "GroupSort";
1663 1664
static const char* jkTableScanPhysiPlanTags = "Tags";
static const char* jkTableScanPhysiPlanSubtable = "Subtable";
1665
static const char* jkTableScanPhysiPlanAssignBlockUid = "AssignBlockUid";
1666
static const char* jkTableScanPhysiPlanIgnoreUpdate = "IgnoreUpdate";
X
Xiaoyu Wang 已提交
1667 1668 1669 1670 1671 1672

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 已提交
1673 1674 1675 1676
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanScanCount, pNode->scanSeq[0]);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanReverseScanCount, pNode->scanSeq[1]);
X
Xiaoyu Wang 已提交
1677 1678 1679 1680 1681 1682 1683
  }
  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 已提交
1684 1685 1686 1687 1688 1689 1690 1691 1692
  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 已提交
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
  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 已提交
1708 1709 1710 1711 1712 1713 1714
  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) {
1715
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanIgnoreExpired, pNode->igExpired);
5
54liuyao 已提交
1716
  }
X
Xiaoyu Wang 已提交
1717
  if (TSDB_CODE_SUCCESS == code) {
1718 1719 1720 1721
    code = nodeListToJson(pJson, jkTableScanPhysiPlanGroupTags, pNode->pGroupTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkTableScanPhysiPlanGroupSort, pNode->groupSort);
X
Xiaoyu Wang 已提交
1722
  }
1723 1724 1725 1726 1727 1728
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkTableScanPhysiPlanTags, pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkTableScanPhysiPlanSubtable, nodeToJson, pNode->pSubtable);
  }
1729 1730 1731
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkTableScanPhysiPlanAssignBlockUid, pNode->assignBlockUid);
  }
1732 1733 1734
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanIgnoreUpdate, pNode->igCheckUpdate);
  }
X
Xiaoyu Wang 已提交
1735 1736 1737 1738

  return code;
}

X
Xiaoyu Wang 已提交
1739 1740 1741 1742 1743
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 已提交
1744 1745 1746 1747
    code = tjsonGetUTinyIntValue(pJson, jkTableScanPhysiPlanScanCount, &pNode->scanSeq[0]);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkTableScanPhysiPlanReverseScanCount, &pNode->scanSeq[1]);
X
Xiaoyu Wang 已提交
1748 1749 1750 1751 1752 1753 1754
  }
  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 已提交
1755 1756 1757 1758
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetDoubleValue(pJson, jkTableScanPhysiPlanRatio, &pNode->ratio);
  }
  if (TSDB_CODE_SUCCESS == code) {
1759
    code = tjsonGetIntValue(pJson, jkTableScanPhysiPlanDataRequired, &pNode->dataRequired);
S
Shengliang Guan 已提交
1760 1761 1762 1763
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableScanPhysiPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs);
  }
X
Xiaoyu Wang 已提交
1764
  if (TSDB_CODE_SUCCESS == code) {
1765
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanInterval, &pNode->interval);
X
Xiaoyu Wang 已提交
1766 1767
  }
  if (TSDB_CODE_SUCCESS == code) {
1768
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanOffset, &pNode->offset);
X
Xiaoyu Wang 已提交
1769 1770
  }
  if (TSDB_CODE_SUCCESS == code) {
1771
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanSliding, &pNode->sliding);
X
Xiaoyu Wang 已提交
1772 1773
  }
  if (TSDB_CODE_SUCCESS == code) {
1774
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanIntervalUnit, &pNode->intervalUnit);
X
Xiaoyu Wang 已提交
1775
  }
5
54liuyao 已提交
1776
  if (TSDB_CODE_SUCCESS == code) {
1777
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanSlidingUnit, &pNode->slidingUnit);
5
54liuyao 已提交
1778 1779
  }
  if (TSDB_CODE_SUCCESS == code) {
1780
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanTriggerType, &pNode->triggerType);
5
54liuyao 已提交
1781 1782
  }
  if (TSDB_CODE_SUCCESS == code) {
1783
    code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanWatermark, &pNode->watermark);
5
54liuyao 已提交
1784
  }
5
54liuyao 已提交
1785
  if (TSDB_CODE_SUCCESS == code) {
1786
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanIgnoreExpired, &pNode->igExpired);
5
54liuyao 已提交
1787
  }
X
Xiaoyu Wang 已提交
1788
  if (TSDB_CODE_SUCCESS == code) {
1789 1790 1791 1792
    code = jsonToNodeList(pJson, jkTableScanPhysiPlanGroupTags, &pNode->pGroupTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkTableScanPhysiPlanGroupSort, &pNode->groupSort);
X
Xiaoyu Wang 已提交
1793
  }
1794 1795 1796 1797 1798 1799
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableScanPhysiPlanTags, &pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkTableScanPhysiPlanSubtable, &pNode->pSubtable);
  }
1800 1801 1802
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkTableScanPhysiPlanAssignBlockUid, &pNode->assignBlockUid);
  }
1803 1804 1805
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkTableScanPhysiPlanIgnoreUpdate, &pNode->igCheckUpdate);
  }
X
Xiaoyu Wang 已提交
1806

X
Xiaoyu Wang 已提交
1807 1808 1809
  return code;
}

X
Xiaoyu Wang 已提交
1810
static const char* jkSysTableScanPhysiPlanMnodeEpSet = "MnodeEpSet";
D
dapan1121 已提交
1811 1812
static const char* jkSysTableScanPhysiPlanShowRewrite = "ShowRewrite";
static const char* jkSysTableScanPhysiPlanAccountId = "AccountId";
1813
static const char* jkSysTableScanPhysiPlanSysInfo = "SysInfo";
X
Xiaoyu Wang 已提交
1814

X
Xiaoyu Wang 已提交
1815
static int32_t physiSysTableScanNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
1816 1817 1818 1819 1820 1821
  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 已提交
1822 1823 1824 1825 1826 1827
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkSysTableScanPhysiPlanShowRewrite, pNode->showRewrite);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId);
  }
1828 1829 1830
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkSysTableScanPhysiPlanSysInfo, pNode->sysInfo);
  }
X
Xiaoyu Wang 已提交
1831 1832

  return code;
X
Xiaoyu Wang 已提交
1833 1834 1835
}

static int32_t jsonToPhysiSysTableScanNode(const SJson* pJson, void* pObj) {
X
Xiaoyu Wang 已提交
1836 1837 1838 1839 1840 1841
  SSystemTableScanPhysiNode* pNode = (SSystemTableScanPhysiNode*)pObj;

  int32_t code = jsonToPhysiScanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkSysTableScanPhysiPlanMnodeEpSet, jsonToEpSet, &pNode->mgmtEpSet);
  }
D
dapan1121 已提交
1842 1843 1844 1845
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSysTableScanPhysiPlanShowRewrite, &pNode->showRewrite);
  }
  if (TSDB_CODE_SUCCESS == code) {
1846
    tjsonGetNumberValue(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId, code);
1847 1848 1849
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSysTableScanPhysiPlanSysInfo, &pNode->sysInfo);
D
dapan1121 已提交
1850
  }
X
Xiaoyu Wang 已提交
1851 1852

  return code;
X
Xiaoyu Wang 已提交
1853 1854
}

X
Xiaoyu Wang 已提交
1855
static const char* jkProjectPhysiPlanProjections = "Projections";
1856
static const char* jkProjectPhysiPlanMergeDataBlock = "MergeDataBlock";
1857
static const char* jkProjectPhysiPlanIgnoreGroupId = "IgnoreGroupId";
X
Xiaoyu Wang 已提交
1858 1859 1860 1861 1862 1863

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 已提交
1864 1865
    code = nodeListToJson(pJson, jkProjectPhysiPlanProjections, pNode->pProjections);
  }
1866 1867 1868
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkProjectPhysiPlanMergeDataBlock, pNode->mergeDataBlock);
  }
1869 1870 1871
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkProjectPhysiPlanIgnoreGroupId, pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881

  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 已提交
1882
  }
1883 1884 1885
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkProjectPhysiPlanMergeDataBlock, &pNode->mergeDataBlock);
  }
1886 1887 1888
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkProjectPhysiPlanIgnoreGroupId, &pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
1889 1890

  return code;
X
Xiaoyu Wang 已提交
1891 1892
}

X
Xiaoyu Wang 已提交
1893
static const char* jkJoinPhysiPlanJoinType = "JoinType";
1894
static const char* jkJoinPhysiPlanInputTsOrder = "InputTsOrder";
1895
static const char* jkJoinPhysiPlanMergeCondition = "MergeCondition";
X
Xiaoyu Wang 已提交
1896 1897
static const char* jkJoinPhysiPlanOnConditions = "OnConditions";
static const char* jkJoinPhysiPlanTargets = "Targets";
S
slzhou 已提交
1898
static const char* jkJoinPhysiPlanColEqualOnConditions = "ColumnEqualOnConditions";
X
Xiaoyu Wang 已提交
1899 1900

static int32_t physiJoinNodeToJson(const void* pObj, SJson* pJson) {
1901
  const SSortMergeJoinPhysiNode* pNode = (const SSortMergeJoinPhysiNode*)pObj;
X
Xiaoyu Wang 已提交
1902 1903 1904 1905 1906

  int32_t code = physicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanJoinType, pNode->joinType);
  }
1907 1908 1909
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanInputTsOrder, pNode->inputTsOrder);
  }
1910 1911 1912
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinPhysiPlanMergeCondition, nodeToJson, pNode->pMergeCondition);
  }
X
Xiaoyu Wang 已提交
1913 1914 1915 1916
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinPhysiPlanOnConditions, nodeToJson, pNode->pOnConditions);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1917 1918
    code = nodeListToJson(pJson, jkJoinPhysiPlanTargets, pNode->pTargets);
  }
1919
  if (TSDB_CODE_SUCCESS == code) {
S
slzhou 已提交
1920
    code = tjsonAddObject(pJson, jkJoinPhysiPlanColEqualOnConditions, nodeToJson, pNode->pColEqualOnConditions);
1921
  }
X
Xiaoyu Wang 已提交
1922 1923 1924 1925
  return code;
}

static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) {
1926
  SSortMergeJoinPhysiNode* pNode = (SSortMergeJoinPhysiNode*)pObj;
X
Xiaoyu Wang 已提交
1927 1928 1929

  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
1930
    tjsonGetNumberValue(pJson, jkJoinPhysiPlanJoinType, pNode->joinType, code);
1931 1932 1933
  }
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkJoinPhysiPlanInputTsOrder, pNode->inputTsOrder, code);
X
Xiaoyu Wang 已提交
1934 1935 1936 1937
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions);
  }
1938 1939 1940
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinPhysiPlanMergeCondition, &pNode->pMergeCondition);
  }
X
Xiaoyu Wang 已提交
1941 1942
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkJoinPhysiPlanTargets, &pNode->pTargets);
X
Xiaoyu Wang 已提交
1943
  }
1944
  if (TSDB_CODE_SUCCESS == code) {
S
slzhou 已提交
1945
    code = jsonToNodeObject(pJson, jkJoinPhysiPlanColEqualOnConditions, &pNode->pColEqualOnConditions);
1946
  }
X
Xiaoyu Wang 已提交
1947 1948 1949 1950 1951 1952
  return code;
}

static const char* jkAggPhysiPlanExprs = "Exprs";
static const char* jkAggPhysiPlanGroupKeys = "GroupKeys";
static const char* jkAggPhysiPlanAggFuncs = "AggFuncs";
1953
static const char* jkAggPhysiPlanMergeDataBlock = "MergeDataBlock";
1954
static const char* jkAggPhysiPlanGroupKeyOptimized = "GroupKeyOptimized";
X
Xiaoyu Wang 已提交
1955 1956 1957 1958 1959 1960

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 已提交
1961
    code = nodeListToJson(pJson, jkAggPhysiPlanExprs, pNode->pExprs);
X
Xiaoyu Wang 已提交
1962 1963
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1964
    code = nodeListToJson(pJson, jkAggPhysiPlanGroupKeys, pNode->pGroupKeys);
X
Xiaoyu Wang 已提交
1965 1966
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
1967 1968
    code = nodeListToJson(pJson, jkAggPhysiPlanAggFuncs, pNode->pAggFuncs);
  }
1969 1970 1971
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkAggPhysiPlanMergeDataBlock, pNode->mergeDataBlock);
  }
1972 1973 1974
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkAggPhysiPlanGroupKeyOptimized, pNode->groupKeyOptimized);
  }
X
Xiaoyu Wang 已提交
1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990

  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 已提交
1991
  }
1992 1993 1994
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkAggPhysiPlanMergeDataBlock, &pNode->mergeDataBlock);
  }
1995 1996 1997
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkAggPhysiPlanGroupKeyOptimized, &pNode->groupKeyOptimized);
  }
X
Xiaoyu Wang 已提交
1998 1999 2000 2001

  return code;
}

2002 2003
static const char* jkExchangePhysiPlanSrcStartGroupId = "SrcStartGroupId";
static const char* jkExchangePhysiPlanSrcEndGroupId = "SrcEndGroupId";
X
Xiaoyu Wang 已提交
2004
static const char* jkExchangePhysiPlanSrcEndPoints = "SrcEndPoints";
X
Xiaoyu Wang 已提交
2005
static const char* jkExchangePhysiPlanSeqRecvData = "SeqRecvData";
X
Xiaoyu Wang 已提交
2006 2007 2008 2009 2010 2011

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) {
2012 2013 2014 2015
    code = tjsonAddIntegerToObject(pJson, jkExchangePhysiPlanSrcStartGroupId, pNode->srcStartGroupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkExchangePhysiPlanSrcEndGroupId, pNode->srcEndGroupId);
X
Xiaoyu Wang 已提交
2016 2017 2018 2019
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkExchangePhysiPlanSrcEndPoints, pNode->pSrcEndPoints);
  }
X
Xiaoyu Wang 已提交
2020 2021 2022
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkExchangePhysiPlanSeqRecvData, pNode->seqRecvData);
  }
X
Xiaoyu Wang 已提交
2023 2024 2025 2026 2027 2028 2029 2030 2031

  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) {
2032 2033 2034 2035
    code = tjsonGetIntValue(pJson, jkExchangePhysiPlanSrcStartGroupId, &pNode->srcStartGroupId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkExchangePhysiPlanSrcEndGroupId, &pNode->srcEndGroupId);
X
Xiaoyu Wang 已提交
2036 2037 2038 2039
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkExchangePhysiPlanSrcEndPoints, &pNode->pSrcEndPoints);
  }
X
Xiaoyu Wang 已提交
2040 2041 2042
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkExchangePhysiPlanSeqRecvData, &pNode->seqRecvData);
  }
X
Xiaoyu Wang 已提交
2043 2044 2045 2046

  return code;
}

X
Xiaoyu Wang 已提交
2047
static const char* jkMergePhysiPlanMergeKeys = "MergeKeys";
X
Xiaoyu Wang 已提交
2048
static const char* jkMergePhysiPlanTargets = "Targets";
X
Xiaoyu Wang 已提交
2049 2050
static const char* jkMergePhysiPlanNumOfChannels = "NumOfChannels";
static const char* jkMergePhysiPlanSrcGroupId = "SrcGroupId";
2051
static const char* jkMergePhysiPlanGroupSort = "GroupSort";
D
dapan1121 已提交
2052
static const char* jkMergePhysiPlanIgnoreGroupID = "IgnoreGroupID";
X
Xiaoyu Wang 已提交
2053 2054 2055 2056 2057 2058 2059 2060

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 已提交
2061 2062 2063
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkMergePhysiPlanTargets, pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
2064 2065 2066 2067 2068 2069
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkMergePhysiPlanNumOfChannels, pNode->numOfChannels);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkMergePhysiPlanSrcGroupId, pNode->srcGroupId);
  }
2070 2071 2072
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkMergePhysiPlanGroupSort, pNode->groupSort);
  }
D
dapan1121 已提交
2073 2074 2075
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkMergePhysiPlanIgnoreGroupID, pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086

  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 已提交
2087 2088 2089
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkMergePhysiPlanTargets, &pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
2090 2091 2092 2093 2094 2095
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkMergePhysiPlanNumOfChannels, &pNode->numOfChannels);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkMergePhysiPlanSrcGroupId, &pNode->srcGroupId);
  }
2096 2097 2098
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkMergePhysiPlanGroupSort, &pNode->groupSort);
  }
D
dapan1121 已提交
2099 2100 2101
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkMergePhysiPlanIgnoreGroupID, &pNode->ignoreGroupId);
  }
X
Xiaoyu Wang 已提交
2102 2103 2104 2105

  return code;
}

X
Xiaoyu Wang 已提交
2106 2107
static const char* jkSortPhysiPlanExprs = "Exprs";
static const char* jkSortPhysiPlanSortKeys = "SortKeys";
X
Xiaoyu Wang 已提交
2108
static const char* jkSortPhysiPlanTargets = "Targets";
X
Xiaoyu Wang 已提交
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119

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 已提交
2120 2121 2122
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSortPhysiPlanTargets, pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136

  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 已提交
2137 2138 2139
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSortPhysiPlanTargets, &pNode->pTargets);
  }
X
Xiaoyu Wang 已提交
2140 2141 2142 2143

  return code;
}

X
Xiaoyu Wang 已提交
2144 2145
static const char* jkWindowPhysiPlanExprs = "Exprs";
static const char* jkWindowPhysiPlanFuncs = "Funcs";
2146
static const char* jkWindowPhysiPlanTsPk = "TsPk";
5
54liuyao 已提交
2147
static const char* jkWindowPhysiPlanTsEnd = "TsEnd";
X
Xiaoyu Wang 已提交
2148 2149
static const char* jkWindowPhysiPlanTriggerType = "TriggerType";
static const char* jkWindowPhysiPlanWatermark = "Watermark";
2150
static const char* jkWindowPhysiPlanDeleteMark = "DeleteMark";
2151
static const char* jkWindowPhysiPlanIgnoreExpired = "IgnoreExpired";
2152
static const char* jkWindowPhysiPlanInputTsOrder = "InputTsOrder";
X
Xiaoyu Wang 已提交
2153
static const char* jkWindowPhysiPlanOutputTsOrder = "outputTsOrder";
2154
static const char* jkWindowPhysiPlanMergeDataBlock = "MergeDataBlock";
X
Xiaoyu Wang 已提交
2155 2156

static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) {
2157
  const SWindowPhysiNode* pNode = (const SWindowPhysiNode*)pObj;
X
Xiaoyu Wang 已提交
2158 2159 2160 2161 2162 2163 2164 2165

  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);
  }
2166 2167 2168
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk);
  }
5
54liuyao 已提交
2169 2170 2171
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWindowPhysiPlanTsEnd, nodeToJson, pNode->pTsEnd);
  }
X
Xiaoyu Wang 已提交
2172 2173 2174 2175 2176 2177
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanWatermark, pNode->watermark);
  }
2178 2179 2180
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanDeleteMark, pNode->deleteMark);
  }
5
54liuyao 已提交
2181
  if (TSDB_CODE_SUCCESS == code) {
2182
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanIgnoreExpired, pNode->igExpired);
5
54liuyao 已提交
2183
  }
X
Xiaoyu Wang 已提交
2184 2185 2186 2187 2188 2189
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanInputTsOrder, pNode->inputTsOrder);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanOutputTsOrder, pNode->outputTsOrder);
  }
2190 2191 2192
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkWindowPhysiPlanMergeDataBlock, pNode->mergeDataBlock);
  }
X
Xiaoyu Wang 已提交
2193 2194 2195 2196 2197

  return code;
}

static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) {
2198
  SWindowPhysiNode* pNode = (SWindowPhysiNode*)pObj;
X
Xiaoyu Wang 已提交
2199 2200 2201 2202 2203 2204 2205 2206

  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);
  }
2207 2208 2209
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk);
  }
5
54liuyao 已提交
2210 2211 2212
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsEnd, (SNode**)&pNode->pTsEnd);
  }
X
Xiaoyu Wang 已提交
2213
  if (TSDB_CODE_SUCCESS == code) {
2214
    code = tjsonGetTinyIntValue(pJson, jkWindowPhysiPlanTriggerType, &pNode->triggerType);
X
Xiaoyu Wang 已提交
2215 2216
  }
  if (TSDB_CODE_SUCCESS == code) {
2217
    code = tjsonGetBigIntValue(pJson, jkWindowPhysiPlanWatermark, &pNode->watermark);
X
Xiaoyu Wang 已提交
2218
  }
2219 2220 2221
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkWindowPhysiPlanDeleteMark, &pNode->deleteMark);
  }
5
54liuyao 已提交
2222
  if (TSDB_CODE_SUCCESS == code) {
2223
    code = tjsonGetTinyIntValue(pJson, jkWindowPhysiPlanIgnoreExpired, &pNode->igExpired);
5
54liuyao 已提交
2224
  }
X
Xiaoyu Wang 已提交
2225 2226 2227 2228 2229 2230
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkWindowPhysiPlanInputTsOrder, pNode->inputTsOrder, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkWindowPhysiPlanOutputTsOrder, pNode->outputTsOrder, code);
  }
2231 2232 2233
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkWindowPhysiPlanMergeDataBlock, &pNode->mergeDataBlock);
  }
X
Xiaoyu Wang 已提交
2234 2235 2236 2237

  return code;
}

X
Xiaoyu Wang 已提交
2238 2239 2240
static const char* jkIntervalPhysiPlanInterval = "Interval";
static const char* jkIntervalPhysiPlanOffset = "Offset";
static const char* jkIntervalPhysiPlanSliding = "Sliding";
H
Haojun Liao 已提交
2241
static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit";
X
Xiaoyu Wang 已提交
2242
static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit";
X
Xiaoyu Wang 已提交
2243 2244 2245 2246

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

X
Xiaoyu Wang 已提交
2247
  int32_t code = physiWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
2248 2249 2250 2251 2252 2253 2254 2255 2256
  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 已提交
2257 2258 2259 2260 2261 2262
  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 已提交
2263 2264 2265 2266 2267 2268 2269

  return code;
}

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

X
Xiaoyu Wang 已提交
2270
  int32_t code = jsonToPhysiWindowNode(pJson, pObj);
X
Xiaoyu Wang 已提交
2271 2272 2273 2274 2275 2276 2277 2278 2279
  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 已提交
2280 2281 2282 2283 2284 2285
  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 已提交
2286 2287 2288 2289 2290

  return code;
}

static const char* jkFillPhysiPlanMode = "Mode";
2291 2292
static const char* jkFillPhysiPlanFillExprs = "FillExprs";
static const char* jkFillPhysiPlanNotFillExprs = "NotFillExprs";
X
Xiaoyu Wang 已提交
2293 2294
static const char* jkFillPhysiPlanWStartTs = "WStartTs";
static const char* jkFillPhysiPlanValues = "Values";
X
Xiaoyu Wang 已提交
2295 2296
static const char* jkFillPhysiPlanStartTime = "StartTime";
static const char* jkFillPhysiPlanEndTime = "EndTime";
X
Xiaoyu Wang 已提交
2297
static const char* jkFillPhysiPlanInputTsOrder = "inputTsOrder";
X
Xiaoyu Wang 已提交
2298 2299 2300 2301 2302 2303 2304 2305

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 已提交
2306
  if (TSDB_CODE_SUCCESS == code) {
2307
    code = nodeListToJson(pJson, jkFillPhysiPlanFillExprs, pNode->pFillExprs);
X
Xiaoyu Wang 已提交
2308 2309
  }
  if (TSDB_CODE_SUCCESS == code) {
2310
    code = nodeListToJson(pJson, jkFillPhysiPlanNotFillExprs, pNode->pNotFillExprs);
X
Xiaoyu Wang 已提交
2311 2312
  }
  if (TSDB_CODE_SUCCESS == code) {
2313 2314 2315 2316
    code = tjsonAddObject(pJson, jkFillPhysiPlanWStartTs, nodeToJson, pNode->pWStartTs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkFillPhysiPlanValues, nodeToJson, pNode->pValues);
X
Xiaoyu Wang 已提交
2317
  }
X
Xiaoyu Wang 已提交
2318 2319 2320 2321 2322 2323
  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 已提交
2324 2325 2326
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFillPhysiPlanInputTsOrder, pNode->inputTsOrder);
  }
X
Xiaoyu Wang 已提交
2327 2328 2329 2330 2331 2332 2333

  return code;
}

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

2334
  int32_t code = jsonToPhysicPlanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
2335
  if (TSDB_CODE_SUCCESS == code) {
2336
    tjsonGetNumberValue(pJson, jkFillPhysiPlanMode, pNode->mode, code);
X
Xiaoyu Wang 已提交
2337 2338
  }
  if (TSDB_CODE_SUCCESS == code) {
2339
    code = jsonToNodeList(pJson, jkFillPhysiPlanFillExprs, &pNode->pFillExprs);
X
Xiaoyu Wang 已提交
2340 2341
  }
  if (TSDB_CODE_SUCCESS == code) {
2342 2343 2344 2345
    code = jsonToNodeList(pJson, jkFillPhysiPlanNotFillExprs, &pNode->pNotFillExprs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillPhysiPlanWStartTs, &pNode->pWStartTs);
X
Xiaoyu Wang 已提交
2346
  }
X
Xiaoyu Wang 已提交
2347
  if (TSDB_CODE_SUCCESS == code) {
2348
    code = jsonToNodeObject(pJson, jkFillPhysiPlanValues, &pNode->pValues);
X
Xiaoyu Wang 已提交
2349
  }
X
Xiaoyu Wang 已提交
2350 2351 2352 2353 2354
  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 已提交
2355
  }
X
Xiaoyu Wang 已提交
2356 2357 2358
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkFillPhysiPlanInputTsOrder, pNode->inputTsOrder, code);
  }
X
Xiaoyu Wang 已提交
2359 2360 2361 2362

  return code;
}

X
Xiaoyu Wang 已提交
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380
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) {
2381
    tjsonGetNumberValue(pJson, jkSessionWindowPhysiPlanGap, pNode->gap, code);
X
Xiaoyu Wang 已提交
2382 2383 2384 2385 2386
  }

  return code;
}

2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410
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;
}

X
Xiaoyu Wang 已提交
2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441
static const char* jkEventWindowPhysiPlanStartCond = "StartCond";
static const char* jkEventWindowPhysiPlanEndCond = "EndCond";

static int32_t physiEventWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SEventWinodwPhysiNode* pNode = (const SEventWinodwPhysiNode*)pObj;

  int32_t code = physiWindowNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkEventWindowPhysiPlanStartCond, nodeToJson, pNode->pStartCond);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkEventWindowPhysiPlanEndCond, nodeToJson, pNode->pEndCond);
  }

  return code;
}

static int32_t jsonToPhysiEventWindowNode(const SJson* pJson, void* pObj) {
  SEventWinodwPhysiNode* pNode = (SEventWinodwPhysiNode*)pObj;

  int32_t code = jsonToPhysiWindowNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkEventWindowPhysiPlanStartCond, &pNode->pStartCond);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkEventWindowPhysiPlanEndCond, &pNode->pEndCond);
  }

  return code;
}

2442 2443
static const char* jkPartitionPhysiPlanExprs = "Exprs";
static const char* jkPartitionPhysiPlanPartitionKeys = "PartitionKeys";
X
Xiaoyu Wang 已提交
2444
static const char* jkPartitionPhysiPlanTargets = "Targets";
2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455

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 已提交
2456 2457 2458
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkPartitionPhysiPlanTargets, pNode->pTargets);
  }
2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472

  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 已提交
2473 2474 2475
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkPartitionPhysiPlanTargets, &pNode->pTargets);
  }
2476 2477 2478 2479

  return code;
}

2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510
static const char* jkStreamPartitionPhysiPlanTags = "Tags";
static const char* jkStreamPartitionPhysiPlanSubtable = "Subtable";

static int32_t physiStreamPartitionNodeToJson(const void* pObj, SJson* pJson) {
  const SStreamPartitionPhysiNode* pNode = (const SStreamPartitionPhysiNode*)pObj;

  int32_t code = physiPartitionNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkStreamPartitionPhysiPlanTags, pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkStreamPartitionPhysiPlanSubtable, nodeToJson, pNode->pSubtable);
  }

  return code;
}

static int32_t jsonToPhysiStreamPartitionNode(const SJson* pJson, void* pObj) {
  SStreamPartitionPhysiNode* pNode = (SStreamPartitionPhysiNode*)pObj;

  int32_t code = jsonToPhysiPartitionNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkStreamPartitionPhysiPlanTags, &pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkStreamPartitionPhysiPlanSubtable, &pNode->pSubtable);
  }

  return code;
}

2511
static const char* jkIndefRowsFuncPhysiPlanExprs = "Exprs";
X
Xiaoyu Wang 已提交
2512
static const char* jkIndefRowsFuncPhysiPlanFuncs = "Funcs";
2513 2514 2515 2516 2517 2518 2519 2520 2521

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 已提交
2522
    code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanFuncs, pNode->pFuncs);
2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535
  }

  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 已提交
2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546
    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 已提交
2547 2548 2549
static const char* jkInterpFuncPhysiPlanFillMode = "FillMode";
static const char* jkInterpFuncPhysiPlanFillValues = "FillValues";
static const char* jkInterpFuncPhysiPlanTimeSeries = "TimeSeries";
X
Xiaoyu Wang 已提交
2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569

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 已提交
2570 2571 2572 2573 2574 2575 2576 2577 2578
  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 已提交
2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600

  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);
2601
  }
X
Xiaoyu Wang 已提交
2602 2603 2604 2605 2606 2607 2608 2609 2610
  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);
  }
2611 2612 2613 2614

  return code;
}

X
Xiaoyu Wang 已提交
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626
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 已提交
2627
static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return physicDataSinkNodeToJson(pObj, pJson); }
X
Xiaoyu Wang 已提交
2628

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

2631 2632
static const char* jkQueryInsertPhysiPlanInsertCols = "InsertCols";
static const char* jkQueryInsertPhysiPlanStableId = "StableId";
2633 2634 2635 2636 2637
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";
X
Xiaoyu Wang 已提交
2638
static const char* jkQueryInsertPhysiPlanExplain = "Explain";
2639 2640 2641 2642 2643

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

  int32_t code = physicDataSinkNodeToJson(pObj, pJson);
2644 2645 2646 2647 2648 2649
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkQueryInsertPhysiPlanInsertCols, pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanStableId, pNode->stableId);
  }
2650 2651 2652 2653 2654 2655 2656
  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) {
2657
    code = tjsonAddStringToObject(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableName);
2658 2659 2660 2661 2662 2663 2664
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanVgId, pNode->vgId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkQueryInsertPhysiPlanEpSet, epSetToJson, &pNode->epSet);
  }
X
Xiaoyu Wang 已提交
2665 2666 2667
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkQueryInsertPhysiPlanExplain, pNode->explain);
  }
2668 2669 2670 2671 2672 2673 2674 2675 2676

  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) {
2677 2678 2679 2680 2681 2682
    code = jsonToNodeList(pJson, jkQueryInsertPhysiPlanInsertCols, &pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUBigIntValue(pJson, jkQueryInsertPhysiPlanStableId, &pNode->stableId);
  }
  if (TSDB_CODE_SUCCESS == code) {
2683 2684 2685 2686 2687 2688
    code = tjsonGetUBigIntValue(pJson, jkQueryInsertPhysiPlanTableId, &pNode->tableId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkQueryInsertPhysiPlanTableType, &pNode->tableType);
  }
  if (TSDB_CODE_SUCCESS == code) {
2689
    code = tjsonGetStringValue(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableName);
2690 2691 2692 2693 2694 2695 2696
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkQueryInsertPhysiPlanVgId, &pNode->vgId);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkQueryInsertPhysiPlanEpSet, jsonToEpSet, &pNode->epSet);
  }
X
Xiaoyu Wang 已提交
2697 2698 2699
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkQueryInsertPhysiPlanExplain, &pNode->explain);
  }
2700 2701 2702 2703

  return code;
}

X
Xiaoyu Wang 已提交
2704 2705 2706
static const char* jkDeletePhysiPlanTableId = "TableId";
static const char* jkDeletePhysiPlanTableType = "TableType";
static const char* jkDeletePhysiPlanTableFName = "TableFName";
2707
static const char* jkDeletePhysiPlanTsColName = "TsColName";
X
Xiaoyu Wang 已提交
2708 2709
static const char* jkDeletePhysiPlanDeleteTimeRangeStartKey = "DeleteTimeRangeStartKey";
static const char* jkDeletePhysiPlanDeleteTimeRangeEndKey = "DeleteTimeRangeEndKey";
X
Xiaoyu Wang 已提交
2710
static const char* jkDeletePhysiPlanAffectedRows = "AffectedRows";
2711 2712
static const char* jkDeletePhysiPlanStartTs = "StartTs";
static const char* jkDeletePhysiPlanEndTs = "EndTs";
X
Xiaoyu Wang 已提交
2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726

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);
  }
2727 2728 2729
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDeletePhysiPlanTsColName, pNode->tsColName);
  }
X
Xiaoyu Wang 已提交
2730 2731 2732 2733 2734 2735
  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 已提交
2736 2737 2738
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkDeletePhysiPlanAffectedRows, nodeToJson, pNode->pAffectedRows);
  }
2739 2740 2741 2742 2743 2744
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkDeletePhysiPlanStartTs, nodeToJson, pNode->pStartTs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkDeletePhysiPlanEndTs, nodeToJson, pNode->pEndTs);
  }
X
Xiaoyu Wang 已提交
2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761

  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);
  }
2762 2763 2764
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDeletePhysiPlanTsColName, pNode->tsColName);
  }
X
Xiaoyu Wang 已提交
2765 2766 2767 2768 2769 2770
  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 已提交
2771 2772 2773
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkDeletePhysiPlanAffectedRows, &pNode->pAffectedRows);
  }
2774 2775 2776 2777 2778 2779
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkDeletePhysiPlanStartTs, &pNode->pStartTs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkDeletePhysiPlanEndTs, &pNode->pEndTs);
  }
X
Xiaoyu Wang 已提交
2780 2781 2782 2783

  return code;
}

X
Xiaoyu Wang 已提交
2784 2785 2786 2787 2788 2789 2790 2791 2792 2793
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 已提交
2794
    code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrInUse, pNode->epSet.inUse);
X
Xiaoyu Wang 已提交
2795 2796
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2797
    code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrNumOfEps, pNode->epSet.numOfEps);
X
Xiaoyu Wang 已提交
2798 2799
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2800
    code = tjsonAddArray(pJson, jkQueryNodeAddrEps, epToJson, pNode->epSet.eps, sizeof(SEp), pNode->epSet.numOfEps);
X
Xiaoyu Wang 已提交
2801 2802 2803 2804 2805 2806 2807 2808 2809 2810
  }

  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 已提交
2811
    code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrInUse, &pNode->epSet.inUse);
X
Xiaoyu Wang 已提交
2812 2813
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2814
    code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrNumOfEps, &pNode->epSet.numOfEps);
X
Xiaoyu Wang 已提交
2815 2816
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2817
    code = tjsonToArray(pJson, jkQueryNodeAddrEps, jsonToEp, pNode->epSet.eps, sizeof(SEp));
X
Xiaoyu Wang 已提交
2818 2819 2820 2821 2822 2823 2824 2825 2826
  }

  return code;
}

static const char* jkSubplanId = "Id";
static const char* jkSubplanType = "SubplanType";
static const char* jkSubplanMsgType = "MsgType";
static const char* jkSubplanLevel = "Level";
2827
static const char* jkSubplanDbFName = "DbFName";
X
Xiaoyu Wang 已提交
2828
static const char* jkSubplanUser = "User";
X
Xiaoyu Wang 已提交
2829 2830 2831
static const char* jkSubplanNodeAddr = "NodeAddr";
static const char* jkSubplanRootNode = "RootNode";
static const char* jkSubplanDataSink = "DataSink";
X
Xiaoyu Wang 已提交
2832
static const char* jkSubplanTagCond = "TagCond";
X
Xiaoyu Wang 已提交
2833
static const char* jkSubplanTagIndexCond = "TagIndexCond";
2834
static const char* jkSubplanShowRewrite = "ShowRewrite";
X
Xiaoyu Wang 已提交
2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848

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);
  }
2849 2850 2851
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSubplanDbFName, pNode->dbFName);
  }
X
Xiaoyu Wang 已提交
2852 2853 2854
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSubplanUser, pNode->user);
  }
X
Xiaoyu Wang 已提交
2855 2856 2857 2858 2859 2860 2861 2862 2863
  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 已提交
2864 2865 2866
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSubplanTagCond, nodeToJson, pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
2867 2868 2869
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSubplanTagIndexCond, nodeToJson, pNode->pTagIndexCond);
  }
2870 2871 2872
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkSubplanShowRewrite, pNode->showRewrite);
  }
X
Xiaoyu Wang 已提交
2873 2874 2875 2876 2877 2878 2879 2880 2881

  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) {
2882
    tjsonGetNumberValue(pJson, jkSubplanType, pNode->subplanType, code);
X
Xiaoyu Wang 已提交
2883 2884 2885 2886 2887 2888 2889
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkSubplanMsgType, &pNode->msgType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkSubplanLevel, &pNode->level);
  }
2890 2891 2892
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSubplanDbFName, pNode->dbFName);
  }
X
Xiaoyu Wang 已提交
2893 2894 2895
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSubplanUser, pNode->user);
  }
X
Xiaoyu Wang 已提交
2896 2897 2898 2899 2900 2901 2902 2903 2904
  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 已提交
2905 2906 2907
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSubplanTagCond, (SNode**)&pNode->pTagCond);
  }
X
Xiaoyu Wang 已提交
2908 2909 2910
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSubplanTagIndexCond, (SNode**)&pNode->pTagIndexCond);
  }
2911 2912 2913
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSubplanShowRewrite, &pNode->showRewrite);
  }
X
Xiaoyu Wang 已提交
2914 2915 2916 2917

  return code;
}

X
Xiaoyu Wang 已提交
2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949
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 已提交
2950 2951 2952
static const char* jkAggLogicPlanGroupKeys = "GroupKeys";
static const char* jkAggLogicPlanAggFuncs = "AggFuncs";

X
Xiaoyu Wang 已提交
2953
static int32_t logicAggNodeToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
2954
  const SAggLogicNode* pNode = (const SAggLogicNode*)pObj;
2955

X
Xiaoyu Wang 已提交
2956 2957
  int32_t code = logicPlanNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2958
    code = nodeListToJson(pJson, jkAggLogicPlanGroupKeys, pNode->pGroupKeys);
X
Xiaoyu Wang 已提交
2959 2960
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
2961
    code = nodeListToJson(pJson, jkAggLogicPlanAggFuncs, pNode->pAggFuncs);
X
Xiaoyu Wang 已提交
2962 2963 2964 2965 2966
  }

  return code;
}

2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980
static int32_t jsonToLogicAggNode(const SJson* pJson, void* pObj) {
  SAggLogicNode* pNode = (SAggLogicNode*)pObj;

  int32_t code = jsonToLogicPlanNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkAggLogicPlanGroupKeys, &pNode->pGroupKeys);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkAggLogicPlanAggFuncs, &pNode->pAggFuncs);
  }

  return code;
}

X
Xiaoyu Wang 已提交
2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002
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 已提交
3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019
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 已提交
3020 3021
static const char* jkExprDataType = "DataType";
static const char* jkExprAliasName = "AliasName";
X
Xiaoyu Wang 已提交
3022
static const char* jkExprUserAlias = "UserAlias";
X
Xiaoyu Wang 已提交
3023 3024 3025 3026 3027 3028 3029 3030

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 已提交
3031 3032 3033
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkExprUserAlias, pNode->userAlias);
  }
X
Xiaoyu Wang 已提交
3034 3035 3036 3037

  return code;
}

X
Xiaoyu Wang 已提交
3038 3039 3040 3041 3042 3043 3044
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 已提交
3045 3046 3047
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkExprUserAlias, pNode->userAlias);
  }
X
Xiaoyu Wang 已提交
3048 3049 3050 3051

  return code;
}

X
Xiaoyu Wang 已提交
3052
static const char* jkColumnTableId = "TableId";
L
Liu Jicong 已提交
3053
static const char* jkColumnTableType = "TableType";
X
Xiaoyu Wang 已提交
3054 3055 3056 3057 3058 3059
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 已提交
3060 3061
static const char* jkColumnDataBlockId = "DataBlockId";
static const char* jkColumnSlotId = "SlotId";
X
Xiaoyu Wang 已提交
3062 3063 3064 3065 3066 3067 3068 3069

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 已提交
3070 3071 3072
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkColumnTableType, pNode->tableType);
  }
X
Xiaoyu Wang 已提交
3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090
  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 已提交
3091 3092 3093 3094 3095 3096
  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 已提交
3097 3098 3099 3100

  return code;
}

X
Xiaoyu Wang 已提交
3101 3102 3103 3104 3105 3106 3107
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 已提交
3108 3109 3110
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkColumnTableType, &pNode->tableType);
  }
X
Xiaoyu Wang 已提交
3111 3112 3113 3114
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetSmallIntValue(pJson, jkColumnColId, &pNode->colId);
  }
  if (TSDB_CODE_SUCCESS == code) {
3115
    tjsonGetNumberValue(pJson, jkColumnColType, pNode->colType, code);
X
Xiaoyu Wang 已提交
3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138
  }
  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;
}

3139
static const char* jkValueLiteralSize = "LiteralSize";
X
Xiaoyu Wang 已提交
3140 3141
static const char* jkValueLiteral = "Literal";
static const char* jkValueDuration = "Duration";
3142
static const char* jkValueTranslate = "Translate";
5
54liuyao 已提交
3143
static const char* jkValueNotReserved = "NotReserved";
3144
static const char* jkValueIsNull = "IsNull";
X
Xiaoyu Wang 已提交
3145
static const char* jkValueUnit = "Unit";
X
Xiaoyu Wang 已提交
3146 3147
static const char* jkValueDatum = "Datum";

3148
static int32_t datumToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
3149 3150
  const SValueNode* pNode = (const SValueNode*)pObj;

3151
  int32_t code = TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
3152 3153 3154 3155
  switch (pNode->node.resType.type) {
    case TSDB_DATA_TYPE_NULL:
      break;
    case TSDB_DATA_TYPE_BOOL:
X
Xiaoyu Wang 已提交
3156
      code = tjsonAddBoolToObject(pJson, jkValueDatum, pNode->datum.b);
X
Xiaoyu Wang 已提交
3157 3158 3159 3160 3161 3162
      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:
3163
      code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.i);
X
Xiaoyu Wang 已提交
3164 3165 3166 3167 3168
      break;
    case TSDB_DATA_TYPE_UTINYINT:
    case TSDB_DATA_TYPE_USMALLINT:
    case TSDB_DATA_TYPE_UINT:
    case TSDB_DATA_TYPE_UBIGINT:
3169
      code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.u);
X
Xiaoyu Wang 已提交
3170 3171 3172
      break;
    case TSDB_DATA_TYPE_FLOAT:
    case TSDB_DATA_TYPE_DOUBLE:
3173
      code = tjsonAddDoubleToObject(pJson, jkValueDatum, pNode->datum.d);
X
Xiaoyu Wang 已提交
3174
      break;
3175
    case TSDB_DATA_TYPE_NCHAR: {
3176 3177
      // cJSON only support utf-8 encoding. Convert memory content to hex string.
      char* buf = taosMemoryCalloc(varDataLen(pNode->datum.p) * 2 + 1, sizeof(char));
3178
      code = taosHexEncode(varDataVal(pNode->datum.p), buf, varDataLen(pNode->datum.p));
3179
      if (code != TSDB_CODE_SUCCESS) {
3180 3181 3182 3183 3184 3185 3186
        taosMemoryFree(buf);
        return TSDB_CODE_TSC_INVALID_VALUE;
      }
      code = tjsonAddStringToObject(pJson, jkValueDatum, buf);
      taosMemoryFree(buf);
      break;
    }
X
Xiaoyu Wang 已提交
3187 3188
    case TSDB_DATA_TYPE_VARCHAR:
    case TSDB_DATA_TYPE_VARBINARY:
D
Dingle Zhang 已提交
3189
    case TSDB_DATA_TYPE_GEOMETRY:
X
Xiaoyu Wang 已提交
3190
      code = tjsonAddStringToObject(pJson, jkValueDatum, varDataVal(pNode->datum.p));
X
Xiaoyu Wang 已提交
3191
      break;
3192
    case TSDB_DATA_TYPE_JSON: {
wmmhello's avatar
wmmhello 已提交
3193
      int32_t len = getJsonValueLen(pNode->datum.p);
3194
      char*   buf = taosMemoryCalloc(len * 2 + 1, sizeof(char));
wmmhello's avatar
wmmhello 已提交
3195 3196 3197 3198 3199 3200 3201 3202 3203
      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 已提交
3204 3205 3206 3207 3208 3209 3210
    case TSDB_DATA_TYPE_DECIMAL:
    case TSDB_DATA_TYPE_BLOB:
      // todo
    default:
      break;
  }

X
Xiaoyu Wang 已提交
3211
  return code;
X
Xiaoyu Wang 已提交
3212 3213 3214 3215
}

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

X
Xiaoyu Wang 已提交
3217
  int32_t code = exprNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
3218
  if (TSDB_CODE_SUCCESS == code) {
3219
    code = tjsonAddIntegerToObject(pJson, jkValueLiteralSize, NULL != pNode->literal ? strlen(pNode->literal) : 0);
X
Xiaoyu Wang 已提交
3220
  }
3221
  if (TSDB_CODE_SUCCESS == code && NULL != pNode->literal) {
X
Xiaoyu Wang 已提交
3222
    code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->literal);
X
Xiaoyu Wang 已提交
3223 3224 3225 3226
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkValueDuration, pNode->isDuration);
  }
X
Xiaoyu Wang 已提交
3227
  if (TSDB_CODE_SUCCESS == code) {
3228 3229
    code = tjsonAddBoolToObject(pJson, jkValueTranslate, pNode->translate);
  }
5
54liuyao 已提交
3230 3231 3232
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkValueNotReserved, pNode->notReserved);
  }
3233 3234 3235
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkValueIsNull, pNode->isNull);
  }
X
Xiaoyu Wang 已提交
3236 3237 3238
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkValueUnit, pNode->unit);
  }
D
dapan1121 已提交
3239
  if (TSDB_CODE_SUCCESS == code && pNode->translate && !pNode->isNull) {
3240 3241 3242 3243 3244 3245 3246 3247 3248 3249
    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 已提交
3250 3251 3252 3253
  switch (pNode->node.resType.type) {
    case TSDB_DATA_TYPE_NULL:
      break;
    case TSDB_DATA_TYPE_BOOL:
3254
      code = tjsonGetBoolValue(pJson, jkValueDatum, &pNode->datum.b);
D
dapan1121 已提交
3255
      *(bool*)&pNode->typeData = pNode->datum.b;
X
Xiaoyu Wang 已提交
3256 3257
      break;
    case TSDB_DATA_TYPE_TINYINT:
D
dapan1121 已提交
3258 3259 3260
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int8_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
3261
    case TSDB_DATA_TYPE_SMALLINT:
D
dapan1121 已提交
3262 3263 3264
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int16_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
3265
    case TSDB_DATA_TYPE_INT:
D
dapan1121 已提交
3266 3267 3268
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int32_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
3269
    case TSDB_DATA_TYPE_BIGINT:
D
dapan1121 已提交
3270 3271 3272
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
      *(int64_t*)&pNode->typeData = pNode->datum.i;
      break;
X
Xiaoyu Wang 已提交
3273
    case TSDB_DATA_TYPE_TIMESTAMP:
3274
      code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i);
D
dapan1121 已提交
3275
      *(int64_t*)&pNode->typeData = pNode->datum.i;
X
Xiaoyu Wang 已提交
3276 3277
      break;
    case TSDB_DATA_TYPE_UTINYINT:
D
dapan1121 已提交
3278 3279 3280
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
      *(uint8_t*)&pNode->typeData = pNode->datum.u;
      break;
X
Xiaoyu Wang 已提交
3281
    case TSDB_DATA_TYPE_USMALLINT:
D
dapan1121 已提交
3282 3283 3284
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
      *(uint16_t*)&pNode->typeData = pNode->datum.u;
      break;
X
Xiaoyu Wang 已提交
3285
    case TSDB_DATA_TYPE_UINT:
D
dapan1121 已提交
3286 3287 3288
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
      *(uint32_t*)&pNode->typeData = pNode->datum.u;
      break;
X
Xiaoyu Wang 已提交
3289
    case TSDB_DATA_TYPE_UBIGINT:
3290
      code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u);
D
dapan1121 已提交
3291
      *(uint64_t*)&pNode->typeData = pNode->datum.u;
X
Xiaoyu Wang 已提交
3292 3293
      break;
    case TSDB_DATA_TYPE_FLOAT:
D
dapan1121 已提交
3294 3295 3296
      code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d);
      *(float*)&pNode->typeData = pNode->datum.d;
      break;
X
Xiaoyu Wang 已提交
3297
    case TSDB_DATA_TYPE_DOUBLE:
3298
      code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d);
D
dapan1121 已提交
3299
      *(double*)&pNode->typeData = pNode->datum.d;
X
Xiaoyu Wang 已提交
3300 3301 3302
      break;
    case TSDB_DATA_TYPE_NCHAR:
    case TSDB_DATA_TYPE_VARCHAR:
D
Dingle Zhang 已提交
3303 3304
    case TSDB_DATA_TYPE_VARBINARY:
    case TSDB_DATA_TYPE_GEOMETRY: {
3305
      pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + 1);
X
Xiaoyu Wang 已提交
3306 3307 3308 3309
      if (NULL == pNode->datum.p) {
        code = TSDB_CODE_OUT_OF_MEMORY;
        break;
      }
D
dapan1121 已提交
3310
      varDataSetLen(pNode->datum.p, pNode->node.resType.bytes - VARSTR_HEADER_SIZE);
3311
      if (TSDB_DATA_TYPE_NCHAR == pNode->node.resType.type) {
3312
        char* buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + VARSTR_HEADER_SIZE + 1);
3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330
        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 已提交
3331
      break;
X
Xiaoyu Wang 已提交
3332
    }
3333
    case TSDB_DATA_TYPE_JSON: {
wmmhello's avatar
wmmhello 已提交
3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356
      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 已提交
3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370
    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);
3371
  int32_t literalSize = 0;
X
Xiaoyu Wang 已提交
3372
  if (TSDB_CODE_SUCCESS == code) {
3373
    code = tjsonGetIntValue(pJson, jkValueLiteralSize, &literalSize);
X
Xiaoyu Wang 已提交
3374
  }
3375
  if (TSDB_CODE_SUCCESS == code && literalSize > 0) {
X
Xiaoyu Wang 已提交
3376 3377 3378 3379 3380
    code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->literal);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkValueDuration, &pNode->isDuration);
  }
X
Xiaoyu Wang 已提交
3381
  if (TSDB_CODE_SUCCESS == code) {
3382 3383
    code = tjsonGetBoolValue(pJson, jkValueTranslate, &pNode->translate);
  }
5
54liuyao 已提交
3384 3385 3386
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkValueNotReserved, &pNode->notReserved);
  }
3387 3388 3389
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkValueIsNull, &pNode->isNull);
  }
X
Xiaoyu Wang 已提交
3390 3391 3392
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkValueUnit, &pNode->unit);
  }
D
dapan1121 已提交
3393
  if (TSDB_CODE_SUCCESS == code && pNode->translate && !pNode->isNull) {
3394
    code = jsonToDatum(pJson, pNode);
X
Xiaoyu Wang 已提交
3395 3396 3397 3398 3399
  }

  return code;
}

X
Xiaoyu Wang 已提交
3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420
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 已提交
3421 3422 3423 3424 3425
static int32_t jsonToOperatorNode(const SJson* pJson, void* pObj) {
  SOperatorNode* pNode = (SOperatorNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
3426
    tjsonGetNumberValue(pJson, jkOperatorType, pNode->opType, code);
X
Xiaoyu Wang 已提交
3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437
  }
  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 已提交
3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448
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 已提交
3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459
    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) {
3460
    tjsonGetNumberValue(pJson, jkLogicCondType, pNode->condType, code);
X
Xiaoyu Wang 已提交
3461 3462 3463
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkLogicCondParameters, &pNode->pParameterList);
X
Xiaoyu Wang 已提交
3464 3465 3466 3467 3468 3469 3470 3471 3472
  }

  return code;
}

static const char* jkFunctionName = "Name";
static const char* jkFunctionId = "Id";
static const char* jkFunctionType = "Type";
static const char* jkFunctionParameter = "Parameters";
S
slzhou 已提交
3473
static const char* jkFunctionUdfBufSize = "UdfBufSize";
X
Xiaoyu Wang 已提交
3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488

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 已提交
3489 3490
    code = nodeListToJson(pJson, jkFunctionParameter, pNode->pParameterList);
  }
S
slzhou 已提交
3491 3492 3493
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkFunctionUdfBufSize, pNode->udfBufSize);
  }
X
Xiaoyu Wang 已提交
3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512

  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 已提交
3513
  }
S
slzhou 已提交
3514 3515 3516
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkFunctionUdfBufSize, &pNode->udfBufSize);
  }
X
Xiaoyu Wang 已提交
3517 3518 3519 3520

  return code;
}

X
Xiaoyu Wang 已提交
3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558
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 已提交
3559 3560 3561 3562 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 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632
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 已提交
3633 3634 3635 3636
static const char* jkRealTableMetaSize = "MetaSize";
static const char* jkRealTableMeta = "Meta";
static const char* jkRealTableVgroupsInfoSize = "VgroupsInfoSize";
static const char* jkRealTableVgroupsInfo = "VgroupsInfo";
X
Xiaoyu Wang 已提交
3637
static const char* jkRealTableSmaIndexes = "SmaIndexes";
X
Xiaoyu Wang 已提交
3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654

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 已提交
3655 3656 3657
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddTArray(pJson, jkRealTableSmaIndexes, tableIndexInfoToJson, pNode->pSmaIndexes);
  }
X
Xiaoyu Wang 已提交
3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678

  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 已提交
3679 3680 3681 3682
  if (TSDB_CODE_SUCCESS == code) {
    code =
        tjsonToTArray(pJson, jkRealTableSmaIndexes, jsonToTableIndexInfo, &pNode->pSmaIndexes, sizeof(STableIndexInfo));
  }
X
Xiaoyu Wang 已提交
3683 3684 3685 3686

  return code;
}

3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710
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 已提交
3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755
static const char* jkJoinTableJoinType = "JoinType";
static const char* jkJoinTableLeft = "Left";
static const char* jkJoinTableRight = "Right";
static const char* jkJoinTableOnCond = "OnCond";

static int32_t joinTableNodeToJson(const void* pObj, SJson* pJson) {
  const SJoinTableNode* pNode = (const SJoinTableNode*)pObj;

  int32_t code = tableNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkJoinTableJoinType, pNode->joinType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinTableLeft, nodeToJson, pNode->pLeft);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinTableRight, nodeToJson, pNode->pRight);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkJoinTableOnCond, nodeToJson, pNode->pOnCond);
  }

  return code;
}

static int32_t jsonToJoinTableNode(const SJson* pJson, void* pObj) {
  SJoinTableNode* pNode = (SJoinTableNode*)pObj;

  int32_t code = jsonToTableNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkJoinTableJoinType, pNode->joinType, code);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinTableLeft, &pNode->pLeft);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinTableRight, &pNode->pRight);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkJoinTableOnCond, &pNode->pOnCond);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3756 3757 3758 3759 3760 3761 3762 3763
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 已提交
3764
    code = nodeListToJson(pJson, jkGroupingSetParameter, pNode->pParameterList);
X
Xiaoyu Wang 已提交
3765 3766 3767 3768 3769
  }

  return code;
}

3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781
static int32_t jsonToGroupingSetNode(const SJson* pJson, void* pObj) {
  SGroupingSetNode* pNode = (SGroupingSetNode*)pObj;

  int32_t code = TSDB_CODE_SUCCESS;
  tjsonGetNumberValue(pJson, jkGroupingSetType, pNode->groupingSetType, code);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkGroupingSetParameter, &pNode->pParameterList);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804
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) {
3805
    tjsonGetNumberValue(pJson, jkOrderByExprOrder, pNode->order, code);
X
Xiaoyu Wang 已提交
3806 3807
  }
  if (TSDB_CODE_SUCCESS == code) {
3808
    tjsonGetNumberValue(pJson, jkOrderByExprNullOrder, pNode->nullOrder, code);
X
Xiaoyu Wang 已提交
3809 3810 3811 3812 3813
  }

  return code;
}

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
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 已提交
3839 3840 3841 3842 3843
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 已提交
3844
  int32_t                 code = tjsonAddObject(pJson, jkStateWindowCol, nodeToJson, pNode->pCol);
5
54liuyao 已提交
3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860
  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 已提交
3861 3862 3863 3864
static const char* jkSessionWindowTsPrimaryKey = "TsPrimaryKey";
static const char* jkSessionWindowGap = "Gap";

static int32_t sessionWindowNodeToJson(const void* pObj, SJson* pJson) {
3865
  const SSessionWindowNode* pNode = (const SSessionWindowNode*)pObj;
5
54liuyao 已提交
3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876

  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;

3877
  int32_t code = jsonToNodeObject(pJson, jkSessionWindowTsPrimaryKey, (SNode**)&pNode->pCol);
5
54liuyao 已提交
3878
  if (TSDB_CODE_SUCCESS == code) {
3879
    code = jsonToNodeObject(pJson, jkSessionWindowGap, (SNode**)&pNode->pGap);
5
54liuyao 已提交
3880 3881 3882 3883
  }
  return code;
}

X
Xiaoyu Wang 已提交
3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913
static const char* jkEventWindowTsPrimaryKey = "TsPrimaryKey";
static const char* jkEventWindowStartCond = "StartCond";
static const char* jkEventWindowEndCond = "EndCond";

static int32_t eventWindowNodeToJson(const void* pObj, SJson* pJson) {
  const SEventWindowNode* pNode = (const SEventWindowNode*)pObj;

  int32_t code = tjsonAddObject(pJson, jkEventWindowTsPrimaryKey, nodeToJson, pNode->pCol);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkEventWindowStartCond, nodeToJson, pNode->pStartCond);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkEventWindowEndCond, nodeToJson, pNode->pEndCond);
  }
  return code;
}

static int32_t jsonToEventWindowNode(const SJson* pJson, void* pObj) {
  SEventWindowNode* pNode = (SEventWindowNode*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkEventWindowTsPrimaryKey, &pNode->pCol);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkEventWindowStartCond, &pNode->pStartCond);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkEventWindowEndCond, &pNode->pEndCond);
  }
  return code;
}

X
bugfix  
Xiaoyu Wang 已提交
3914 3915 3916 3917
static const char* jkIntervalWindowInterval = "Interval";
static const char* jkIntervalWindowOffset = "Offset";
static const char* jkIntervalWindowSliding = "Sliding";
static const char* jkIntervalWindowFill = "Fill";
X
bugfix  
Xiaoyu Wang 已提交
3918
static const char* jkIntervalWindowTsPk = "TsPk";
X
bugfix  
Xiaoyu Wang 已提交
3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932

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 已提交
3933 3934 3935
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIntervalWindowTsPk, nodeToJson, pNode->pCol);
  }
X
bugfix  
Xiaoyu Wang 已提交
3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952

  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 已提交
3953 3954 3955
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIntervalWindowTsPk, &pNode->pCol);
  }
X
bugfix  
Xiaoyu Wang 已提交
3956 3957 3958 3959

  return code;
}

X
Xiaoyu Wang 已提交
3960 3961 3962 3963 3964 3965
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;

3966
  int32_t code = tjsonAddObject(pJson, jkNodeListDataType, dataTypeToJson, &pNode->node.resType);
X
Xiaoyu Wang 已提交
3967 3968 3969 3970 3971 3972 3973 3974 3975 3976
  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;

3977
  int32_t code = tjsonToObject(pJson, jkNodeListDataType, jsonToDataType, &pNode->node.resType);
X
Xiaoyu Wang 已提交
3978 3979 3980 3981 3982 3983 3984
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkNodeListNodeList, &pNode->pNodeList);
  }

  return code;
}

X
Xiaoyu Wang 已提交
3985 3986
static const char* jkFillMode = "Mode";
static const char* jkFillValues = "Values";
X
Xiaoyu Wang 已提交
3987
static const char* jkFillWStartTs = "WStartTs";
X
Xiaoyu Wang 已提交
3988 3989
static const char* jkFillStartTime = "StartTime";
static const char* jkFillEndTime = "EndTime";
X
Xiaoyu Wang 已提交
3990 3991 3992 3993 3994 3995 3996 3997

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 已提交
3998 3999 4000
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkFillWStartTs, nodeToJson, pNode->pWStartTs);
  }
X
Xiaoyu Wang 已提交
4001 4002 4003 4004 4005 4006
  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 已提交
4007 4008 4009 4010 4011 4012 4013

  return code;
}

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

4014
  int32_t code;
4015
  tjsonGetNumberValue(pJson, jkFillMode, pNode->mode, code);
X
Xiaoyu Wang 已提交
4016 4017 4018
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillValues, &pNode->pValues);
  }
X
Xiaoyu Wang 已提交
4019 4020 4021
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkFillWStartTs, &pNode->pWStartTs);
  }
X
Xiaoyu Wang 已提交
4022 4023 4024 4025 4026 4027
  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 已提交
4028 4029 4030 4031

  return code;
}

X
Xiaoyu Wang 已提交
4032
static const char* jkTargetDataBlockId = "DataBlockId";
X
Xiaoyu Wang 已提交
4033 4034 4035 4036 4037 4038
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 已提交
4039
  int32_t code = tjsonAddIntegerToObject(pJson, jkTargetDataBlockId, pNode->dataBlockId);
X
Xiaoyu Wang 已提交
4040 4041 4042 4043 4044 4045 4046 4047 4048 4049
  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 已提交
4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063
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 已提交
4064 4065
static const char* jkSlotDescSlotId = "SlotId";
static const char* jkSlotDescDataType = "DataType";
X
Xiaoyu Wang 已提交
4066 4067
static const char* jkSlotDescReserve = "Reserve";
static const char* jkSlotDescOutput = "Output";
4068
static const char* jkSlotDescName = "Name";
X
Xiaoyu Wang 已提交
4069 4070 4071 4072 4073 4074 4075 4076

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 已提交
4077
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4078
    code = tjsonAddBoolToObject(pJson, jkSlotDescReserve, pNode->reserve);
X
Xiaoyu Wang 已提交
4079 4080
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4081 4082
    code = tjsonAddBoolToObject(pJson, jkSlotDescOutput, pNode->output);
  }
4083 4084 4085
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSlotDescName, pNode->name);
  }
X
Xiaoyu Wang 已提交
4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101

  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 已提交
4102
  }
4103 4104 4105
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSlotDescName, pNode->name);
  }
X
Xiaoyu Wang 已提交
4106 4107 4108 4109

  return code;
}

X
Xiaoyu Wang 已提交
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
static const char* jkColumnDefColName = "ColName";
static const char* jkColumnDefDataType = "DataType";
static const char* jkColumnDefComments = "Comments";
static const char* jkColumnDefSma = "Sma";

static int32_t columnDefNodeToJson(const void* pObj, SJson* pJson) {
  const SColumnDefNode* pNode = (const SColumnDefNode*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkColumnDefColName, pNode->colName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkColumnDefDataType, dataTypeToJson, &pNode->dataType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkColumnDefComments, pNode->comments);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkColumnDefSma, pNode->sma);
  }

  return code;
}

static int32_t jsonToColumnDefNode(const SJson* pJson, void* pObj) {
  SColumnDefNode* pNode = (SColumnDefNode*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkColumnDefColName, pNode->colName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonToObject(pJson, jkColumnDefDataType, jsonToDataType, &pNode->dataType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkColumnDefComments, pNode->comments);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkColumnDefSma, &pNode->sma);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4149 4150 4151
static const char* jkDownstreamSourceAddr = "Addr";
static const char* jkDownstreamSourceTaskId = "TaskId";
static const char* jkDownstreamSourceSchedId = "SchedId";
D
dapan1121 已提交
4152
static const char* jkDownstreamSourceExecId = "ExecId";
D
dapan1121 已提交
4153
static const char* jkDownstreamSourceFetchMsgType = "FetchMsgType";
X
Xiaoyu Wang 已提交
4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164

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 已提交
4165
  if (TSDB_CODE_SUCCESS == code) {
D
dapan1121 已提交
4166
    code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceExecId, pNode->execId);
D
dapan1121 已提交
4167
  }
D
dapan1121 已提交
4168 4169 4170
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceFetchMsgType, pNode->fetchMsgType);
  }
X
Xiaoyu Wang 已提交
4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184

  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 已提交
4185
  if (TSDB_CODE_SUCCESS == code) {
D
dapan1121 已提交
4186
    code = tjsonGetIntValue(pJson, jkDownstreamSourceExecId, &pNode->execId);
D
dapan1121 已提交
4187
  }
D
dapan1121 已提交
4188 4189 4190
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDownstreamSourceFetchMsgType, &pNode->fetchMsgType);
  }
X
Xiaoyu Wang 已提交
4191 4192 4193 4194

  return code;
}

4195
static const char* jkDatabaseOptionsBuffer = "Buffer";
4196
static const char* jkDatabaseOptionsCacheModel = "CacheModel";
4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219
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) {
4220
    code = tjsonAddIntegerToObject(pJson, jkDatabaseOptionsCacheModel, pNode->cacheModel);
4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281
  }
  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) {
4282
    code = tjsonGetTinyIntValue(pJson, jkDatabaseOptionsCacheModel, &pNode->cacheModel);
4283 4284 4285 4286 4287 4288 4289 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 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338
  }
  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 已提交
4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398
static const char* jkTableOptionsComment = "Comment";
static const char* jkTableOptionsMaxDelay = "MaxDelay";
static const char* jkTableOptionsWatermark = "Watermark";
static const char* jkTableOptionsDeleteMark = "DeleteMark";
static const char* jkTableOptionsRollupFuncs = "RollupFuncs";
static const char* jkTableOptionsTtl = "Ttl";
static const char* jkTableOptionsSma = "Sma";

static int32_t tableOptionsToJson(const void* pObj, SJson* pJson) {
  const STableOptions* pNode = (const STableOptions*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkTableOptionsComment, pNode->comment);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkTableOptionsMaxDelay, pNode->pMaxDelay);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkTableOptionsWatermark, pNode->pWatermark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkTableOptionsDeleteMark, pNode->pDeleteMark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkTableOptionsRollupFuncs, pNode->pRollupFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTableOptionsTtl, pNode->ttl);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkTableOptionsSma, pNode->pSma);
  }

  return code;
}

static int32_t jsonToTableOptions(const SJson* pJson, void* pObj) {
  STableOptions* pNode = (STableOptions*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkTableOptionsComment, pNode->comment);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableOptionsMaxDelay, &pNode->pMaxDelay);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableOptionsWatermark, &pNode->pWatermark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableOptionsDeleteMark, &pNode->pDeleteMark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableOptionsRollupFuncs, &pNode->pRollupFuncs);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkTableOptionsTtl, &pNode->ttl);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkTableOptionsSma, &pNode->pSma);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469
static const char* jkIndexOptionsFuncs = "Funcs";
static const char* jkIndexOptionsInterval = "Interval";
static const char* jkIndexOptionsOffset = "Offset";
static const char* jkIndexOptionsSliding = "Sliding";
static const char* jkIndexOptionsStreamOptions = "StreamOptions";

static int32_t indexOptionsToJson(const void* pObj, SJson* pJson) {
  const SIndexOptions* pNode = (const SIndexOptions*)pObj;

  int32_t code = nodeListToJson(pJson, jkIndexOptionsFuncs, pNode->pFuncs);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIndexOptionsInterval, nodeToJson, pNode->pInterval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIndexOptionsOffset, nodeToJson, pNode->pOffset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIndexOptionsSliding, nodeToJson, pNode->pSliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkIndexOptionsStreamOptions, nodeToJson, pNode->pStreamOptions);
  }

  return code;
}

static int32_t jsonToIndexOptions(const SJson* pJson, void* pObj) {
  SIndexOptions* pNode = (SIndexOptions*)pObj;

  int32_t code = jsonToNodeList(pJson, jkIndexOptionsFuncs, &pNode->pFuncs);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIndexOptionsInterval, &pNode->pInterval);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIndexOptionsOffset, &pNode->pOffset);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIndexOptionsSliding, &pNode->pSliding);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkIndexOptionsStreamOptions, &pNode->pStreamOptions);
  }

  return code;
}

static const char* jkExplainOptionsVerbose = "Verbose";
static const char* jkExplainOptionsRatio = "Ratio";

static int32_t explainOptionsToJson(const void* pObj, SJson* pJson) {
  const SExplainOptions* pNode = (const SExplainOptions*)pObj;

  int32_t code = tjsonAddBoolToObject(pJson, jkExplainOptionsVerbose, pNode->verbose);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddDoubleToObject(pJson, jkExplainOptionsRatio, pNode->ratio);
  }

  return code;
}

static int32_t jsonToExplainOptions(const SJson* pJson, void* pObj) {
  SExplainOptions* pNode = (SExplainOptions*)pObj;

  int32_t code = tjsonGetBoolValue(pJson, jkExplainOptionsVerbose, &pNode->verbose);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetDoubleValue(pJson, jkExplainOptionsRatio, &pNode->ratio);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522
static const char* jkStreamOptionsTriggerType = "TriggerType";
static const char* jkStreamOptionsDelay = "Delay";
static const char* jkStreamOptionsWatermark = "Watermark";
static const char* jkStreamOptionsDeleteMark = "DeleteMark";
static const char* jkStreamOptionsFillHistory = "FillHistory";
static const char* jkStreamOptionsIgnoreExpired = "IgnoreExpired";

static int32_t streamOptionsToJson(const void* pObj, SJson* pJson) {
  const SStreamOptions* pNode = (const SStreamOptions*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkStreamOptionsTriggerType, pNode->triggerType);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkStreamOptionsDelay, nodeToJson, pNode->pDelay);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkStreamOptionsWatermark, nodeToJson, pNode->pWatermark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkStreamOptionsDeleteMark, nodeToJson, pNode->pDeleteMark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkStreamOptionsFillHistory, pNode->fillHistory);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkStreamOptionsIgnoreExpired, pNode->ignoreExpired);
  }

  return code;
}

static int32_t jsonToStreamOptions(const SJson* pJson, void* pObj) {
  SStreamOptions* pNode = (SStreamOptions*)pObj;

  int32_t code = tjsonGetTinyIntValue(pJson, jkStreamOptionsTriggerType, &pNode->triggerType);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkStreamOptionsDelay, &pNode->pDelay);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkStreamOptionsWatermark, &pNode->pWatermark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkStreamOptionsDeleteMark, &pNode->pDeleteMark);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkStreamOptionsFillHistory, &pNode->fillHistory);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkStreamOptionsIgnoreExpired, &pNode->ignoreExpired);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591
static const char* jkWhenThenWhen = "When";
static const char* jkWhenThenThen = "Then";

static int32_t whenThenNodeToJson(const void* pObj, SJson* pJson) {
  const SWhenThenNode* pNode = (const SWhenThenNode*)pObj;

  int32_t code = exprNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWhenThenWhen, nodeToJson, pNode->pWhen);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkWhenThenThen, nodeToJson, pNode->pThen);
  }

  return code;
}

static int32_t jsonToWhenThenNode(const SJson* pJson, void* pObj) {
  SWhenThenNode* pNode = (SWhenThenNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWhenThenWhen, &pNode->pWhen);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkWhenThenThen, &pNode->pThen);
  }

  return code;
}

static const char* jkCaseWhenCase = "Case";
static const char* jkCaseWhenWhenThenList = "WhenThenList";
static const char* jkCaseWhenElse = "Else";

static int32_t caseWhenNodeToJson(const void* pObj, SJson* pJson) {
  const SCaseWhenNode* pNode = (const SCaseWhenNode*)pObj;

  int32_t code = exprNodeToJson(pObj, pJson);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCaseWhenCase, nodeToJson, pNode->pCase);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkCaseWhenWhenThenList, pNode->pWhenThenList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCaseWhenElse, nodeToJson, pNode->pElse);
  }

  return code;
}

static int32_t jsonToCaseWhenNode(const SJson* pJson, void* pObj) {
  SCaseWhenNode* pNode = (SCaseWhenNode*)pObj;

  int32_t code = jsonToExprNode(pJson, pObj);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCaseWhenCase, &pNode->pCase);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkCaseWhenWhenThenList, &pNode->pWhenThenList);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCaseWhenElse, &pNode->pElse);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4592 4593
static const char* jkDataBlockDescDataBlockId = "DataBlockId";
static const char* jkDataBlockDescSlots = "Slots";
4594 4595 4596
static const char* jkDataBlockTotalRowSize = "TotalRowSize";
static const char* jkDataBlockOutputRowSize = "OutputRowSize";
static const char* jkDataBlockPrecision = "Precision";
X
Xiaoyu Wang 已提交
4597

X
Xiaoyu Wang 已提交
4598 4599
static int32_t dataBlockDescNodeToJson(const void* pObj, SJson* pJson) {
  const SDataBlockDescNode* pNode = (const SDataBlockDescNode*)pObj;
X
Xiaoyu Wang 已提交
4600

X
Xiaoyu Wang 已提交
4601
  int32_t code = tjsonAddIntegerToObject(pJson, jkDataBlockDescDataBlockId, pNode->dataBlockId);
4602
  if (TSDB_CODE_SUCCESS == code) {
4603 4604 4605 4606
    code = tjsonAddIntegerToObject(pJson, jkDataBlockTotalRowSize, pNode->totalRowSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDataBlockOutputRowSize, pNode->outputRowSize);
4607
  }
X
Xiaoyu Wang 已提交
4608
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4609 4610
    code = nodeListToJson(pJson, jkDataBlockDescSlots, pNode->pSlots);
  }
4611 4612 4613
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDataBlockPrecision, pNode->precision);
  }
X
Xiaoyu Wang 已提交
4614 4615 4616 4617 4618 4619 4620 4621

  return code;
}

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

  int32_t code = tjsonGetSmallIntValue(pJson, jkDataBlockDescDataBlockId, &pNode->dataBlockId);
4622
  if (TSDB_CODE_SUCCESS == code) {
4623 4624 4625 4626
    code = tjsonGetIntValue(pJson, jkDataBlockTotalRowSize, &pNode->totalRowSize);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDataBlockOutputRowSize, &pNode->outputRowSize);
4627
  }
X
Xiaoyu Wang 已提交
4628 4629
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkDataBlockDescSlots, &pNode->pSlots);
X
Xiaoyu Wang 已提交
4630
  }
4631
  if (TSDB_CODE_SUCCESS == code) {
4632
    code = tjsonGetUTinyIntValue(pJson, jkDataBlockPrecision, &pNode->precision);
4633
  }
X
Xiaoyu Wang 已提交
4634 4635 4636 4637

  return code;
}

4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670
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;

4671 4672
  int32_t code = TSDB_CODE_SUCCESS;
  tjsonGetNumberValue(pJson, jkSetOperatorOpType, pNode->opType, code);
4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691
  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 已提交
4692 4693 4694 4695 4696
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";
4697 4698
static const char* jkSelectStmtTags = "Tags";
static const char* jkSelectStmtSubtable = "Subtable";
X
Xiaoyu Wang 已提交
4699 4700 4701 4702 4703 4704
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 已提交
4705
static const char* jkSelectStmtStmtName = "StmtName";
X
Xiaoyu Wang 已提交
4706
static const char* jkSelectStmtHasAggFuncs = "HasAggFuncs";
X
Xiaoyu Wang 已提交
4707

4708
static int32_t selectStmtToJson(const void* pObj, SJson* pJson) {
X
Xiaoyu Wang 已提交
4709 4710
  const SSelectStmt* pNode = (const SSelectStmt*)pObj;

X
Xiaoyu Wang 已提交
4711
  int32_t code = tjsonAddBoolToObject(pJson, jkSelectStmtDistinct, pNode->isDistinct);
X
Xiaoyu Wang 已提交
4712
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4713
    code = nodeListToJson(pJson, jkSelectStmtProjections, pNode->pProjectionList);
X
Xiaoyu Wang 已提交
4714 4715 4716 4717 4718 4719 4720 4721
  }
  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 已提交
4722
    code = nodeListToJson(pJson, jkSelectStmtPartitionBy, pNode->pPartitionByList);
X
Xiaoyu Wang 已提交
4723
  }
4724 4725 4726 4727 4728 4729
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkSelectStmtTags, pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtSubtable, nodeToJson, pNode->pSubtable);
  }
X
Xiaoyu Wang 已提交
4730 4731 4732 4733
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtWindow, nodeToJson, pNode->pWindow);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4734
    code = nodeListToJson(pJson, jkSelectStmtGroupBy, pNode->pGroupByList);
X
Xiaoyu Wang 已提交
4735 4736 4737 4738 4739
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkSelectStmtHaving, nodeToJson, pNode->pHaving);
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4740
    code = nodeListToJson(pJson, jkSelectStmtOrderBy, pNode->pOrderByList);
X
Xiaoyu Wang 已提交
4741 4742 4743 4744 4745 4746 4747
  }
  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 已提交
4748 4749 4750
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName);
  }
X
Xiaoyu Wang 已提交
4751 4752 4753
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkSelectStmtHasAggFuncs, pNode->hasAggFuncs);
  }
X
Xiaoyu Wang 已提交
4754 4755 4756 4757

  return code;
}

X
Xiaoyu Wang 已提交
4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773
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);
  }
4774 4775 4776 4777 4778 4779
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkSelectStmtTags, &pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkSelectStmtSubtable, &pNode->pSubtable);
  }
X
Xiaoyu Wang 已提交
4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792
  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 已提交
4793
    code = jsonToNodeObject(pJson, jkSelectStmtLimit, (SNode**)&pNode->pLimit);
X
Xiaoyu Wang 已提交
4794 4795
  }
  if (TSDB_CODE_SUCCESS == code) {
X
Xiaoyu Wang 已提交
4796
    code = jsonToNodeObject(pJson, jkSelectStmtSlimit, (SNode**)&pNode->pSlimit);
X
Xiaoyu Wang 已提交
4797
  }
X
bugfix  
Xiaoyu Wang 已提交
4798 4799 4800
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName);
  }
X
Xiaoyu Wang 已提交
4801 4802 4803
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkSelectStmtHasAggFuncs, &pNode->hasAggFuncs);
  }
X
Xiaoyu Wang 已提交
4804 4805 4806 4807

  return code;
}

X
Xiaoyu Wang 已提交
4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840
static const char* jkVnodeModifyOpStmtSqlNodeType = "SqlNodeType";
static const char* jkVnodeModifyOpStmtTotalRowsNum = "TotalRowsNum";
static const char* jkVnodeModifyOpStmtTotalTbNum = "TotalTbNum";

static int32_t vnodeModifyStmtToJson(const void* pObj, SJson* pJson) {
  const SVnodeModifyOpStmt* pNode = (const SVnodeModifyOpStmt*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkVnodeModifyOpStmtSqlNodeType, pNode->sqlNodeType);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkVnodeModifyOpStmtTotalRowsNum, pNode->totalRowsNum);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkVnodeModifyOpStmtTotalTbNum, pNode->totalTbNum);
  }

  return code;
}

static int32_t jsonToVnodeModifyStmt(const SJson* pJson, void* pObj) {
  SVnodeModifyOpStmt* pNode = (SVnodeModifyOpStmt*)pObj;

  int32_t code = TSDB_CODE_SUCCESS;
  tjsonGetNumberValue(pJson, jkVnodeModifyOpStmtSqlNodeType, pNode->sqlNodeType, code);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkVnodeModifyOpStmtTotalRowsNum, &pNode->totalRowsNum);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkVnodeModifyOpStmtTotalTbNum, &pNode->totalTbNum);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872
static const char* jkCreateDatabaseStmtDbName = "DbName";
static const char* jkCreateDatabaseStmtIgnoreExists = "IgnoreExists";
static const char* jkCreateDatabaseStmtOptions = "Options";

static int32_t createDatabaseStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateDatabaseStmt* pNode = (const SCreateDatabaseStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkCreateDatabaseStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkCreateDatabaseStmtIgnoreExists, pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateDatabaseStmtOptions, nodeToJson, pNode->pOptions);
  }

  return code;
}

static int32_t jsonToCreateDatabaseStmt(const SJson* pJson, void* pObj) {
  SCreateDatabaseStmt* pNode = (SCreateDatabaseStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkCreateDatabaseStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkCreateDatabaseStmtIgnoreExists, &pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateDatabaseStmtOptions, (SNode**)&pNode->pOptions);
  }

  return code;
}

4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897
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;
}

X
Xiaoyu Wang 已提交
4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922
static const char* jkTrimDatabaseStmtDbName = "DbName";
static const char* jkTrimDatabaseStmtMaxSpeed = "MaxSpeed";

static int32_t trimDatabaseStmtToJson(const void* pObj, SJson* pJson) {
  const STrimDatabaseStmt* pNode = (const STrimDatabaseStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkTrimDatabaseStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkTrimDatabaseStmtMaxSpeed, pNode->maxSpeed);
  }

  return code;
}

static int32_t jsonToTrimDatabaseStmt(const SJson* pJson, void* pObj) {
  STrimDatabaseStmt* pNode = (STrimDatabaseStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkTrimDatabaseStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkTrimDatabaseStmtMaxSpeed, &pNode->maxSpeed);
  }

  return code;
}

X
Xiaoyu Wang 已提交
4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054
static const char* jkCreateTableStmtDbName = "DbName";
static const char* jkCreateTableStmtTableName = "TableName";
static const char* jkCreateTableStmtIgnoreExists = "IgnoreExists";
static const char* jkCreateTableStmtCols = "Cols";
static const char* jkCreateTableStmtTags = "Tags";
static const char* jkCreateTableStmtOptions = "Options";

static int32_t createTableStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateTableStmt* pNode = (const SCreateTableStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkCreateTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateTableStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkCreateTableStmtIgnoreExists, pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkCreateTableStmtCols, pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkCreateTableStmtTags, pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateTableStmtOptions, nodeToJson, pNode->pOptions);
  }

  return code;
}

static int32_t jsonToCreateTableStmt(const SJson* pJson, void* pObj) {
  SCreateTableStmt* pNode = (SCreateTableStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkCreateTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateTableStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkCreateTableStmtIgnoreExists, &pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkCreateTableStmtCols, &pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkCreateTableStmtTags, &pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateTableStmtOptions, (SNode**)&pNode->pOptions);
  }

  return code;
}

static const char* jkCreateSubTableClauseDbName = "DbName";
static const char* jkCreateSubTableClauseTableName = "TableName";
static const char* jkCreateSubTableClauseUseDbName = "UseDbName";
static const char* jkCreateSubTableClauseUseTableName = "UseTableName";
static const char* jkCreateSubTableClauseIgnoreExists = "IgnoreExists";
static const char* jkCreateSubTableClauseSpecificTags = "SpecificTags";
static const char* jkCreateSubTableClauseValsOfTags = "ValsOfTags";
static const char* jkCreateSubTableClauseOptions = "Options";

static int32_t createSubTableClauseToJson(const void* pObj, SJson* pJson) {
  const SCreateSubTableClause* pNode = (const SCreateSubTableClause*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkCreateSubTableClauseDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateSubTableClauseTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateSubTableClauseUseDbName, pNode->useDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateSubTableClauseUseTableName, pNode->useTableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkCreateSubTableClauseIgnoreExists, pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkCreateSubTableClauseSpecificTags, pNode->pSpecificTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkCreateSubTableClauseValsOfTags, pNode->pValsOfTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateSubTableClauseOptions, nodeToJson, pNode->pOptions);
  }

  return code;
}

static int32_t jsonToCreateSubTableClause(const SJson* pJson, void* pObj) {
  SCreateSubTableClause* pNode = (SCreateSubTableClause*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkCreateSubTableClauseDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateSubTableClauseTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateSubTableClauseUseDbName, pNode->useDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateSubTableClauseUseTableName, pNode->useTableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkCreateSubTableClauseIgnoreExists, &pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkCreateSubTableClauseSpecificTags, &pNode->pSpecificTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkCreateSubTableClauseValsOfTags, &pNode->pValsOfTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateSubTableClauseOptions, (SNode**)&pNode->pOptions);
  }

  return code;
}

static const char* jkCreateMultiTablesStmtSubTables = "SubTables";

static int32_t createMultiTablesStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateMultiTablesStmt* pNode = (const SCreateMultiTablesStmt*)pObj;
  return nodeListToJson(pJson, jkCreateMultiTablesStmtSubTables, pNode->pSubTables);
}

static int32_t jsonToCreateMultiTablesStmt(const SJson* pJson, void* pObj) {
  SCreateMultiTablesStmt* pNode = (SCreateMultiTablesStmt*)pObj;
  return jsonToNodeList(pJson, jkCreateMultiTablesStmtSubTables, &pNode->pSubTables);
}

X
Xiaoyu Wang 已提交
5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130
static const char* jkDropTableClauseDbName = "DbName";
static const char* jkDropTableClauseTableName = "TableName";
static const char* jkDropTableClauseIgnoreNotExists = "IgnoreNotExists";

static int32_t dropTableClauseToJson(const void* pObj, SJson* pJson) {
  const SDropTableClause* pNode = (const SDropTableClause*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkDropTableClauseDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDropTableClauseTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDropTableClauseIgnoreNotExists, pNode->ignoreNotExists);
  }

  return code;
}

static int32_t jsonToDropTableClause(const SJson* pJson, void* pObj) {
  SDropTableClause* pNode = (SDropTableClause*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkDropTableClauseDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDropTableClauseTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDropTableClauseIgnoreNotExists, &pNode->ignoreNotExists);
  }

  return code;
}

static const char* jkDropTableStmtTables = "Tables";

static int32_t dropTableStmtToJson(const void* pObj, SJson* pJson) {
  const SDropTableStmt* pNode = (const SDropTableStmt*)pObj;
  return nodeListToJson(pJson, jkDropTableStmtTables, pNode->pTables);
}

static int32_t jsonToDropTableStmt(const SJson* pJson, void* pObj) {
  SDropTableStmt* pNode = (SDropTableStmt*)pObj;
  return jsonToNodeList(pJson, jkDropTableStmtTables, &pNode->pTables);
}

static const char* jkDropSuperTableStmtDbName = "DbName";
static const char* jkDropSuperTableStmtTableName = "TableName";
static const char* jkDropSuperTableStmtIgnoreNotExists = "IgnoreNotExists";

static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) {
  const SDropSuperTableStmt* pNode = (const SDropSuperTableStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkDropSuperTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDropSuperTableStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtIgnoreNotExists, pNode->ignoreNotExists);
  }

  return code;
}

static int32_t jsonToDropStableStmt(const SJson* pJson, void* pObj) {
  SDropSuperTableStmt* pNode = (SDropSuperTableStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkDropSuperTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDropSuperTableStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtIgnoreNotExists, &pNode->ignoreNotExists);
  }

  return code;
}

5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197
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;
}

X
Xiaoyu Wang 已提交
5198 5199 5200 5201
static int32_t alterStableStmtToJson(const void* pObj, SJson* pJson) { return alterTableStmtToJson(pObj, pJson); }

static int32_t jsonToAlterStableStmt(const SJson* pJson, void* pObj) { return jsonToAlterTableStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233
static const char* jkCreateUserStmtUserName = "UserName";
static const char* jkCreateUserStmtPassword = "Password";
static const char* jkCreateUserStmtSysinfo = "Sysinfo";

static int32_t createUserStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateUserStmt* pNode = (const SCreateUserStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkCreateUserStmtUserName, pNode->userName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateUserStmtPassword, pNode->password);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkCreateUserStmtSysinfo, pNode->sysinfo);
  }

  return code;
}

static int32_t jsonToCreateUserStmt(const SJson* pJson, void* pObj) {
  SCreateUserStmt* pNode = (SCreateUserStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkCreateUserStmtUserName, pNode->userName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateUserStmtPassword, pNode->password);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkCreateUserStmtSysinfo, &pNode->sysinfo);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279
static const char* jkAlterUserStmtUserName = "UserName";
static const char* jkAlterUserStmtAlterType = "AlterType";
static const char* jkAlterUserStmtPassword = "Password";
static const char* jkAlterUserStmtEnable = "Enable";
static const char* jkAlterUserStmtSysinfo = "Sysinfo";

static int32_t alterUserStmtToJson(const void* pObj, SJson* pJson) {
  const SAlterUserStmt* pNode = (const SAlterUserStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkAlterUserStmtUserName, pNode->userName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkAlterUserStmtAlterType, pNode->alterType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkAlterUserStmtPassword, pNode->password);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkAlterUserStmtEnable, pNode->enable);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkAlterUserStmtSysinfo, pNode->sysinfo);
  }

  return code;
}

static int32_t jsonToAlterUserStmt(const SJson* pJson, void* pObj) {
  SAlterUserStmt* pNode = (SAlterUserStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkAlterUserStmtUserName, pNode->userName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkAlterUserStmtAlterType, &pNode->alterType);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkAlterUserStmtPassword, pNode->password);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkAlterUserStmtEnable, &pNode->enable);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetTinyIntValue(pJson, jkAlterUserStmtSysinfo, &pNode->sysinfo);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291
static const char* jkDropUserStmtUserName = "UserName";

static int32_t dropUserStmtToJson(const void* pObj, SJson* pJson) {
  const SDropUserStmt* pNode = (const SDropUserStmt*)pObj;
  return tjsonAddStringToObject(pJson, jkDropUserStmtUserName, pNode->userName);
}

static int32_t jsonToDropUserStmt(const SJson* pJson, void* pObj) {
  SDropUserStmt* pNode = (SDropUserStmt*)pObj;
  return tjsonGetStringValue(pJson, jkDropUserStmtUserName, pNode->userName);
}

X
Xiaoyu Wang 已提交
5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303
static const char* jkUseDatabaseStmtDbName = "DbName";

static int32_t useDatabaseStmtToJson(const void* pObj, SJson* pJson) {
  const SUseDatabaseStmt* pNode = (const SUseDatabaseStmt*)pObj;
  return tjsonAddStringToObject(pJson, jkUseDatabaseStmtDbName, pNode->dbName);
}

static int32_t jsonToUseDatabaseStmt(const SJson* pJson, void* pObj) {
  SUseDatabaseStmt* pNode = (SUseDatabaseStmt*)pObj;
  return tjsonGetStringValue(pJson, jkUseDatabaseStmtDbName, pNode->dbName);
}

X
Xiaoyu Wang 已提交
5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328
static const char* jkCreateDnodeStmtFqdn = "Fqdn";
static const char* jkCreateDnodeStmtPort = "Port";

static int32_t createDnodeStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateDnodeStmt* pNode = (const SCreateDnodeStmt*)pObj;

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

  return code;
}

static int32_t jsonToCreateDnodeStmt(const SJson* pJson, void* pObj) {
  SCreateDnodeStmt* pNode = (SCreateDnodeStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkCreateDnodeStmtFqdn, pNode->fqdn);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkCreateDnodeStmtPort, &pNode->port);
  }

  return code;
}

5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360
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 已提交
5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428
static const char* jkCreateIndexStmtIndexType = "IndexType";
static const char* jkCreateIndexStmtIgnoreExists = "IgnoreExists";
static const char* jkCreateIndexStmtIndexDbName = "IndexDbName";
static const char* jkCreateIndexStmtIndexName = "indexName";
static const char* jkCreateIndexStmtDbName = "DbName";
static const char* jkCreateIndexStmtTableName = "TableName";
static const char* jkCreateIndexStmtCols = "Cols";
static const char* jkCreateIndexStmtOptions = "Options";

static int32_t createIndexStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateIndexStmt* pNode = (const SCreateIndexStmt*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkCreateIndexStmtIndexType, pNode->indexType);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkCreateIndexStmtIgnoreExists, pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateIndexStmtIndexDbName, pNode->indexDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateIndexStmtIndexName, pNode->indexName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateIndexStmtDbName, pNode->dbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateIndexStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkCreateIndexStmtCols, pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateIndexStmtOptions, nodeToJson, pNode->pOptions);
  }

  return code;
}

static int32_t jsonToCreateIndexStmt(const SJson* pJson, void* pObj) {
  SCreateIndexStmt* pNode = (SCreateIndexStmt*)pObj;

  int32_t code = TSDB_CODE_SUCCESS;
  tjsonGetNumberValue(pJson, jkCreateIndexStmtIndexType, pNode->indexType, code);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkCreateIndexStmtIgnoreExists, &pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateIndexStmtIndexDbName, pNode->indexDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateIndexStmtIndexName, pNode->indexName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateIndexStmtDbName, pNode->dbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateIndexStmtTableName, pNode->tableName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkCreateIndexStmtCols, &pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateIndexStmtOptions, (SNode**)&pNode->pOptions);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460
static const char* jkDropIndexStmtIgnoreNotExists = "IgnoreNotExists";
static const char* jkDropIndexStmtIndexDbName = "IndexDbName";
static const char* jkDropIndexStmtIndexName = "IndexName";

static int32_t dropIndexStmtToJson(const void* pObj, SJson* pJson) {
  const SDropIndexStmt* pNode = (const SDropIndexStmt*)pObj;

  int32_t code = tjsonAddBoolToObject(pJson, jkDropIndexStmtIgnoreNotExists, pNode->ignoreNotExists);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDropIndexStmtIndexDbName, pNode->indexDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDropIndexStmtIndexName, pNode->indexName);
  }

  return code;
}

static int32_t jsonToDropIndexStmt(const SJson* pJson, void* pObj) {
  SDropIndexStmt* pNode = (SDropIndexStmt*)pObj;

  int32_t code = tjsonGetBoolValue(pJson, jkDropIndexStmtIgnoreNotExists, &pNode->ignoreNotExists);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDropIndexStmtIndexDbName, pNode->indexDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDropIndexStmtIndexName, pNode->indexName);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472
static const char* jkCreateComponentNodeStmtDnodeId = "DnodeId";

static int32_t createComponentNodeStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateComponentNodeStmt* pNode = (const SCreateComponentNodeStmt*)pObj;
  return tjsonAddIntegerToObject(pJson, jkCreateComponentNodeStmtDnodeId, pNode->dnodeId);
}

static int32_t jsonToCreateComponentNodeStmt(const SJson* pJson, void* pObj) {
  SCreateComponentNodeStmt* pNode = (SCreateComponentNodeStmt*)pObj;
  return tjsonGetIntValue(pJson, jkCreateComponentNodeStmtDnodeId, &pNode->dnodeId);
}

X
Xiaoyu Wang 已提交
5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484
static const char* jkDropComponentNodeStmtDnodeId = "DnodeId";

static int32_t dropComponentNodeStmtToJson(const void* pObj, SJson* pJson) {
  const SDropComponentNodeStmt* pNode = (const SDropComponentNodeStmt*)pObj;
  return tjsonAddIntegerToObject(pJson, jkDropComponentNodeStmtDnodeId, pNode->dnodeId);
}

static int32_t jsonToDropComponentNodeStmt(const SJson* pJson, void* pObj) {
  SDropComponentNodeStmt* pNode = (SDropComponentNodeStmt*)pObj;
  return tjsonGetIntValue(pJson, jkDropComponentNodeStmtDnodeId, &pNode->dnodeId);
}

X
Xiaoyu Wang 已提交
5485 5486
static int32_t createQnodeStmtToJson(const void* pObj, SJson* pJson) {
  return createComponentNodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
5487 5488
}

X
Xiaoyu Wang 已提交
5489 5490
static int32_t jsonToCreateQnodeStmt(const SJson* pJson, void* pObj) {
  return jsonToCreateComponentNodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
5491 5492
}

X
Xiaoyu Wang 已提交
5493 5494 5495 5496
static int32_t dropQnodeStmtToJson(const void* pObj, SJson* pJson) { return dropComponentNodeStmtToJson(pObj, pJson); }

static int32_t jsonToDropQnodeStmt(const SJson* pJson, void* pObj) { return jsonToDropComponentNodeStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
5497 5498 5499 5500 5501 5502 5503 5504
static int32_t createSnodeStmtToJson(const void* pObj, SJson* pJson) {
  return createComponentNodeStmtToJson(pObj, pJson);
}

static int32_t jsonToCreateSnodeStmt(const SJson* pJson, void* pObj) {
  return jsonToCreateComponentNodeStmt(pJson, pObj);
}

X
Xiaoyu Wang 已提交
5505 5506 5507 5508
static int32_t dropSnodeStmtToJson(const void* pObj, SJson* pJson) { return dropComponentNodeStmtToJson(pObj, pJson); }

static int32_t jsonToDropSnodeStmt(const SJson* pJson, void* pObj) { return jsonToDropComponentNodeStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
5509 5510 5511 5512 5513 5514 5515 5516
static int32_t createMnodeStmtToJson(const void* pObj, SJson* pJson) {
  return createComponentNodeStmtToJson(pObj, pJson);
}

static int32_t jsonToCreateMnodeStmt(const SJson* pJson, void* pObj) {
  return jsonToCreateComponentNodeStmt(pJson, pObj);
}

X
Xiaoyu Wang 已提交
5517 5518 5519 5520 5521 5522 5523 5524
static int32_t dropMnodeStmtToJson(const void* pObj, SJson* pJson) { return dropComponentNodeStmtToJson(pObj, pJson); }

static int32_t jsonToDropMnodeStmt(const SJson* pJson, void* pObj) { return jsonToDropComponentNodeStmt(pJson, pObj); }

static const char* jkDropDnodeStmtDnodeId = "DnodeId";
static const char* jkDropDnodeStmtFqdn = "Fqdn";
static const char* jkDropDnodeStmtPort = "Port";
static const char* jkDropDnodeStmtForce = "Force";
D
dapan1121 已提交
5525
static const char* jkDropDnodeStmtUnsafe = "Unsafe";
X
Xiaoyu Wang 已提交
5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539

static int32_t dropDnodeStmtToJson(const void* pObj, SJson* pJson) {
  const SDropDnodeStmt* pNode = (const SDropDnodeStmt*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkDropDnodeStmtDnodeId, pNode->dnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDropDnodeStmtFqdn, pNode->fqdn);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkDropDnodeStmtPort, pNode->port);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDropDnodeStmtForce, pNode->force);
  }
D
dapan1121 已提交
5540 5541 5542
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDropDnodeStmtUnsafe, pNode->unsafe);
  }
X
Xiaoyu Wang 已提交
5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559

  return code;
}

static int32_t jsonToDropDnodeStmt(const SJson* pJson, void* pObj) {
  SDropDnodeStmt* pNode = (SDropDnodeStmt*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkDropDnodeStmtDnodeId, &pNode->dnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDropDnodeStmtFqdn, pNode->fqdn);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkDropDnodeStmtPort, &pNode->port);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDropDnodeStmtForce, &pNode->force);
  }
D
dapan1121 已提交
5560 5561 5562
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDropDnodeStmtUnsafe, &pNode->unsafe);
  }
X
Xiaoyu Wang 已提交
5563 5564 5565 5566

  return code;
}

D
dapan1121 已提交
5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595
static const char* jkRestoreComponentNodeStmtDnodeId = "DnodeId";

static int32_t restoreComponentNodeStmtToJson(const void* pObj, SJson* pJson) {
  const SRestoreComponentNodeStmt* pNode = (const SRestoreComponentNodeStmt*)pObj;
  return tjsonAddIntegerToObject(pJson, jkRestoreComponentNodeStmtDnodeId, pNode->dnodeId);
}

static int32_t jsonToRestoreComponentNodeStmt(const SJson* pJson, void* pObj) {
  SRestoreComponentNodeStmt* pNode = (SRestoreComponentNodeStmt*)pObj;
  return tjsonGetIntValue(pJson, jkRestoreComponentNodeStmtDnodeId, &pNode->dnodeId);
}

static int32_t jsonToRestoreDnodeStmt(const SJson* pJson, void* pObj) {
  return jsonToRestoreComponentNodeStmt(pJson, pObj);
}
static int32_t jsonToRestoreQnodeStmt(const SJson* pJson, void* pObj) {
  return jsonToRestoreComponentNodeStmt(pJson, pObj);
}
static int32_t jsonToRestoreMnodeStmt(const SJson* pJson, void* pObj) {
  return jsonToRestoreComponentNodeStmt(pJson, pObj);
}
static int32_t jsonToRestoreVnodeStmt(const SJson* pJson, void* pObj) {
  return jsonToRestoreComponentNodeStmt(pJson, pObj);
}





X
Xiaoyu Wang 已提交
5596 5597 5598 5599 5600 5601 5602 5603 5604 5605
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) {
5606
    code = tjsonAddStringToObject(pJson, jkCreateTopicStmtSubscribeDbName, pNode->subDbName);
X
Xiaoyu Wang 已提交
5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622
  }
  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) {
5623
    code = tjsonGetStringValue(pJson, jkCreateTopicStmtSubscribeDbName, pNode->subDbName);
X
Xiaoyu Wang 已提交
5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634
  }
  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 已提交
5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659
static const char* jkDropTopicStmtTopicName = "TopicName";
static const char* jkDropTopicStmtIgnoreNotExists = "IgnoreNotExists";

static int32_t dropTopicStmtToJson(const void* pObj, SJson* pJson) {
  const SDropTopicStmt* pNode = (const SDropTopicStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkDropTopicStmtTopicName, pNode->topicName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDropTopicStmtIgnoreNotExists, pNode->ignoreNotExists);
  }

  return code;
}

static int32_t jsonToDropTopicStmt(const SJson* pJson, void* pObj) {
  SDropTopicStmt* pNode = (SDropTopicStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkDropTopicStmtTopicName, pNode->topicName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDropTopicStmtIgnoreNotExists, &pNode->ignoreNotExists);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691
static const char* jkDropCGroupStmtTopicName = "TopicName";
static const char* jkDropCGroupStmtConsumerGroup = "ConsumerGroup";
static const char* jkDropCGroupStmtIgnoreNotExists = "IgnoreNotExists";

static int32_t dropConsumerGroupStmtToJson(const void* pObj, SJson* pJson) {
  const SDropCGroupStmt* pNode = (const SDropCGroupStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkDropCGroupStmtTopicName, pNode->topicName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDropCGroupStmtConsumerGroup, pNode->cgroup);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDropCGroupStmtIgnoreNotExists, pNode->ignoreNotExists);
  }

  return code;
}

static int32_t jsonToDropConsumerGroupStmt(const SJson* pJson, void* pObj) {
  SDropCGroupStmt* pNode = (SDropCGroupStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkDropCGroupStmtTopicName, pNode->topicName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDropCGroupStmtConsumerGroup, pNode->cgroup);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDropCGroupStmtIgnoreNotExists, &pNode->ignoreNotExists);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748
static const char* jkAlterLocalStmtConfig = "Config";
static const char* jkAlterLocalStmtValue = "Value";

static int32_t alterLocalStmtToJson(const void* pObj, SJson* pJson) {
  const SAlterLocalStmt* pNode = (const SAlterLocalStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkAlterLocalStmtConfig, pNode->config);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkAlterLocalStmtValue, pNode->value);
  }

  return code;
}

static int32_t jsonToAlterLocalStmt(const SJson* pJson, void* pObj) {
  SAlterLocalStmt* pNode = (SAlterLocalStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkAlterLocalStmtConfig, pNode->config);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkAlterLocalStmtValue, pNode->value);
  }

  return code;
}

static const char* jkExplainStmtAnalyze = "Analyze";
static const char* jkExplainStmtOptions = "Options";
static const char* jkExplainStmtQuery = "Query";

static int32_t explainStmtToJson(const void* pObj, SJson* pJson) {
  const SExplainStmt* pNode = (const SExplainStmt*)pObj;

  int32_t code = tjsonAddBoolToObject(pJson, jkExplainStmtAnalyze, pNode->analyze);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkExplainStmtOptions, nodeToJson, pNode->pOptions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkExplainStmtQuery, nodeToJson, pNode->pQuery);
  }

  return code;
}

static int32_t jsonToExplainStmt(const SJson* pJson, void* pObj) {
  SExplainStmt* pNode = (SExplainStmt*)pObj;

  int32_t code = tjsonGetBoolValue(pJson, jkExplainStmtAnalyze, &pNode->analyze);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkExplainStmtOptions, (SNode**)&pNode->pOptions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkExplainStmtQuery, &pNode->pQuery);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773
static const char* jkDescribeStmtDbName = "DbName";
static const char* jkDescribeStmtTableName = "TableName";

static int32_t describeStmtToJson(const void* pObj, SJson* pJson) {
  const SDescribeStmt* pNode = (const SDescribeStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkDescribeStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkDescribeStmtTableName, pNode->tableName);
  }

  return code;
}

static int32_t jsonToDescribeStmt(const SJson* pJson, void* pObj) {
  SDescribeStmt* pNode = (SDescribeStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkDescribeStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkDescribeStmtTableName, pNode->tableName);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785
static const char* jkCompactDatabaseStmtDbName = "DbName";

static int32_t compactDatabaseStmtToJson(const void* pObj, SJson* pJson) {
  const SCompactDatabaseStmt* pNode = (const SCompactDatabaseStmt*)pObj;
  return tjsonAddStringToObject(pJson, jkCompactDatabaseStmtDbName, pNode->dbName);
}

static int32_t jsonToCompactDatabaseStmt(const SJson* pJson, void* pObj) {
  SCompactDatabaseStmt* pNode = (SCompactDatabaseStmt*)pObj;
  return tjsonGetStringValue(pJson, jkCompactDatabaseStmtDbName, pNode->dbName);
}

X
Xiaoyu Wang 已提交
5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852
static const char* jkCreateStreamStmtStreamName = "StreamName";
static const char* jkCreateStreamStmtTargetDbName = "TargetDbName";
static const char* jkCreateStreamStmtTargetTabName = "TargetTabName";
static const char* jkCreateStreamStmtIgnoreExists = "IgnoreExists";
static const char* jkCreateStreamStmtOptions = "Options";
static const char* jkCreateStreamStmtQuery = "Query";
static const char* jkCreateStreamStmtTags = "Tags";
static const char* jkCreateStreamStmtSubtable = "Subtable";

static int32_t createStreamStmtToJson(const void* pObj, SJson* pJson) {
  const SCreateStreamStmt* pNode = (const SCreateStreamStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkCreateStreamStmtStreamName, pNode->streamName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateStreamStmtTargetDbName, pNode->targetDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkCreateStreamStmtTargetTabName, pNode->targetTabName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkCreateStreamStmtIgnoreExists, pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateStreamStmtOptions, nodeToJson, pNode->pOptions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateStreamStmtQuery, nodeToJson, pNode->pQuery);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkCreateStreamStmtTags, pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkCreateStreamStmtSubtable, nodeToJson, pNode->pSubtable);
  }

  return code;
}

static int32_t jsonToCreateStreamStmt(const SJson* pJson, void* pObj) {
  SCreateStreamStmt* pNode = (SCreateStreamStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkCreateStreamStmtStreamName, pNode->streamName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateStreamStmtTargetDbName, pNode->targetDbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkCreateStreamStmtTargetTabName, pNode->targetTabName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkCreateStreamStmtIgnoreExists, &pNode->ignoreExists);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateStreamStmtOptions, (SNode**)&pNode->pOptions);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateStreamStmtQuery, &pNode->pQuery);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkCreateStreamStmtTags, &pNode->pTags);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkCreateStreamStmtSubtable, &pNode->pSubtable);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877
static const char* jkDropStreamStmtStreamName = "StreamName";
static const char* jkDropStreamStmtIgnoreNotExists = "IgnoreNotExists";

static int32_t dropStreamStmtToJson(const void* pObj, SJson* pJson) {
  const SDropStreamStmt* pNode = (const SDropStreamStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkDropStreamStmtStreamName, pNode->streamName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddBoolToObject(pJson, jkDropStreamStmtIgnoreNotExists, pNode->ignoreNotExists);
  }

  return code;
}

static int32_t jsonToDropStreamStmt(const SJson* pJson, void* pObj) {
  SDropStreamStmt* pNode = (SDropStreamStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkDropStreamStmtStreamName, pNode->streamName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBoolValue(pJson, jkDropStreamStmtIgnoreNotExists, &pNode->ignoreNotExists);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948
static const char* jkMergeVgroupStmtVgroupId1 = "VgroupId1";
static const char* jkMergeVgroupStmtVgroupId2 = "VgroupId2";

static int32_t mergeVgroupStmtToJson(const void* pObj, SJson* pJson) {
  const SMergeVgroupStmt* pNode = (const SMergeVgroupStmt*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkMergeVgroupStmtVgroupId1, pNode->vgId1);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkMergeVgroupStmtVgroupId2, pNode->vgId2);
  }

  return code;
}

static int32_t jsonToMergeVgroupStmt(const SJson* pJson, void* pObj) {
  SMergeVgroupStmt* pNode = (SMergeVgroupStmt*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkMergeVgroupStmtVgroupId1, &pNode->vgId1);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkMergeVgroupStmtVgroupId2, &pNode->vgId2);
  }

  return code;
}

static const char* jkRedistributeVgroupStmtVgroupId = "VgroupId";
static const char* jkRedistributeVgroupStmtDnodeId1 = "DnodeId1";
static const char* jkRedistributeVgroupStmtDnodeId2 = "DnodeId2";
static const char* jkRedistributeVgroupStmtDnodeId3 = "DnodeId3";
static const char* jkRedistributeVgroupStmtDnodes = "Dnodes";

static int32_t redistributeVgroupStmtToJson(const void* pObj, SJson* pJson) {
  const SRedistributeVgroupStmt* pNode = (const SRedistributeVgroupStmt*)pObj;

  int32_t code = tjsonAddIntegerToObject(pJson, jkRedistributeVgroupStmtVgroupId, pNode->vgId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkRedistributeVgroupStmtDnodeId1, pNode->dnodeId1);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkRedistributeVgroupStmtDnodeId2, pNode->dnodeId2);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkRedistributeVgroupStmtDnodeId3, pNode->dnodeId3);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkRedistributeVgroupStmtDnodes, pNode->pDnodes);
  }

  return code;
}

static int32_t jsonToRedistributeVgroupStmt(const SJson* pJson, void* pObj) {
  SRedistributeVgroupStmt* pNode = (SRedistributeVgroupStmt*)pObj;

  int32_t code = tjsonGetIntValue(pJson, jkRedistributeVgroupStmtVgroupId, &pNode->vgId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkRedistributeVgroupStmtDnodeId1, &pNode->dnodeId1);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkRedistributeVgroupStmtDnodeId2, &pNode->dnodeId2);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetIntValue(pJson, jkRedistributeVgroupStmtDnodeId3, &pNode->dnodeId3);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkRedistributeVgroupStmtDnodes, &pNode->pDnodes);
  }

  return code;
}

X
Xiaoyu Wang 已提交
5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960
static const char* jkSplitVgroupStmtVgroupId = "VgroupId";

static int32_t splitVgroupStmtToJson(const void* pObj, SJson* pJson) {
  const SSplitVgroupStmt* pNode = (const SSplitVgroupStmt*)pObj;
  return tjsonAddIntegerToObject(pJson, jkSplitVgroupStmtVgroupId, pNode->vgId);
}

static int32_t jsonToSplitVgroupStmt(const SJson* pJson, void* pObj) {
  SSplitVgroupStmt* pNode = (SSplitVgroupStmt*)pObj;
  return tjsonGetIntValue(pJson, jkSplitVgroupStmtVgroupId, &pNode->vgId);
}

X
Xiaoyu Wang 已提交
5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996
static const char* jkGrantStmtUserName = "UserName";
static const char* jkGrantStmtObjName = "ObjName";
static const char* jkGrantStmtPrivileges = "Privileges";

static int32_t grantStmtToJson(const void* pObj, SJson* pJson) {
  const SGrantStmt* pNode = (const SGrantStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkGrantStmtUserName, pNode->userName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkGrantStmtObjName, pNode->objName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkGrantStmtPrivileges, pNode->privileges);
  }

  return code;
}

static int32_t jsonToGrantStmt(const SJson* pJson, void* pObj) {
  SGrantStmt* pNode = (SGrantStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkGrantStmtUserName, pNode->userName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkGrantStmtObjName, pNode->objName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetBigIntValue(pJson, jkGrantStmtPrivileges, &pNode->privileges);
  }

  return code;
}

static int32_t revokeStmtToJson(const void* pObj, SJson* pJson) { return grantStmtToJson(pObj, pJson); }

static int32_t jsonToRevokeStmt(const SJson* pJson, void* pObj) { return jsonToGrantStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028
static const char* jkShowStmtDbName = "DbName";
static const char* jkShowStmtTbName = "TbName";
static const char* jkShowStmtTableCondType = "TableCondType";

static int32_t showStmtToJson(const void* pObj, SJson* pJson) {
  const SShowStmt* pNode = (const SShowStmt*)pObj;

  int32_t code = tjsonAddObject(pJson, jkShowStmtDbName, nodeToJson, pNode->pDbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkShowStmtTbName, nodeToJson, pNode->pTbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkShowStmtTableCondType, pNode->tableCondType);
  }

  return code;
}

static int32_t jsonToShowStmt(const SJson* pJson, void* pObj) {
  SShowStmt* pNode = (SShowStmt*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkShowStmtDbName, &pNode->pDbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkShowStmtTbName, &pNode->pTbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    tjsonGetNumberValue(pJson, jkShowStmtTableCondType, pNode->tableCondType, code);
  }

  return code;
}

X
Xiaoyu Wang 已提交
6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044
static int32_t showDnodesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowDnodesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showMnodesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowMnodesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showQnodesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowQnodesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showClusterStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowClusterStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6045 6046 6047 6048
static int32_t showDatabasesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowDatabasesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064
static int32_t showFunctionsStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowFunctionsStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showIndexesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowIndexesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showStablesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowStablesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showStreamsStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowStreamsStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080
static int32_t showTablesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowTablesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showTagsStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowTagsStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showUsersStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowUsersStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showVgroupsStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowVgroupsStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6081 6082 6083 6084
static int32_t showConsumersStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowConsumersStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6085 6086 6087 6088
static int32_t showVariablesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowVariablesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121
static const char* jkShowDnodeVariablesStmtDnodeId = "DnodeId";
static const char* jkShowDnodeVariablesStmtLikePattern = "LikePattern";

static int32_t showDnodeVariablesStmtToJson(const void* pObj, SJson* pJson) {
  const SShowDnodeVariablesStmt* pNode = (const SShowDnodeVariablesStmt*)pObj;

  int32_t code = tjsonAddObject(pJson, jkShowDnodeVariablesStmtDnodeId, nodeToJson, pNode->pDnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkShowDnodeVariablesStmtLikePattern, nodeToJson, pNode->pLikePattern);
  }

  return code;
}

static int32_t jsonToShowDnodeVariablesStmt(const SJson* pJson, void* pObj) {
  SShowDnodeVariablesStmt* pNode = (SShowDnodeVariablesStmt*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkShowDnodeVariablesStmtDnodeId, &pNode->pDnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkShowDnodeVariablesStmtLikePattern, &pNode->pLikePattern);
  }

  return code;
}

static int32_t showTransactionsStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowTransactionsStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

static int32_t showSubscriptionsStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowSubscriptionsStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150
static const char* jkShowVnodesStmtDnodeId = "DnodeId";
static const char* jkShowVnodesStmtDnodeEndpoint = "DnodeEndpoint";

static int32_t showVnodesStmtToJson(const void* pObj, SJson* pJson) {
  const SShowVnodesStmt* pNode = (const SShowVnodesStmt*)pObj;

  int32_t code = tjsonAddObject(pJson, jkShowVnodesStmtDnodeId, nodeToJson, pNode->pDnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkShowVnodesStmtDnodeEndpoint, nodeToJson, pNode->pDnodeEndpoint);
  }

  return code;
}

static int32_t jsonToShowVnodesStmt(const SJson* pJson, void* pObj) {
  SShowVnodesStmt* pNode = (SShowVnodesStmt*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkShowVnodesStmtDnodeId, &pNode->pDnodeId);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkShowVnodesStmtDnodeEndpoint, &pNode->pDnodeEndpoint);
  }

  return code;
}

static int32_t showUserPrivilegesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowUserPrivilegesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224
static const char* jkShowCreateDatabaseStmtDbName = "DbName";

static int32_t showCreateDatabaseStmtToJson(const void* pObj, SJson* pJson) {
  const SShowCreateDatabaseStmt* pNode = (const SShowCreateDatabaseStmt*)pObj;
  return tjsonAddStringToObject(pJson, jkShowCreateDatabaseStmtDbName, pNode->dbName);
}

static int32_t jsonToShowCreateDatabaseStmt(const SJson* pJson, void* pObj) {
  SShowCreateDatabaseStmt* pNode = (SShowCreateDatabaseStmt*)pObj;
  return tjsonGetStringValue(pJson, jkShowCreateDatabaseStmtDbName, pNode->dbName);
}

static const char* jkShowCreateTableStmtDbName = "DbName";
static const char* jkShowCreateTableStmtTableName = "TableName";

static int32_t showCreateTableStmtToJson(const void* pObj, SJson* pJson) {
  const SShowCreateTableStmt* pNode = (const SShowCreateTableStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkShowCreateTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkShowCreateTableStmtTableName, pNode->tableName);
  }

  return code;
}

static int32_t jsonToShowCreateTableStmt(const SJson* pJson, void* pObj) {
  SShowCreateTableStmt* pNode = (SShowCreateTableStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkShowCreateTableStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkShowCreateTableStmtTableName, pNode->tableName);
  }

  return code;
}

static int32_t showCreateStableStmtToJson(const void* pObj, SJson* pJson) {
  return showCreateTableStmtToJson(pObj, pJson);
}

static int32_t jsonToShowCreateStableStmt(const SJson* pJson, void* pObj) {
  return jsonToShowCreateTableStmt(pJson, pObj);
}

static const char* jkShowTableDistributedStmtDbName = "DbName";
static const char* jkShowTableDistributedStmtTableName = "TableName";

static int32_t showTableDistributedStmtToJson(const void* pObj, SJson* pJson) {
  const SShowTableDistributedStmt* pNode = (const SShowTableDistributedStmt*)pObj;

  int32_t code = tjsonAddStringToObject(pJson, jkShowTableDistributedStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddStringToObject(pJson, jkShowTableDistributedStmtTableName, pNode->tableName);
  }

  return code;
}

static int32_t jsonToShowTableDistributedStmt(const SJson* pJson, void* pObj) {
  SShowTableDistributedStmt* pNode = (SShowTableDistributedStmt*)pObj;

  int32_t code = tjsonGetStringValue(pJson, jkShowTableDistributedStmtDbName, pNode->dbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetStringValue(pJson, jkShowTableDistributedStmtTableName, pNode->tableName);
  }

  return code;
}

static int32_t showLocalVariablesStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }

static int32_t jsonToShowLocalVariablesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }

X
Xiaoyu Wang 已提交
6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256
static const char* jkShowTableTagsStmtDbName = "DbName";
static const char* jkShowTableTagsStmtTbName = "TbName";
static const char* jkShowTableTagsStmtTags = "Tags";

static int32_t showTableTagsStmtToJson(const void* pObj, SJson* pJson) {
  const SShowTableTagsStmt* pNode = (const SShowTableTagsStmt*)pObj;

  int32_t code = tjsonAddObject(pJson, jkShowTableTagsStmtDbName, nodeToJson, pNode->pDbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkShowTableTagsStmtTbName, nodeToJson, pNode->pTbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkShowTableTagsStmtTags, pNode->pTags);
  }

  return code;
}

static int32_t jsonToShowTableTagsStmt(const SJson* pJson, void* pObj) {
  SShowTableTagsStmt* pNode = (SShowTableTagsStmt*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkShowTableTagsStmtDbName, &pNode->pDbName);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkShowTableTagsStmtTbName, &pNode->pTbName);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkShowTableTagsStmtTags, &pNode->pTags);
  }

  return code;
}

X
Xiaoyu Wang 已提交
6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276
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 已提交
6277
    code = tjsonAddObject(pJson, jkDeleteStmtTagIndexCond, nodeToJson, pNode->pTagCond);
X
Xiaoyu Wang 已提交
6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305
  }
  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 已提交
6306
    code = jsonToNodeObject(pJson, jkDeleteStmtTagIndexCond, &pNode->pTagCond);
X
Xiaoyu Wang 已提交
6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323
  }
  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 已提交
6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362
static const char* jkInsertStmtTable = "Table";
static const char* jkInsertStmtCols = "Cols";
static const char* jkInsertStmtQuery = "Query";
static const char* jkInsertStmtPrecision = "Precision";

static int32_t insertStmtToJson(const void* pObj, SJson* pJson) {
  const SInsertStmt* pNode = (const SInsertStmt*)pObj;

  int32_t code = tjsonAddObject(pJson, jkInsertStmtTable, nodeToJson, pNode->pTable);
  if (TSDB_CODE_SUCCESS == code) {
    code = nodeListToJson(pJson, jkInsertStmtCols, pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddObject(pJson, jkInsertStmtQuery, nodeToJson, pNode->pQuery);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonAddIntegerToObject(pJson, jkInsertStmtPrecision, pNode->precision);
  }

  return code;
}

static int32_t jsonToInsertStmt(const SJson* pJson, void* pObj) {
  SInsertStmt* pNode = (SInsertStmt*)pObj;

  int32_t code = jsonToNodeObject(pJson, jkInsertStmtTable, &pNode->pTable);
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeList(pJson, jkInsertStmtCols, &pNode->pCols);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = jsonToNodeObject(pJson, jkInsertStmtQuery, &pNode->pQuery);
  }
  if (TSDB_CODE_SUCCESS == code) {
    code = tjsonGetUTinyIntValue(pJson, jkInsertStmtPrecision, &pNode->precision);
  }

  return code;
}

X
Xiaoyu Wang 已提交
6363 6364 6365
static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
  switch (nodeType(pObj)) {
    case QUERY_NODE_COLUMN:
X
Xiaoyu Wang 已提交
6366
      return columnNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6367
    case QUERY_NODE_VALUE:
X
Xiaoyu Wang 已提交
6368
      return valueNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6369
    case QUERY_NODE_OPERATOR:
X
Xiaoyu Wang 已提交
6370
      return operatorNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6371
    case QUERY_NODE_LOGIC_CONDITION:
X
Xiaoyu Wang 已提交
6372
      return logicConditionNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6373
    case QUERY_NODE_FUNCTION:
X
Xiaoyu Wang 已提交
6374
      return functionNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6375
    case QUERY_NODE_REAL_TABLE:
X
Xiaoyu Wang 已提交
6376
      return realTableNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6377
    case QUERY_NODE_TEMP_TABLE:
6378
      return tempTableNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6379
    case QUERY_NODE_JOIN_TABLE:
X
Xiaoyu Wang 已提交
6380
      return joinTableNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6381
    case QUERY_NODE_GROUPING_SET:
X
Xiaoyu Wang 已提交
6382
      return groupingSetNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6383
    case QUERY_NODE_ORDER_BY_EXPR:
X
Xiaoyu Wang 已提交
6384
      return orderByExprNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6385
    case QUERY_NODE_LIMIT:
6386
      return limitNodeToJson(pObj, pJson);
5
54liuyao 已提交
6387 6388
    case QUERY_NODE_STATE_WINDOW:
      return stateWindowNodeToJson(pObj, pJson);
5
54liuyao 已提交
6389 6390
    case QUERY_NODE_SESSION_WINDOW:
      return sessionWindowNodeToJson(pObj, pJson);
X
bugfix  
Xiaoyu Wang 已提交
6391 6392
    case QUERY_NODE_INTERVAL_WINDOW:
      return intervalWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6393
    case QUERY_NODE_NODE_LIST:
X
Xiaoyu Wang 已提交
6394
      return nodeListNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6395
    case QUERY_NODE_FILL:
X
Xiaoyu Wang 已提交
6396
      return fillNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6397
    case QUERY_NODE_RAW_EXPR:
X
Xiaoyu Wang 已提交
6398
      break;
X
Xiaoyu Wang 已提交
6399
    case QUERY_NODE_TARGET:
X
Xiaoyu Wang 已提交
6400
      return targetNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6401 6402
    case QUERY_NODE_DATABLOCK_DESC:
      return dataBlockDescNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6403 6404
    case QUERY_NODE_SLOT_DESC:
      return slotDescNodeToJson(pObj, pJson);
6405
    case QUERY_NODE_COLUMN_DEF:
X
Xiaoyu Wang 已提交
6406
      return columnDefNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6407 6408
    case QUERY_NODE_DOWNSTREAM_SOURCE:
      return downstreamSourceNodeToJson(pObj, pJson);
6409 6410
    case QUERY_NODE_DATABASE_OPTIONS:
      return databaseOptionsToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6411 6412
    case QUERY_NODE_TABLE_OPTIONS:
      return tableOptionsToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6413 6414 6415 6416
    case QUERY_NODE_INDEX_OPTIONS:
      return indexOptionsToJson(pObj, pJson);
    case QUERY_NODE_EXPLAIN_OPTIONS:
      return explainOptionsToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6417 6418
    case QUERY_NODE_STREAM_OPTIONS:
      return streamOptionsToJson(pObj, pJson);
6419 6420
    case QUERY_NODE_LEFT_VALUE:
      return TSDB_CODE_SUCCESS;  // SLeftValueNode has no fields to serialize.
X
Xiaoyu Wang 已提交
6421 6422 6423 6424
    case QUERY_NODE_WHEN_THEN:
      return whenThenNodeToJson(pObj, pJson);
    case QUERY_NODE_CASE_WHEN:
      return caseWhenNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6425 6426
    case QUERY_NODE_EVENT_WINDOW:
      return eventWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6427
    case QUERY_NODE_SET_OPERATOR:
6428
      return setOperatorToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6429
    case QUERY_NODE_SELECT_STMT:
6430
      return selectStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6431 6432
    case QUERY_NODE_VNODE_MODIFY_STMT:
      return vnodeModifyStmtToJson(pObj, pJson);
6433
    case QUERY_NODE_CREATE_DATABASE_STMT:
X
Xiaoyu Wang 已提交
6434
      return createDatabaseStmtToJson(pObj, pJson);
6435 6436
    case QUERY_NODE_ALTER_DATABASE_STMT:
      return alterDatabaseStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6437 6438
    case QUERY_NODE_TRIM_DATABASE_STMT:
      return trimDatabaseStmtToJson(pObj, pJson);
6439
    case QUERY_NODE_CREATE_TABLE_STMT:
X
Xiaoyu Wang 已提交
6440 6441 6442 6443 6444
      return createTableStmtToJson(pObj, pJson);
    case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
      return createSubTableClauseToJson(pObj, pJson);
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
      return createMultiTablesStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6445 6446 6447 6448 6449 6450
    case QUERY_NODE_DROP_TABLE_CLAUSE:
      return dropTableClauseToJson(pObj, pJson);
    case QUERY_NODE_DROP_TABLE_STMT:
      return dropTableStmtToJson(pObj, pJson);
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
      return dropStableStmtToJson(pObj, pJson);
6451 6452
    case QUERY_NODE_ALTER_TABLE_STMT:
      return alterTableStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6453 6454
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
      return alterStableStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6455 6456
    case QUERY_NODE_CREATE_USER_STMT:
      return createUserStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6457 6458
    case QUERY_NODE_ALTER_USER_STMT:
      return alterUserStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6459 6460
    case QUERY_NODE_DROP_USER_STMT:
      return dropUserStmtToJson(pObj, pJson);
6461
    case QUERY_NODE_USE_DATABASE_STMT:
X
Xiaoyu Wang 已提交
6462
      return useDatabaseStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6463 6464
    case QUERY_NODE_CREATE_DNODE_STMT:
      return createDnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6465 6466
    case QUERY_NODE_DROP_DNODE_STMT:
      return dropDnodeStmtToJson(pObj, pJson);
6467 6468
    case QUERY_NODE_ALTER_DNODE_STMT:
      return alterDnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6469 6470
    case QUERY_NODE_CREATE_INDEX_STMT:
      return createIndexStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6471 6472
    case QUERY_NODE_DROP_INDEX_STMT:
      return dropIndexStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6473 6474
    case QUERY_NODE_CREATE_QNODE_STMT:
      return createQnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6475 6476
    case QUERY_NODE_DROP_QNODE_STMT:
      return dropQnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6477 6478
    case QUERY_NODE_CREATE_SNODE_STMT:
      return createSnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6479 6480
    case QUERY_NODE_DROP_SNODE_STMT:
      return dropSnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6481 6482
    case QUERY_NODE_CREATE_MNODE_STMT:
      return createMnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6483 6484
    case QUERY_NODE_DROP_MNODE_STMT:
      return dropMnodeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6485 6486
    case QUERY_NODE_CREATE_TOPIC_STMT:
      return createTopicStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6487 6488
    case QUERY_NODE_DROP_TOPIC_STMT:
      return dropTopicStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6489 6490
    case QUERY_NODE_DROP_CGROUP_STMT:
      return dropConsumerGroupStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6491 6492 6493 6494
    case QUERY_NODE_ALTER_LOCAL_STMT:
      return alterLocalStmtToJson(pObj, pJson);
    case QUERY_NODE_EXPLAIN_STMT:
      return explainStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6495 6496
    case QUERY_NODE_DESCRIBE_STMT:
      return describeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6497 6498
    case QUERY_NODE_COMPACT_DATABASE_STMT:
      return compactDatabaseStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6499 6500
    case QUERY_NODE_CREATE_STREAM_STMT:
      return createStreamStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6501 6502
    case QUERY_NODE_DROP_STREAM_STMT:
      return dropStreamStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6503 6504
    case QUERY_NODE_BALANCE_VGROUP_STMT:
      return TSDB_CODE_SUCCESS;  // SBalanceVgroupStmt has no fields to serialize.
C
cadem 已提交
6505 6506
    case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT:
      return TSDB_CODE_SUCCESS;  // SBalanceVgroupLeaderStmt has no fields to serialize.
X
Xiaoyu Wang 已提交
6507 6508 6509 6510
    case QUERY_NODE_MERGE_VGROUP_STMT:
      return mergeVgroupStmtToJson(pObj, pJson);
    case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
      return redistributeVgroupStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6511 6512
    case QUERY_NODE_SPLIT_VGROUP_STMT:
      return splitVgroupStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6513 6514 6515 6516
    case QUERY_NODE_GRANT_STMT:
      return grantStmtToJson(pObj, pJson);
    case QUERY_NODE_REVOKE_STMT:
      return revokeStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6517 6518 6519 6520 6521 6522 6523 6524
    case QUERY_NODE_SHOW_DNODES_STMT:
      return showDnodesStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_MNODES_STMT:
      return showMnodesStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_QNODES_STMT:
      return showQnodesStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_CLUSTER_STMT:
      return showClusterStmtToJson(pObj, pJson);
6525
    case QUERY_NODE_SHOW_DATABASES_STMT:
X
Xiaoyu Wang 已提交
6526
      return showDatabasesStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6527 6528 6529 6530 6531 6532 6533 6534
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
      return showFunctionsStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_INDEXES_STMT:
      return showIndexesStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_STABLES_STMT:
      return showStablesStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_STREAMS_STMT:
      return showStreamsStmtToJson(pObj, pJson);
6535
    case QUERY_NODE_SHOW_TABLES_STMT:
X
Xiaoyu Wang 已提交
6536
      return showTablesStmtToJson(pObj, pJson);
6537
    case QUERY_NODE_SHOW_TAGS_STMT:
X
Xiaoyu Wang 已提交
6538 6539 6540 6541 6542
      return showTagsStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_USERS_STMT:
      return showUsersStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_VGROUPS_STMT:
      return showVgroupsStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6543 6544
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
      return showConsumersStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6545 6546
    case QUERY_NODE_SHOW_VARIABLES_STMT:
      return showVariablesStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6547 6548 6549 6550 6551 6552
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
      return showDnodeVariablesStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
      return showTransactionsStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
      return showSubscriptionsStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6553 6554 6555 6556
    case QUERY_NODE_SHOW_VNODES_STMT:
      return showVnodesStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
      return showUserPrivilegesStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6557 6558 6559 6560 6561 6562 6563 6564 6565 6566
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
      return showCreateDatabaseStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
      return showCreateTableStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
      return showCreateStableStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
      return showTableDistributedStmtToJson(pObj, pJson);
    case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
      return showLocalVariablesStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6567 6568
    case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
      return showTableTagsStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6569 6570
    case QUERY_NODE_DELETE_STMT:
      return deleteStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6571 6572
    case QUERY_NODE_INSERT_STMT:
      return insertStmtToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6573
    case QUERY_NODE_LOGIC_PLAN_SCAN:
X
Xiaoyu Wang 已提交
6574
      return logicScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6575
    case QUERY_NODE_LOGIC_PLAN_JOIN:
X
Xiaoyu Wang 已提交
6576
      return logicJoinNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6577
    case QUERY_NODE_LOGIC_PLAN_AGG:
X
Xiaoyu Wang 已提交
6578
      return logicAggNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6579
    case QUERY_NODE_LOGIC_PLAN_PROJECT:
X
Xiaoyu Wang 已提交
6580
      return logicProjectNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6581 6582
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
      return logicVnodeModifyNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6583 6584
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
      return logicExchangeNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6585 6586 6587 6588
    case QUERY_NODE_LOGIC_PLAN_MERGE:
      return logicMergeNodeToJson(pObj, pJson);
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
      return logicWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6589 6590
    case QUERY_NODE_LOGIC_PLAN_FILL:
      return logicFillNodeToJson(pObj, pJson);
6591 6592
    case QUERY_NODE_LOGIC_PLAN_SORT:
      return logicSortNodeToJson(pObj, pJson);
6593 6594
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
      return logicPartitionNodeToJson(pObj, pJson);
6595 6596
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
      return logicIndefRowsFuncNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6597 6598
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
      return logicInterpFuncNodeToJson(pObj, pJson);
6599
    case QUERY_NODE_LOGIC_SUBPLAN:
6600
      return logicSubplanToJson(pObj, pJson);
6601
    case QUERY_NODE_LOGIC_PLAN:
6602
      return logicPlanToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6603
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
6604
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
X
Xiaoyu Wang 已提交
6605
      return physiScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6606
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
X
Xiaoyu Wang 已提交
6607
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN:
X
Xiaoyu Wang 已提交
6608
      return physiLastRowScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6609
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
X
Xiaoyu Wang 已提交
6610
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
6611
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
X
Xiaoyu Wang 已提交
6612
      return physiTableScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6613 6614
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
      return physiSysTableScanNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6615 6616
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
      return physiProjectNodeToJson(pObj, pJson);
6617
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
X
Xiaoyu Wang 已提交
6618
      return physiJoinNodeToJson(pObj, pJson);
6619
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
X
Xiaoyu Wang 已提交
6620
      return physiAggNodeToJson(pObj, pJson);
6621
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
X
Xiaoyu Wang 已提交
6622
      return physiExchangeNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6623 6624
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
      return physiMergeNodeToJson(pObj, pJson);
6625
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
6626
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT:
X
Xiaoyu Wang 已提交
6627
      return physiSortNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6628
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
6629
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
X
Xiaoyu Wang 已提交
6630
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
6631 6632
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
X
Xiaoyu Wang 已提交
6633
      return physiIntervalNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6634
    case QUERY_NODE_PHYSICAL_PLAN_FILL:
5
54liuyao 已提交
6635
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL:
X
Xiaoyu Wang 已提交
6636
      return physiFillNodeToJson(pObj, pJson);
6637 6638
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
6639 6640
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
X
Xiaoyu Wang 已提交
6641
      return physiSessionWindowNodeToJson(pObj, pJson);
6642 6643
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE:
6644
      return physiStateWindowNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6645 6646 6647
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT:
      return physiEventWindowNodeToJson(pObj, pJson);
6648 6649
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
      return physiPartitionNodeToJson(pObj, pJson);
6650 6651
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION:
      return physiStreamPartitionNodeToJson(pObj, pJson);
6652 6653
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
      return physiIndefRowsFuncNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6654 6655
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
      return physiInterpFuncNodeToJson(pObj, pJson);
6656
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
X
Xiaoyu Wang 已提交
6657
      return physiDispatchNodeToJson(pObj, pJson);
6658 6659
    case QUERY_NODE_PHYSICAL_PLAN_INSERT:
      break;
6660 6661
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return physiQueryInsertNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6662 6663
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return physiDeleteNodeToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6664 6665
    case QUERY_NODE_PHYSICAL_SUBPLAN:
      return subplanToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6666 6667
    case QUERY_NODE_PHYSICAL_PLAN:
      return planToJson(pObj, pJson);
X
Xiaoyu Wang 已提交
6668 6669 6670
    default:
      break;
  }
6671
  nodesWarn("specificNodeToJson unknown node = %s", nodesNodeName(nodeType(pObj)));
X
Xiaoyu Wang 已提交
6672 6673 6674
  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686
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 已提交
6687 6688
    case QUERY_NODE_REAL_TABLE:
      return jsonToRealTableNode(pJson, pObj);
6689 6690
    case QUERY_NODE_TEMP_TABLE:
      return jsonToTempTableNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6691 6692
    case QUERY_NODE_JOIN_TABLE:
      return jsonToJoinTableNode(pJson, pObj);
6693 6694
    case QUERY_NODE_GROUPING_SET:
      return jsonToGroupingSetNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6695 6696
    case QUERY_NODE_ORDER_BY_EXPR:
      return jsonToOrderByExprNode(pJson, pObj);
6697 6698
    case QUERY_NODE_LIMIT:
      return jsonToLimitNode(pJson, pObj);
5
54liuyao 已提交
6699 6700
    case QUERY_NODE_STATE_WINDOW:
      return jsonToStateWindowNode(pJson, pObj);
5
54liuyao 已提交
6701 6702
    case QUERY_NODE_SESSION_WINDOW:
      return jsonToSessionWindowNode(pJson, pObj);
X
bugfix  
Xiaoyu Wang 已提交
6703 6704
    case QUERY_NODE_INTERVAL_WINDOW:
      return jsonToIntervalWindowNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6705 6706
    case QUERY_NODE_NODE_LIST:
      return jsonToNodeListNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6707 6708
    case QUERY_NODE_FILL:
      return jsonToFillNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6709 6710 6711 6712 6713 6714
    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 已提交
6715 6716
    case QUERY_NODE_COLUMN_DEF:
      return jsonToColumnDefNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6717 6718
    case QUERY_NODE_DOWNSTREAM_SOURCE:
      return jsonToDownstreamSourceNode(pJson, pObj);
6719 6720
    case QUERY_NODE_DATABASE_OPTIONS:
      return jsonToDatabaseOptions(pJson, pObj);
X
Xiaoyu Wang 已提交
6721 6722
    case QUERY_NODE_TABLE_OPTIONS:
      return jsonToTableOptions(pJson, pObj);
X
Xiaoyu Wang 已提交
6723 6724 6725 6726
    case QUERY_NODE_INDEX_OPTIONS:
      return jsonToIndexOptions(pJson, pObj);
    case QUERY_NODE_EXPLAIN_OPTIONS:
      return jsonToExplainOptions(pJson, pObj);
X
Xiaoyu Wang 已提交
6727 6728
    case QUERY_NODE_STREAM_OPTIONS:
      return jsonToStreamOptions(pJson, pObj);
6729 6730
    case QUERY_NODE_LEFT_VALUE:
      return TSDB_CODE_SUCCESS;  // SLeftValueNode has no fields to deserialize.
X
Xiaoyu Wang 已提交
6731 6732 6733 6734
    case QUERY_NODE_WHEN_THEN:
      return jsonToWhenThenNode(pJson, pObj);
    case QUERY_NODE_CASE_WHEN:
      return jsonToCaseWhenNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6735 6736
    case QUERY_NODE_EVENT_WINDOW:
      return jsonToEventWindowNode(pJson, pObj);
6737 6738
    case QUERY_NODE_SET_OPERATOR:
      return jsonToSetOperator(pJson, pObj);
X
Xiaoyu Wang 已提交
6739 6740
    case QUERY_NODE_SELECT_STMT:
      return jsonToSelectStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6741 6742
    case QUERY_NODE_VNODE_MODIFY_STMT:
      return jsonToVnodeModifyStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6743 6744
    case QUERY_NODE_CREATE_DATABASE_STMT:
      return jsonToCreateDatabaseStmt(pJson, pObj);
6745 6746
    case QUERY_NODE_ALTER_DATABASE_STMT:
      return jsonToAlterDatabaseStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6747 6748
    case QUERY_NODE_TRIM_DATABASE_STMT:
      return jsonToTrimDatabaseStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6749 6750 6751 6752 6753 6754
    case QUERY_NODE_CREATE_TABLE_STMT:
      return jsonToCreateTableStmt(pJson, pObj);
    case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
      return jsonToCreateSubTableClause(pJson, pObj);
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
      return jsonToCreateMultiTablesStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6755 6756 6757 6758 6759 6760
    case QUERY_NODE_DROP_TABLE_CLAUSE:
      return jsonToDropTableClause(pJson, pObj);
    case QUERY_NODE_DROP_TABLE_STMT:
      return jsonToDropTableStmt(pJson, pObj);
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
      return jsonToDropStableStmt(pJson, pObj);
6761 6762
    case QUERY_NODE_ALTER_TABLE_STMT:
      return jsonToAlterTableStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6763 6764
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
      return jsonToAlterStableStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6765 6766
    case QUERY_NODE_CREATE_USER_STMT:
      return jsonToCreateUserStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6767 6768
    case QUERY_NODE_ALTER_USER_STMT:
      return jsonToAlterUserStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6769 6770
    case QUERY_NODE_DROP_USER_STMT:
      return jsonToDropUserStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6771 6772
    case QUERY_NODE_USE_DATABASE_STMT:
      return jsonToUseDatabaseStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6773 6774
    case QUERY_NODE_CREATE_DNODE_STMT:
      return jsonToCreateDnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6775 6776
    case QUERY_NODE_DROP_DNODE_STMT:
      return jsonToDropDnodeStmt(pJson, pObj);
6777 6778
    case QUERY_NODE_ALTER_DNODE_STMT:
      return jsonToAlterDnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6779 6780
    case QUERY_NODE_CREATE_INDEX_STMT:
      return jsonToCreateIndexStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6781 6782
    case QUERY_NODE_DROP_INDEX_STMT:
      return jsonToDropIndexStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6783 6784
    case QUERY_NODE_CREATE_QNODE_STMT:
      return jsonToCreateQnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6785 6786
    case QUERY_NODE_DROP_QNODE_STMT:
      return jsonToDropQnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6787 6788
    case QUERY_NODE_CREATE_SNODE_STMT:
      return jsonToCreateSnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6789 6790
    case QUERY_NODE_DROP_SNODE_STMT:
      return jsonToDropSnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6791 6792
    case QUERY_NODE_CREATE_MNODE_STMT:
      return jsonToCreateMnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6793 6794
    case QUERY_NODE_DROP_MNODE_STMT:
      return jsonToDropMnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6795 6796
    case QUERY_NODE_CREATE_TOPIC_STMT:
      return jsonToCreateTopicStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6797 6798
    case QUERY_NODE_DROP_TOPIC_STMT:
      return jsonToDropTopicStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6799 6800
    case QUERY_NODE_DROP_CGROUP_STMT:
      return jsonToDropConsumerGroupStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6801 6802 6803 6804
    case QUERY_NODE_ALTER_LOCAL_STMT:
      return jsonToAlterLocalStmt(pJson, pObj);
    case QUERY_NODE_EXPLAIN_STMT:
      return jsonToExplainStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6805 6806
    case QUERY_NODE_DESCRIBE_STMT:
      return jsonToDescribeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6807 6808
    case QUERY_NODE_COMPACT_DATABASE_STMT:
      return jsonToCompactDatabaseStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6809 6810
    case QUERY_NODE_CREATE_STREAM_STMT:
      return jsonToCreateStreamStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6811 6812
    case QUERY_NODE_DROP_STREAM_STMT:
      return jsonToDropStreamStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6813 6814
    case QUERY_NODE_BALANCE_VGROUP_STMT:
      return TSDB_CODE_SUCCESS;  // SBalanceVgroupStmt has no fields to deserialize.
C
cadem 已提交
6815 6816
    case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT:
      return TSDB_CODE_SUCCESS;  // SBalanceVgroupLeaderStmt has no fields to deserialize.
X
Xiaoyu Wang 已提交
6817 6818 6819 6820
    case QUERY_NODE_MERGE_VGROUP_STMT:
      return jsonToMergeVgroupStmt(pJson, pObj);
    case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
      return jsonToRedistributeVgroupStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6821 6822
    case QUERY_NODE_SPLIT_VGROUP_STMT:
      return jsonToSplitVgroupStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6823 6824 6825 6826
    case QUERY_NODE_GRANT_STMT:
      return jsonToGrantStmt(pJson, pObj);
    case QUERY_NODE_REVOKE_STMT:
      return jsonToRevokeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6827 6828 6829 6830 6831 6832 6833 6834
    case QUERY_NODE_SHOW_DNODES_STMT:
      return jsonToShowDnodesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_MNODES_STMT:
      return jsonToShowMnodesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_QNODES_STMT:
      return jsonToShowQnodesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_CLUSTER_STMT:
      return jsonToShowClusterStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6835 6836
    case QUERY_NODE_SHOW_DATABASES_STMT:
      return jsonToShowDatabasesStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6837 6838 6839 6840 6841 6842 6843 6844
    case QUERY_NODE_SHOW_FUNCTIONS_STMT:
      return jsonToShowFunctionsStmt(pJson, pObj);
    case QUERY_NODE_SHOW_INDEXES_STMT:
      return jsonToShowIndexesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_STABLES_STMT:
      return jsonToShowStablesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_STREAMS_STMT:
      return jsonToShowStreamsStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6845 6846 6847 6848 6849 6850 6851 6852
    case QUERY_NODE_SHOW_TABLES_STMT:
      return jsonToShowTablesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_TAGS_STMT:
      return jsonToShowTagsStmt(pJson, pObj);
    case QUERY_NODE_SHOW_USERS_STMT:
      return jsonToShowUsersStmt(pJson, pObj);
    case QUERY_NODE_SHOW_VGROUPS_STMT:
      return jsonToShowVgroupsStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6853 6854
    case QUERY_NODE_SHOW_CONSUMERS_STMT:
      return jsonToShowConsumersStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6855 6856
    case QUERY_NODE_SHOW_VARIABLES_STMT:
      return jsonToShowVariablesStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6857 6858 6859 6860 6861 6862
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
      return jsonToShowDnodeVariablesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
      return jsonToShowTransactionsStmt(pJson, pObj);
    case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
      return jsonToShowSubscriptionsStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6863 6864 6865 6866
    case QUERY_NODE_SHOW_VNODES_STMT:
      return jsonToShowVnodesStmt(pJson, pObj);
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
      return jsonToShowUserPrivilegesStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6867 6868 6869 6870 6871 6872 6873 6874 6875 6876
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
      return jsonToShowCreateDatabaseStmt(pJson, pObj);
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
      return jsonToShowCreateTableStmt(pJson, pObj);
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
      return jsonToShowCreateStableStmt(pJson, pObj);
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
      return jsonToShowTableDistributedStmt(pJson, pObj);
    case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
      return jsonToShowLocalVariablesStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6877 6878
    case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
      return jsonToShowTableTagsStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6879 6880
    case QUERY_NODE_DELETE_STMT:
      return jsonToDeleteStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6881 6882
    case QUERY_NODE_INSERT_STMT:
      return jsonToInsertStmt(pJson, pObj);
D
dapan1121 已提交
6883 6884 6885 6886 6887 6888 6889 6890
    case QUERY_NODE_RESTORE_DNODE_STMT:
      return jsonToRestoreDnodeStmt(pJson, pObj);
    case QUERY_NODE_RESTORE_QNODE_STMT:
      return jsonToRestoreQnodeStmt(pJson, pObj);
    case QUERY_NODE_RESTORE_MNODE_STMT:
      return jsonToRestoreMnodeStmt(pJson, pObj);
    case QUERY_NODE_RESTORE_VNODE_STMT:  
      return jsonToRestoreVnodeStmt(pJson, pObj);
X
Xiaoyu Wang 已提交
6891 6892
    case QUERY_NODE_LOGIC_PLAN_SCAN:
      return jsonToLogicScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6893 6894
    case QUERY_NODE_LOGIC_PLAN_JOIN:
      return jsonToLogicJoinNode(pJson, pObj);
6895 6896
    case QUERY_NODE_LOGIC_PLAN_AGG:
      return jsonToLogicAggNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6897 6898
    case QUERY_NODE_LOGIC_PLAN_PROJECT:
      return jsonToLogicProjectNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6899 6900
    case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY:
      return jsonToLogicVnodeModifyNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6901 6902
    case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
      return jsonToLogicExchangeNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6903 6904 6905 6906
    case QUERY_NODE_LOGIC_PLAN_MERGE:
      return jsonToLogicMergeNode(pJson, pObj);
    case QUERY_NODE_LOGIC_PLAN_WINDOW:
      return jsonToLogicWindowNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6907 6908
    case QUERY_NODE_LOGIC_PLAN_FILL:
      return jsonToLogicFillNode(pJson, pObj);
6909 6910
    case QUERY_NODE_LOGIC_PLAN_SORT:
      return jsonToLogicSortNode(pJson, pObj);
6911 6912
    case QUERY_NODE_LOGIC_PLAN_PARTITION:
      return jsonToLogicPartitionNode(pJson, pObj);
6913 6914
    case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
      return jsonToLogicIndefRowsFuncNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6915 6916
    case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC:
      return jsonToLogicInterpFuncNode(pJson, pObj);
6917 6918
    case QUERY_NODE_LOGIC_SUBPLAN:
      return jsonToLogicSubplan(pJson, pObj);
6919 6920
    case QUERY_NODE_LOGIC_PLAN:
      return jsonToLogicPlan(pJson, pObj);
X
Xiaoyu Wang 已提交
6921
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
6922
    case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
6923
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN:
X
Xiaoyu Wang 已提交
6924
      return jsonToPhysiScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6925
    case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
X
Xiaoyu Wang 已提交
6926
      return jsonToPhysiLastRowScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6927
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
X
Xiaoyu Wang 已提交
6928
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
X
Xiaoyu Wang 已提交
6929
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
X
Xiaoyu Wang 已提交
6930
      return jsonToPhysiTableScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6931
    case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
X
Xiaoyu Wang 已提交
6932
      return jsonToPhysiSysTableScanNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6933 6934
    case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
      return jsonToPhysiProjectNode(pJson, pObj);
6935
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
X
Xiaoyu Wang 已提交
6936
      return jsonToPhysiJoinNode(pJson, pObj);
6937
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
X
Xiaoyu Wang 已提交
6938
      return jsonToPhysiAggNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6939 6940
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
      return jsonToPhysiExchangeNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6941 6942
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
      return jsonToPhysiMergeNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6943
    case QUERY_NODE_PHYSICAL_PLAN_SORT:
6944
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT:
X
Xiaoyu Wang 已提交
6945
      return jsonToPhysiSortNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6946
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
6947
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
X
Xiaoyu Wang 已提交
6948
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
6949 6950
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
X
Xiaoyu Wang 已提交
6951
      return jsonToPhysiIntervalNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6952
    case QUERY_NODE_PHYSICAL_PLAN_FILL:
5
54liuyao 已提交
6953
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL:
X
Xiaoyu Wang 已提交
6954
      return jsonToPhysiFillNode(pJson, pObj);
6955 6956
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION:
6957 6958
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION:
X
Xiaoyu Wang 已提交
6959
      return jsonToPhysiSessionWindowNode(pJson, pObj);
6960 6961
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE:
6962
      return jsonToPhysiStateWindowNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6963 6964 6965
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT:
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT:
      return jsonToPhysiEventWindowNode(pJson, pObj);
6966 6967
    case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
      return jsonToPhysiPartitionNode(pJson, pObj);
6968 6969
    case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION:
      return jsonToPhysiStreamPartitionNode(pJson, pObj);
6970 6971
    case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
      return jsonToPhysiIndefRowsFuncNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6972 6973
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
      return jsonToPhysiInterpFuncNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6974 6975
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
      return jsonToPhysiDispatchNode(pJson, pObj);
6976 6977
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return jsonToPhysiQueryInsertNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6978 6979
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return jsonToPhysiDeleteNode(pJson, pObj);
X
Xiaoyu Wang 已提交
6980 6981
    case QUERY_NODE_PHYSICAL_SUBPLAN:
      return jsonToSubplan(pJson, pObj);
X
Xiaoyu Wang 已提交
6982 6983
    case QUERY_NODE_PHYSICAL_PLAN:
      return jsonToPlan(pJson, pObj);
X
Xiaoyu Wang 已提交
6984 6985 6986
    default:
      break;
  }
6987
  nodesWarn("jsonToSpecificNode unknown node = %s", nodesNodeName(nodeType(pObj)));
X
Xiaoyu Wang 已提交
6988 6989 6990
  return TSDB_CODE_SUCCESS;
}

X
Xiaoyu Wang 已提交
6991
static const char* jkNodeType = "NodeType";
X
Xiaoyu Wang 已提交
6992 6993
static const char* jkNodeName = "Name";

X
Xiaoyu Wang 已提交
6994 6995 6996
static int32_t nodeToJson(const void* pObj, SJson* pJson) {
  const SNode* pNode = (const SNode*)pObj;

X
Xiaoyu Wang 已提交
6997 6998
  int32_t code = tjsonAddIntegerToObject(pJson, jkNodeType, pNode->type);
  if (TSDB_CODE_SUCCESS == code) {
6999
    code = tjsonAddStringToObject(pJson, jkNodeName, nodesNodeName(pNode->type));
X
Xiaoyu Wang 已提交
7000
  }
X
Xiaoyu Wang 已提交
7001
  if (TSDB_CODE_SUCCESS == code) {
7002
    code = tjsonAddObject(pJson, nodesNodeName(pNode->type), specificNodeToJson, pNode);
7003 7004 7005
    if (TSDB_CODE_SUCCESS != code) {
      nodesError("%s ToJson error", nodesNodeName(pNode->type));
    }
X
Xiaoyu Wang 已提交
7006 7007 7008 7009 7010
  }

  return code;
}

X
Xiaoyu Wang 已提交
7011 7012 7013
static int32_t jsonToNode(const SJson* pJson, void* pObj) {
  SNode* pNode = (SNode*)pObj;

7014
  int32_t code;
7015
  tjsonGetNumberValue(pJson, jkNodeType, pNode->type, code);
X
Xiaoyu Wang 已提交
7016
  if (TSDB_CODE_SUCCESS == code) {
7017
    code = tjsonToObject(pJson, nodesNodeName(pNode->type), jsonToSpecificNode, pNode);
X
Xiaoyu Wang 已提交
7018
    if (TSDB_CODE_SUCCESS != code) {
7019
      nodesError("%s toNode error", nodesNodeName(pNode->type));
X
Xiaoyu Wang 已提交
7020
    }
X
Xiaoyu Wang 已提交
7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042
  }

  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 已提交
7043
    return TSDB_CODE_SUCCESS;
X
Xiaoyu Wang 已提交
7044 7045 7046 7047
  }
  return makeNodeByJson(pJsonNode, pNode);
}

7048
int32_t nodesNodeToString(const SNode* pNode, bool format, char** pStr, int32_t* pLen) {
7049
  if (NULL == pNode || NULL == pStr) {
7050 7051
    terrno = TSDB_CODE_FAILED;
    return TSDB_CODE_FAILED;
X
Xiaoyu Wang 已提交
7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065
  }

  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 已提交
7066
  *pStr = format ? tjsonToString(pJson) : tjsonToUnformattedString(pJson);
X
Xiaoyu Wang 已提交
7067 7068
  tjsonDelete(pJson);

7069 7070 7071 7072
  if (NULL != pLen) {
    *pLen = strlen(*pStr) + 1;
  }

X
Xiaoyu Wang 已提交
7073 7074 7075 7076
  return TSDB_CODE_SUCCESS;
}

int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
X
Xiaoyu Wang 已提交
7077 7078 7079 7080 7081 7082 7083 7084
  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 已提交
7085
  tjsonDelete(pJson);
X
Xiaoyu Wang 已提交
7086 7087
  if (TSDB_CODE_SUCCESS != code) {
    nodesDestroyNode(*pNode);
X
Xiaoyu Wang 已提交
7088
    *pNode = NULL;
X
Xiaoyu Wang 已提交
7089 7090 7091
    terrno = code;
    return code;
  }
X
Xiaoyu Wang 已提交
7092
  return TSDB_CODE_SUCCESS;
7093
}
X
Xiaoyu Wang 已提交
7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135

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 已提交
7136
  tjsonDelete(pJson);
X
Xiaoyu Wang 已提交
7137 7138
  if (TSDB_CODE_SUCCESS != code) {
    nodesDestroyList(*pList);
X
Xiaoyu Wang 已提交
7139
    *pList = NULL;
X
Xiaoyu Wang 已提交
7140 7141 7142
    terrno = code;
    return code;
  }
X
Xiaoyu Wang 已提交
7143
  return TSDB_CODE_SUCCESS;
7144
}