diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index a6b04624d7..d18142cebf 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -305,6 +305,8 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { } else { CHECK_CODE_GOTO(getPlan(pRequest, pQuery, &pDag), _return); CHECK_CODE_GOTO(scheduleQuery(pRequest, pDag, &pJob), _return); + pRequest->code = terrno; + return pRequest; } _return: diff --git a/source/libs/planner/src/physicalPlanJson.c b/source/libs/planner/src/physicalPlanJson.c index 20da1842cf..d67ff956b9 100644 --- a/source/libs/planner/src/physicalPlanJson.c +++ b/source/libs/planner/src/physicalPlanJson.c @@ -62,7 +62,7 @@ static bool fromObjectWithAlloc(const cJSON* json, const char* name, FFromJson f return func(jObj, *obj); } -static bool addArray(cJSON* json, const char* name, FToJson func, const SArray* array) { +static bool addTarray(cJSON* json, const char* name, FToJson func, const SArray* array, bool isPoint) { size_t size = (NULL == array) ? 0 : taosArrayGetSize(array); if (size > 0) { cJSON* jArray = cJSON_AddArrayToObject(json, name); @@ -70,7 +70,7 @@ static bool addArray(cJSON* json, const char* name, FToJson func, const SArray* return false; } for (size_t i = 0; i < size; ++i) { - if (!addItem(jArray, func, taosArrayGetP(array, i))) { + if (!addItem(jArray, func, isPoint ? taosArrayGetP(array, i) : taosArrayGet(array, i))) { return false; } } @@ -78,11 +78,19 @@ static bool addArray(cJSON* json, const char* name, FToJson func, const SArray* return true; } -static bool fromArray(const cJSON* json, const char* name, FFromJson func, SArray** array, int32_t itemSize) { +static bool addInlineArray(cJSON* json, const char* name, FToJson func, const SArray* array) { + return addTarray(json, name, func, array, false); +} + +static bool addArray(cJSON* json, const char* name, FToJson func, const SArray* array) { + return addTarray(json, name, func, array, true); +} + +static bool fromTarray(const cJSON* json, const char* name, FFromJson func, SArray** array, int32_t itemSize, bool isPoint) { const cJSON* jArray = cJSON_GetObjectItem(json, name); int32_t size = (NULL == jArray ? 0 : cJSON_GetArraySize(jArray)); if (size > 0) { - *array = taosArrayInit(size, POINTER_BYTES); + *array = taosArrayInit(size, isPoint ? POINTER_BYTES : itemSize); if (NULL == *array) { return false; } @@ -92,11 +100,19 @@ static bool fromArray(const cJSON* json, const char* name, FFromJson func, SArra if (NULL == item || !func(cJSON_GetArrayItem(jArray, i), item)) { return false; } - taosArrayPush(*array, &item); + taosArrayPush(*array, isPoint ? &item : item); } return true; } +static bool fromInlineArray(const cJSON* json, const char* name, FFromJson func, SArray** array, int32_t itemSize) { + return fromTarray(json, name, func, array, itemSize, false); +} + +static bool fromArray(const cJSON* json, const char* name, FFromJson func, SArray** array, int32_t itemSize) { + return fromTarray(json, name, func, array, itemSize, true); +} + static bool addRawArray(cJSON* json, const char* name, FToJson func, const void* array, int32_t itemSize, int32_t size) { if (size > 0) { cJSON* jArray = cJSON_AddArrayToObject(json, name); @@ -556,6 +572,32 @@ static bool epAddrFromJson(const cJSON* json, void* obj) { return true; } +static const char* jkNodeAddrId = "NodeId"; +static const char* jkNodeAddrInUse = "InUse"; +static const char* jkNodeAddrEpAddrs = "EpAddrs"; + +static bool nodeAddrToJson(const void* obj, cJSON* json) { + const SQueryNodeAddr* ep = (const SQueryNodeAddr*)obj; + bool res = cJSON_AddNumberToObject(json, jkNodeAddrId, ep->nodeId); + if (res) { + res = cJSON_AddNumberToObject(json, jkNodeAddrInUse, ep->inUse); + } + if (res) { + res = addRawArray(json, jkNodeAddrEpAddrs, epAddrToJson, ep->epAddr, ep->numOfEps, sizeof(SEpAddrMsg)); + } + return res; +} + +static bool nodeAddrFromJson(const cJSON* json, void* obj) { + SQueryNodeAddr* ep = (SQueryNodeAddr*)obj; + ep->nodeId = getNumber(json, jkNodeAddrId); + ep->inUse = getNumber(json, jkNodeAddrInUse); + int32_t numOfEps = 0; + bool res = fromRawArray(json, jkNodeAddrEpAddrs, nodeAddrFromJson, &ep->epAddr, sizeof(SEpAddrMsg), &numOfEps); + ep->numOfEps = numOfEps; + return res; +} + static const char* jkExchangeNodeSrcTemplateId = "SrcTemplateId"; static const char* jkExchangeNodeSrcEndPoints = "SrcEndPoints"; @@ -563,7 +605,7 @@ static bool exchangeNodeToJson(const void* obj, cJSON* json) { const SExchangePhyNode* exchange = (const SExchangePhyNode*)obj; bool res = cJSON_AddNumberToObject(json, jkExchangeNodeSrcTemplateId, exchange->srcTemplateId); if (res) { - res = addArray(json, jkExchangeNodeSrcEndPoints, epAddrToJson, exchange->pSrcEndPoints); + res = addInlineArray(json, jkExchangeNodeSrcEndPoints, nodeAddrToJson, exchange->pSrcEndPoints); } return res; } @@ -571,7 +613,7 @@ static bool exchangeNodeToJson(const void* obj, cJSON* json) { static bool exchangeNodeFromJson(const cJSON* json, void* obj) { SExchangePhyNode* exchange = (SExchangePhyNode*)obj; exchange->srcTemplateId = getNumber(json, jkExchangeNodeSrcTemplateId); - return fromArray(json, jkExchangeNodeSrcEndPoints, epAddrFromJson, &exchange->pSrcEndPoints, sizeof(SEpAddrMsg)); + return fromInlineArray(json, jkExchangeNodeSrcEndPoints, nodeAddrFromJson, &exchange->pSrcEndPoints, sizeof(SQueryNodeAddr)); } static bool specificPhyNodeToJson(const void* obj, cJSON* json) { @@ -803,7 +845,6 @@ static cJSON* subplanToJson(const SSubplan* subplan) { if (res) { res = addObject(jSubplan, jkSubplanDataSink, dataSinkToJson, subplan->pDataSink); } - if (!res) { cJSON_Delete(jSubplan); return NULL;