mndDef.c 4.1 KB
Newer Older
L
Liu Jicong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "mndDef.h"

int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
L
Liu Jicong 已提交
19
  int32_t sz = 0;
L
Liu Jicong 已提交
20
  /*int32_t outputNameSz = 0;*/
L
Liu Jicong 已提交
21 22 23 24 25 26 27 28 29 30 31
  if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1;
  if (tEncodeCStr(pEncoder, pObj->db) < 0) return -1;
  if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1;
  if (tEncodeI64(pEncoder, pObj->updateTime) < 0) return -1;
  if (tEncodeI64(pEncoder, pObj->uid) < 0) return -1;
  if (tEncodeI64(pEncoder, pObj->dbUid) < 0) return -1;
  if (tEncodeI32(pEncoder, pObj->version) < 0) return -1;
  if (tEncodeI8(pEncoder, pObj->status) < 0) return -1;
  if (tEncodeCStr(pEncoder, pObj->sql) < 0) return -1;
  if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1;
  if (tEncodeCStr(pEncoder, pObj->physicalPlan) < 0) return -1;
L
Liu Jicong 已提交
32 33
  // TODO encode tasks
  if (pObj->tasks) {
L
Liu Jicong 已提交
34 35 36 37 38
    sz = taosArrayGetSize(pObj->tasks);
  }
  if (tEncodeI32(pEncoder, sz) < 0) return -1;

  for (int32_t i = 0; i < sz; i++) {
L
Liu Jicong 已提交
39
    SArray *pArray = taosArrayGetP(pObj->tasks, i);
L
Liu Jicong 已提交
40 41 42
    int32_t innerSz = taosArrayGetSize(pArray);
    if (tEncodeI32(pEncoder, innerSz) < 0) return -1;
    for (int32_t j = 0; j < innerSz; j++) {
L
Liu Jicong 已提交
43
      SStreamTask *pTask = taosArrayGetP(pArray, j);
L
Liu Jicong 已提交
44
      if (tEncodeSStreamTask(pEncoder, pTask) < 0) return -1;
L
Liu Jicong 已提交
45 46
    }
  }
L
Liu Jicong 已提交
47

L
Liu Jicong 已提交
48 49 50
  if (tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema) < 0) return -1;

#if 0
L
Liu Jicong 已提交
51 52
  if (pObj->ColAlias != NULL) {
    outputNameSz = taosArrayGetSize(pObj->ColAlias);
L
Liu Jicong 已提交
53 54 55
  }
  if (tEncodeI32(pEncoder, outputNameSz) < 0) return -1;
  for (int32_t i = 0; i < outputNameSz; i++) {
L
Liu Jicong 已提交
56
    char *name = taosArrayGetP(pObj->ColAlias, i);
L
Liu Jicong 已提交
57 58
    if (tEncodeCStr(pEncoder, name) < 0) return -1;
  }
L
Liu Jicong 已提交
59
#endif
L
Liu Jicong 已提交
60 61 62 63 64 65 66 67 68 69 70 71
  return pEncoder->pos;
}

int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
  if (tDecodeCStrTo(pDecoder, pObj->name) < 0) return -1;
  if (tDecodeCStrTo(pDecoder, pObj->db) < 0) return -1;
  if (tDecodeI64(pDecoder, &pObj->createTime) < 0) return -1;
  if (tDecodeI64(pDecoder, &pObj->updateTime) < 0) return -1;
  if (tDecodeI64(pDecoder, &pObj->uid) < 0) return -1;
  if (tDecodeI64(pDecoder, &pObj->dbUid) < 0) return -1;
  if (tDecodeI32(pDecoder, &pObj->version) < 0) return -1;
  if (tDecodeI8(pDecoder, &pObj->status) < 0) return -1;
L
Liu Jicong 已提交
72 73 74
  if (tDecodeCStrAlloc(pDecoder, &pObj->sql) < 0) return -1;
  if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;
  if (tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan) < 0) return -1;
L
Liu Jicong 已提交
75
  pObj->tasks = NULL;
L
Liu Jicong 已提交
76 77 78
  int32_t sz;
  if (tDecodeI32(pDecoder, &sz) < 0) return -1;
  if (sz != 0) {
L
Liu Jicong 已提交
79
    pObj->tasks = taosArrayInit(sz, sizeof(void *));
L
Liu Jicong 已提交
80 81 82
    for (int32_t i = 0; i < sz; i++) {
      int32_t innerSz;
      if (tDecodeI32(pDecoder, &innerSz) < 0) return -1;
L
Liu Jicong 已提交
83
      SArray *pArray = taosArrayInit(innerSz, sizeof(void *));
L
Liu Jicong 已提交
84
      for (int32_t j = 0; j < innerSz; j++) {
L
Liu Jicong 已提交
85 86 87 88
        SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask));
        if (pTask == NULL) return -1;
        if (tDecodeSStreamTask(pDecoder, pTask) < 0) return -1;
        taosArrayPush(pArray, &pTask);
L
Liu Jicong 已提交
89
      }
L
Liu Jicong 已提交
90
      taosArrayPush(pObj->tasks, &pArray);
L
Liu Jicong 已提交
91 92
    }
  }
L
Liu Jicong 已提交
93 94 95

  if (tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema) < 0) return -1;
#if 0
L
Liu Jicong 已提交
96 97
  int32_t outputNameSz;
  if (tDecodeI32(pDecoder, &outputNameSz) < 0) return -1;
L
Liu Jicong 已提交
98 99 100 101 102
  if (outputNameSz != 0) {
    pObj->ColAlias = taosArrayInit(outputNameSz, sizeof(void *));
    if (pObj->ColAlias == NULL) {
      return -1;
    }
L
Liu Jicong 已提交
103 104 105 106
  }
  for (int32_t i = 0; i < outputNameSz; i++) {
    char *name;
    if (tDecodeCStrAlloc(pDecoder, &name) < 0) return -1;
L
Liu Jicong 已提交
107
    taosArrayPush(pObj->ColAlias, &name);
L
Liu Jicong 已提交
108
  }
L
Liu Jicong 已提交
109
#endif
L
Liu Jicong 已提交
110 111
  return 0;
}