add dag serialize and deserialize
This commit is contained in:
parent
073f6b5e39
commit
a53d1d95fb
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "tmsg.h"
|
||||
#include "tarray.h"
|
||||
|
||||
#define QUERY_TYPE_MERGE 1
|
||||
#define QUERY_TYPE_PARTIAL 2
|
||||
|
@ -158,6 +159,8 @@ int32_t qStringToSubplan(const char* str, SSubplan** subplan);
|
|||
|
||||
void qDestroySubplan(SSubplan* pSubplan);
|
||||
|
||||
char* qDagSerialize(const SQueryDag* pDag);
|
||||
|
||||
/**
|
||||
* Destroy the physical plan.
|
||||
* @param pQueryPhyNode
|
||||
|
@ -165,8 +168,11 @@ void qDestroySubplan(SSubplan* pSubplan);
|
|||
*/
|
||||
void qDestroyQueryDag(SQueryDag* pDag);
|
||||
|
||||
char* qDagToString(const SQueryDag* pDag);
|
||||
SQueryDag* qStringToDag(const char* pStr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_PLANNER_H_*/
|
||||
#endif /*_TD_PLANNER_H_*/
|
||||
|
|
|
@ -857,3 +857,53 @@ int32_t stringToSubplan(const char* str, SSubplan** subplan) {
|
|||
*subplan = subplanFromJson(json);
|
||||
return (NULL == *subplan ? TSDB_CODE_FAILED : TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
cJSON* qDagToJson(const SQueryDag* pDag) {
|
||||
cJSON* pRoot = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(pRoot, "numOfSubplans", pDag->numOfSubplans);
|
||||
cJSON_AddNumberToObject(pRoot, "queryId", pDag->queryId);
|
||||
cJSON *pLevels = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(pRoot, "pSubplans", pLevels);
|
||||
size_t level = taosArrayGetSize(pDag->pSubplans);
|
||||
for(size_t i = 0; i < level; i++) {
|
||||
const SArray* pSubplans = (const SArray*)taosArrayGetP(pDag->pSubplans, i);
|
||||
size_t num = taosArrayGetSize(pSubplans);
|
||||
cJSON* plansOneLevel = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(pLevels, plansOneLevel);
|
||||
for(size_t j = 0; j < num; j++) {
|
||||
cJSON* pSubplan = subplanToJson((const SSubplan*)taosArrayGetP(pSubplans, j));
|
||||
cJSON_AddItemToArray(plansOneLevel, pSubplan);
|
||||
}
|
||||
}
|
||||
return pRoot;
|
||||
}
|
||||
|
||||
char* qDagToString(const SQueryDag* pDag) {
|
||||
cJSON* pRoot = qDagToJson(pDag);
|
||||
return cJSON_Print(pRoot);
|
||||
}
|
||||
|
||||
SQueryDag* qJsonToDag(const cJSON* pRoot) {
|
||||
SQueryDag* pDag = malloc(sizeof(SQueryDag));
|
||||
if(pDag == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pDag->numOfSubplans = cJSON_GetNumberValue(cJSON_GetObjectItem(pRoot, "numOfSubplans"));
|
||||
pDag->pSubplans = taosArrayInit(0, sizeof(SArray));
|
||||
cJSON* pLevels = cJSON_GetObjectItem(pRoot, "numOfSubplans");
|
||||
int level = cJSON_GetArraySize(pLevels);
|
||||
for(int i = 0; i < level; i++) {
|
||||
cJSON* pItem = cJSON_GetArrayItem(pLevels, i);
|
||||
int sz = cJSON_GetArraySize(pItem);
|
||||
for(int j = 0; j < sz; j++) {
|
||||
cJSON* pSubplanJson = cJSON_GetArrayItem(pItem, j);
|
||||
SSubplan* pSubplan = subplanFromJson(pSubplanJson);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SQueryDag* qStringToDag(const char* pStr) {
|
||||
cJSON* pRoot = cJSON_Parse(pStr);
|
||||
return qJsonToDag(pRoot);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue