TDengine/source/dnode/mnode/impl/src/mndDef.c

118 lines
4.5 KiB
C
Raw Normal View History

2022-03-10 09:15:45 +00:00
/*
* 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) {
2022-03-24 08:18:08 +00:00
int32_t sz = 0;
2022-03-26 08:48:14 +00:00
/*int32_t outputNameSz = 0;*/
2022-03-10 09:15:45 +00:00
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;
2022-03-29 02:40:13 +00:00
if (tEncodeI8(pEncoder, pObj->createdBy) < 0) return -1;
if (tEncodeI32(pEncoder, pObj->fixedSinkVgId) < 0) return -1;
if (tEncodeI64(pEncoder, pObj->smaId) < 0) return -1;
2022-03-10 09:15:45 +00:00
if (tEncodeCStr(pEncoder, pObj->sql) < 0) return -1;
2022-03-29 02:40:13 +00:00
/*if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1;*/
2022-03-10 09:15:45 +00:00
if (tEncodeCStr(pEncoder, pObj->physicalPlan) < 0) return -1;
2022-03-17 09:48:21 +00:00
// TODO encode tasks
if (pObj->tasks) {
2022-03-24 08:18:08 +00:00
sz = taosArrayGetSize(pObj->tasks);
}
if (tEncodeI32(pEncoder, sz) < 0) return -1;
for (int32_t i = 0; i < sz; i++) {
2022-03-28 06:16:58 +00:00
SArray *pArray = taosArrayGetP(pObj->tasks, i);
2022-03-24 08:18:08 +00:00
int32_t innerSz = taosArrayGetSize(pArray);
if (tEncodeI32(pEncoder, innerSz) < 0) return -1;
for (int32_t j = 0; j < innerSz; j++) {
2022-03-28 06:16:58 +00:00
SStreamTask *pTask = taosArrayGetP(pArray, j);
2022-03-24 08:18:08 +00:00
if (tEncodeSStreamTask(pEncoder, pTask) < 0) return -1;
2022-03-17 09:48:21 +00:00
}
}
2022-03-23 11:58:32 +00:00
2022-03-26 08:48:14 +00:00
if (tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema) < 0) return -1;
#if 0
2022-03-24 03:34:43 +00:00
if (pObj->ColAlias != NULL) {
outputNameSz = taosArrayGetSize(pObj->ColAlias);
2022-03-23 11:58:32 +00:00
}
if (tEncodeI32(pEncoder, outputNameSz) < 0) return -1;
for (int32_t i = 0; i < outputNameSz; i++) {
2022-03-24 03:34:43 +00:00
char *name = taosArrayGetP(pObj->ColAlias, i);
2022-03-23 11:58:32 +00:00
if (tEncodeCStr(pEncoder, name) < 0) return -1;
}
2022-03-26 08:48:14 +00:00
#endif
2022-03-10 09:15:45 +00:00
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;
2022-03-29 02:40:13 +00:00
if (tDecodeI8(pDecoder, &pObj->createdBy) < 0) return -1;
if (tDecodeI32(pDecoder, &pObj->fixedSinkVgId) < 0) return -1;
if (tDecodeI64(pDecoder, &pObj->smaId) < 0) return -1;
2022-03-16 11:40:48 +00:00
if (tDecodeCStrAlloc(pDecoder, &pObj->sql) < 0) return -1;
2022-03-29 02:40:13 +00:00
/*if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;*/
2022-03-16 11:40:48 +00:00
if (tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan) < 0) return -1;
2022-03-24 08:18:08 +00:00
pObj->tasks = NULL;
2022-03-17 09:48:21 +00:00
int32_t sz;
if (tDecodeI32(pDecoder, &sz) < 0) return -1;
if (sz != 0) {
2022-03-28 06:16:58 +00:00
pObj->tasks = taosArrayInit(sz, sizeof(void *));
2022-03-17 09:48:21 +00:00
for (int32_t i = 0; i < sz; i++) {
int32_t innerSz;
if (tDecodeI32(pDecoder, &innerSz) < 0) return -1;
2022-03-28 06:16:58 +00:00
SArray *pArray = taosArrayInit(innerSz, sizeof(void *));
2022-03-17 09:48:21 +00:00
for (int32_t j = 0; j < innerSz; j++) {
2022-03-28 06:16:58 +00:00
SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask));
if (pTask == NULL) return -1;
if (tDecodeSStreamTask(pDecoder, pTask) < 0) return -1;
taosArrayPush(pArray, &pTask);
2022-03-17 09:48:21 +00:00
}
2022-03-28 06:16:58 +00:00
taosArrayPush(pObj->tasks, &pArray);
2022-03-17 09:48:21 +00:00
}
}
2022-03-26 08:48:14 +00:00
if (tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema) < 0) return -1;
#if 0
2022-03-23 11:58:32 +00:00
int32_t outputNameSz;
if (tDecodeI32(pDecoder, &outputNameSz) < 0) return -1;
2022-03-24 08:18:08 +00:00
if (outputNameSz != 0) {
pObj->ColAlias = taosArrayInit(outputNameSz, sizeof(void *));
if (pObj->ColAlias == NULL) {
return -1;
}
2022-03-23 11:58:32 +00:00
}
for (int32_t i = 0; i < outputNameSz; i++) {
char *name;
if (tDecodeCStrAlloc(pDecoder, &name) < 0) return -1;
2022-03-24 03:34:43 +00:00
taosArrayPush(pObj->ColAlias, &name);
2022-03-23 11:58:32 +00:00
}
2022-03-26 08:48:14 +00:00
#endif
2022-03-10 09:15:45 +00:00
return 0;
}